use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class MergeParameterPage method getConfiguration.
/**
* @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
*/
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
ListMultimap<String, ParameterValue> configuration = ArrayListMultimap.create();
for (EntityDefinition selected : selection) {
// build property path (QNames separated by .)
/*
* FIXME this is problematic with property names that contain dots
* and only works out because only top level properties are allowed.
* If multiple levels are needed, properties should be stored as
* Lists of QNames (Complex values) or EntityDefinitions.
*/
// FIXME use MergeUtil helper function instead
String propertyPath = Joiner.on('.').join(Collections2.transform(selected.getPropertyPath(), new Function<ChildContext, String>() {
@Override
public String apply(ChildContext input) {
return input.getChild().getName().toString();
}
}));
// add it to configuration
configuration.put(parameter.getName(), new ParameterValue(propertyPath));
}
return configuration;
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class SourceListParameterPage method setParameter.
/**
* @see ParameterPage#setParameter(Set, ListMultimap)
*/
@Override
public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) {
for (FunctionParameterDefinition param : params) {
if (param.getName().equals(getParameterName())) {
String description = param.getDescription();
if (description != null) {
setMessage(description);
}
String displayName = param.getDisplayName();
if (displayName != null) {
setTitle(displayName);
}
break;
}
}
if (initialValues != null) {
List<ParameterValue> initialData = initialValues.get(getParameterName());
if (initialData.size() > 0)
initialValue = initialData.get(0).as(String.class);
}
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testClassificationHandler.
@Test
public void testClassificationHandler() {
final int FIRST_SOURCE = 1000;
final String FIRST_TARGET = "http://www.example.com/first";
final int SECOND_SOURCE = 2000;
final String SECOND_TARGET = "http://www.example.com/second";
final int THIRD_SOURCE = 3000;
final String THIRD_TARGET = "http://www.example.com/third";
final String FIXED_VALUE = "http://www.example.com/unknown";
final String OCQL_PATTERN = "if_then_else(in(unit_id,%s), Recode(unit_id,%s), %s)";
Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(ClassificationMappingFunction.ID);
cell.setSource(getUnitIdSourceProperty(unitDenormType));
cell.setTarget(getMetaDataHrefTargetProperty());
Map<Value, Value> tableValues = new HashMap<Value, Value>();
tableValues.put(new StringValue(FIRST_SOURCE), new StringValue(FIRST_TARGET));
tableValues.put(new StringValue(SECOND_SOURCE), new StringValue(SECOND_TARGET));
tableValues.put(new StringValue(THIRD_SOURCE), new StringValue(THIRD_TARGET));
LookupTable lookupTable = new LookupTableImpl(tableValues);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(ClassificationMappingFunction.PARAMETER_LOOKUPTABLE, new ParameterValue(new ComplexValue(lookupTable)));
parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_SOURCE_ACTION));
cell.setTransformationParameters(parameters);
StringBuilder inArgs = new StringBuilder();
StringBuilder recodeArgs = new StringBuilder();
int count = 0;
for (Value sourceValue : tableValues.keySet()) {
inArgs.append(sourceValue.as(String.class));
recodeArgs.append(sourceValue).append(",'").append(tableValues.get(sourceValue)).append("'");
if (count < tableValues.size() - 1) {
inArgs.append(",");
recodeArgs.append(",");
}
count++;
}
final String OCQL_USE_SOURCE = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "unit_id");
final String OCQL_USE_NULL = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "Expression.NIL");
final String OCQL_USE_FIXED = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "'" + FIXED_VALUE + "'");
ClassificationHandler classificationHandler = new ClassificationHandler();
AttributeMappingType attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
assertNotNull(attrMapping.getClientProperty());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
assertEquals(OCQL_USE_SOURCE, attrMapping.getClientProperty().get(0).getValue());
assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
// reset mapping
initMapping();
parameters.removeAll(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION);
parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_NULL_ACTION));
cell.setTransformationParameters(parameters);
attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
assertNotNull(attrMapping.getClientProperty());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
assertEquals(OCQL_USE_NULL, attrMapping.getClientProperty().get(0).getValue());
assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
// reset mapping
initMapping();
parameters.removeAll(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION);
parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_FIXED_VALUE_ACTION_PREFIX + FIXED_VALUE));
cell.setTransformationParameters(parameters);
attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
assertNotNull(attrMapping.getClientProperty());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
assertEquals(OCQL_USE_FIXED, attrMapping.getClientProperty().get(0).getValue());
assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testDateExtractionHandler.
@Test
public void testDateExtractionHandler() {
final String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
final String OCQL = "dateParse(" + SOURCE_UUID_V1 + ", '" + DATE_FORMAT + "')";
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(DateExtractionFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(DateExtractionFunction.PARAMETER_DATE_FORMAT, new ParameterValue(DATE_FORMAT));
cell.setSource(getUuidSourceProperty(unitDenormType));
cell.setTarget(getFirstObservationDateTargetProperty());
cell.setTransformationParameters(parameters);
DateExtractionHandler handler = new DateExtractionHandler();
AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_FIRST_OBSERVATION_DATE, attrMapping.getTargetAttribute());
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testMathematicalExpressionHandler.
@Test
public void testMathematicalExpressionHandler() {
final String EXPRESSION = "100 * unit_id / 2";
final String OCQL = EXPRESSION;
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(MathematicalExpressionFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(MathematicalExpressionFunction.PARAMETER_EXPRESSION, new ParameterValue(EXPRESSION));
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.putAll(MathematicalExpressionFunction.ENTITY_VARIABLE, getUnitIdSourceProperty(unitDenormType).values());
cell.setSource(source);
cell.setTarget(getLocalIdTargetProperty());
cell.setTransformationParameters(parameters);
MathematicalExpressionHandler handler = new MathematicalExpressionHandler();
AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
Aggregations