Search in sources :

Example 81 with EntityDefinition

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

the class JoinContext method apply.

/**
 * Apply information collected in the context to the cell.
 *
 * @param newCell the merged cell
 * @param log the cell log
 * @param migration the alignment migration
 */
public void apply(MutableCell newCell, AlignmentMigration migration, SimpleLog log) {
    ListMultimap<String, ParameterValue> params = ArrayListMultimap.create();
    /*
		 * Order: Keep original order but replace entities w/ all matches
		 */
    Set<TypeEntityDefinition> types = new LinkedHashSet<>();
    for (TypeEntityDefinition type : orgParameter.getTypes()) {
        List<TypeEntityDefinition> repl = replacements.get(type);
        if (repl.isEmpty()) {
            log.error("Could not find replacement for type {0} in join order", type);
            types.add(type);
        } else {
            types.addAll(repl);
        }
    }
    /*
		 * Conditions: (1) add conditions from matches and (2) add conditions
		 * from original cell translated to new schema (via property mapping),
		 * if they are not duplicates
		 */
    Set<Pair<PropertyEntityDefinition, PropertyEntityDefinition>> cons = new LinkedHashSet<>();
    // add conditions from matches
    for (Cell match : joinMatches) {
        JoinParameter matchParameter = CellUtil.getFirstParameter(match, JoinFunction.PARAMETER_JOIN).as(JoinParameter.class);
        for (JoinCondition condition : matchParameter.getConditions()) {
            cons.add(new Pair<>(condition.baseProperty, condition.joinProperty));
        }
    }
    // migrate original conditions
    Set<JoinCondition> migrated = orgParameter.getConditions().stream().map(condition -> {
        PropertyEntityDefinition baseProperty = processOriginalConditionProperty(condition.baseProperty, migration, log);
        PropertyEntityDefinition joinProperty = processOriginalConditionProperty(condition.joinProperty, migration, log);
        JoinCondition result = new JoinCondition(baseProperty, joinProperty);
        return result;
    }).collect(Collectors.toSet());
    for (JoinCondition condition : migrated) {
        if (!condition.baseProperty.equals(condition.joinProperty)) {
            // migrated condition may contain "loop" condition
            cons.add(new Pair<>(condition.baseProperty, condition.joinProperty));
        }
    }
    // add messages on dropped filter/conditions
    for (EntityDefinition stripped : strippedSources) {
        if (!AlignmentUtil.isDefaultEntity(stripped)) {
            String msg = "Conditions/contexts for an original source could not be transfered and were dropped: " + MergeUtil.getContextInfoString(stripped);
            log.warn(msg);
        }
    }
    // all conditions
    Set<JoinCondition> conditions = new HashSet<>();
    for (Pair<PropertyEntityDefinition, PropertyEntityDefinition> condition : cons) {
        conditions.add(new JoinCondition(condition.getFirst(), condition.getSecond()));
    }
    JoinParameter newParam = new JoinParameter(new ArrayList<>(types), conditions);
    params.replaceValues(JoinFunction.PARAMETER_JOIN, Collections.singleton(new ParameterValue(Value.of(newParam))));
    // Use Groovy Join if original or match uses a script
    if (!scripts.isEmpty()) {
        boolean originalScript = scripts.size() == 1 && GroovyJoin.ID.equals(newCell.getTransformationIdentifier());
        Text script;
        if (originalScript) {
            // use original script
            script = new Text(scripts.get(0).getSecond());
            // create annotation
            log.warn("The Groovy script from the original cell was reused, logic and references to sources are very likely not valid anymore.");
        } else {
            // dummy script with all original scripts
            newCell.setTransformationIdentifier(GroovyJoin.ID);
            script = buildScript(scripts);
            // create annotation
            log.warn("At least one source mapping used a Groovy script, the script could not be combined automatically and was replaced with a dummy script (old scripts are commented out). Please check how you can migrate the old functionality.");
        }
        params.replaceValues(GroovyConstants.PARAMETER_SCRIPT, Collections.singleton(new ParameterValue(Value.of(script))));
    }
    newCell.setTransformationParameters(params);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Arrays(java.util.Arrays) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Text(eu.esdihumboldt.hale.common.core.io.Text) ListMultimap(com.google.common.collect.ListMultimap) GroovyConstants(eu.esdihumboldt.cst.functions.groovy.GroovyConstants) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) MergeUtil(eu.esdihumboldt.hale.common.align.merge.MergeUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JoinFunction(eu.esdihumboldt.hale.common.align.model.functions.JoinFunction) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) Pair(eu.esdihumboldt.util.Pair) LinkedHashSet(java.util.LinkedHashSet) Value(eu.esdihumboldt.hale.common.core.io.Value) SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Set(java.util.Set) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Collectors(java.util.stream.Collectors) CellUtil(eu.esdihumboldt.hale.common.align.model.CellUtil) GroovyJoin(eu.esdihumboldt.cst.functions.groovy.GroovyJoin) List(java.util.List) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Collections(java.util.Collections) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Text(eu.esdihumboldt.hale.common.core.io.Text) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) 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) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) Pair(eu.esdihumboldt.util.Pair) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 82 with EntityDefinition

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

