Search in sources :

Example 1 with Attribute

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ArrayList(java.util.ArrayList)

Example 2 with Attribute

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);
        }
    });
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 3 with Attribute

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);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute)

Example 4 with Attribute

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);
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute)

Example 5 with Attribute

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;
}
Also used : SystemAttribute(org.molgenis.data.meta.system.SystemAttribute) Attribute(org.molgenis.data.meta.model.Attribute) SystemAttribute(org.molgenis.data.meta.system.SystemAttribute)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16