private static Set<String> determineSourceAttributes(final Component component, final Map<String, List<String>> mappingInputsVariablesMap, final String[] inputStrings) throws DMPConverterException { // this is a list of input variable names related to current component, which should be unique and ordered final Set<String> sourceAttributes = new LinkedHashSet<>(); Collections.addAll(sourceAttributes, inputStrings); // if no inputString is set, take input component name if (sourceAttributes.isEmpty() && component.getInputComponents() != null && !component.getInputComponents().isEmpty()) { for (final Component inputComponent : component.getInputComponents()) { sourceAttributes.add(getComponentName(inputComponent)); } } // or input attribute path variable else if (sourceAttributes.isEmpty()) { // take input attribute path variables if (mappingInputsVariablesMap != null && !mappingInputsVariablesMap.isEmpty()) { final Set<Entry<String, List<String>>> mappingInputVariablesEntries = mappingInputsVariablesMap.entrySet(); for (final Entry<String, List<String>> mappingInputVariablesEntry : mappingInputVariablesEntries) { final List<String> mappingInputVariables = mappingInputVariablesEntry.getValue(); sourceAttributes.addAll(mappingInputVariables); } } } return sourceAttributes; }
@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()); }
public Transformation getComplexTransformation() throws Exception { final String transformation2Name = "my transformation 2"; final String transformation2Description = "transformation which makes use of three functions (two transformations and one function)"; final String transformation2Parameter = "firstName"; final String transformation2Parameter2 = "familyName"; final Set<Component> components2 = Sets.newLinkedHashSet(); final Component component4 = componentServiceTestUtils.getFullNameComponent(); final Iterator<Component> iter = component4.getInputComponents().iterator(); components2.add(iter.next()); components2.add(iter.next()); components2.add(component4); final LinkedList<String> transformation2Parameters = Lists.newLinkedList(); transformation2Parameters.add(transformation2Parameter); transformation2Parameters.add(transformation2Parameter2); return createTransformation(transformation2Name, transformation2Description, components2, transformation2Parameters); } }
final Set<Component> inputComponents = currentComponent.getInputComponents();
/** * note: result will be cache (temporarily - for re-utilisation in a test) * * @return * @throws Exception */ @Override public Transformation createAndPersistDefaultCompleteObject() throws Exception { final String transformationName = "my transformation"; if (!cache.containsKey(transformationName)) { final String transformationDescription = "transformation which just makes use of one function"; final String transformationParameter = "transformationInputString"; final Component component = componentServiceTestUtils.createAndPersistDefaultCompleteObject(); final Set<Component> components = Sets.newLinkedHashSet(); components.add(component.getInputComponents().iterator().next()); components.add(component); components.add(component.getOutputComponents().iterator().next()); final LinkedList<String> parameters = Lists.newLinkedList(); parameters.add(transformationParameter); final Transformation transformation = createTransformation(transformationName, transformationDescription, components, parameters); cache.put(transformationName, transformation); } return cache.get(transformationName); }
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())); }
/** * {@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); }
/** * 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 component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, component .getParameterMappings().get(functionParameterName)); Assert.assertNotNull("the component input components set shouldn't be null", component.getInputComponents()); Assert.assertEquals("the component input components set are not equal", 1, component.getInputComponents().size()); Assert.assertTrue("the component input components set doesn't contain component '" + component1.getUuid() + "'", component.getInputComponents() .contains(component1)); Assert.assertEquals("the component input component '" + component1.getUuid() + "' are not equal", component1, component.getInputComponents() .iterator().next()); Assert.assertNotNull("the component output components set shouldn't be null", component.getOutputComponents());
Assert.assertEquals("the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, mainComponent.getParameterMappings().get(functionParameterName)); Assert.assertNotNull("the component input components set shouldn't be null", mainComponent.getInputComponents()); Assert.assertEquals("the component input components set are not equal", 1, mainComponent.getInputComponents().size()); Assert.assertTrue("the component input components set doesn't contain component '" + component1.getUuid() + "'", mainComponent .getInputComponents().contains(component1)); Assert.assertEquals("the component input component '" + component1.getUuid() + "' are not equal", component1, mainComponent .getInputComponents().iterator().next()); Assert.assertNotNull("the component output components set shouldn't be null", mainComponent.getOutputComponents()); Assert.assertEquals("the component output components set are not equal", 1, mainComponent.getOutputComponents().size());
if (expectedComponent.getInputComponents() == null || expectedComponent.getInputComponents().isEmpty()) { final boolean actualComponentHasNoInputComponents = (actualComponent.getInputComponents() == null || actualComponent.getInputComponents() .isEmpty()); Assert.assertTrue("actual component should not have any input components", actualComponentHasNoInputComponents); prepareAndCompareComponents(actualComponent.getUuid(), expectedComponent.getInputComponents(), actualComponent.getInputComponents(), "input");
object.setParameterMappings(objectWithUpdates.getParameterMappings()); final Set<Component> inputComponents = objectWithUpdates.getInputComponents(); Set<Component> newInputComponents;