use of org.molgenis.api.model.Order in project molgenis by molgenis.
the class SortMapper method map.
/**
* @param sort api-sort that will be mapped to a data-sort
* @param entityType data-sort entity type
* @throws UnknownSortAttributeException if api-sort contains an unknown entity type attribute
*/
public Sort map(org.molgenis.api.model.Sort sort, EntityType entityType) {
Sort newSort = new Sort();
sort.getOrders().forEach(order -> {
String attributeName = order.getId();
if (entityType.getAttribute(attributeName) == null) {
throw new UnknownSortAttributeException(entityType, attributeName);
}
Order.Direction direction = order.getDirection();
newSort.on(attributeName, direction != null ? Direction.valueOf(direction.name()) : Direction.ASC);
});
return newSort;
}
use of org.molgenis.api.model.Order in project molgenis by molgenis.
the class AttributeRequestMapperImpl method toAttribute.
private Attribute toAttribute(CreateAttributeRequest attributeRequest, EntityType entityType, @Nullable @CheckForNull Integer index) {
Attribute attribute = attributeFactory.create();
// set id/label/lookupIndex before setting other properties
attribute.setIdAttribute(attributeRequest.getIdAttribute());
attribute.setLabelAttribute(attributeRequest.getLabelAttribute());
attribute.setLookupAttributeIndex(attributeRequest.getLookupAttributeIndex());
String id = attributeRequest.getId();
if (id != null) {
attribute.setIdentifier(id);
}
attribute.setName(attributeRequest.getName());
attribute.setEntity(entityType);
Integer sequenceNumber = attributeRequest.getSequenceNr();
if (sequenceNumber == null) {
sequenceNumber = index;
}
if (sequenceNumber != null) {
attribute.setSequenceNumber(sequenceNumber);
}
String type = attributeRequest.getType();
if (type != null) {
attribute.setDataType(AttributeType.toEnum(type));
}
Optional.ofNullable(attributeRequest.getMaxLength()).ifPresent(attribute::setMaxLength);
EntityType refEntityType;
String refEntityTypeId = attributeRequest.getRefEntityType();
if (refEntityTypeId != null) {
refEntityType = (EntityType) entityManager.getReference(entityTypeMetadata, refEntityTypeId);
attribute.setRefEntity(refEntityType);
}
if (attributeRequest.getCascadeDelete() != null) {
attribute.setCascadeDelete(attributeRequest.getCascadeDelete());
}
ImmutableList<Order> orderBy = attributeRequest.getOrderBy();
attribute.setOrderBy(orderBy != null ? sortMapper.map(Sort.create(orderBy), entityType) : null);
attribute.setExpression(attributeRequest.getExpression());
Boolean nullable = attributeRequest.getNullable();
if (nullable != null) {
attribute.setNillable(nullable);
}
Boolean auto = attributeRequest.getAuto();
if (auto != null) {
attribute.setAuto(auto);
}
Boolean visible = attributeRequest.getVisible();
if (visible != null) {
attribute.setVisible(visible);
}
processI18nLabel(attributeRequest.getLabel(), attribute);
processI18nDescription(attributeRequest.getDescription(), attribute);
Boolean aggregatable = attributeRequest.getAggregatable();
if (aggregatable != null) {
attribute.setAggregatable(aggregatable);
}
List<String> enumOptions = attributeRequest.getEnumOptions();
if (enumOptions != null) {
attribute.setEnumOptions(enumOptions);
}
Range range = attributeRequest.getRange();
if (range != null) {
attribute.setRange(map(range));
}
Boolean readonly = attributeRequest.getReadonly();
if (readonly != null) {
attribute.setReadOnly(readonly);
}
Boolean unique = attributeRequest.getUnique();
if (unique != null) {
attribute.setUnique(unique);
}
attribute.setNullableExpression(attributeRequest.getNullableExpression());
attribute.setVisibleExpression(attributeRequest.getVisibleExpression());
attribute.setValidationExpression(attributeRequest.getValidationExpression());
attribute.setDefaultValue(attributeRequest.getDefaultValue());
return attribute;
}
use of org.molgenis.api.model.Order in project molgenis by molgenis.
the class AttributeRequestMapperImpl method mapOrderBy.
@SuppressWarnings({ "unchecked", "UnstableApiUsage" })
private Optional<org.molgenis.data.Sort> mapOrderBy(Object value) {
List<Object> values = (List<Object>) value;
ImmutableList<Order> orders = values.stream().map(item -> mapOrderByItem((Map<String, String>) item)).collect(toImmutableList());
Sort sort = Sort.create(orders);
return Optional.of(sortMapper.map(sort, attributeFactory.getAttributeMetadata()));
}
Aggregations