Search in sources :

Example 36 with TypeEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition 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)

Example 37 with TypeEntityDefinition

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

the class FeatureChainingConfigurationPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    if (firstShow) {
        for (ChainPage page : pages) page.dispose();
        pages.clear();
        AlignmentService alignmentService = HaleUI.getServiceProvider().getService(AlignmentService.class);
        Alignment alignment = alignmentService.getAlignment();
        int pageIdx = 0;
        Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
        for (Cell typeCell : typeCells) {
            if (AppSchemaMappingUtils.isJoin(typeCell)) {
                JoinParameter joinParameter = getJoinParameter(typeCell);
                List<JoinCondition> conditions = getSortedJoinConditions(joinParameter);
                TypeEntityDefinition joinTarget = getTargetType(typeCell).getDefinition();
                for (int i = 0; i < joinParameter.getTypes().size() - 1; i++) {
                    ChainPage chainPage = new ChainPage(pageIdx, typeCell.getId(), i, joinParameter.getTypes(), conditions, joinTarget);
                    chainPage.setWizard(getWizard());
                    pages.add(chainPage);
                    pageIdx++;
                }
            }
        }
    }
    setPageComplete(true);
    if (!goingBack) {
        getContainer().showPage(getNextPage());
    } else {
        getContainer().showPage(getPreviousPage());
    }
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) AppSchemaMappingUtils.getJoinParameter(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingUtils.getJoinParameter) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) Cell(eu.esdihumboldt.hale.common.align.model.Cell) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)

Example 38 with TypeEntityDefinition

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

the class JoinHandler method handleTypeTransformation.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.TypeTransformationHandler#handleTypeTransformation(eu.esdihumboldt.hale.common.align.model.Cell,
 *      eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)
 */
