Search in sources :

Example 1 with Package

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

the class EmxMetaDataParser method buildValidationReport.

private EntitiesValidationReport buildValidationReport(RepositoryCollection source, MyEntitiesValidationReport report, Map<String, EntityType> metaDataMap) {
    metaDataMap.values().forEach(entityTypeValidator::validate);
    metaDataMap.values().stream().map(EntityType::getAllAttributes).forEach(attributes -> attributes.forEach(attr -> {
        attributeValidator.validate(attr, ValidationMode.ADD_SKIP_ENTITY_VALIDATION);
    }));
    // validate package/entity/attribute tags
    metaDataMap.values().stream().map(EntityType::getPackage).filter(Objects::nonNull).forEach(package_ -> package_.getTags().forEach(tagValidator::validate));
    metaDataMap.values().forEach(entityType -> entityType.getTags().forEach(tagValidator::validate));
    metaDataMap.values().stream().map(EntityType::getAllAttributes).forEach(attributes -> attributes.forEach(attr -> {
        attr.getTags().forEach(tagValidator::validate);
    }));
    report = generateEntityValidationReport(source, report, metaDataMap);
    // Add entities without data
    for (String entityTypeId : metaDataMap.keySet()) {
        if (!report.getSheetsImportable().containsKey(entityTypeId))
            report.addEntity(entityTypeId, true);
    }
    return report;
}
Also used : EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) DefaultPackage(org.molgenis.data.meta.DefaultPackage) Language(org.molgenis.data.i18n.model.Language) StringUtils(org.apache.commons.lang3.StringUtils) L10N_STRING(org.molgenis.data.i18n.model.L10nStringMetaData.L10N_STRING) SystemEntityType(org.molgenis.data.meta.SystemEntityType) PACKAGE_SEPARATOR(org.molgenis.data.meta.model.Package.PACKAGE_SEPARATOR) EntityTypeValidator(org.molgenis.data.validation.meta.EntityTypeValidator) L10nString(org.molgenis.data.i18n.model.L10nString) AttributeState(org.molgenis.data.importer.MyEntitiesValidationReport.AttributeState) LanguageService(org.molgenis.i18n.LanguageService) MetaDataParser(org.molgenis.data.importer.MetaDataParser) ValidationMode(org.molgenis.data.validation.meta.AttributeValidator.ValidationMode) org.molgenis.data(org.molgenis.data) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collections.emptyList(java.util.Collections.emptyList) EntityTypeUtils(org.molgenis.data.support.EntityTypeUtils) ParsedMetaData(org.molgenis.data.importer.ParsedMetaData) TagValidator(org.molgenis.data.validation.meta.TagValidator) String.format(java.lang.String.format) EntityTypeUtils.isStringType(org.molgenis.data.support.EntityTypeUtils.isStringType) FILE_META(org.molgenis.data.file.model.FileMetaMetaData.FILE_META) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) AttributeUtils.isIdAttributeTypeAllowed(org.molgenis.data.support.AttributeUtils.isIdAttributeTypeAllowed) EntityTypeUtils.isReferenceType(org.molgenis.data.support.EntityTypeUtils.isReferenceType) LANGUAGE(org.molgenis.data.i18n.model.LanguageMetadata.LANGUAGE) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) TRUE(java.lang.Boolean.TRUE) EntityTypeDependencyResolver(org.molgenis.data.meta.EntityTypeDependencyResolver) I18nUtils.getLanguageCode(org.molgenis.data.i18n.I18nUtils.getLanguageCode) EntityUtils(org.molgenis.data.util.EntityUtils) Iterables(com.google.common.collect.Iterables) java.util(java.util) I18nUtils.isI18n(org.molgenis.data.i18n.I18nUtils.isI18n) MyEntitiesValidationReport(org.molgenis.data.importer.MyEntitiesValidationReport) DataConverter.toList(org.molgenis.data.DataConverter.toList) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) Objects.requireNonNull(java.util.Objects.requireNonNull) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) FALSE(java.lang.Boolean.FALSE) AttributeType(org.molgenis.data.meta.AttributeType) L10nStringFactory(org.molgenis.data.i18n.model.L10nStringFactory) LanguageFactory(org.molgenis.data.i18n.model.LanguageFactory) org.molgenis.data.meta.model(org.molgenis.data.meta.model) ImmutableMap.builder(com.google.common.collect.ImmutableMap.builder) Package(org.molgenis.data.meta.model.Package) AttributeValidator(org.molgenis.data.validation.meta.AttributeValidator) TAG(org.molgenis.data.meta.model.TagMetadata.TAG) SystemEntityType(org.molgenis.data.meta.SystemEntityType) L10nString(org.molgenis.data.i18n.model.L10nString)

Example 2 with Package

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

the class EmxMetaDataParser method parsePackagesSheet.

