Hi all.
I need to associate and store in plugin settings List of customfields keys with lists of users
I've implemented entity class (there could be several exemplers of it to be saved)
@Getter
@Setter
public class FieldGroup extends Entity {
List<String> fieldKeys;
List<String> userKeys;
}
but found out that AO do not work in such way.
one solution is to define separate FieldKey and UserKey entities and FieldToUser class to define many to many relationsheeps among them. But it won't be able to represent several FieldGroups as distinct entities.
Is it some other way to store List (or arrays) of Strings in AO entity field?
Hi @Ignat
Unfortunately with the AO entity we have very basic persistency capabilities. I'd have separate entities linked to FieldGroup with many-to-one relation (child table for each linking with fieldGroupId).
The second option is to have fieldKeys and userKeys as String fields delimited by a character and convert them into Lists before using them.
By the way, you can write a Wrapper Entity class using @Implementation annotation.
Something like this:
@Implementation(MyEntityImpl.class)
public interface MyEntity {
public String getFieldKeys() ...
}
public class MyEntityImpl {
public List<String> getFieldKeyList() {
String strList = getFieldKeys();
return StringUtils.split(....)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank for usefull hint!
I've implemented transformation in method of my service class, whose purpose is to acquire settings groups List from AO
@Table("settings")
public interface FieldsGroupSettingsRaw extends Entity {
void setDescription(String description);
void setFieldsKeys(String fieldsKeys);
void setUsersKeys(String usersKeys);
String getDescription();
String getFieldsKeys();
String getUsersKeys();
}
@Getter
@Setter
@AllArgsConstructor
public class FieldsGroupSettings {
private int ID;
private String description;
private List<String> fieldsKeys;
private List<String> usersKeys;
}
public List<FieldsGroupSettings> all() {
log.info("retrying settings");
return Arrays.stream(activeObjects.find(FieldsGroupSettingsRaw.class))
.map(r -> new FieldsGroupSettings(r.getID(),
r.getDescription(),
Arrays.asList(r.getFieldsKeys()
.replace("[", "")
.replace("]", "")
.split(", ")),
Arrays.asList(r.getUsersKeys()
.replace("[", "")
.replace("]", "")
.split(", "))))
.collect(Collectors.toList());
}
But use implemening class as the adapter leads to more clear code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.