/** * {@inheritDoc} */ @Override public void updateObjectInternal(final Mapping object, final Mapping updateObject) throws DMPPersistenceException { super.updateObjectInternal(object, updateObject); final Set<MappingAttributePathInstance> inputAttributePaths = object.getInputAttributePaths(); final MappingAttributePathInstance outputAttributePath = object.getOutputAttributePath(); final Component transformation = object.getTransformation(); updateObject.setInputAttributePaths(inputAttributePaths); updateObject.setOutputAttributePath(outputAttributePath); updateObject.setTransformation(transformation); }
final Element rules) throws DMPConverterException { final Set<MappingAttributePathInstance> inputMappingAttributePathInstances = mapping.getInputAttributePaths(); LOG.debug("there are no mapping inputs for mapping '{}'", mapping.getName()); final MappingAttributePathInstance mappingOutput = mapping.getOutputAttributePath(); LOG.debug("there is no mapping output for mapping '{}'", mapping.getName());
@Override public MorphScriptBuilder apply(final Task task) throws DMPConverterException { super.apply(task); final List<String> metas = new ArrayList<>(); final Optional<Map<String, Integer>> optionalInputSchemaMap = generateInputSchemaMap(task); final Optional<DataModel> optionalInputDataModel = Optional.ofNullable(task) .flatMap(task2 -> Optional.ofNullable(task2.getInputDataModel())); final Optional<Schema> optionalInputSchema = optionalInputDataModel .flatMap(inputDataModel -> Optional.ofNullable(inputDataModel.getSchema())); final boolean isXmlSchema = isXmlSchema(optionalInputDataModel); final List<Tuple5<Optional<String>, javaslang.collection.List<String>, String, Element, Optional<String>>> mappingOutputs = new ArrayList<>(); for (final Mapping mapping : task.getJob().getMappings()) { metas.add(MorphScriptBuilder.MAPPING_PREFIX + mapping.getUuid()); final Optional<String> optionalDeepestMappingInput = determineDeepestMappingInputAttributePath(mapping, optionalInputSchemaMap); final Optional<Boolean> optionalSelectValueFromSameSubEntity = determineFilterUseCase(mapping, optionalInputSchema); final Optional<String> optionalCommonAttributePathOfMappingInputs = determineCommonAttributePathOfMappingInputs(mapping, optionalInputSchema, isXmlSchema); createTransformation(rules, mapping, optionalDeepestMappingInput, optionalSelectValueFromSameSubEntity, optionalCommonAttributePathOfMappingInputs) .ifPresent(currentMappingOutputs -> currentMappingOutputs .forEach(currentMappingOutput -> mappingOutputs.add(Tuple.of(currentMappingOutput._1, currentMappingOutput._2, currentMappingOutput._3, currentMappingOutput._4, optionalCommonAttributePathOfMappingInputs)))); createLookupTable(maps, mapping.getTransformation()); } createMappingOutputs(mappingOutputs, rules, doc); metaName.setTextContent(Joiner.on(", ").join(metas)); return this; }
/** * {@inheritDoc}<br/> * Clears the relationship to the input attribute paths, output attribute path, input filter and output filter. */ @Override protected void prepareObjectForRemoval(final Mapping object) { // should clear the relationship to the input attribute paths, output attribute path + transformation function object.setInputAttributePaths(null); object.setOutputAttributePath(null); final Component transformation = object.getTransformation(); if (transformation != null) { transformation.setFunction(null); } }
@Override public boolean completeEquals(final Object obj) { return Mapping.class.isInstance(obj) && super.completeEquals(obj) && DMPPersistenceUtil.getMappingAttributePathInstanceUtils().completeEquals(((Mapping) obj).getInputAttributePaths(), getInputAttributePaths()) && DMPPersistenceUtil.getMappingAttributePathInstanceUtils().completeEquals(((Mapping) obj).getOutputAttributePath(), getOutputAttributePath()) && DMPPersistenceUtil.getComponentUtils().completeEquals(((Mapping) obj).getTransformation(), getTransformation()); } }
final Mapping mapping = new Mapping(mappingUUID); mapping.setName(mappingName); mapping.addInputAttributePath(inputMappingAttributePathInstance); mapping.setOutputAttributePath(outputMappingAttributePathInstance); mapping.setTransformation(transformationComponent); Assert.assertNotNull("the mapping name shouldn't be null", mapping.getName()); Assert.assertEquals("the mapping names are not equal", mappingName, mapping.getName()); Assert.assertNotNull("the transformation component parameter mappings shouldn't be null", mapping.getTransformation().getParameterMappings()); Assert.assertEquals("the transformation component parameter mappings' size are not equal", 2, mapping.getTransformation() .getParameterMappings().size()); Assert.assertTrue("the transformation component parameter mappings doesn't contain a mapping for function parameter '" + transformation.getParameters().get(0) + "'", mapping.getTransformation().getParameterMappings().containsKey(transformation.getParameters().get(0))); Assert.assertEquals("the transformation component parameter mapping for '" + transformation.getParameters().get(0) + "' are not equal", inputAttributePath.toAttributePath(), mapping.getTransformation().getParameterMappings().get(transformation.getParameters().get(0))); Assert.assertNotNull("the transformation shouldn't be null", mapping.getTransformation().getFunction()); Assert.assertNotNull("the transformation name shouldn't be null", mapping.getTransformation().getFunction().getName()); Assert.assertEquals("the transformation names are not equal", transformationName, mapping.getTransformation().getFunction().getName()); Assert.assertNotNull("the transformation description shouldn't be null", mapping.getTransformation().getFunction().getDescription()); Assert.assertEquals("the transformation descriptions are not equal", transformationDescription, mapping.getTransformation().getFunction() .getDescription()); Assert.assertEquals("the transformation parameters' size are not equal", 1, mapping.getTransformation().getFunction().getParameters().size()); Assert.assertTrue("the transformation parameters doesn't contain transformation parameter '" + transformationParameter + "'", mapping .getTransformation().getFunction().getParameters().contains(transformationParameter)); Assert.assertEquals("the transformation parameter for '" + transformationParameter + "' are not equal", transformationParameter, mapping .getTransformation().getFunction().getParameters().iterator().next()); Assert.assertNotNull("the transformation components set shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents());
@Override public Mapping createDefaultObject() throws Exception { final MappingAttributePathInstance inputAttributePath = mappingAttributePathInstanceServiceTestUtils.getDefaultInputMAPI(); final MappingAttributePathInstance outputAttributePath = mappingAttributePathInstanceServiceTestUtils.getDefaultOutputMAPI(); final Component transformationComponent = componentServiceTestUtils .getTransformationComponentSimpleTrimComponent(inputAttributePath.getAttributePath().toAttributePath(), outputAttributePath.getAttributePath().toAttributePath()); final String mappingName = "my mapping"; // TODO: think about this? final String uuid = UUIDService.getUUID(Mapping.class.getSimpleName()); final Mapping mapping = new Mapping(uuid); mapping.setName(mappingName); mapping.addInputAttributePath(inputAttributePath); mapping.setOutputAttributePath(outputAttributePath); mapping.setTransformation(transformationComponent); return mapping; }
final Component transformationComponent = mapping.getTransformation(); .debug("transformation component for mapping '{}' was empty. Just delegate mapping input to mapping output.", mapping.getUuid()); mapping.getUuid()); final Set<MappingAttributePathInstance> mappingInputs = mapping.getInputAttributePaths(); final String mappingOutputName = mapping.getOutputAttributePath().getName(); final Optional<List<Tuple4<Optional<String>, javaslang.collection.List<String>, String, Element>>> mappingOutputs = addMappingOutputMapping(variablesFromMappingOutput, mapping.getOutputAttributePath());
/** * replace functions with persistent ones (i.e. those that are at a project and those that are at a mapping) * * @param project */ private void replaceFunctions(final Project project) throws DMPPersistenceException { final Set<Function> existingProjectFunctions = project.getFunctions(); // replace project functions if (existingProjectFunctions != null) { final Set<Function> persistentProjectFunctions = new LinkedHashSet<>(); for (final Function existingProjectFunction : existingProjectFunctions) { final Function persistentProjectFunction = replaceFunction(existingProjectFunction); persistentProjectFunctions.add(persistentProjectFunction); } project.setFunctions(persistentProjectFunctions); } final Set<Mapping> existingProjectMappings = project.getMappings(); // replace mapping functions if (existingProjectMappings != null) { for (final Mapping existingProjectMapping : existingProjectMappings) { final Component existingProjectMappingTransformationComponent = existingProjectMapping.getTransformation(); if (existingProjectMappingTransformationComponent != null) { replaceFunctionsInComponent(existingProjectMappingTransformationComponent); } } } }
/** * replace attribute paths of MAPIs with persistent ones (we also fetch APs from inbuilt schemata from DB) * * @param oldUuidNewPersistentAttributePathMap * @param project * @throws DMPPersistenceException */ private void replaceAttributePathsInMappings(final Map<String, AttributePath> oldUuidNewPersistentAttributePathMap, final Project project) throws DMPPersistenceException, JsonProcessingException { if (project == null) { return; } final Set<Mapping> existingMappings = project.getMappings(); if (existingMappings == null) { return; } for (final Mapping existingMapping : existingMappings) { final Set<MappingAttributePathInstance> existingMappingInputAttributePaths = existingMapping.getInputAttributePaths(); if (existingMappingInputAttributePaths != null) { for (final MappingAttributePathInstance existingMAPI : existingMappingInputAttributePaths) { replaceAttributePathInMAPI(oldUuidNewPersistentAttributePathMap, existingMAPI); } } final MappingAttributePathInstance existingMappingOutputAttributePath = existingMapping.getOutputAttributePath(); replaceAttributePathInMAPI(oldUuidNewPersistentAttributePathMap, existingMappingOutputAttributePath); } }
private static Optional<String> determineDeepestMappingInputAttributePath(final Mapping mapping, final Optional<Map<String, Integer>> optionalInputSchemaMap) { return Optional.ofNullable(mapping.getInputAttributePaths()) .filter(mappingInputAttributePathInstances -> !mappingInputAttributePathInstances.isEmpty()) .flatMap(mappingInputAttributePathInstances -> {
final Mapping mapping = new Mapping(mappingUUID); mapping.setName(mappingName); mapping.addInputAttributePath(inputMappingAttributePathInstance); mapping.setOutputAttributePath(outputMappingAttributePathInstance); mapping.setTransformation(transformationComponent); Assert.assertNotNull("the mapping name shouldn't be null", mapping.getName()); Assert.assertEquals("the mapping names are not equal", mappingName, mapping.getName()); Assert.assertNotNull("the transformation component parameter mappings shouldn't be null", mapping.getTransformation().getParameterMappings()); Assert.assertEquals("the transformation component parameter mappings' size are not equal", 2, mapping.getTransformation() .getParameterMappings().size()); Assert.assertTrue("the transformation component parameter mappings doesn't contain a mapping for function parameter '" + transformation.getParameters().get(0) + "'", mapping.getTransformation().getParameterMappings().containsKey(transformation.getParameters().get(0))); Assert.assertEquals("the transformation component parameter mapping for '" + transformation.getParameters().get(0) + "' are not equal", inputAttributePath.toAttributePath(), mapping.getTransformation().getParameterMappings().get(transformation.getParameters().get(0))); Assert.assertNotNull("the transformation shouldn't be null", mapping.getTransformation().getFunction()); Assert.assertNotNull("the transformation name shouldn't be null", mapping.getTransformation().getFunction().getName()); Assert.assertEquals("the transformation names are not equal", transformationName, mapping.getTransformation().getFunction().getName()); Assert.assertNotNull("the transformation description shouldn't be null", mapping.getTransformation().getFunction().getDescription()); Assert.assertEquals("the transformation descriptions are not equal", transformationDescription, mapping.getTransformation().getFunction() .getDescription()); Assert.assertEquals("the transformation parameters' size are not equal", 1, mapping.getTransformation().getFunction().getParameters().size()); Assert.assertTrue("the transformation parameters doesn't contain transformation parameter '" + transformationParameter + "'", mapping .getTransformation().getFunction().getParameters().contains(transformationParameter)); Assert.assertEquals("the transformation parameter for '" + transformationParameter + "' are not equal", transformationParameter, mapping .getTransformation().getFunction().getParameters().iterator().next()); Assert.assertNotNull("the transformation components set shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents());
@Override public Mapping createAndPersistDefaultCompleteObject() throws Exception { final MappingAttributePathInstance firstNameMappingAttributePathInstance = mappingAttributePathInstanceServiceTestUtils .getDctermsCreatorFoafFirstnameMAPI(); final MappingAttributePathInstance familyNameMappingAttributePathInstance = mappingAttributePathInstanceServiceTestUtils .getDctermsCreatorFoafFamilynameMAPI(); final MappingAttributePathInstance outputMappingAttributePathInstance = mappingAttributePathInstanceServiceTestUtils .getDctermsCreatorFoafNameMAPI(); final Component transformationComponent3 = componentServiceTestUtils .getComplexTransformationComponent(firstNameMappingAttributePathInstance.getAttributePath().toAttributePath(), familyNameMappingAttributePathInstance.getAttributePath().toAttributePath(), outputMappingAttributePathInstance.getAttributePath().toAttributePath()); final String mappingName = "my mapping"; // TODO: think about this? final String uuid = UUIDService.getUUID(Mapping.class.getSimpleName()); final Mapping mapping = new Mapping(uuid); mapping.setName(mappingName); mapping.addInputAttributePath(firstNameMappingAttributePathInstance); mapping.addInputAttributePath(familyNameMappingAttributePathInstance); mapping.setOutputAttributePath(outputMappingAttributePathInstance); mapping.setTransformation(transformationComponent3); return createAndCompareObject(mapping, mapping); }
if (expectedMapping.getTransformation() == null) { Assert.assertNull("the actual mapping '" + actualMapping.getUuid() + "' shouldn't have a transformation", actualMapping.getTransformation()); componentServiceTestUtils.compareObjects(expectedMapping.getTransformation(), actualMapping.getTransformation()); if (expectedMapping.getInputAttributePaths() == null || expectedMapping.getInputAttributePaths().isEmpty()) { final boolean actualMappingHasNoInputAttributePaths = (actualMapping.getInputAttributePaths() == null || actualMapping .getInputAttributePaths().isEmpty()); Assert.assertTrue("actual mapping '" + actualMapping.getUuid() + "' shouldn't have input attribute paths", actualMappingHasNoInputAttributePaths); final Set<MappingAttributePathInstance> actualInputAttributePaths = actualMapping.getInputAttributePaths(); Assert.assertNotNull("input attribute paths of actual mapping '" + actualMapping.getUuid() + "' shouldn't be null", actualInputAttributePaths); Assert.assertFalse("input attribute paths of actual mapping '" + actualMapping.getUuid() + "' shouldn't be empty", actualInputAttributePaths.isEmpty()); for (final MappingAttributePathInstance expectedInputAttributePath : expectedMapping.getInputAttributePaths()) { if (expectedMapping.getOutputAttributePath() == null) { Assert.assertNull("actual mapping '" + actualMapping.getUuid() + "' shouldn't have an output attribute path", actualMapping.getOutputAttributePath()); } else if (!checkAttributePath(expectedMapping.getOutputAttributePath(), checkedExpectedAttributePaths)
@Override public Project createAndPersistDefaultObject() throws Exception { final Mapping simpleMapping = mappingServiceTestUtils.createAndPersistDefaultObject(); final Mapping complexMapping = mappingServiceTestUtils.createAndPersistDefaultCompleteObject(); final Set<Mapping> mappings = Sets.newLinkedHashSet(); mappings.add(simpleMapping); mappings.add(complexMapping); final DataModel inputDataModel = dataModelServiceTestUtils.createAndPersistDefaultObject(); final DataModel outputDataModel = dataModelServiceTestUtils.createAndPersistDefaultObject(); final Function function1 = simpleMapping.getTransformation().getFunction(); final Set<Function> functions = Sets.newLinkedHashSet(); functions.add(function1); final String projectName = "my project"; final String projectDescription = "my project description"; return createAndPersistProject(projectName, projectDescription, mappings, inputDataModel, outputDataModel, functions); }
final boolean isXmlSchema) { return Optional.ofNullable(mapping.getInputAttributePaths()) .filter(mappingInputAttributePathInstances -> !mappingInputAttributePathInstances.isEmpty()) .flatMap(mappingInputAttributePathInstances -> {
actualMappingsMap.put(actualMapping.getUuid(), actualMapping);
final Mapping mapping = new Mapping(mappingUUID); mapping.setName(mappingName); mapping.addInputAttributePath(inputMappingAttributePathInstance); mapping.setOutputAttributePath(outputMappingAttributePathInstance); mapping.setTransformation(transformationComponent); Assert.assertNotNull("the mapping name shouldn't be null", mapping.getName()); Assert.assertEquals("the mapping names are not equal", mappingName, mapping.getName()); Assert.assertNotNull("the transformation component parameter mappings shouldn't be null", mapping.getTransformation().getParameterMappings()); Assert.assertEquals("the transformation component parameter mappings' size are not equal", 2, mapping.getTransformation() .getParameterMappings().size()); Assert.assertTrue("the transformation component parameter mappings doesn't contain a mapping for function parameter '" + transformation.getParameters().get(0) + "'", mapping.getTransformation().getParameterMappings().containsKey(transformation.getParameters().get(0))); Assert.assertEquals("the transformation component parameter mapping for '" + transformation.getParameters().get(0) + "' are not equal", inputAttributePath.toAttributePath(), mapping.getTransformation().getParameterMappings().get(transformation.getParameters().get(0))); Assert.assertNotNull("the transformation shouldn't be null", mapping.getTransformation().getFunction()); Assert.assertNotNull("the transformation name shouldn't be null", mapping.getTransformation().getFunction().getName()); Assert.assertEquals("the transformation names are not equal", transformationName, mapping.getTransformation().getFunction().getName()); Assert.assertNotNull("the transformation description shouldn't be null", mapping.getTransformation().getFunction().getDescription()); Assert.assertEquals("the transformation descriptions are not equal", transformationDescription, mapping.getTransformation().getFunction() .getDescription()); Assert.assertEquals("the transformation parameters' size are not equal", 1, mapping.getTransformation().getFunction().getParameters().size()); Assert.assertTrue("the transformation parameters doesn't contain transformation parameter '" + transformationParameter + "'", mapping .getTransformation().getFunction().getParameters().contains(transformationParameter)); Assert.assertEquals("the transformation parameter for '" + transformationParameter + "' are not equal", transformationParameter, mapping .getTransformation().getFunction().getParameters().iterator().next()); Assert.assertNotNull("the transformation components set shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents());
/** * {@inheritDoc}<br/> * Updates the name, transformation (component), input attribute paths and output attribute path of the mapping. */ @Override protected Mapping prepareObjectForUpdate(final Mapping objectWithUpdates, final Mapping object) { super.prepareObjectForUpdate(objectWithUpdates, object); object.setTransformation(objectWithUpdates.getTransformation()); object.setInputAttributePaths(objectWithUpdates.getInputAttributePaths()); object.setOutputAttributePath(objectWithUpdates.getOutputAttributePath()); return object; }