private static String getComponentFunctionName(final Component component) { final String componentFunctionName = component.getFunction().getName(); if (METAMORPH_FUNCTION_SQLMAP.equals(componentFunctionName)) { return METAMORPH_FUNCTION_LOOKUP; } return componentFunctionName; }
@Override public boolean completeEquals(final Object obj) { return Component.class.isInstance(obj) && super.completeEquals(obj) && Objects.equal(((Component) obj).getParameterMappings(), getParameterMappings()) && DMPPersistenceUtil.getFunctionUtils().completeEquals(((Component) obj).getFunction(), getFunction()) && Objects.equal(((Component) obj).getInputComponents(), getInputComponents()) && Objects.equal(((Component) obj).getOutputComponents(), getOutputComponents()); }
final String funtionName = component.getFunction().getName();
: transformationOutputVariableIdentifier; final Function transformationFunction = transformationComponent.getFunction();
final String functionName = component.getFunction().getName();
private static Function checkFunction(final Component component, final String uuid, final String name, final String description, final String... parameters) { final Function function = component.getFunction(); MatcherAssert.assertThat(function, Matchers.is(Matchers.notNullValue())); MatcherAssert.assertThat(function.getUuid(), Matchers.equalTo(uuid)); MatcherAssert.assertThat(function.getName(), Matchers.equalTo(name)); MatcherAssert.assertThat(function.getDescription(), Matchers.equalTo(description)); MatcherAssert.assertThat(function.getFunctionType(), Matchers.equalTo(FunctionType.Function)); MatcherAssert.assertThat(function.getParameters(), Matchers.hasItems(parameters)); return function; } }
final String functionName = multipleInputComponent.getFunction().getName();
private void replaceFunctionsInComponent(final Component component) throws DMPPersistenceException { if (component == null) { return; } final Function existingComponentFunction = component.getFunction(); final FunctionType componentFunctionFunctionType = existingComponentFunction.getFunctionType(); switch (componentFunctionFunctionType) { case Function: final Function persistentFunction = replaceFunction(existingComponentFunction); component.setFunction(persistentFunction); break; case Transformation: replaceFunctionsInTransformation((Transformation) existingComponentFunction); break; } }
return; final Function transformationFunction = transformationComponent.getFunction(); final String functionName = component.getFunction().getName();
@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); }
@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()); }
@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); }
/** * {@inheritDoc} */ @Override public void updateObjectInternal(final Component object, final Component updateObject) throws DMPPersistenceException { super.updateObjectInternal(object, updateObject); final Function function = object.getFunction(); final Set<Component> inputComponents = object.getInputComponents(); final Set<Component> outputComponents = object.getOutputComponents(); final Map<String, String> parameterMappings = object.getParameterMappings(); // final Transformation transformation = object.getTransformation(); updateObject.setFunction(function); updateObject.setInputComponents(inputComponents); updateObject.setOutputComponents(outputComponents); updateObject.setParameterMappings(parameterMappings); // updateObject.setTransformation(transformation); }
@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 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); }
if (expectedComponent.getFunction() == null) { Assert.assertNull("the function of actual component '" + actualComponent.getUuid() + "' should be null", actualComponent.getFunction()); actualComponent.getFunction()); Assert.assertNotNull("function type of component must not be null", expectedComponent.getFunction().getFunctionType()); Assert.assertEquals("the function types are not equal", expectedComponent.getFunction().getFunctionType(), actualComponent.getFunction() .getFunctionType()); switch (expectedComponent.getFunction().getFunctionType()) { functionServiceTestUtils.compareObjects(expectedComponent.getFunction(), actualComponent.getFunction()); transformationsServiceTestUtils.compareObjects((Transformation) expectedComponent.getFunction(), (Transformation) actualComponent.getFunction());
/** * Create a new {@code Component} as a copy from a existing component with a specific id. <br> * <b>Use with care!</b> * <p> * This factory is to be used by {@link org.dswarm.persistence.model.job.utils.TransformationDeserializer} to avoid reflection * based access to a private/protected field, since the Json deserializer needs a way to set the id that was provided by the * JSON. * </p> * <p> * The id is otherwise assigned by the database/Hibernate layer. You should never need this outside of * {@code TransformationDeserializer}. * </p> * * @param component the base component that will be copied * @param uuid the target component's id value * @return a new component with the given id and all other attributes copied from the provided component. */ public static Component withId(final Component component, final String uuid) { final Component newComponent = new Component(uuid); newComponent.setFunction(component.getFunction()); newComponent.setInputComponents(component.getInputComponents()); newComponent.setOutputComponents(component.getOutputComponents()); newComponent.setParameterMappings(component.getParameterMappings()); newComponent.setDescription(component.getDescription()); newComponent.setName(component.getName()); return newComponent; } }
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.assertEquals("the component parameter mappings' size are not equal", 1, ((Transformation) mapping.getTransformation().getFunction()) .getComponents().iterator().next().getParameterMappings().size()); Assert.assertTrue( "the component parameter mappings doesn't contain a mapping for function parameter '" + functionParameterName + "'", ((Transformation) mapping.getTransformation().getFunction()).getComponents().iterator().next().getParameterMappings() .containsKey(functionParameterName));
object.setFunction(objectWithUpdates.getFunction()); object.setParameterMappings(objectWithUpdates.getParameterMappings());