Search in sources :

Example 1 with ComplexValue

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

the class JoinParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> result = ArrayListMultimap.create(1, 1);
    Set<JoinCondition> conditions = new HashSet<>();
    for (ConditionPage page : pages) {
        conditions.addAll(page.conditions);
    }
    JoinParameter param = new JoinParameter(types, conditions);
    result.put(PARAMETER_JOIN, new ParameterValue(new ComplexValue(param)));
    return result;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) HashSet(java.util.HashSet)

Example 2 with ComplexValue

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

the class SpatialJoinParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> result = ArrayListMultimap.create(1, 1);
    Set<SpatialJoinCondition> conditions = new HashSet<>();
    for (ConditionPage page : pages) {
        conditions.addAll(page.conditions);
    }
    SpatialJoinParameter param = new SpatialJoinParameter(types, conditions);
    result.put(PARAMETER_SPATIAL_JOIN, new ParameterValue(new ComplexValue(param)));
    return result;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) SpatialJoinParameter(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter) HashSet(java.util.HashSet)

Example 3 with ComplexValue

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

the class AppSchemaFileWriterTest method writeAlignment.

private void writeAlignment(File targetFile, String contentType) throws IOException, IOProviderConfigurationException {
    AbstractAppSchemaConfigurator alignWriter = new AppSchemaMappingFileWriter();
    prepareProvider(alignWriter, project, tempDir.toURI());
    alignWriter.setAlignment(alignment);
    alignWriter.setSourceSchema(sourceSchemaSpace);
    alignWriter.setTargetSchema(targetSchemaSpace);
    alignWriter.setTarget(new FileIOSupplier(targetFile));
    DataStore dataStoreParam = createDataStoreParam();
    alignWriter.setParameter(AppSchemaIO.PARAM_DATASTORE, new ComplexValue(dataStoreParam));
    alignWriter.setContentType(HalePlatform.getContentTypeManager().getContentType(contentType));
    IOReport report = alignWriter.execute(new LogProgressIndicator());
    assertNotNull(report);
    assertTrue(report.isSuccess());
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) DataStore(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)

Example 4 with ComplexValue

use of eu.esdihumboldt.hale.common.core.io.impl.ComplexValue 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)

Example 5 with ComplexValue

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

the class AppSchemaMappingTest method buildJoinCell.

@SuppressWarnings("null")
private DefaultCell buildJoinCell(FeatureChaining chainingConf) {
    boolean withChaining = chainingConf != null;
    DefaultCell joinCell = new DefaultCell();
    joinCell.setTransformationIdentifier(JoinFunction.ID);
    if (withChaining) {
        // set cell ID from feature chaining configuration
        // WARNING: this code assumes only one join is configured
        joinCell.setId(chainingConf.getJoins().keySet().iterator().next());
    }
    TypeEntityDefinition datasetEntityDef = new TypeEntityDefinition(datasetType, SchemaSpaceID.SOURCE, null);
    TypeEntityDefinition unitEntityDef = null;
    TypeEntityDefinition observationEntityDef = null;
    if (!withChaining) {
        unitEntityDef = new TypeEntityDefinition(unitDenormType, SchemaSpaceID.SOURCE, null);
    } else {
        unitEntityDef = new TypeEntityDefinition(unitType, SchemaSpaceID.SOURCE, null);
        observationEntityDef = new TypeEntityDefinition(observationType, SchemaSpaceID.SOURCE, null);
    }
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(JoinFunction.JOIN_TYPES, new DefaultType(datasetEntityDef));
    source.put(JoinFunction.JOIN_TYPES, new DefaultType(unitEntityDef));
    if (observationEntityDef != null) {
        source.put(JoinFunction.JOIN_TYPES, new DefaultType(observationEntityDef));
        assertEquals(3, source.get(JoinFunction.JOIN_TYPES).size());
    } else {
        assertEquals(2, source.get(JoinFunction.JOIN_TYPES).size());
    }
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(landCoverDatasetType, SchemaSpaceID.TARGET, null)));
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>(Arrays.asList(datasetEntityDef, unitEntityDef));
    Set<JoinCondition> conditions = new HashSet<JoinCondition>();
    // join dataset and unit
    PropertyEntityDefinition baseProperty = getDatasetIdSourceProperty().values().iterator().next().getDefinition();
    PropertyEntityDefinition joinProperty = getUnitDatasetIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
    conditions.add(new JoinCondition(baseProperty, joinProperty));
    if (withChaining) {
        // add observation type
        types.add(observationEntityDef);
        // join unit and observation
        baseProperty = getUnitIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
        joinProperty = getObservationUnitIdSourceProperty().values().iterator().next().getDefinition();
        conditions.add(new JoinCondition(baseProperty, joinProperty));
    }
    JoinParameter joinParam = new JoinParameter(types, conditions);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(JoinFunction.PARAMETER_JOIN, new ParameterValue(new ComplexValue(joinParam)));
    joinCell.setSource(source);
    joinCell.setTarget(target);
    joinCell.setTransformationParameters(parameters);
    return joinCell;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) ArrayList(java.util.ArrayList) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) HashSet(java.util.HashSet)

Aggregations

ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)7 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)4 HashSet (java.util.HashSet)4 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)2 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)2 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)2 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)2 DataStore (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore)2 SpatialJoinParameter (eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter)1 SpatialJoinCondition (eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Type (eu.esdihumboldt.hale.common.align.model.Type)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)1 StringValue (eu.esdihumboldt.hale.common.core.io.impl.StringValue)1 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1