the class JoinMergeMigrator method mergeRetypeSource.

@SuppressWarnings("unused")
private void mergeRetypeSource(MutableCell cell, EntityDefinition source, Cell match, Cell originalCell, SimpleLog log, JoinContext context, boolean groovy) {
    /*
		 * Sources: Add all from match (should be one)
		 */
    addSources(cell, source, match, log, true);
    /*
		 * Join order: Replace type with matched source
		 */
    Entity matchEntity = CellUtil.getFirstEntity(match.getSource());
    TypeEntityDefinition matchSource = null;
    if (matchEntity != null) {
        EntityDefinition def = matchEntity.getDefinition();
        if (def instanceof TypeEntityDefinition) {
            matchSource = (TypeEntityDefinition) def;
        }
    }
    if (matchSource != null) {
        context.addOrderReplacement((TypeEntityDefinition) source, matchSource);
    } else {
        log.error("Match for source {0} is invalid and does not have a type source", source.getDefinition());
        return;
    }
    if (groovy) {
        addScript(match, context);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) 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)

Example 83 with EntityDefinition

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

the class AbstractBaseAlignmentLoader method migrateCells.

private List<MutableCell> migrateCells(List<MutableCell> cells, SimpleLog log) {
    List<MutableCell> result = new ArrayList<>();
    // Collect mappings from all UnmigratedCells
    Map<EntityDefinition, EntityDefinition> allMappings = new HashMap<>();
    cells.stream().filter(c -> c instanceof UnmigratedCell).map(c -> (UnmigratedCell) c).forEach(uc -> allMappings.putAll(uc.getEntityMappings()));
    // Add cells to the alignment, migrate UnmigratedCells
    for (MutableCell cell : cells) {
        if (cell instanceof UnmigratedCell) {
            result.add(((UnmigratedCell) cell).migrate(allMappings, log));
        } else {
            result.add(cell);
        }
    }
    return result;
}
Also used : IOUtils(eu.esdihumboldt.util.io.IOUtils) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) HashMap(java.util.HashMap) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Map(java.util.Map) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) URI(java.net.URI) LinkedList(java.util.LinkedList) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Collection(java.util.Collection) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) Set(java.util.Set) IOException(java.io.IOException) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) List(java.util.List) Entry(java.util.Map.Entry) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeIndex(eu.esdihumboldt.hale.common.schema.model.TypeIndex) InputStream(java.io.InputStream) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 84 with EntityDefinition

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

the class JaxbToAlignment method createUnmigratedCell.

