Search in sources :

Example 1 with Builder

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();
}
Also used : EntityTypeResponseData(org.molgenis.api.metadata.v3.model.EntityTypeResponseData) EntityType(org.molgenis.data.meta.model.EntityType) AttributesResponse(org.molgenis.api.metadata.v3.model.AttributesResponse) EntityTypeResponse(org.molgenis.api.metadata.v3.model.EntityTypeResponse) Package(org.molgenis.data.meta.model.Package)

Example 2 with Builder

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();
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Builder(org.molgenis.api.metadata.v3.model.AttributeResponseData.Builder)

Aggregations

Builder (org.molgenis.api.metadata.v3.model.AttributeResponseData.Builder)1 AttributesResponse (org.molgenis.api.metadata.v3.model.AttributesResponse)1 EntityTypeResponse (org.molgenis.api.metadata.v3.model.EntityTypeResponse)1 EntityTypeResponseData (org.molgenis.api.metadata.v3.model.EntityTypeResponseData)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 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1