/**
 * Parses the packages sheet
 *
 * @param repo                {@link Repository} for the packages
 * @param intermediateResults {@link IntermediateParseResults} containing the parsed tag entities
 */
private void parsePackagesSheet(Repository<Entity> repo, IntermediateParseResults intermediateResults) {
    if (repo == null)
        return;
    // Collect packages
    int rowIndex = 1;
    for (Entity packageEntity : resolvePackages(repo)) {
        rowIndex++;
        // Package name is required
        String name = packageEntity.getString(EMX_PACKAGE_NAME);
        if (name == null)
            throw new IllegalArgumentException("package.name is missing on line " + rowIndex);
        Package package_ = packageFactory.create(name);
        package_.setDescription(packageEntity.getString(EMX_PACKAGE_DESCRIPTION));
        String label = packageEntity.getString(EMX_PACKAGE_LABEL);
        if (label == null) {
            label = name;
        }
        package_.setLabel(label);
        // Set parent package
        String parentName = packageEntity.getString(EMX_PACKAGE_PARENT);
        if (parentName != null) {
            if (!name.toLowerCase().startsWith(parentName.toLowerCase()))
                throw new MolgenisDataException("Inconsistent package structure. Package: '" + name + "', parent: '" + parentName + '\'');
            package_.setParent(intermediateResults.getPackage(parentName));
        }
        // Set package tags
        List<String> tagIdentifiers = toList(packageEntity.getString(EMX_PACKAGE_TAGS));
        if (tagIdentifiers != null && !tagIdentifiers.isEmpty()) {
            List<Tag> tags = toTags(intermediateResults, tagIdentifiers);
            package_.setTags(tags);
        }
        // Add the complete package to the parse results
        intermediateResults.addPackage(name, package_);
    }
}
Also used : L10nString(org.molgenis.data.i18n.model.L10nString) DefaultPackage(org.molgenis.data.meta.DefaultPackage) Package(org.molgenis.data.meta.model.Package)

Example 3 with Package

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

the class IntermediateParseResults method addEntityType.

public EntityType addEntityType(String fullyQualifiedName) {
    String entityTypeLabel = fullyQualifiedName;
    Package pack = null;
    for (Package p : packages.values()) {
        String packageName = p.getId();
        if (fullyQualifiedName.toLowerCase().startsWith(packageName.toLowerCase())) {
            // package_entity
            entityTypeLabel = fullyQualifiedName.substring(packageName.length() + 1);
            pack = p;
        }
    }
    String entityTypeId;
    if (pack == null) {
        pack = this.defaultPackage;
        entityTypeId = DefaultPackage.PACKAGE_DEFAULT + Package.PACKAGE_SEPARATOR + fullyQualifiedName;
    } else {
        entityTypeId = fullyQualifiedName;
    }
    EntityType emd = entityTypeFactory.create(entityTypeId).setLabel(entityTypeLabel).setPackage(pack);
    entities.put(fullyQualifiedName, emd);
    return emd;
}
Also used : L10nString(org.molgenis.data.i18n.model.L10nString) DefaultPackage(org.molgenis.data.meta.DefaultPackage) Package(org.molgenis.data.meta.model.Package)

Example 4 with Package

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

the class EntityTypeUtilsTest method isSystemEntityNotASystemIfNotInSystemPackage.

@Test
public void isSystemEntityNotASystemIfNotInSystemPackage() {
    EntityType entity = mock(EntityType.class);
    Package entityPackage = mock(Package.class);
    when(entity.getPackage()).thenReturn(entityPackage);
    when(entityPackage.getId()).thenReturn("not-system");
    when(entity.getId()).thenReturn("foo_bar_Entity");
    assertFalse(EntityTypeUtils.isSystemEntity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 5 with Package

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

the class EntityTypeUtilsTest method buildFullNamePackage.

@Test
public void buildFullNamePackage() {
    Package package_ = when(mock(Package.class).getId()).thenReturn("my_first_package").getMock();
    assertEquals(EntityTypeUtils.buildFullName(package_, "simpleName"), "my_first_package_simpleName");
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Aggregations

Package (org.molgenis.data.meta.model.Package)98 Test (org.testng.annotations.Test)70 EntityType (org.molgenis.data.meta.model.EntityType)22 Stream (java.util.stream.Stream)20 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Attribute (org.molgenis.data.meta.model.Attribute)11 DefaultPackage (org.molgenis.data.meta.DefaultPackage)10 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 Objects.requireNonNull (java.util.Objects.requireNonNull)6 L10nString (org.molgenis.data.i18n.model.L10nString)6 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 Collectors.toList (java.util.stream.Collectors.toList)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)5 DataService (org.molgenis.data.DataService)5 QueryImpl (org.molgenis.data.support.QueryImpl)5 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 java.util (java.util)3 Collections.singletonList (java.util.Collections.singletonList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3