@Override
public FeatureTypeMapping handleTypeTransformation(Cell typeCell, AppSchemaMappingContext context) {
    AppSchemaMappingWrapper mapping = context.getMappingWrapper();
    Alignment alignment = context.getAlignment();
    FeatureChaining featureChaining = context.getFeatureChaining();
    final JoinParameter joinParameter = typeCell.getTransformationParameters().get(PARAMETER_JOIN).get(0).as(JoinParameter.class);
    String validation = joinParameter.validate();
    if (validation != null)
        throw new IllegalArgumentException("Join parameter invalid: " + validation);
    // check only single predicate conditions have been used
    int[] conditionCount = new int[joinParameter.getTypes().size()];
    List<JoinCondition> joinConditions = getSortedJoinConditions(joinParameter);
    for (JoinCondition joinCondition : joinConditions) {
        TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(joinCondition.joinProperty);
        int typeIdx = joinParameter.getTypes().indexOf(joinType);
        conditionCount[typeIdx]++;
        if (conditionCount[typeIdx] > 1) {
            throw new IllegalArgumentException("Only single condition joins are supported so far");
        }
    }
    FeatureTypeMapping topMostMapping = null;
    for (int chainIdx = 0; chainIdx < joinParameter.getTypes().size() - 1; chainIdx++) {
        ChainConfiguration previousChainConf = null;
        ChainConfiguration chainConf = null;
        if (featureChaining != null) {
            chainConf = featureChaining.getChain(typeCell.getId(), chainIdx);
            if (chainConf != null && chainConf.getPrevChainIndex() >= 0) {
                previousChainConf = featureChaining.getChain(typeCell.getId(), chainConf.getPrevChainIndex());
            }
        }
        // join is done pair-wise: I assume the first type is the container
        // type, whereas the second type is nested in the first
        JoinCondition joinCondition = joinConditions.get(chainIdx);
        baseProperty = joinCondition.baseProperty;
        joinProperty = joinCondition.joinProperty;
        TypeEntityDefinition containerType = AlignmentUtil.getTypeEntity(baseProperty);
        TypeEntityDefinition nestedType = AlignmentUtil.getTypeEntity(joinProperty);
        // build FeatureTypeMapping for container type
        // Entity containerTypeTarget = typeCell.getTarget().values().iterator().next();
        // TypeDefinition containerTypeTargetType = containerTypeTarget.getDefinition().getType();
        EntityDefinition containerTypeTarget = null;
        TypeDefinition containerTypeTargetType = null;
        String containerTypeTargetMappingName = null;
        if (previousChainConf == null) {
            containerTypeTarget = getTargetType(typeCell).getDefinition();
            containerTypeTargetType = containerTypeTarget.getType();
        } else {
            containerTypeTarget = previousChainConf.getNestedTypeTarget();
            containerTypeTargetType = previousChainConf.getNestedTypeTarget().getDefinition().getPropertyType();
            containerTypeTargetMappingName = previousChainConf.getMappingName();
        }
        String containerMappingName = null;
        if (previousChainConf != null) {
            containerMappingName = previousChainConf.getMappingName();
        }
        FeatureTypeMapping containerFTMapping = context.getOrCreateFeatureTypeMapping(containerTypeTargetType, containerMappingName);
        containerFTMapping.setSourceType(containerType.getDefinition().getName().getLocalPart());
        // build FeatureTypeMapping for nested type
        TypeDefinition nestedFT = null;
        List<ChildContext> nestedFTPath = null;
        FeatureTypeMapping nestedFTMapping = null;
        if (chainConf != null) {
            nestedFT = chainConf.getNestedTypeTarget().getDefinition().getPropertyType();
            nestedFTPath = chainConf.getNestedTypeTarget().getPropertyPath();
            // remove last element
            nestedFTPath = nestedFTPath.subList(0, nestedFTPath.size() - 1);
            nestedFTMapping = context.getOrCreateFeatureTypeMapping(nestedFT, chainConf.getMappingName());
            nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
        } else {
            if (joinParameter.getTypes().size() > 2) {
                throw new IllegalArgumentException("If no feature chaining configuration is provided, only join between 2 types is supported");
            }
            // do your best to figure it out on your own... good luck!
            Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell);
            for (Cell propertyCell : propertyCells) {
                Property sourceProperty = AppSchemaMappingUtils.getSourceProperty(propertyCell);
                if (sourceProperty != null) {
                    TypeDefinition sourceType = sourceProperty.getDefinition().getDefinition().getParentType();
                    if (sourceType.getName().equals(nestedType.getDefinition().getName())) {
                        // source property belongs to nested type: determine
                        // target type
                        Property targetProperty = getTargetProperty(propertyCell);
                        // nestedFT =
                        // findOwningFeatureType(targetProperty.getDefinition());
                        nestedFT = findOwningType(targetProperty.getDefinition(), context.getRelevantTargetTypes());
                        if (nestedFT != null && !nestedFT.getName().equals(containerTypeTargetType.getName())) {
                            // target property belongs to a feature type
                            // different from the already mapped one: build
                            // a new mapping
                            nestedFTPath = findOwningTypePath(targetProperty.getDefinition(), context.getRelevantTargetTypes());
                            nestedFTMapping = context.getOrCreateFeatureTypeMapping(nestedFT);
                            nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
                            // in the join
                            break;
                        } else if (isHRefAttribute(targetProperty.getDefinition().getDefinition())) {
                            // check if target property is a href attribute
                            Property hrefProperty = targetProperty;
                            List<ChildContext> hrefPropertyPath = hrefProperty.getDefinition().getPropertyPath();
                            List<ChildContext> hrefContainerPath = hrefPropertyPath.subList(0, hrefPropertyPath.size() - 1);
                            TypeDefinition hrefParentType = hrefProperty.getDefinition().getDefinition().getParentType();
                            // TypeDefinition childFT =
                            // findChildFeatureType(hrefParentType);
                            TypeDefinition childFT = AppSchemaMappingUtils.findChildType(hrefParentType, context.getRelevantTargetTypes());
                            if (childFT != null) {
                                nestedFTPath = hrefContainerPath;
                                nestedFTMapping = context.getOrCreateFeatureTypeMapping(childFT);
                                nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
                                // involved in the join
                                break;
                            }
                        }
                    }
                }
            }
        }
        // build join mapping
        if (nestedFTMapping != null && nestedFTPath != null) {
            AttributeMappingType containerJoinMapping = context.getOrCreateAttributeMapping(containerTypeTargetType, containerTypeTargetMappingName, nestedFTPath);
            containerJoinMapping.setTargetAttribute(mapping.buildAttributeXPath(containerTypeTargetType, nestedFTPath));
            // set isMultiple attribute
            PropertyDefinition targetPropertyDef = nestedFTPath.get(nestedFTPath.size() - 1).getChild().asProperty();
            if (AppSchemaMappingUtils.isMultiple(targetPropertyDef)) {
                containerJoinMapping.setIsMultiple(true);
            }
            AttributeExpressionMappingType containerSourceExpr = new AttributeExpressionMappingType();
            // join column extracted from join condition
            containerSourceExpr.setOCQL(baseProperty.getDefinition().getName().getLocalPart());
            containerSourceExpr.setLinkElement(getLinkElementValue(nestedFTMapping));
            String linkField = context.getUniqueFeatureLinkAttribute(nestedFT, nestedFTMapping.getMappingName());
            containerSourceExpr.setLinkField(linkField);
            containerJoinMapping.setSourceExpression(containerSourceExpr);
            AttributeMappingType nestedJoinMapping = new AttributeMappingType();
            AttributeExpressionMappingType nestedSourceExpr = new AttributeExpressionMappingType();
            // join column extracted from join condition
            nestedSourceExpr.setOCQL(joinProperty.getDefinition().getName().getLocalPart());
            nestedJoinMapping.setSourceExpression(nestedSourceExpr);
            nestedJoinMapping.setTargetAttribute(linkField);
            nestedFTMapping.getAttributeMappings().getAttributeMapping().add(nestedJoinMapping);
        }
        if (chainIdx == 0) {
            topMostMapping = containerFTMapping;
        }
    }
    return topMostMapping;
}
Also used : FeatureChaining(eu.esdihumboldt.hale.io.appschema.model.FeatureChaining) ChainConfiguration(eu.esdihumboldt.hale.io.appschema.model.ChainConfiguration) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) List(java.util.List) AppSchemaMappingWrapper(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper) AttributeExpressionMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeExpressionMappingType) Cell(eu.esdihumboldt.hale.common.align.model.Cell) AppSchemaMappingUtils.getTargetProperty(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingUtils.getTargetProperty) Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 39 with TypeEntityDefinition

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

