/** Start transformation service. */ protected void initTransformService() { if (getTransformationService() != null || StringUtils.isBlank(getTransformationServiceName())) { return; } BundleContext context = MqttActivator.getContext(); transformationService = TransformationHelper.getTransformationService(context, getTransformationServiceName()); if (transformationService == null) { logger.debug("No transformation service found for {}", getTransformationServiceName()); } }
protected String transformResponse(String transformation, String response) { String transformedResponse; try { String[] parts = splitTransformationConfig(transformation); String transformationType = parts[0]; String transformationFunction = parts[1]; TransformationService transformationService = TransformationHelper.getTransformationService( TCPActivator.getContext(), transformationType); if (transformationService != null) { transformedResponse = transformationService.transform(transformationFunction, response); } else { transformedResponse = response; logger.warn( "couldn't transform response because transformationService of type '{}' is unavailable", transformationType); } } catch (TransformationException te) { logger.error( "transformation throws exception [transformation=" + transformation + ", response=" + response + "]", te); // in case of an error we return the response without any // transformation transformedResponse = response; } logger.debug("transformed response is '{}'", transformedResponse); return transformedResponse; }
/** * Resolves LCN commands (with mappings) to plain commands. * * @param lcnTarget the target or a mapping * @param openHABcmd the command send by openHAB * @return the resolved result (can be null) */ private static String resolveMappings(String lcnTarget, String openHABcmd) { String result = null; Matcher matcher = PATTERN_MAPPING.matcher(lcnTarget); if (!matcher.matches()) { result = lcnTarget; } else { matcher.reset(); matcher.find(); String s1 = matcher.group(1); String s2 = matcher.group(2); TransformationService transformationService = TransformationHelper.getTransformationService(LcnBindingActivator.getContext(), s1); if (transformationService != null) { try { result = transformationService.transform(s2, openHABcmd); } catch (TransformationException e) { result = lcnTarget; } } else { result = lcnTarget; } } return result; }