Search in sources :

Example 6 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AppSchemaMappingTest method createTargetProperty.

private ListMultimap<String, Property> createTargetProperty(TypeDefinition targetType, List<ChildDefinition<?>> childDefs, List<Integer> contextNames, List<Condition> conditions) {
    if (contextNames == null) {
        contextNames = Collections.emptyList();
    }
    if (conditions == null) {
        conditions = Collections.emptyList();
    }
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    for (int i = 0; i < childDefs.size(); i++) {
        ChildDefinition<?> childDef = childDefs.get(i);
        Integer contextName = (contextNames.size() > i) ? contextNames.get(i) : null;
        Condition condition = (conditions.size() > 1) ? conditions.get(i) : null;
        childContext.add(new ChildContext(contextName, null, condition, childDef));
    }
    ListMultimap<String, Property> target = ArrayListMultimap.create();
    target.put(null, new DefaultProperty(new PropertyEntityDefinition(targetType, childContext, SchemaSpaceID.TARGET, null)));
    return target;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 7 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AppSchemaMappingTest method createSourceProperty.

private ListMultimap<String, Property> createSourceProperty(TypeDefinition sourceType, ChildDefinition<?> childDef) {
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    childContext.add(new ChildContext(childDef));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.put(null, new DefaultProperty(new PropertyEntityDefinition(sourceType, childContext, SchemaSpaceID.SOURCE, null)));
    return source;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 8 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AppSchemaMappingTest method testEncodeIfEmptyFalse.

@Test
public void testEncodeIfEmptyFalse() {
    final String XLINK_HREF_PATTERN = "#lcu.{dataset_id}";
    final String OCQL_STR_CONCAT = "strConcat('#lcu.', dataset_id)";
    DefaultCell format = new DefaultCell();
    format.setTransformationIdentifier(FormattedStringFunction.ID);
    ListMultimap<String, ParameterValue> formatParameters = ArrayListMultimap.create();
    formatParameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(XLINK_HREF_PATTERN));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getDatasetIdSourceProperty().values());
    format.setSource(source);
    format.setTarget(getNestedUnitHrefTargetProperty());
    format.setTransformationParameters(formatParameters);
    FormattedStringHandler formatHandler = new FormattedStringHandler();
    AttributeMappingType attrMapping = formatHandler.handlePropertyTransformation(getDefaultTypeCell(datasetType, landCoverDatasetType), format, new AppSchemaMappingContext(mappingWrapper));
    assertNull(attrMapping.getSourceExpression());
    assertEquals("lcv:member", attrMapping.getTargetAttribute());
    assertNotNull(attrMapping.getClientProperty());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
    assertEquals(OCQL_STR_CONCAT, attrMapping.getClientProperty().get(0).getValue());
    // expression is NOT constant, so encodeIfEmpty=null (won't be XML
    // encoded)
    assertNull(attrMapping.isEncodeIfEmpty());
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) FormattedStringHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) Test(org.junit.Test)

Example 9 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AppSchemaMappingUtils method resolvePropertyTypes.

/**
 * Goes through all chain configurations in the provided feature chaining
 * configuration and attempts to resolve all unresolved property entity
 * definitions.
 *
 * <p>
 * More specifically, resolution for a particular chain configuration is
 * attempted if {@link ChainConfiguration#getJaxbNestedTypeTarget()} returns
 * a value, while {@link ChainConfiguration#getNestedTypeTarget()} returns
 * <code>null</code>.
 * </p>
 *
 * <p>
 * Upon successful resolution,
 * {@link ChainConfiguration#setJaxbNestedTypeTarget(PropertyType)} is
 * invoked with a <code>null</code> argument, to avoid further entity
 * resolution attempts.
 * </p>
 *
 * <p>
 * A {@link DefaultEntityResolver} instance is used to resolve entities.
 * </p>
 *
 * @param featureChaining the global feature chaining configuration
 * @param types the schema to use for entity lookup
 * @param ssid the schema space identifier
 */
public static void resolvePropertyTypes(FeatureChaining featureChaining, TypeIndex types, SchemaSpaceID ssid) {
    if (featureChaining != null) {
        EntityResolver resolver = new DefaultEntityResolver();
        for (String joinCellId : featureChaining.getJoins().keySet()) {
            List<ChainConfiguration> chains = featureChaining.getChains(joinCellId);
            for (ChainConfiguration chain : chains) {
                if (chain.getNestedTypeTarget() == null && chain.getJaxbNestedTypeTarget() != null) {
                    Property resolved = resolver.resolveProperty(chain.getJaxbNestedTypeTarget(), types, ssid);
                    if (resolved != null) {
                        chain.setNestedTypeTarget(resolved.getDefinition());
                        chain.setJaxbNestedTypeTarget(null);
                    }
                }
            }
        }
    }
}
Also used : DefaultEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.DefaultEntityResolver) ChainConfiguration(eu.esdihumboldt.hale.io.appschema.model.ChainConfiguration) EntityResolver(eu.esdihumboldt.hale.common.align.io.EntityResolver) DefaultEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.DefaultEntityResolver) Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 10 with Property

use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.

the class AssignHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    ListMultimap<String, ? extends Entity> sourceEntities = propertyCell.getSource();
    Property anchor = null;
    if (sourceEntities != null && sourceEntities.containsKey(ENTITY_ANCHOR)) {
        anchor = (Property) sourceEntities.get(ENTITY_ANCHOR).get(0);
    }
    ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
    List<ParameterValue> valueParams = parameters.get(PARAMETER_VALUE);
    String value = valueParams.get(0).getStringRepresentation();
    String ocql = null;
    if (anchor != null) {
        // TODO: generalize this code
        String anchorAttr = anchor.getDefinition().getDefinition().getName().getLocalPart();
        ocql = "if_then_else(isNull(" + anchorAttr + "), Expression.NIL, '" + value + "')";
        ocql = getConditionalExpression(anchor.getDefinition(), ocql);
    } else {
        ocql = "'" + value + "'";
    }
    return ocql;
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Property(eu.esdihumboldt.hale.common.align.model.Property)

Aggregations

Property (eu.esdihumboldt.hale.common.align.model.Property)25 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)13 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)11 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 ArrayList (java.util.ArrayList)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)8 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)8 Test (org.junit.Test)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)7 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 Type (eu.esdihumboldt.hale.common.align.model.Type)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2