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; } }
/** * {@inheritDoc} */ @Override public void updateObjectInternal(final FUNCTIONIMPL object, final FUNCTIONIMPL updateObject) throws DMPPersistenceException { final LinkedList<String> parameters = object.getParameters(); updateObject.setParameters(parameters); updateObject.setFunctionDescription(object.getFunctionDescription()); super.updateObjectInternal(object, updateObject); }
private Function createFunction() { final String functionName = "trim"; final String functionDescription = "trims leading and trailing whitespaces from a given string"; final String functionParameter = "inputString"; final String functionUUID = UUIDService.getUUID(Function.class.getSimpleName()); final Function function = new Function(functionUUID); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter); return function; }
@Override public boolean completeEquals(final Object obj) { return Function.class.isInstance(obj) && super.completeEquals(obj) && Objects.equal(((Function) obj).getFunctionType(), getFunctionType()) && Objects.equal(((Function) obj).getParameters(), getParameters()) && Objects.equal(((Function) obj).getFunctionDescription(), getFunctionDescription()); } }
final Function function = new Function(functionUUID); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter); 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());
final Function function = new Function(uuid); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter); function.setFunctionDescription(functionFunctionDescription); Assert.assertNotNull("the function name shouldn't be null", function.getName()); Assert.assertEquals("the function names are not equal", functionName, function.getName()); Assert.assertNotNull("the function description shouldn't be null", function.getDescription()); Assert.assertEquals("the function descriptions are not equal", functionDescription, function.getDescription()); Assert.assertNotNull("the function description JSON shouldn't be null", function.getFunctionDescription()); final String functionDescriptionJSONString = objectMapper.writeValueAsString(function.getFunctionDescription()); Assert.assertNotNull("the function parameters shouldn't be null", function.getParameters()); Assert.assertEquals("the function parameters' size are not equal", 1, function.getParameters().size()); Assert.assertEquals("the function parameter '" + functionParameter + "' are not equal", functionParameter, function.getParameters().get(0));
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; }
if (transformationFunction != null && transformationFunction.getFunctionType().equals(FunctionType.Transformation)) { final String functionName = component.getFunction().getName();
function.setName(functionName); function.setDescription(functionDescription); function.setParameters(parameters); function.setFunctionDescription(metafactureFunctionDescriptionJSON);
switch (transformationFunction.getFunctionType()) {
public POJOCLASS createFunction(final String name, final String description, final LinkedList<String> parameters) throws Exception { // TODO: think about this? final String uuid = UUIDService.getUUID(pojoClassName); final POJOCLASS function = createNewObject(uuid); function.setName(name); function.setDescription(description); function.setParameters(parameters); return createAndCompareObject(function, function); }
if (expectedObject.getFunctionDescription() == null) { Assert.assertNull("the actual " + pojoClassName + " description JSON should be null", actualObject.getFunctionDescription()); Assert.assertNotNull("the actual " + pojoClassName + " description JSON shouldn't be null", actualObject.getFunctionDescription()); actualFunctionDescriptionJSONString = objectMapper.writeValueAsString(actualObject.getFunctionDescription()); } catch (final JsonProcessingException e) { expectedFunctionDescriptionJSONString = objectMapper.writeValueAsString(expectedObject.getFunctionDescription()); } catch (final JsonProcessingException e) { Assert.assertEquals("the " + pojoClassName + " parameters should be equal", expectedObject.getParameters(), actualObject.getParameters());
private Function replaceFunction(final Function existingFunction) throws DMPPersistenceException { if (existingFunction == null) { return null; } final String existingFunctionUuid = existingFunction.getUuid(); if (!persistentFunctionsCache.containsKey(existingFunctionUuid)) { final FunctionService functionService = functionPersistenceServiceProvider.get(); final Function persistentFunction = functionService.getObject(existingFunctionUuid); if (persistentFunction == null) { final String message = String.format("could not find function '%s' in the persistent functions cache nor in the metadata repository", existingFunctionUuid); LOG.error(message); throw new DMPPersistenceException(message); } persistentFunctionsCache.put(existingFunctionUuid, persistentFunction); } return persistentFunctionsCache.get(existingFunctionUuid); }
final Function function = new Function(functionUUID); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter); 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());
final String funtionName = component.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; } }
final Function function = new Function(functionUUID); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter); 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());
@Override public Function createAndPersistDefaultObject() throws Exception { final String functionName = "trim"; final String functionDescription = "trims leading and trailing whitespaces from a given string"; final String functionParameter1 = "inputString"; final String functionParameter2 = "parameter2"; final String functionFunctionDescriptionString = DMPPersistenceUtil.getResourceAsString("function_description.prettyprint.json"); Assert.assertNotNull("the function description JSON string shouldn't be null", functionFunctionDescriptionString); final ObjectNode functionFunctionDescription = objectMapper.readValue(functionFunctionDescriptionString, ObjectNode.class); Assert.assertNotNull("the function description JSON shouldn't be null", functionFunctionDescription); // TODO: think about this? final String functionUUID = UUIDService.getUUID(Function.class.getSimpleName()); final Function function = new Function(functionUUID); function.setName(functionName); function.setDescription(functionDescription); function.addParameter(functionParameter1); function.addParameter(functionParameter2); function.setFunctionDescription(functionFunctionDescription); return createAndCompareObject(function, function); }
/** * {@inheritDoc}<br/> * Updates the name, description, parameters and machine processable function description of the function. */ @Override protected POJOCLASS prepareObjectForUpdate(final POJOCLASS objectWithUpdates, final POJOCLASS object) { super.prepareObjectForUpdate(objectWithUpdates, object); object.setFunctionDescription(objectWithUpdates.getFunctionDescription()); object.setParameters(objectWithUpdates.getParameters()); return object; } }