Search in sources :

Example 76 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class AttributeMappingRepositoryImpl method toAttributeMappingEntity.

private Entity toAttributeMappingEntity(AttributeMapping attributeMapping) {
    Entity attributeMappingEntity = new DynamicEntity(attributeMappingMetaData);
    attributeMappingEntity.set(IDENTIFIER, attributeMapping.getIdentifier());
    attributeMappingEntity.set(TARGET_ATTRIBUTE, attributeMapping.getTargetAttributeName());
    attributeMappingEntity.set(ALGORITHM, attributeMapping.getAlgorithm());
    attributeMappingEntity.set(SOURCE_ATTRIBUTES, attributeMapping.getSourceAttributes().stream().map(Attribute::getName).collect(Collectors.joining(",")));
    attributeMappingEntity.set(ALGORITHM_STATE, attributeMapping.getAlgorithmState().toString());
    return attributeMappingEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute)

Example 77 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class MappingProjectRepositoryImpl method toMappingProject.

/**
 * Creates a fully reconstructed MappingProject from an Entity retrieved from the repository.
 *
 * @param mappingProjectEntity Entity with {@link MappingProjectMetaData} metadata
 * @return fully reconstructed MappingProject
 */
private MappingProject toMappingProject(Entity mappingProjectEntity) {
    String identifier = mappingProjectEntity.getString(MappingProjectMetaData.IDENTIFIER);
    String name = mappingProjectEntity.getString(MappingProjectMetaData.NAME);
    User owner = mappingProjectEntity.getEntity(MappingProjectMetaData.OWNER, User.class);
    List<Entity> mappingTargetEntities = Lists.newArrayList(mappingProjectEntity.getEntities(MappingProjectMetaData.MAPPING_TARGETS));
    List<MappingTarget> mappingTargets = mappingTargetRepo.toMappingTargets(mappingTargetEntities);
    return new MappingProject(identifier, name, owner, mappingTargets);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) User(org.molgenis.data.security.auth.User) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget)

Example 78 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class MappingProjectRepositoryImpl method toEntity.

/**
 * Creates a new Entity for a MappingProject. Upserts the {@link MappingProject}'s {@link MappingTarget}s in the
 * {@link #mappingTargetRepo}.
 *
 * @param mappingProject the {@link MappingProject} used to create an Entity
 * @return Entity filled with the data from the MappingProject
 */
private Entity toEntity(MappingProject mappingProject) {
    Entity result = new DynamicEntity(mappingProjectMeta);
    if (mappingProject.getIdentifier() == null) {
        mappingProject.setIdentifier(idGenerator.generateId());
    }
    result.set(MappingProjectMetaData.IDENTIFIER, mappingProject.getIdentifier());
    result.set(MappingProjectMetaData.OWNER, mappingProject.getOwner());
    result.set(MappingProjectMetaData.NAME, mappingProject.getName());
    List<Entity> mappingTargetEntities = mappingTargetRepo.upsert(mappingProject.getMappingTargets());
    result.set(MappingProjectMetaData.MAPPING_TARGETS, mappingTargetEntities);
    return result;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 79 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EntityMappingRepositoryImpl method upsert.

private Entity upsert(EntityMapping entityMapping) {
    List<Entity> attributeMappingEntities = attributeMappingRepository.upsert(entityMapping.getAttributeMappings());
    Entity entityMappingEntity;
    if (entityMapping.getIdentifier() == null) {
        entityMapping.setIdentifier(idGenerator.generateId());
        entityMappingEntity = toEntityMappingEntity(entityMapping, attributeMappingEntities);
        dataService.add(entityMappingMetaData.getId(), entityMappingEntity);
    } else {
        entityMappingEntity = toEntityMappingEntity(entityMapping, attributeMappingEntities);
        dataService.update(entityMappingMetaData.getId(), entityMappingEntity);
    }
    return entityMappingEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity)

Example 80 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class MappingTargetRepositoryImpl method toMappingTarget.

/**
 * Creates a fully reconstructed MappingProject from an Entity retrieved from the repository.
 *
 * @param mappingTargetEntity Entity with {@link MappingProjectMetaData} metadata
 * @return fully reconstructed MappingProject
 */
private MappingTarget toMappingTarget(Entity mappingTargetEntity) {
    List<EntityMapping> entityMappings = Collections.emptyList();
    String identifier = mappingTargetEntity.getString(MappingTargetMetaData.IDENTIFIER);
    if (!dataService.hasRepository(mappingTargetEntity.getString(MappingTargetMetaData.TARGET))) {
        return null;
    }
    EntityType target = dataService.getEntityType(mappingTargetEntity.getString(MappingTargetMetaData.TARGET));
    if (mappingTargetEntity.getEntities(MappingTargetMetaData.ENTITY_MAPPINGS) != null) {
        List<Entity> entityMappingEntities = Lists.newArrayList(mappingTargetEntity.getEntities(MappingTargetMetaData.ENTITY_MAPPINGS));
        entityMappings = entityMappingRepository.toEntityMappings(entityMappingEntities);
    }
    return new MappingTarget(identifier, target, entityMappings);
}
Also used : EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13