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); }
/** * Initialises the function description from the string that holds the serialised JSON object of the function description. * * @param fromScratch flag that indicates, whether the function description should be initialised from scratch or not */ private void initFunctionDescription(final boolean fromScratch) { if (functionDescription == null && !functionDescriptionInitialized) { if (functionDescriptionString == null) { Function.LOG.debug("function description JSON string is null"); if (fromScratch) { functionDescription = new ObjectNode(DMPPersistenceUtil.getJSONFactory()); } functionDescriptionInitialized = true; return; } try { functionDescription = DMPPersistenceUtil.getJSON(StringUtils.toEncodedString(functionDescriptionString, Charsets.UTF_8)); } catch (final DMPException e) { Function.LOG.debug("couldn't parse function description JSON string for function '" + getUuid() + "'"); } functionDescriptionInitialized = true; } }
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; } }
actualFunctionsMap.put(actualFunction.getUuid(), actualFunction);