use of ca.bc.gov.educ.penreg.api.struct.v1.ValueType in project geotoolkit by Geomatys.
the class WPS2ProcessDescriptor method toDescriptor.
/**
* Convert Description to GeneralParameterDescriptor.
*
* @throws UnsupportedOperationException if data type could not be mapped
*/
private static GeneralParameterDescriptor toDescriptor(String processId, Description input) throws UnsupportedParameterException {
final List<? extends Description> subInputs;
final DataDescription dataDescType;
final int min;
final int max;
if (input instanceof InputDescription) {
final InputDescription id = (InputDescription) input;
subInputs = id.getInput();
dataDescType = id.getDataDescription();
max = id.getMaxOccurs();
min = id.getMinOccurs();
} else if (input instanceof OutputDescription) {
final OutputDescription od = (OutputDescription) input;
subInputs = od.getOutput();
dataDescType = od.getDataDescription();
min = 1;
max = 1;
} else {
throw new IllegalArgumentException("Unexpected description type " + input.getClass());
}
final String inputName = input.getIdentifier().getValue();
final String title = input.getFirstTitle();
final String remarks = input.getFirstAbstract();
Map userObject = new HashMap();
for (MetadataType meta : input.getMetadata()) {
if (meta instanceof AdditionalParametersType) {
AdditionalParametersType params = (AdditionalParametersType) meta;
for (AdditionalParameter param : params.getAdditionalParameter()) {
userObject.put(param.getName().getValue(), param.getValue());
}
}
}
if (dataDescType instanceof LiteralData) {
final LiteralData cd = (LiteralData) dataDescType;
for (LiteralDataDomain domain : cd.getLiteralDataDomain()) {
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
if (adaptor == null)
continue;
String defaultValueValue = null;
final ValueType defaultValue = domain.getDefaultValue();
if (defaultValue != null)
defaultValueValue = defaultValue.getValue();
final Unit unit = getUnit(domain.getUOM());
Object[] allowedValues = null;
if (domain.getAllowedValues() != null && domain.getAllowedValues().getStringValues() != null) {
allowedValues = new Object[domain.getAllowedValues().getStringValues().size()];
int i = 0;
for (String value : domain.getAllowedValues().getStringValues()) {
allowedValues[i] = adaptor.convert(value);
i++;
}
}
try {
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), adaptor.convert(defaultValueValue), allowedValues, userObject);
} catch (UnconvertibleObjectException ex2) {
throw new UnsupportedParameterException(processId, inputName, "Can't convert the default literal input value.", ex2);
}
}
throw new UnsupportedParameterException(processId, inputName, "Unidentifiable literal input " + inputName);
} else if (dataDescType instanceof ComplexData) {
final ComplexData cdt = (ComplexData) dataDescType;
// ensure default format is first in the list
Collections.sort(cdt.getFormat(), (Format o1, Format o2) -> {
boolean d1 = Boolean.TRUE.equals(o1.isDefault());
boolean d2 = Boolean.TRUE.equals(o2.isDefault());
if (d1 == d2)
return 0;
return d1 ? -1 : +1;
});
// find a complexe type adaptor
DataAdaptor adaptor = null;
for (Format format : cdt.getFormat()) {
adaptor = ComplexAdaptor.getAdaptor(format);
if (adaptor != null)
break;
}
if (adaptor == null) {
final StringBuilder sb = new StringBuilder();
for (Format format : cdt.getFormat()) {
if (sb.length() != 0)
sb.append(", ");
sb.append(format.getMimeType()).append(' ');
sb.append(format.getEncoding()).append(' ');
sb.append(format.getSchema());
}
throw new UnsupportedParameterException(processId, inputName, "No compatible format found for parameter " + inputName + " formats : " + sb);
}
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), null, null, userObject);
} else if (dataDescType instanceof BoundingBoxData) {
final BboxAdaptor adaptor = BboxAdaptor.create((BoundingBoxData) dataDescType);
userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, Envelope.class, null, null, userObject);
} else if (!subInputs.isEmpty()) {
// sub group type
final List<GeneralParameterDescriptor> params = new ArrayList<>();
for (Description dt : subInputs) {
params.add(toDescriptor(processId, dt));
}
return new ParameterBuilder().addName(inputName).addName(title).setRemarks(remarks).createGroup(params.toArray(new GeneralParameterDescriptor[0]));
} else {
throw new UnsupportedParameterException(processId, inputName, "Unidentifiable input " + inputName + " " + dataDescType);
}
}
use of ca.bc.gov.educ.penreg.api.struct.v1.ValueType in project entity-service by hypertrace.
the class ArrayFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
if (ARRAY_OPERATORS.contains(operator)) {
return primitiveFilteringExpressionConverter.convert(columnIdentifier, operator, constant, requestContext);
}
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final List<?> list = valueOneOfAccessor.access(value, valueType);
if (list.isEmpty()) {
throw new ConversionException("Conversion of empty-list is unsupported");
}
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final List<RelationalExpression> expressions = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
final IdentifierExpression lhs = IdentifierExpression.of(String.format(suffixedSubDocPath, i));
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression rhs = valueHelper.convertToConstantExpression(value, i);
final RelationalExpression expression = RelationalExpression.of(lhs, relationalOperator, rhs);
expressions.add(expression);
}
if (expressions.size() == 1) {
return expressions.get(0);
}
return LogicalExpression.builder().operator(LogicalOperator.AND).operands(expressions).build();
}
use of ca.bc.gov.educ.penreg.api.struct.v1.ValueType in project entity-service by hypertrace.
the class MapFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
if (!SUPPORTED_OPERATORS.contains(operator)) {
throw new ConversionException(String.format("Operator %s is not supported", operator));
}
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final Map<?, ?> map = valueOneOfAccessor.access(value, valueType);
if (map.isEmpty()) {
throw new ConversionException("Conversion of empty-map is unsupported");
}
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final List<RelationalExpression> expressions = new ArrayList<>();
for (final Map.Entry<?, ?> entry : map.entrySet()) {
final IdentifierExpression lhs = IdentifierExpression.of(String.format(suffixedSubDocPath, entry.getKey()));
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression rhs = valueHelper.convertToConstantExpression(value, entry.getKey());
final RelationalExpression expression = RelationalExpression.of(lhs, relationalOperator, rhs);
expressions.add(expression);
}
if (expressions.size() == 1) {
return expressions.get(0);
}
return LogicalExpression.builder().operator(LogicalOperator.AND).operands(expressions).build();
}
use of ca.bc.gov.educ.penreg.api.struct.v1.ValueType in project entity-service by hypertrace.
the class NullFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final IdentifierExpression identifierExpression = IdentifierExpression.of(suffixedSubDocPath);
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression constantExpression = constantExpressionConverter.convert(constant, requestContext);
RelationalExpression relationalExpression = RelationalExpression.of(identifierExpression, relationalOperator, constantExpression);
switch(operator) {
// 'field' EQ 'null' -> 'field' EQ 'null' || 'field' NOT_EXISTS
case EQ:
RelationalExpression nonExistenceRelationalExpression = RelationalExpression.of(identifierExpression, convertOperator(Operator.NOT_EXISTS), constantExpression);
return LogicalExpression.builder().operator(LogicalOperator.OR).operands(List.of(nonExistenceRelationalExpression, relationalExpression)).build();
default:
return relationalExpression;
}
}
use of ca.bc.gov.educ.penreg.api.struct.v1.ValueType in project entity-service by hypertrace.
the class PrimitiveFilteringExpressionConverter method convert.
@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
final String id = columnIdentifier.getColumnName();
final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
final Value value = constant.getValue();
final ValueType valueType = value.getValueType();
final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
final IdentifierExpression identifierExpression = IdentifierExpression.of(suffixedSubDocPath);
final RelationalOperator relationalOperator = convertOperator(operator);
final ConstantExpression constantExpression = constantExpressionConverter.convert(constant, requestContext);
return RelationalExpression.of(identifierExpression, relationalOperator, constantExpression);
}
Aggregations