private static List<String> getParameterMappingKeys(final String variableName, final Component transformationComponent) { List<String> parameterMappingKeys = null; final Map<String, String> transformationParameterMapping = transformationComponent.getParameterMappings(); for (final Entry<String, String> parameterMapping : transformationParameterMapping.entrySet()) { if (StringEscapeUtils.unescapeXml(parameterMapping.getValue()).equals(variableName)) { if (parameterMappingKeys == null) { parameterMappingKeys = new ArrayList<>(); } parameterMappingKeys.add(parameterMapping.getKey()); } } return parameterMappingKeys; }
private static String determineTransformationOutputVariable(final Component transformationComponent) { if (transformationComponent == null) { MorphScriptBuilder.LOG.error("transformation component is null, couldn't identify transformation output variable identifier"); return null; } final Map<String, String> parameterMappings = transformationComponent.getParameterMappings(); if (parameterMappings == null) { MorphScriptBuilder.LOG .error("transformation component parameter mappings are null, couldn't identify transformation output variable identifier"); return null; } if (parameterMappings.isEmpty()) { MorphScriptBuilder.LOG .error("transformation component parameter mappings are empty, couldn't identify transformation output variable identifier"); return null; } for (final String key : parameterMappings.keySet()) { if (key.startsWith(MorphScriptBuilder.OUTPUT_VARIABLE_PREFIX_IDENTIFIER)) { // found output variable identifier return key; } } MorphScriptBuilder.LOG.error("couldn't find transformation output variable identifier"); return null; }
final Set<String> collectionSourceAttributes) { final Map<String, String> parameters = multipleInputComponent.getParameterMappings();
final Map<String, String> parameterMappings = component.getParameterMappings();
@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()); }
private Element convertIfElseFunction(final Component multipleInputComponent, final String collectionNameAttribute, final Element collection) throws DMPConverterException { final Map<String, String> parameters = multipleInputComponent.getParameterMappings(); if (parameters == null) { throw new DMPConverterException("cannot convert if/else component; there are not parameter mappings"); } if (!parameters.containsKey(IF_VARIABLE_IDENTIFIER)) { throw new DMPConverterException("cannot convert if/else component; cannot find parameter mapping for if-branch in parameter mappings"); } final String ifBranchComponentVariableName = parameters.get(IF_VARIABLE_IDENTIFIER); if (!parameters.containsKey(ELSE_VARIABLE_IDENTIFIER)) { throw new DMPConverterException("cannot convert if/else component; cannot find parameter mapping for else-branch in parameter mappings"); } final String elseBranchComponentVariableName = parameters.get(ELSE_VARIABLE_IDENTIFIER); final String ifElseComponentID = multipleInputComponent.getUuid(); final String ifElseComponentName = IF_ELSE_COMPONENT_NAME_PREFIX + ifElseComponentID; collection.setAttribute(METAMORPH_DATA_TARGET, MF_VARIABLE_PREFIX + collectionNameAttribute); createDataElement(collection, ifBranchComponentVariableName, ifElseComponentName + IF_BRANCH_POSTFIX, Optional.empty()); createDataElement(collection, elseBranchComponentVariableName, ifElseComponentName + ELSE_BRANCH_POSTFIX, Optional.empty()); return collection; }
final Map<String, String> componentParameterMapping = component.getParameterMappings();
@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()); }
@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 Map<String, String> parameterMappings = component.getParameterMappings();
if (transformationComponent.getParameterMappings() == null || transformationComponent.getParameterMappings().isEmpty()) {
/** * {@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); }
Assert.assertNotNull("the component parameter mappings shouldn't be null", component.getParameterMappings()); Assert.assertEquals("the component parameter mappings' size are not equal", 1, component.getParameterMappings().size()); Assert.assertTrue("the component parameter mappings doesn't contain a mapping for function parameter '" + functionParameterName + "'", component.getParameterMappings().containsKey(functionParameterName)); Assert.assertEquals("the component parameter mapping for '" + functionParameterName + "' are not equal", componentVariableName, component .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 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); }
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));
/** * 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.assertNotNull("the component parameter mappings shouldn't be null", component.getParameterMappings()); Assert.assertEquals("the component parameter mappings' size are not equal", 1, component.getParameterMappings().size()); Assert.assertTrue("the component parameter mappings doesn't contain a mapping for function parameter '" + functionParameterName + "'", component.getParameterMappings().containsKey(functionParameterName)); 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());
object.setParameterMappings(objectWithUpdates.getParameterMappings());