use of org.molgenis.api.metadata.v3.model.AttributeResponseData.Builder in project molgenis by molgenis.
the class EntityTypeResponseMapperImpl method mapInternal.
private EntityTypeResponse mapInternal(EntityType entityType, boolean flattenAttrs, boolean includeData, boolean expandAttrs, boolean i18n) {
EntityTypeResponse.Builder entityTypeResponseBuilder = EntityTypeResponse.builder();
entityTypeResponseBuilder.setLinks(LinksResponse.create(null, createEntityTypeResponseUri(entityType), null));
if (includeData) {
EntityTypeResponseData.Builder builder = EntityTypeResponseData.builder();
builder.setId(entityType.getId());
Package pack = entityType.getPackage();
if (pack != null) {
builder.setPackage(PackageResponse.builder().setLinks(LinksResponse.create(null, createPackageResponseUri(pack), null)).build());
}
builder.setLabel(entityType.getLabel(LocaleContextHolder.getLocale().getLanguage()));
builder.setDescription(entityType.getDescription(LocaleContextHolder.getLocale().getLanguage()));
if (i18n) {
builder.setLabelI18n(getI18nEntityTypeLabel(entityType));
getI18nEntityTypeDesc(entityType).ifPresent(builder::setDescriptionI18n);
}
AttributesResponse.Builder attributesResponseBuilder = AttributesResponse.builder().setLinks(LinksResponse.create(null, createAttributesResponseUri(entityType), null));
if (expandAttrs) {
attributesResponseBuilder.setItems(flattenAttrs ? attributeResponseMapper.mapInternal(entityType.getAllAttributes(), i18n) : attributeResponseMapper.mapInternal(entityType.getOwnAllAttributes(), i18n));
}
builder.setAttributes(attributesResponseBuilder.build());
builder.setAbstract(entityType.isAbstract());
EntityType parent = entityType.getExtends();
builder.setExtends(parent != null ? mapInternal(parent, false, false, false, i18n) : null);
builder.setIndexingDepth(entityType.getIndexingDepth());
entityTypeResponseBuilder.setData(builder.build());
}
return entityTypeResponseBuilder.build();
}
use of org.molgenis.api.metadata.v3.model.AttributeResponseData.Builder in project molgenis by molgenis.
the class AttributeResponseMapperImpl method mapInternal.
private AttributeResponseData mapInternal(Attribute attr, boolean i18n) {
Builder builder = AttributeResponseData.builder();
builder.setId(attr.getIdentifier());
builder.setName(attr.getName());
builder.setSequenceNr(attr.getSequenceNumber());
builder.setType(getValueString(attr.getDataType()));
Optional.ofNullable(attr.getMaxLength()).ifPresent(builder::setMaxLength);
builder.setIdAttribute(attr.isIdAttribute());
builder.setLabelAttribute(attr.isLabelAttribute());
builder.setLookupAttributeIndex(attr.getLookupAttributeIndex());
if (EntityTypeUtils.isReferenceType(attr)) {
builder.setRefEntityType(LinksResponse.create(null, createEntityTypeResponseUri(attr.getRefEntity()), null));
}
builder.setCascadeDelete(attr.getCascadeDelete());
builder.setMappedBy(attr.getMappedBy() != null ? toAttributeResponse(attr.getMappedBy(), i18n) : null);
if (attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()) {
builder.setOrderBy(map(attr));
}
builder.setLabel(attr.getLabel(LocaleContextHolder.getLocale().getLanguage()));
builder.setDescription(attr.getDescription(LocaleContextHolder.getLocale().getLanguage()));
if (i18n) {
builder.setLabelI18n(getI18nAttrLabel(attr));
getI18nAttrDesc(attr).ifPresent(builder::setDescriptionI18n);
}
builder.setNullable(attr.isNillable());
builder.setAuto(attr.isAuto());
builder.setVisible(attr.isVisible());
builder.setUnique(attr.isUnique());
builder.setReadOnly(attr.isReadOnly());
builder.setAggregatable(attr.isAggregatable());
builder.setExpression(attr.getExpression());
if (attr.getDataType() == AttributeType.ENUM) {
builder.setEnumOptions(attr.getEnumOptions());
}
if (attr.getDataType() == AttributeType.CATEGORICAL || attr.getDataType() == AttributeType.CATEGORICAL_MREF) {
builder.setCategoricalOptions(getCategories(attr.getRefEntity()));
}
org.molgenis.data.Range range = attr.getRange();
if (range != null) {
builder.setRange(Range.create(range.getMin(), range.getMax()));
}
Attribute parent = attr.getParent();
builder.setParentAttributeId(parent != null ? parent.getIdentifier() : null);
builder.setNullableExpression(attr.getNullableExpression());
builder.setVisibleExpression(attr.getVisibleExpression());
builder.setValidationExpression(attr.getValidationExpression());
builder.setDefaultValue(attr.getDefaultValue());
return builder.build();
}
Aggregations