private static UnmigratedCell createUnmigratedCell(CellType cell, LoadAlignmentContext context, IOReporter reporter, EntityResolver resolver, ServiceProvider serviceProvider) {
    // The sourceCell represents the cell as it was imported from the
    // XML alignment. The conversion to the resolved cell must be performed
    // later by migrating the UnmigratedCell returned from this function.
    final DefaultCell sourceCell = new DefaultCell();
    sourceCell.setTransformationIdentifier(cell.getRelation());
    final FunctionDefinition<?> cellFunction = FunctionUtil.getFunction(sourceCell.getTransformationIdentifier(), serviceProvider);
    final CellMigrator migrator;
    if (cellFunction != null) {
        migrator = cellFunction.getCustomMigrator().orElse(new DefaultCellMigrator());
    } else {
        migrator = new DefaultCellMigrator();
    }
    Map<EntityDefinition, EntityDefinition> mappings = new HashMap<>();
    try {
        // The returned Entity pair consists of
        // (1st) a dummy entity representing the entity read from JAXB
        // (2nd) the resolved entity
        ListMultimap<String, Pair<Entity, Entity>> convertedSourceEntities = convertEntities(cell.getSource(), context.getSourceTypes(), SchemaSpaceID.SOURCE, resolver);
        if (convertedSourceEntities == null) {
            sourceCell.setSource(null);
        } else {
            sourceCell.setSource(Multimaps.transformValues(convertedSourceEntities, pair -> pair.getFirst()));
            for (Pair<Entity, Entity> pair : convertedSourceEntities.values()) {
                mappings.put(pair.getFirst().getDefinition(), pair.getSecond().getDefinition());
            }
        }
        ListMultimap<String, Pair<Entity, Entity>> convertedTargetEntities = convertEntities(cell.getTarget(), context.getTargetTypes(), SchemaSpaceID.TARGET, resolver);
        if (convertedTargetEntities == null) {
            sourceCell.setTarget(null);
        } else {
            sourceCell.setTarget(Multimaps.transformValues(convertedTargetEntities, pair -> pair.getFirst()));
            for (Pair<Entity, Entity> pair : convertedTargetEntities.values()) {
                mappings.put(pair.getFirst().getDefinition(), pair.getSecond().getDefinition());
            }
        }
        if (sourceCell.getTarget() == null || sourceCell.getTarget().isEmpty()) {
            // target is mandatory for cells!
            throw new IllegalStateException("Cannot create cell without target");
        }
    } catch (Exception e) {
        if (reporter != null) {
            reporter.error(new IOMessageImpl("Could not create cell", e));
        }
        return null;
    }
    if (!cell.getAbstractParameter().isEmpty()) {
        ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
        for (JAXBElement<? extends AbstractParameterType> param : cell.getAbstractParameter()) {
            AbstractParameterType apt = param.getValue();
            if (apt instanceof ParameterType) {
                // treat string parameters or null parameters
                ParameterType pt = (ParameterType) apt;
                ParameterValue pv = new ParameterValue(pt.getType(), Value.of(pt.getValue()));
                parameters.put(pt.getName(), pv);
            } else if (apt instanceof ComplexParameterType) {
                // complex parameters
                ComplexParameterType cpt = (ComplexParameterType) apt;
                parameters.put(cpt.getName(), new ParameterValue(new ElementValue(cpt.getAny(), context)));
            } else
                throw new IllegalStateException("Illegal parameter type");
        }
        sourceCell.setTransformationParameters(parameters);
    }
    // annotations & documentation
    for (Object element : cell.getDocumentationOrAnnotation()) {
        if (element instanceof AnnotationType) {
            // add annotation to the cell
            AnnotationType annot = (AnnotationType) element;
            // but first load it from the DOM
            AnnotationDescriptor<?> desc = AnnotationExtension.getInstance().get(annot.getType());
            if (desc != null) {
                try {
                    Object value = desc.fromDOM(annot.getAny(), null);
                    sourceCell.addAnnotation(annot.getType(), value);
                } catch (Exception e) {
                    if (reporter != null) {
                        reporter.error(new IOMessageImpl("Error loading cell annotation", e));
                    } else
                        throw new IllegalStateException("Error loading cell annotation", e);
                }
            } else
                reporter.error(new IOMessageImpl("Cell annotation of type {0} unknown, cannot load the annotation object", null, -1, -1, annot.getType()));
        } else if (element instanceof DocumentationType) {
            // add documentation to the cell
            DocumentationType doc = (DocumentationType) element;
            sourceCell.getDocumentation().put(doc.getType(), doc.getValue());
        }
    }
    sourceCell.setId(cell.getId());
    // a default value is assured for priority
    String priorityStr = cell.getPriority().value();
    Priority priority = Priority.fromValue(priorityStr);
    if (priority != null) {
        sourceCell.setPriority(priority);
    } else {
        // used.
        throw new IllegalArgumentException();
    }
    return new UnmigratedCell(sourceCell, migrator, mappings);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) Collections2(com.google.common.collect.Collections2) ModifierType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ModifierType) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) HaleIO(eu.esdihumboldt.hale.common.core.io.HaleIO) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Map(java.util.Map) ParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ParameterType) Pair(eu.esdihumboldt.util.Pair) AnnotationDescriptor(eu.esdihumboldt.hale.common.align.model.AnnotationDescriptor) URI(java.net.URI) AnnotationExtension(eu.esdihumboldt.hale.common.align.extension.annotation.AnnotationExtension) Value(eu.esdihumboldt.hale.common.core.io.Value) Function(com.google.common.base.Function) Collection(java.util.Collection) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) JAXBException(javax.xml.bind.JAXBException) LoadAlignmentContext(eu.esdihumboldt.hale.common.align.io.LoadAlignmentContext) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) CustomFunctionType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CustomFunctionType) DummyEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.dummy.DummyEntityResolver) List(java.util.List) Base(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType.Base) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) TypeIndex(eu.esdihumboldt.hale.common.schema.model.TypeIndex) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) Priority(eu.esdihumboldt.hale.common.align.model.Priority) StreamSource(javax.xml.transform.stream.StreamSource) AnnotationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AnnotationType) HashMap(java.util.HashMap) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) JaxbAlignmentIO(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentIO) EntityResolver(eu.esdihumboldt.hale.common.align.io.EntityResolver) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DisableFor(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ModifierType.DisableFor) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DocumentationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.DocumentationType) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) DefaultEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.DefaultEntityResolver) Entity(eu.esdihumboldt.hale.common.align.model.Entity) FunctionUtil(eu.esdihumboldt.hale.common.align.extension.function.FunctionUtil) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Element(org.w3c.dom.Element) NamedEntityType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.NamedEntityType) AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) InputStream(java.io.InputStream) Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) AnnotationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AnnotationType) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) Pair(eu.esdihumboldt.util.Pair) ParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ParameterType) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Priority(eu.esdihumboldt.hale.common.align.model.Priority) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DocumentationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.DocumentationType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 85 with EntityDefinition

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

