Search in sources :

Example 6 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class IndexDependencyModel method getReferencingEntities.

private Set<String> getReferencingEntities(String entityTypeId) {
    ImmutableSet.Builder<String> result = ImmutableSet.builder();
    EntityType entityType = entityTypes.get(entityTypeId);
    if (entityType == null) {
        return emptySet();
    }
    for (Map.Entry<String, EntityType> candidate : entityTypes.entrySet()) {
        EntityType candidateEntityType = candidate.getValue();
        if (hasAttributeThatReferences(candidateEntityType, entityTypeId)) {
            if (candidateEntityType.isAbstract()) {
                result.addAll(getDescendants(candidate.getKey()));
            } else {
                result.add(candidate.getKey());
            }
        }
    }
    return result.build();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) ImmutableSet(com.google.common.collect.ImmutableSet) Map(java.util.Map)

Example 7 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class IndexBootstrapper method registerIndexAction.

private void registerIndexAction(IndexAction action) {
    String entityTypeId = action.getEntityTypeId();
    EntityType entityType = dataService.findOneById(ENTITY_TYPE_META_DATA, entityTypeId, EntityType.class);
    if (entityType != null) {
        Object typedEntityId = getTypedValue(action.getEntityId(), entityType.getIdAttribute());
        indexActionRegisterService.register(entityType, typedEntityId);
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType)

Example 8 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class DataPersisterImpl method persistSecondPass.

private void persistSecondPass(DataProvider dataProvider, List<EntityType> topologicalSortedEntityTypes) {
    topologicalSortedEntityTypes.forEach(entityType -> {
        EntityType persistedEntityType = persistEntityTypeSecondPass(entityType);
        if (dataProvider.hasEntities(entityType)) {
            Stream<Entity> entities = dataProvider.getEntities(entityType);
            persistEntitiesSecondPass(persistedEntityType, entities);
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity)

Example 9 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class ImportWriter method groupEntityTypes.

private GroupedEntityTypes groupEntityTypes(ImmutableCollection<EntityType> entities) {
    return runAsSystem(() -> {
        Map<String, EntityType> existingEntityTypeMap = new HashMap<>();
        for (EntityType entityType : entities) {
            EntityType existing = metaDataService.getEntityTypeById(entityType.getId());
            if (existing != null) {
                existingEntityTypeMap.put(entityType.getId(), entityType);
            }
        }
        ImmutableCollection<EntityType> newEntityTypes = entities.stream().filter(entityType -> !existingEntityTypeMap.containsKey(entityType.getId())).collect(collectingAndThen(toList(), ImmutableList::copyOf));
        ImmutableCollection<EntityType> existingEntityTypes = entities.stream().filter(entityType -> existingEntityTypeMap.containsKey(entityType.getId())).collect(collectingAndThen(toList(), ImmutableList::copyOf));
        return new GroupedEntityTypes(newEntityTypes, existingEntityTypes);
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) ConstraintViolation(org.molgenis.data.validation.ConstraintViolation) ImmutableCollection(com.google.common.collect.ImmutableCollection) HashMap(java.util.HashMap) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) PermissionSystemService(org.molgenis.data.security.permission.PermissionSystemService) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) MetaDataService(org.molgenis.data.meta.MetaDataService) DataMode(org.molgenis.data.importer.DataPersister.DataMode) DatabaseAction(org.molgenis.data.DatabaseAction) Tag(org.molgenis.data.meta.model.Tag) ImmutableList(com.google.common.collect.ImmutableList) PersistResult(org.molgenis.data.importer.PersistResult) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) UPSERT(org.molgenis.data.importer.DataPersister.MetadataMode.UPSERT) RepositoryCollection(org.molgenis.data.RepositoryCollection) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) DataPersister(org.molgenis.data.importer.DataPersister) EntityImportReport(org.molgenis.data.importer.EntityImportReport) ParsedMetaData(org.molgenis.data.importer.ParsedMetaData) EntityType(org.molgenis.data.meta.model.EntityType) String.format(java.lang.String.format) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) Package(org.molgenis.data.meta.model.Package) EntityManager(org.molgenis.data.EntityManager) Transactional(org.springframework.transaction.annotation.Transactional) HashMap(java.util.HashMap)

Example 10 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class FileMetaRepositoryDecoratorTest method setUpBeforeMethod.

@BeforeMethod
public void setUpBeforeMethod() {
    EntityType entityType = when(mock(EntityType.class).getLabel()).thenReturn("file metadata").getMock();
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    when(fileStore.delete(anyString())).thenReturn(true);
    fileMetaRepositoryDecorator = new FileMetaRepositoryDecorator(delegateRepository, fileStore);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15