Search in sources :

Example 1 with EmptyAttributesException

use of org.molgenis.api.metadata.v3.exception.EmptyAttributesException 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)

Aggregations

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 UnknownEntityTypeException (org.molgenis.data.UnknownEntityTypeException)1 UnknownPackageException (org.molgenis.data.UnknownPackageException)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 Package (org.molgenis.data.meta.model.Package)1