Search in sources :

Example 1 with UnknownPackageException

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

the class EmxMetadataParser method putEntitiesInDefaultPackage.

/**
 * Put the entities that are not in a package in the selected package
 */
List<EntityType> putEntitiesInDefaultPackage(IntermediateParseResults intermediateResults, String defaultPackageId) {
    Package p = getPackage(intermediateResults, defaultPackageId);
    if (p == null) {
        throw new UnknownPackageException(defaultPackageId);
    }
    List<EntityType> entities = newArrayList();
    for (EntityType entityType : intermediateResults.getEntityTypes()) {
        if (entityType.getPackage() == null) {
            entityType.setId(defaultPackageId + PACKAGE_SEPARATOR + entityType.getId());
            entityType.setPackage(p);
        }
        entities.add(entityType);
    }
    return entities;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownPackageException(org.molgenis.data.UnknownPackageException) Package(org.molgenis.data.meta.model.Package)

Example 2 with UnknownPackageException

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

the class EmxMetadataParser method setPackage.

private void setPackage(IntermediateParseResults intermediateResults, int rowIndex, String emxEntityPackage, EntityType entityType) {
    Package p = intermediateResults.getPackage(emxEntityPackage);
    if (p == null) {
        throw new EmxImportException(new UnknownPackageException(emxEntityPackage), EMX_ENTITIES, rowIndex);
    }
    entityType.setPackage(p);
}
Also used : EmxImportException(org.molgenis.data.importer.emx.exception.EmxImportException) UnknownPackageException(org.molgenis.data.UnknownPackageException) Package(org.molgenis.data.meta.model.Package)

Example 3 with UnknownPackageException

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

the class EntityTypeRequestMapperImpl method updateEntityType.

@SuppressWarnings({ "java:S1192" })
private // ATTRIBUTES constant in this class is not related to the one in this switch
void updateEntityType(EntityType entityType, Entry<String, Object> entry) {
    switch(entry.getKey()) {
        case "package":
            String packageId = String.valueOf(entry.getValue());
            Package pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(packageId));
            entityType.setPackage(pack);
            break;
        case "id":
        case "abstract":
            throw new ReadOnlyFieldException(entry.getKey(), "entityType");
        case "extends":
            String extendsValue = String.valueOf(entry.getValue());
            EntityType parent = metaDataService.getEntityType(extendsValue).orElseThrow(() -> new UnknownEntityTypeException(extendsValue));
            entityType.setExtends(parent);
            break;
        case "label":
            I18nValue label = I18nValueMapper.toI18nValue(entry.getValue());
            processI18nLabel(label, entityType);
            break;
        case "description":
            I18nValue description = I18nValueMapper.toI18nValue(entry.getValue());
            processI18nDescription(description, entityType);
            break;
        case "attributes":
            if (entry.getValue() != null) {
                Iterable<Attribute> attributes = mapAttributes(entityType, entry);
                entityType.setOwnAllAttributes(attributes);
            } else {
                throw new EmptyAttributesException();
            }
            break;
        case "tags":
        case "backend":
            throw new UnsupportedFieldException(entry.getKey());
        default:
            throw new InvalidKeyException("entityType", entry.getKey());
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) ReadOnlyFieldException(org.molgenis.api.metadata.v3.exception.ReadOnlyFieldException) Attribute(org.molgenis.data.meta.model.Attribute) UnknownPackageException(org.molgenis.data.UnknownPackageException) UnsupportedFieldException(org.molgenis.api.metadata.v3.exception.UnsupportedFieldException) Package(org.molgenis.data.meta.model.Package) I18nValue(org.molgenis.api.metadata.v3.model.I18nValue) InvalidKeyException(org.molgenis.api.metadata.v3.exception.InvalidKeyException) EmptyAttributesException(org.molgenis.api.metadata.v3.exception.EmptyAttributesException)

Example 4 with UnknownPackageException

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

the class EntityTypeRequestMapperImpl method toEntityType.

@Override
public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) {
    EntityType entityType = entityTypeFactory.create();
    String entityTypeId = entityTypeRequest.getId();
    if (entityTypeId != null) {
        entityType.setId(entityTypeId);
    }
    String packageId = entityTypeRequest.getPackage();
    Package pack = null;
    if (packageId != null) {
        pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage()));
    }
    entityType.setPackage(pack);
    String extendsEntityTypeId = entityTypeRequest.getExtends();
    if (extendsEntityTypeId != null) {
        EntityType extendsEntityType = metaDataService.getEntityType(extendsEntityTypeId).orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId));
        entityType.setExtends(extendsEntityType);
    }
    processI18nLabel(entityTypeRequest.getLabel(), entityType);
    processI18nDescription(entityTypeRequest.getDescription(), entityType);
    List<Attribute> ownAttributes = attributeRequestMapper.toAttributes(entityTypeRequest.getAttributes(), entityTypeRequest, entityType);
    entityType.setOwnAllAttributes(ownAttributes);
    Boolean abstractEntityType = entityTypeRequest.getAbstract();
    if (abstractEntityType != null) {
        entityType.setAbstract(abstractEntityType);
    }
    entityType.setBackend(metaDataService.getDefaultBackend().getName());
    processSelfReferencingAttributes(entityType, ownAttributes);
    return entityType;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Attribute(org.molgenis.data.meta.model.Attribute) UnknownPackageException(org.molgenis.data.UnknownPackageException) Package(org.molgenis.data.meta.model.Package)

Aggregations

UnknownPackageException (org.molgenis.data.UnknownPackageException)4 Package (org.molgenis.data.meta.model.Package)4 EntityType (org.molgenis.data.meta.model.EntityType)3 UnknownEntityTypeException (org.molgenis.data.UnknownEntityTypeException)2 Attribute (org.molgenis.data.meta.model.Attribute)2 EmptyAttributesException (org.molgenis.api.metadata.v3.exception.EmptyAttributesException)1 InvalidKeyException (org.molgenis.api.metadata.v3.exception.InvalidKeyException)1 ReadOnlyFieldException (org.molgenis.api.metadata.v3.exception.ReadOnlyFieldException)1 UnsupportedFieldException (org.molgenis.api.metadata.v3.exception.UnsupportedFieldException)1 I18nValue (org.molgenis.api.metadata.v3.model.I18nValue)1 EmxImportException (org.molgenis.data.importer.emx.exception.EmxImportException)1