use of org.molgenis.api.metadata.v3.model.I18nValue 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);
}
}
use of org.molgenis.api.metadata.v3.model.I18nValue in project molgenis by molgenis.
the class EntityTypeRequestMapperImplTest method toEntityType.
@Test
void toEntityType() {
String id = "MyEntityTypeId";
I18nValue label = I18nValue.builder().setDefaultValue("My Entity Type").build();
String packageId = "MyPackageId";
String extendsEntityTypeId = "MyExtendsEntityTypeId";
ImmutableList<CreateAttributeRequest> attributes = ImmutableList.of();
CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.builder().setId(id).setLabel(label).setDescription(null).setAbstract(false).setPackage(packageId).setExtends(extendsEntityTypeId).setAttributes(attributes).build();
Package aPackage = mock(Package.class);
when(metaDataService.getPackage(packageId)).thenReturn(Optional.of(aPackage));
EntityType extendsEntityType = mock(EntityType.class);
when(metaDataService.getEntityType(extendsEntityTypeId)).thenReturn(Optional.of(extendsEntityType));
EntityType entityType = mock(EntityType.class);
RepositoryCollection repositoryCollection = mock(RepositoryCollection.class);
when(repositoryCollection.getName()).thenReturn("PostgreSQL");
when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
when(entityTypeFactory.create()).thenReturn(entityType);
EntityType mappedEntityType = entityTypeRequestMapper.toEntityType(createEntityTypeRequest);
assertAll(() -> verify(mappedEntityType).setId("MyEntityTypeId"), () -> verify(mappedEntityType).setLabel("My Entity Type"), () -> verify(mappedEntityType).setBackend("PostgreSQL"), () -> verify(mappedEntityType).setPackage(aPackage), () -> verify(mappedEntityType).setExtends(extendsEntityType), () -> verify(mappedEntityType).setOwnAllAttributes(emptyList()), () -> verify(mappedEntityType).setAbstract(false), () -> verifyNoMoreInteractions(mappedEntityType));
}
use of org.molgenis.api.metadata.v3.model.I18nValue 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());
}
}
Aggregations