use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class EmxDataProvider method toRefEntities.
private List<Entity> toRefEntities(Attribute attr, Object emxValue) {
List<Entity> refEntities;
if (emxValue != null) {
if (emxValue instanceof Iterable<?>) {
List<Entity> mrefEntities = new ArrayList<>();
for (Object emxValueItem : (Iterable<?>) emxValue) {
Entity entityValue;
if (emxValueItem instanceof Entity) {
entityValue = toEntity(attr.getRefEntity(), (Entity) emxValueItem);
} else {
EntityType xrefEntity = attr.getRefEntity();
Object entityId = DataConverter.convert(emxValueItem, xrefEntity.getIdAttribute());
entityValue = entityManager.getReference(xrefEntity, entityId);
}
mrefEntities.add(entityValue);
}
refEntities = mrefEntities;
} else {
EntityType mrefEntity = attr.getRefEntity();
Attribute refIdAttr = mrefEntity.getIdAttribute();
String[] tokens = StringUtils.split(emxValue.toString(), ',');
List<Entity> mrefEntities = new ArrayList<>();
for (String token : tokens) {
Object entityId = DataConverter.convert(token.trim(), refIdAttr);
mrefEntities.add(entityManager.getReference(mrefEntity, entityId));
}
refEntities = mrefEntities;
}
} else {
refEntities = emptyList();
}
return refEntities;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class DataPersisterImpl method injectAttributeIdentifiers.
private void injectAttributeIdentifiers(EntityType entityType, EntityType existingEntityType) {
entityType.getOwnAllAttributes().forEach(ownAttr -> {
Attribute existingAttr = existingEntityType.getAttribute(ownAttr.getName());
if (existingAttr != null) {
ownAttr.setIdentifier(existingAttr.getIdentifier());
ownAttr.setEntity(existingEntityType);
}
});
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeRepositoryDecorator method updateBackend.
private void updateBackend(Attribute attr) {
Attribute currentAttr = findOneById(attr.getIdentifier());
updateAttributeInBackend(currentAttr, attr);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class EntityTypeRepositoryDecorator method addAndRemoveAttributesInBackend.
/**
* Add and remove entity attributes in the backend for an {@link EntityType}.
* If the {@link EntityType} is abstract, will update all concrete extending {@link EntityType}s.
* Attribute updates are handled by the {@link AttributeRepositoryDecorator}.
*
* @param entityType {@link EntityType} containing the desired situation.
*/
private void addAndRemoveAttributesInBackend(EntityType entityType) {
EntityType existingEntityType = delegate().findOneById(entityType.getId());
Map<String, Attribute> attrsMap = toAttributesMap(entityType);
Map<String, Attribute> existingAttrsMap = toAttributesMap(existingEntityType);
dataService.getMeta().getConcreteChildren(entityType).forEach(concreteEntityType -> {
RepositoryCollection backend = dataService.getMeta().getBackend(concreteEntityType);
EntityType concreteExistingEntityType = delegate().findOneById(concreteEntityType.getId());
addNewAttributesInBackend(attrsMap, existingAttrsMap, backend, concreteExistingEntityType);
deleteRemovedAttributesInBackend(attrsMap, existingAttrsMap, backend, concreteExistingEntityType);
});
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class SystemEntityType method addAttribute.
public Attribute addAttribute(String attrName, AttributeRole... attrTypes) {
Attribute attr = new SystemAttribute(attributeFactory.getAttributeMetadata());
attr.setIdentifier(idGenerator.generateId());
attr.setDefaultValues();
attr.setName(attrName);
addAttribute(attr, attrTypes);
return attr;
}
Aggregations