the class GenerateDefaults method generateMapping.

private void generateMapping() {
    System.out.println("Generating default value mapping cells for");
    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(schema);
    // visit ADE properties and create cells
    DefaultsVisitor defs = new DefaultsVisitor(defaultValues);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        defs.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }
    if (defs.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(defs.getCells().size() + " cells were created.");
    }
    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : defs.getCells()) {
        align.addCell(cell);
    }
    this.alignment = align;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 40 with TypeEntityDefinition

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

the class GenerateDuplicates method generateMapping.

private void generateMapping() {
    System.out.println("Indexing example cells...");
    // index all cells based on the target property name
    SetMultimap<String, Cell> exampleCells = HashMultimap.create();
    for (Cell cell : examples.getCells()) {
        if (cell.getTarget().size() == 1) {
            // only supports cells with one target
            EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
            if (entityDef.getDefinition() instanceof PropertyDefinition) {
                if (ADE_NS.equals(entityDef.getDefinition().getName().getNamespaceURI())) {
                    exampleCells.put(entityDef.getDefinition().getName().getLocalPart(), cell);
                } else
                    System.out.println("WARNING: ignoring cell with non-ADE target property");
            } else
                System.out.println("WARNING: ignoring type cell");
        } else
            System.out.println("WARNING: ignoring cell with multiple or no targets");
    }
    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);
    // visit ADE properties and create cells
    System.out.println("Generating mapping from example cells for");
    String cellNote = MessageFormat.format("Generated through duplication of example cells on BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
    DuplicateVisitor visitor = new DuplicateVisitor(exampleCells, cellNote);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }
    if (visitor.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(visitor.getCells().size() + " cells were created.");
    }
    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : visitor.getCells()) {
        align.addCell(cell);
    }
    this.alignment = align;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Aggregations

TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)64 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)23 ArrayList (java.util.ArrayList)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)16 Type (eu.esdihumboldt.hale.common.align.model.Type)16 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)16 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)11 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)10 QName (javax.xml.namespace.QName)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)8 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)6 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 LinkedList (java.util.LinkedList)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)5