Search in sources :

Example 46 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ClassificationMappingParameterPage method addSourceValuesIfNew.

/**
 * Adds the given values to the lookup table.
 *
 * @param values the values to add
 */
private void addSourceValuesIfNew(Iterable<?> values) {
    ConversionService cs = HalePlatform.getService(ConversionService.class);
    for (Object value : values) {
        Value sourceValue = Value.of(cs.convert(value, String.class));
        if (!lookupTable.containsKey(sourceValue))
            lookupTable.put(sourceValue, null);
    }
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            tableViewer.refresh();
        }
    });
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) StyledString(org.eclipse.jface.viewers.StyledString)

Example 47 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class DefaultXLSLookupTableReader method read.

/**
 * Reads a xls/xlsx lookup table workbook (from apache POI). The selected
 * columns specified by parameters keyColumn and valueColumn are mapped
 * together.
 *
 * @param workbook the workbook to read
 * @param skipFirst true, if first row should be skipped
 * @param keyColumn source column of the lookup table
 * @param valueColumn target column of the lookup table
 * @param ignoreEmptyStrings if empty strings should be ignored and treated
 *            as <code>null</code>
 * @return the lookup table as map
 */
public Map<Value, Value> read(Workbook workbook, boolean skipFirst, int keyColumn, int valueColumn, boolean ignoreEmptyStrings) {
    Map<Value, Value> map = new LinkedHashMap<Value, Value>();
    Sheet sheet = workbook.getSheetAt(0);
    FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
    int row = 0;
    if (skipFirst)
        row++;
    for (; row < sheet.getPhysicalNumberOfRows(); row++) {
        Row currentRow = sheet.getRow(row);
        String value = XLSUtil.extractText(currentRow.getCell(valueColumn), evaluator);
        if (value != null && (!ignoreEmptyStrings || !value.isEmpty())) {
            map.put(Value.of(XLSUtil.extractText(currentRow.getCell(keyColumn), evaluator)), Value.of(value));
        }
    }
    return map;
}
Also used : Value(eu.esdihumboldt.hale.common.core.io.Value) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) LinkedHashMap(java.util.LinkedHashMap) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 48 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class XmlElementsFactory method restore.

@Override
public XmlElements restore(Value value, Definition<?> definition, TypeResolver typeResolver, ClassResolver classResolver) throws Exception {
    XmlElements result = new XmlElements();
    ValueList list = value.as(ValueList.class);
    if (list != null) {
        for (Value val : list) {
            XmlElement element = valueToElement(val, definition, typeResolver);
            if (element != null) {
                result.addElement(element);
            }
        }
    }
    return result;
}
Also used : XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Value(eu.esdihumboldt.hale.common.core.io.Value) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 49 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class XmlSchemaReader method getRelevantElements.

/**
 * @return the names of the elements configured as relevant
 */
public Set<? extends QName> getRelevantElements() {
    Set<QName> result = new HashSet<>();
    ValueList elementList = getParameter(PARAM_RELEVANT_ELEMENTS).as(ValueList.class);
    if (elementList != null) {
        for (Value val : elementList) {
            QName name = val.as(QName.class);
            if (name != null) {
                result.add(name);
            }
        }
    }
    return result;
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) QName(javax.xml.namespace.QName) Value(eu.esdihumboldt.hale.common.core.io.Value) HasNotInheritableValue(eu.esdihumboldt.hale.io.xsd.model.HasNotInheritableValue) HashSet(java.util.HashSet)

Example 50 with Value

use of eu.esdihumboldt.hale.common.core.io.Value 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());
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) HashMap(java.util.HashMap) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) StringValue(eu.esdihumboldt.hale.common.core.io.impl.StringValue) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) StringValue(eu.esdihumboldt.hale.common.core.io.impl.StringValue) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ClassificationHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.ClassificationHandler) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4