use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.
the class LookupTableTypeTest method testComplexLookupJsonGroovy.
/**
* Test if a lookup table containing only complex values is the same when
* converted to JSON and back again.
*/
@Test
public void testComplexLookupJsonGroovy() {
Map<Value, Value> values2 = createComplexLookup();
LookupTable org2 = new LookupTableImpl(values2);
// converter
LookupTableType ltt = new LookupTableType();
// convert to Json
Object json = ltt.toJson(org2);
System.out.println(new JsonBuilder(json).toString());
// convert back
LookupTable conv = ltt.fromJson(json, null);
checkTable(conv, values2);
}
use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.
the class LookupTableTypeTest method createComplexLookup.
private Map<Value, Value> createComplexLookup() {
// simple internal table
Map<Value, Value> values = new HashMap<Value, Value>();
values.put(Value.of("a"), Value.of("1"));
values.put(Value.of("b"), Value.of("1"));
LookupTable org = new LookupTableImpl(values);
// external table
Map<Value, Value> values2 = new HashMap<Value, Value>();
values2.put(Value.of("sub"), Value.complex(org));
values2.put(Value.of("c"), Value.of("2"));
return values2;
}
use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.
the class ClassificationMapping method evaluate.
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
String source = variables.values().iterator().next().getValueAs(String.class);
LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(getParameters(), getExecutionContext());
if (lookup == null) {
// throw new TransformationException("No classification specified");
log.warn(log.createMessage("No classification specified", null));
} else {
Value target = lookup.lookup(Value.of(source));
if (target != null) {
// return value w/ transformation variables replaced
return getExecutionContext().getVariables().replaceVariables(target);
}
}
String notClassifiedAction = getOptionalParameter(PARAMETER_NOT_CLASSIFIED_ACTION, Value.of(USE_NULL_ACTION)).as(String.class);
if (USE_SOURCE_ACTION.equals(notClassifiedAction)) {
return source;
} else if (notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX)) {
String notClassified = notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1);
// return w/ transformation variables replaced
return getExecutionContext().getVariables().replaceVariables(notClassified);
} else {
// return null;
throw new NoResultException();
}
}
use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.
the class ClassificationMappingParameterPage method setParameter.
@Override
public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) {
// this page is only for parameter classificationMapping, ignore params
if (initialValues == null)
return;
// Load the lookupTableConfiguration
List<ParameterValue> lookupTableId = initialValues.get(PARAMETER_LOOKUPTABLE_ID);
if (!lookupTableId.isEmpty()) {
selectedLookupTableID = lookupTableId.get(0).as(String.class);
}
// Load the complex value configuration
List<ParameterValue> lookupTableComplex = initialValues.get(PARAMETER_LOOKUPTABLE);
if (!lookupTableComplex.isEmpty()) {
LookupTable table = (LookupTable) lookupTableComplex.get(0).getValue();
lookupTable.putAll(table.asMap());
}
// For reason of compatibility we need the following code
List<ParameterValue> mappings = initialValues.get(PARAMETER_CLASSIFICATIONS);
for (ParameterValue value : mappings) {
String s = value.as(String.class);
String[] splitted = s.split(" ");
try {
for (int i = 0; i < splitted.length; i++) splitted[i] = URLDecoder.decode(splitted[i], "UTF-8");
} catch (UnsupportedEncodingException e) {
// UTF-8 should be everywhere
}
Value targetValue = Value.of(splitted[0]);
for (int i = 1; i < splitted.length; i++) lookupTable.put(Value.of(splitted[i]), targetValue);
}
List<ParameterValue> notClassifiedActionParams = initialValues.get(PARAMETER_NOT_CLASSIFIED_ACTION);
if (!notClassifiedActionParams.isEmpty())
notClassifiedAction = notClassifiedActionParams.get(0).as(String.class);
}
use of eu.esdihumboldt.hale.common.lookup.LookupTable in project hale by halestudio.
the class ClassificationMappingParameterPage 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 (TabItem tabItem : tabs.getSelection()) {
if (tabItem.equals(fromFileItem)) {
// Set the selected lookupTable
IStructuredSelection selection = (IStructuredSelection) lookupTableComboViewer.getSelection();
configuration.put(PARAMETER_LOOKUPTABLE_ID, new ParameterValue(selection.getFirstElement().toString()));
} else {
if (tabItem.equals(manualItem)) {
LookupTable realLookupTable = new LookupTableImpl(lookupTable);
configuration.put(PARAMETER_LOOKUPTABLE, new ParameterValue(Value.complex(realLookupTable)));
}
}
}
switch(notClassifiedActionOptions.indexOf(((IStructuredSelection) notClassifiedActionViewer.getSelection()).getFirstElement())) {
case 1:
notClassifiedAction = "source";
break;
case 2:
notClassifiedAction = "fixed:" + fixedValueText.getText();
break;
case 0:
case -1:
default:
notClassifiedAction = "null";
}
configuration.put(PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(notClassifiedAction));
return configuration;
}
Aggregations