Search in sources :

Example 1 with ENTITY_TYPE_META_DATA

use of org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA in project molgenis by molgenis.

the class SystemEntityTypePersister method injectExistingEntityTypeAttributeIdentifiers.

/**
 * Inject existing attribute identifiers in system entity types
 *
 * @param entityTypes system entity types
 */
private void injectExistingEntityTypeAttributeIdentifiers(List<EntityType> entityTypes) {
    Map<String, EntityType> existingEntityTypeMap = dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class).collect(toMap(EntityType::getId, entityType -> entityType));
    entityTypes.forEach(entityType -> {
        EntityType existingEntityType = existingEntityTypeMap.get(entityType.getId());
        if (existingEntityType != null) {
            entityType.setId(existingEntityType.getId());
            Map<String, Attribute> existingAttrs = stream(existingEntityType.getOwnAllAttributes().spliterator(), false).collect(toMap(Attribute::getName, Function.identity()));
            entityType.getOwnAllAttributes().forEach(attr -> {
                Attribute existingAttr = existingAttrs.get(attr.getName());
                if (existingAttr != null) {
                    // inject existing attribute identifier
                    attr.setIdentifier(existingAttr.getIdentifier());
                }
            });
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemEntityType(org.molgenis.data.meta.SystemEntityType) EntityUtils(org.molgenis.data.util.EntityUtils) RepositoryCollection(org.molgenis.data.RepositoryCollection) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) Function(java.util.function.Function) MetaDataService(org.molgenis.data.meta.MetaDataService) MutableAclClassService(org.molgenis.security.acl.MutableAclClassService) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) EntityIdentityUtils(org.molgenis.data.security.EntityIdentityUtils) EntityTypeDependencyResolver(org.molgenis.data.meta.EntityTypeDependencyResolver) Attribute(org.molgenis.data.meta.model.Attribute)

Example 2 with ENTITY_TYPE_META_DATA

use of org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA in project molgenis by molgenis.

the class UntypedTagService method findAttributeEntity.

private Entity findAttributeEntity(EntityType entityType, String attributeName) {
    Entity entityTypeEntity = dataService.findOneById(ENTITY_TYPE_META_DATA, entityType.getId());
    Optional<Entity> result = stream(entityTypeEntity.getEntities(ATTRIBUTES).spliterator(), false).filter(att -> attributeName.equals(att.getString(AttributeMetadata.NAME))).findFirst();
    return result.orElse(null);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) SemanticTag(org.molgenis.data.semantic.SemanticTag) LoggerFactory(org.slf4j.LoggerFactory) TagRepository(org.molgenis.semanticsearch.repository.TagRepository) QueryImpl(org.molgenis.data.support.QueryImpl) Multimap(com.google.common.collect.Multimap) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) ArrayList(java.util.ArrayList) Relation(org.molgenis.data.semantic.Relation) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) LabeledResource(org.molgenis.data.semantic.LabeledResource) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) Logger(org.slf4j.Logger) TagService(org.molgenis.semanticsearch.service.TagService) List(java.util.List) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) ATTRIBUTES(org.molgenis.data.meta.model.EntityTypeMetadata.ATTRIBUTES) StreamSupport.stream(java.util.stream.StreamSupport.stream) org.molgenis.data.meta.model(org.molgenis.data.meta.model) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) Optional(java.util.Optional) UnknownEntityException(org.molgenis.data.UnknownEntityException) Entity(org.molgenis.data.Entity) Entity(org.molgenis.data.Entity)

Aggregations

List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 StreamSupport.stream (java.util.stream.StreamSupport.stream)2 DataService (org.molgenis.data.DataService)2 ENTITY_TYPE_META_DATA (org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA)2 Package (org.molgenis.data.meta.model.Package)2 PACKAGE (org.molgenis.data.meta.model.PackageMetadata.PACKAGE)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1 Entity (org.molgenis.data.Entity)1 RepositoryCollection (org.molgenis.data.RepositoryCollection)1