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;
}
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;
}
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());
}
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);
}
}
}
}
}
}
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;
}
Aggregations