the class InstanceValidator method validateGroupChildren.

/**
 * Validates the given {@link Group}'s children against the {@link Group}'s
 * definition.
 *
 * @param group the group to validate
 * @param childDefs the pre-determined children to validate (can be all
 *            children or a subset)
 * @param reporter the reporter to report to
 * @param type the top level type
 * @param path the current property path
 * @param onlyCheckExistingChildren whether to only validate existing
 *            children (in case of a choice) or not
 * @param reference the instance reference
 * @param context the instance validation context
 * @param parent the parent group's entity definition or <code>null</code>
 */
private void validateGroupChildren(Group group, Collection<? extends ChildDefinition<?>> childDefs, InstanceValidationReporter reporter, QName type, List<QName> path, boolean onlyCheckExistingChildren, InstanceReference reference, InstanceValidationContext context, @Nullable EntityDefinition parent) {
    for (ChildDefinition<?> childDef : childDefs) {
        QName name = childDef.getName();
        path.add(name);
        EntityDefinition child = (parent != null) ? AlignmentUtil.getChild(parent, name) : null;
        // Cannot use getPropertyNames in case of onlyCheckExistingChildren,
        // because then I get no ChildDefinitions.
        Object[] property = group.getProperty(name);
        if (!onlyCheckExistingChildren || (property != null && property.length > 0)) {
            if (childDef.asGroup() != null) {
                validateGroup(property, childDef.asGroup(), reporter, type, path, reference, context, child);
            } else if (childDef.asProperty() != null) {
                validateProperty(property, childDef.asProperty(), reporter, type, path, reference, context, child);
            } else
                throw new IllegalStateException("Illegal child type.");
        }
        path.remove(path.size() - 1);
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) QName(javax.xml.namespace.QName)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5