/** * 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; } }
/** * {@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); }
public Transformation createTransformation(final String name, final String description, final Set<Component> components, final LinkedList<String> parameters) throws Exception { final String uuid = UUIDService.getUUID(Transformation.class.getSimpleName()); final Transformation transformation = new Transformation(uuid); transformation.setName(name); transformation.setDescription(description); transformation.setComponents(components); transformation.setParameters(parameters); return createAndCompareObject(transformation, transformation); }
final Transformation transformation = new Transformation(transformationId); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); Assert.assertNotNull("the transformation name shouldn't be null", transformation.getName()); Assert.assertEquals("the transformation names are not equal", transformationName, transformation.getName()); Assert.assertNotNull("the transformation description shouldn't be null", transformation.getDescription()); Assert.assertEquals("the transformation descriptions are not equal", transformationDescription, transformation.getDescription()); Assert.assertEquals("the transformation parameters' size are not equal", 1, transformation.getParameters().size()); Assert.assertTrue("the transformation parameters doesn't contain transformation parameter '" + transformationParameter + "'", transformation .getParameters().contains(transformationParameter)); 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));
final Transformation transformation = new Transformation(transformationUUID); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); final Transformation transformation2 = new Transformation(transformation2UUID); transformation2.setName(transformation2Name); transformation2.setDescription(transformation2Description); transformation2.setComponents(components2); transformation2.addParameter(transformation2Parameter); transformation2.addParameter(transformation2Parameter2); transformationComponent3.setName(transformation2.getName() + " (component)"); transformationComponent3.setFunction(transformation2); transformationComponent3.setParameterMappings(transformationComponent3ParameterMappings);
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())); }
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); } }
public Component getComplexTransformationComponent(final String firstInputAttributePath, final String secondInputAttributePath, final String outputAttributePath) throws Exception { final Transformation transformation2 = transformationsServiceTestUtils.getComplexTransformation(); final Map<String, String> transformationComponent3ParameterMappings = Maps.newLinkedHashMap(); transformationComponent3ParameterMappings.put(transformation2.getParameters().getFirst(), firstInputAttributePath); transformationComponent3ParameterMappings.put(transformation2.getParameters().get(1), secondInputAttributePath); transformationComponent3ParameterMappings.put("transformationOutputVariable", outputAttributePath); return createComponent(transformation2.getName() + " (component)", transformationComponent3ParameterMappings, transformation2, null, null); } }
/** * {@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); } }
Transformation transformation = new Transformation(uuid); break; case TransformationDeserializer.UUID_KEY: transformation = Transformation.withId(transformation, jp.getText()); break; default:
/** * Set the parameter list of a transformation. * * @param jp the current json parser * @param transformation the target {@code Transformation} * @throws IOException */ private static void setParameters(final JsonParser jp, final Transformation transformation) throws IOException { JsonToken currentToken = jp.nextToken(); final LinkedList<String> parameters = Lists.newLinkedList(); while (currentToken != JsonToken.END_ARRAY) { parameters.add(jp.getText()); currentToken = jp.nextToken(); } transformation.setParameters(parameters); }
components.add(component2); final Transformation transformation = new Transformation(transformationId); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); Assert.assertNotNull("the transformation name shouldn't be null", transformation.getName()); Assert.assertEquals("the transformation names are not equal", transformationName, transformation.getName()); Assert.assertNotNull("the transformation description shouldn't be null", transformation.getDescription()); Assert.assertEquals("the transformation descriptions are not equal", transformationDescription, transformation.getDescription()); Assert.assertEquals("the transformation parameters' size are not equal", 1, transformation.getParameters().size()); Assert.assertTrue("the transformation parameters doesn't contain transformation parameter '" + transformationParameter + "'", transformation .getParameters().contains(transformationParameter)); 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();
final Transformation transformation = new Transformation(transformationUUID); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); final Transformation transformation2 = new Transformation(transformation2UUID); transformation2.setName(transformation2Name); transformation2.setDescription(transformation2Description); transformation2.setComponents(components2); transformation2.addParameter(transformation2Parameter); transformation2.addParameter(transformation2Parameter2); transformationComponent3.setName(transformation2.getName() + " (component)"); transformationComponent3.setFunction(transformation2); transformationComponent3.setParameterMappings(transformationComponent3ParameterMappings);
@Override public boolean completeEquals(final Object obj) { return Transformation.class.isInstance(obj) && super.completeEquals(obj) && DMPPersistenceUtil.getComponentUtils().completeEquals(((Transformation) obj).getComponents(), 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; }
public Component getTransformationComponentSimpleTrimComponent(final String inputAttributePath, final String outputAttributePath) throws Exception { final Transformation transformation = transformationsServiceTestUtils.getSimpleTrimTransformation(); final Map<String, String> transformationComponentParameterMappings = Maps.newLinkedHashMap(); transformationComponentParameterMappings.put(transformation.getParameters().get(0), inputAttributePath); transformationComponentParameterMappings.put("transformationOutputVariable", outputAttributePath); return createComponent(transformation.getName() + " (component)", transformationComponentParameterMappings, transformation, null, null); }
final Transformation transformation = new Transformation(transformationId); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); transformationComponentParameterMappings.put(transformation.getParameters().get(0), inputAttributePath.toAttributePath()); transformationComponentParameterMappings.put("transformationOutputVariable", outputAttributePath.toAttributePath()); transformationComponent.setName(transformation.getName() + " (component)"); transformationComponent.setFunction(transformation); transformationComponent.setParameterMappings(transformationComponentParameterMappings); .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()); .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()
final Transformation transformation = new Transformation(transformationUUID); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); final Transformation transformation2 = new Transformation(transformation2UUID); transformation2.setName(transformation2Name); transformation2.setDescription(transformation2Description); transformation2.setComponents(components2); transformation2.addParameter(transformation2Parameter); transformation2.addParameter(transformation2Parameter2); transformationComponent3.setName(transformation2.getName() + " (component)"); transformationComponent3.setFunction(transformation2); transformationComponent3.setParameterMappings(transformationComponent3ParameterMappings);
/** * {@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 Transformation transformation = new Transformation(transformationUUID); transformation.setName(transformationName); transformation.setDescription(transformationDescription); transformation.setComponents(components); transformation.addParameter(transformationParameter); transformationComponentParameterMappings.put(transformation.getParameters().get(0), inputAttributePath.toAttributePath()); transformationComponentParameterMappings.put("transformationOutputVariable", outputAttributePath.toAttributePath()); transformationComponent.setName(transformation.getName() + " (component)"); transformationComponent.setFunction(transformation); transformationComponent.setParameterMappings(transformationComponentParameterMappings); .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()); .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());