Search in sources :

Example 1 with UnsupportedFieldException

use of org.molgenis.api.metadata.v3.exception.UnsupportedFieldException in project molgenis by molgenis.

the class AttributeRequestMapperImpl method updateAttributeValue.

private void updateAttributeValue(Attribute attribute, String key, Object value) {
    switch(key) {
        case "id":
            attribute.setIdentifier(getStringValue(value));
            break;
        case "name":
            attribute.setName(getStringValue(value));
            break;
        case "sequenceNr":
            setSequenceNumber(attribute, value);
            break;
        case "type":
            setAttributeType(attribute, value);
            break;
        case "refEntityType":
            setRefEntityType(attribute, value);
            break;
        case "cascadeDelete":
            String cascadeValue = getStringValue(value);
            Boolean isCascade = cascadeValue != null ? Boolean.valueOf(cascadeValue) : null;
            attribute.setCascadeDelete(isCascade);
            break;
        case "orderBy":
            mapOrderBy(value).ifPresent(attribute::setOrderBy);
            break;
        case "expression":
            attribute.setExpression(getStringValue(value));
            break;
        case "nullable":
            String nullableValue = getStringValue(value);
            attribute.setNillable(Boolean.parseBoolean(nullableValue));
            break;
        case "auto":
            String autoValue = getStringValue(value);
            attribute.setAuto(Boolean.parseBoolean(autoValue));
            break;
        case "visible":
            String visibleValue = getStringValue(value);
            attribute.setVisible(Boolean.parseBoolean(visibleValue));
            break;
        case "label":
            I18nValue i18Label = I18nValueMapper.toI18nValue(value);
            processI18nLabel(i18Label, attribute);
            break;
        case "description":
            I18nValue i18Description = I18nValueMapper.toI18nValue(value);
            processI18nDescription(i18Description, attribute);
            break;
        case "aggregatable":
            attribute.setAggregatable(Boolean.parseBoolean(value.toString()));
            break;
        case "enumOptions":
            setEnumOptions(attribute, value);
            break;
        case "range":
            Range range = mapRange(value);
            if (range != null) {
                attribute.setRange(map(range));
            }
            break;
        case "readonly":
            setBooleanValue(attribute, value, IS_READ_ONLY);
            break;
        case "unique":
            setBooleanValue(attribute, value, IS_UNIQUE);
            break;
        case "defaultValue":
            attribute.setDefaultValue(getStringValue(value));
            break;
        case "nullableExpression":
            attribute.setNullableExpression(getStringValue(value));
            break;
        case "visibleExpression":
            attribute.setVisibleExpression(getStringValue(value));
            break;
        case "validationExpression":
            attribute.setValidationExpression(getStringValue(value));
            break;
        case "mappedByAttribute":
        case "parent":
            // Skip now and process after all attributes in the request have been processed
            break;
        case "tags":
            throw new UnsupportedFieldException(key);
        case "idAttribute":
            attribute.setIdAttribute(DataConverter.toBoolean(value));
            break;
        case "labelAttribute":
            attribute.setLabelAttribute(DataConverter.toBoolean(value));
            break;
        case "lookupAttributeIndex":
            attribute.setLookupAttributeIndex(DataConverter.toInt(value));
            break;
        default:
            throw new InvalidKeyException("attribute", key);
    }
}
Also used : UnsupportedFieldException(org.molgenis.api.metadata.v3.exception.UnsupportedFieldException) I18nValue(org.molgenis.api.metadata.v3.model.I18nValue) Range(org.molgenis.api.metadata.v3.model.Range) InvalidKeyException(org.molgenis.api.metadata.v3.exception.InvalidKeyException)

Example 2 with UnsupportedFieldException

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

InvalidKeyException (org.molgenis.api.metadata.v3.exception.InvalidKeyException)2 UnsupportedFieldException (org.molgenis.api.metadata.v3.exception.UnsupportedFieldException)2 I18nValue (org.molgenis.api.metadata.v3.model.I18nValue)2 EmptyAttributesException (org.molgenis.api.metadata.v3.exception.EmptyAttributesException)1 ReadOnlyFieldException (org.molgenis.api.metadata.v3.exception.ReadOnlyFieldException)1 Range (org.molgenis.api.metadata.v3.model.Range)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