/** * {@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 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; }
@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()); } }
/** * 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); } } } }
@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); }
/** * {@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); }
@Override public Project createDefaultObject() 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 createProject(projectName, projectDescription, mappings, inputDataModel, outputDataModel, functions); }
@Test public void deserializeNestedTransformationTest() throws IOException { final CharSource source = Resources.asCharSource(Resources.getResource("deser-nested-transformation.json"), Charset.forName("UTF-8")); final Mapping mapping = objectMapper.readValue(source.openStream(), Mapping.class); final Component transformationComponent = mapping.getTransformation(); MatcherAssert.assertThat(transformationComponent.getName(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformationComponent.getDescription(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformationComponent.getParameterMappings(), Matchers.allOf(Matchers.hasKey("dataset"), Matchers.hasKey("variable_name"), Matchers.hasKey("transformationOutputVariable"))); MatcherAssert.assertThat( transformationComponent.getParameterMappings(), Matchers.allOf(Matchers.hasValue("http://data.slub-dresden.de/resources/1/schema#dataset"), Matchers.hasValue("http://data.slub-dresden.de/resources/1/schema#variable_name"), Matchers.hasValue("http://purl.org/dc/elements/1.1/title"))); CustomTransformationDeserializerTest.testTransformation((Transformation) transformationComponent.getFunction()); }
final Component transformationComponent = mapping.getTransformation();
@Test public void testSqlDbRequestTask() throws Exception { final Task task = getTask("sqldbrequest.task.json"); final Job job = task.getJob(); final Set<Mapping> mappings = job.getMappings(); final Mapping mapping = mappings.iterator().next(); final Component mappingTransformationComponent = mapping.getTransformation(); final Transformation mappingTransformationComponentFunction = (Transformation) mappingTransformationComponent.getFunction(); final Set<Component> mappingTransformationComponentFunctionComponents = mappingTransformationComponentFunction.getComponents(); final Component sqlMapLookup = mappingTransformationComponentFunctionComponents.iterator().next(); final Map<String, String> sqlMapLookupParameterMappings = sqlMapLookup.getParameterMappings(); final String user = readManuallyFromTypeSafeConfig("dswarm.db.metadata.username"); final String pass = readManuallyFromTypeSafeConfig("dswarm.db.metadata.password"); final String db = readManuallyFromTypeSafeConfig("dswarm.db.metadata.schema"); setSqlMapParameterMappings(sqlMapLookupParameterMappings, user, pass, db); testXMLTaskWithTuples("sqldbrequest.task.result.json", "sqldbrequest.mabxml.tuples.json", task); }
@Test public void testSqlMapSTask() throws Exception { final Task task = getTask("dd-1386.task.json"); final Job job = task.getJob(); final Set<Mapping> mappings = job.getMappings(); final Mapping mapping = mappings.iterator().next(); final Component mappingTransformationComponent = mapping.getTransformation(); final Transformation mappingTransformationComponentFunction = (Transformation) mappingTransformationComponent.getFunction(); final Set<Component> mappingTransformationComponentFunctionComponents = mappingTransformationComponentFunction.getComponents(); final Iterator<Component> iterator = mappingTransformationComponentFunctionComponents.iterator(); final String user = readManuallyFromTypeSafeConfig("dswarm.db.metadata.username"); final String pass = readManuallyFromTypeSafeConfig("dswarm.db.metadata.password"); final String db = readManuallyFromTypeSafeConfig("dswarm.db.metadata.schema"); while(iterator.hasNext()) { final Component component = iterator.next(); if("sqlmap".equals(component.getFunction().getName())) { final Map<String, String> sqlMapLookupParameterMappings = component.getParameterMappings(); setSqlMapParameterMappings(sqlMapLookupParameterMappings, user, pass, db); } } testXMLTaskWithTuples("dd-1386.task.result.json", "dd-1386.marcxml.tuples.json", task); }
@Test public void testSqlMapTask() throws Exception { final Task task = getTask("sqlmap.lookup.task.json"); final Job job = task.getJob(); final Set<Mapping> mappings = job.getMappings(); final Mapping mapping = mappings.iterator().next(); final Component mappingTransformationComponent = mapping.getTransformation(); final Transformation mappingTransformationComponentFunction = (Transformation) mappingTransformationComponent.getFunction(); final Set<Component> mappingTransformationComponentFunctionComponents = mappingTransformationComponentFunction.getComponents(); final Component sqlMapLookup = mappingTransformationComponentFunctionComponents.iterator().next(); final Map<String, String> sqlMapLookupParameterMappings = sqlMapLookup.getParameterMappings(); final String user = readManuallyFromTypeSafeConfig("dswarm.db.metadata.username"); final String pass = readManuallyFromTypeSafeConfig("dswarm.db.metadata.password"); final String db = readManuallyFromTypeSafeConfig("dswarm.db.metadata.schema"); setSqlMapParameterMappings(sqlMapLookupParameterMappings, user, pass, db); testXMLTaskWithTuples("sqlmap.lookup.task.result.json", "sqlmap.mabxml.tuples.json", task); }
/** * {@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; }
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()); Assert.assertEquals("the transformation component sets are not equal", components, ((Transformation) mapping.getTransformation() .getFunction()).getComponents()); Assert.assertNotNull("the component name shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents() .iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getName()); Assert.assertNotNull("the component parameter mappings shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getParameterMappings());
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()); Assert.assertEquals("the transformation component sets are not equal", components, ((Transformation) mapping.getTransformation() .getFunction()).getComponents()); Assert.assertNotNull("the component name shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents() .iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getName()); Assert.assertNotNull("the component parameter mappings shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getParameterMappings());
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()); Assert.assertEquals("the transformation component sets are not equal", components, ((Transformation) mapping.getTransformation() .getFunction()).getComponents()); Assert.assertNotNull("the component name shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents() .iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getName()); Assert.assertNotNull("the component parameter mappings shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getParameterMappings());
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()); Assert.assertEquals("the transformation component sets are not equal", components, ((Transformation) mapping.getTransformation() .getFunction()).getComponents()); Assert.assertNotNull("the component name shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents() .iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getName()); Assert.assertNotNull("the component parameter mappings shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getParameterMappings());
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()); Assert.assertEquals("the transformation component sets are not equal", components, ((Transformation) mapping.getTransformation() .getFunction()).getComponents()); Assert.assertNotNull("the component name shouldn't be null", ((Transformation) mapping.getTransformation().getFunction()).getComponents() .iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getName());
if (expectedMapping.getTransformation() == null) { actualMapping.getTransformation()); componentServiceTestUtils.compareObjects(expectedMapping.getTransformation(), actualMapping.getTransformation());