private void replaceFunctionsInTransformation(final Transformation transformation) throws DMPPersistenceException { if (transformation == null) { return; } final Set<Component> transformationComponents = transformation.getComponents(); if (transformationComponents == null) { return; } for (final Component transformationComponent : transformationComponents) { replaceFunctionsInComponent(transformationComponent); } }
@Override public boolean completeEquals(final Object obj) { return Transformation.class.isInstance(obj) && super.completeEquals(obj) && DMPPersistenceUtil.getComponentUtils().completeEquals(((Transformation) obj).getComponents(), getComponents()); }
/** * {@inheritDoc} */ @Override public void updateObjectInternal(final Transformation object, final Transformation updateObject) throws DMPPersistenceException { super.updateObjectInternal(object, updateObject); final Set<Component> components = object.getComponents(); updateObject.setComponents(components); }
/** * {@inheritDoc}<br/> * Clears the relationship to the functions of the components and decouples the components from each other. */ @Override protected void prepareObjectForRemoval(final Transformation object) { final Set<Component> components = object.getComponents(); if (components != null) { final Set<Component> componentsToBeDeleted = Sets.newCopyOnWriteArraySet(components); for (final Component component : componentsToBeDeleted) { // release functions from components of a transformation // and disconnect components from each other component.setFunction(null); component.setInputComponents(null); component.setOutputComponents(null); } } TransformationService.LOG.trace("transformation after prepare for removal: " + ToStringBuilder.reflectionToString(object)); }
final Set<Component> components = transformation.getComponents();
/** * {@inheritDoc}<br/> * Updates the name, description, parameters, machine processable function description and components of the transformation. */ @Override protected Transformation prepareObjectForUpdate(final Transformation objectWithUpdates, final Transformation object) { super.prepareObjectForUpdate(objectWithUpdates, object); object.setComponents(objectWithUpdates.getComponents()); return object; }
/** * {@inheritDoc} <br /> * Assert both transformations have either no components or their components are equal, see * {@link org.dswarm.persistence.service.test.utils.BasicJPAServiceTestUtils#compareObjects(Set, Map)} for details. */ @Override public void compareObjects(final Transformation expectedTransformation, final Transformation actualTransformation) throws JsonProcessingException, JSONException { super.compareObjects(expectedTransformation, actualTransformation); if (expectedTransformation.getComponents() == null || expectedTransformation.getComponents().isEmpty()) { final boolean actualTransformationHasNoComponents = (actualTransformation.getComponents() == null || actualTransformation.getComponents() .isEmpty()); Assert.assertTrue("the actual transformation should not have any components", actualTransformationHasNoComponents); } else { // (!null && !empty) final Set<Component> actualComponents = actualTransformation.getComponents(); Assert.assertNotNull("components of actual transformation '" + actualTransformation.getUuid() + "' shouldn't be null", actualComponents); Assert.assertFalse("components of actual transformation '" + actualTransformation.getUuid() + "' shouldn't be empty", actualComponents.isEmpty()); final Map<String, Component> actualComponentsMap = Maps.newHashMap(); for (final Component actualComponent : actualComponents) { actualComponentsMap.put(actualComponent.getUuid(), actualComponent); } componentServiceTestUtils.compareObjects(expectedTransformation.getComponents(), actualComponentsMap); } }
private static void testTransformation(final Transformation transformation) { MatcherAssert.assertThat(transformation.getUuid(), Matchers.equalTo("42")); MatcherAssert.assertThat(transformation.getFunctionType(), Matchers.equalTo(FunctionType.Transformation)); MatcherAssert.assertThat(transformation.getName(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformation.getDescription(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformation.getFunctionDescription(), Matchers.is(Matchers.nullValue())); MatcherAssert.assertThat(transformation.getParameters(), Matchers.hasSize(1)); MatcherAssert.assertThat(transformation.getParameters(), Matchers.hasItems("transformationInputString")); MatcherAssert.assertThat(transformation.getComponents(), Matchers.hasSize(3)); final Component c1 = CustomTransformationDeserializerTest.checkComponent(transformation, "1", "compose", "Add pre- or postfix to a string.", Lists.newArrayList("prefix", "postfix"), Tuple.tuple("inputString", "variable_name")); final Component c2 = CustomTransformationDeserializerTest.checkComponent(transformation, "2", "case", "Upper/lower-case transformation.", Lists.newArrayList("to", "language")); final Component c3 = CustomTransformationDeserializerTest .checkComponent(transformation, "3", "count", "Returns the an increasing count for each received literal.", Collections.<String>emptyList(), Tuple.tuple("inputString", "dataset")); // *C1* --> C2 MatcherAssert.assertThat(c1.getInputComponents(), Matchers.is(Matchers.nullValue())); MatcherAssert.assertThat(c1.getOutputComponents(), Matchers.hasSize(1)); MatcherAssert.assertThat(Iterators.getOnlyElement(c1.getOutputComponents().iterator()), Matchers.is(Matchers.sameInstance(c2))); // C1 --> *C2* MatcherAssert.assertThat(c2.getInputComponents(), Matchers.hasSize(1)); MatcherAssert.assertThat(c2.getOutputComponents(), Matchers.is(Matchers.nullValue())); MatcherAssert.assertThat(Iterators.getOnlyElement(c2.getInputComponents().iterator()), Matchers.is(Matchers.sameInstance(c1))); MatcherAssert.assertThat(c3.getInputComponents(), Matchers.is(Matchers.nullValue())); MatcherAssert.assertThat(c3.getOutputComponents(), Matchers.is(Matchers.nullValue())); }
@SafeVarargs private static Component checkComponent(final Transformation transformation, final String uuid, final String name, final String description, final List<String> functionParameters, final Tuple<String, String>... parameterMappings) { // TODO: changed Configuration.class to Component.class (y Configuration.class here - these are components!) final List<Component> configurations = Lambda.filter(Lambda.having(Lambda.on(Component.class).getUuid(), Matchers.equalTo(uuid)), transformation.getComponents()); MatcherAssert.assertThat(configurations, Matchers.hasSize(1)); final Component component = configurations.get(0); MatcherAssert.assertThat(component.getUuid(), Matchers.equalTo(uuid)); MatcherAssert.assertThat(component.getName(), Matchers.equalTo(name)); MatcherAssert.assertThat(component.getDescription(), Matchers.equalTo(description)); final Map<String, String> componentParameterMappings = component.getParameterMappings(); for (final Tuple<String, String> parameterMapping : parameterMappings) { final String key = parameterMapping.v1(); final String value = parameterMapping.v2(); MatcherAssert.assertThat(componentParameterMappings, Matchers.hasKey(key)); MatcherAssert.assertThat(componentParameterMappings, Matchers.hasValue(value)); } CustomTransformationDeserializerTest.checkFunction(component, uuid, name, description, functionParameters.toArray(new String[functionParameters.size()])); return component; }
final Set<Component> components = transformation.getComponents();
Assert.assertEquals("the transformation parameter for '" + transformationParameter + "' are not equal", transformationParameter, transformation.getParameters().iterator().next()); Assert.assertNotNull("the transformation components set shouldn't be null", transformation.getComponents()); Assert.assertEquals("the transformation component sets are not equal", components, transformation.getComponents()); Assert.assertNotNull("the component name shouldn't be null", transformation.getComponents().iterator().next().getName()); Assert.assertEquals("the component names are not equal", componentName, transformation.getComponents().iterator().next().getName()); Assert.assertNotNull("the component parameter mappings shouldn't be null", transformation.getComponents().iterator().next() .getParameterMappings()); Assert.assertEquals("the component parameter mappings' size are not equal", 1, transformation.getComponents().iterator().next() .getParameterMappings().size()); Assert.assertTrue("the component parameter mappings doesn't contain a mapping for function parameter '" + functionParameterName + "'", transformation.getComponents().iterator().next().getParameterMappings().containsKey(functionParameterName)); Assert.assertEquals("the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, transformation.getComponents().iterator().next().getParameterMappings().get(functionParameterName));
@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); }
@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); }
/** * Create a new {@code Transformation} as a copy from a existing transformation 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 transformation the base transformation that will be copied * @param uuid the target transformation's id value * @return a new transformation with the given id and all other attributes copied from the provided transformation. */ public static Transformation withId(final Transformation transformation, final String uuid) { final Transformation newTransformation = new Transformation(uuid); newTransformation.setComponents(transformation.getComponents()); newTransformation.setFunctionDescription(transformation.getFunctionDescription()); newTransformation.setParameters(transformation.getParameters()); newTransformation.setDescription(transformation.getDescription()); newTransformation.setName(transformation.getName()); return newTransformation; } }
Assert.assertEquals("the transformation parameter for '" + transformationParameter + "' are not equal", transformationParameter, transformation.getParameters().iterator().next()); Assert.assertNotNull("the transformation components set shouldn't be null", transformation.getComponents()); Assert.assertEquals("the transformation component sets are not equal", components, transformation.getComponents()); final Iterator<Component> iter = transformation.getComponents().iterator();
.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)); Assert.assertEquals( "the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, ((Transformation) mapping.getTransformation().getFunction()).getComponents().iterator().next().getParameterMappings() .get(functionParameterName));
.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)); Assert.assertEquals( "the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, ((Transformation) mapping.getTransformation().getFunction()).getComponents().iterator().next().getParameterMappings() .get(functionParameterName));
.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)); Assert.assertEquals( "the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, ((Transformation) mapping.getTransformation().getFunction()).getComponents().iterator().next().getParameterMappings() .get(functionParameterName));
.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)); Assert.assertEquals( "the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, ((Transformation) mapping.getTransformation().getFunction()).getComponents().iterator().next().getParameterMappings() .get(functionParameterName));