diff options
author | 2018-07-14 02:32:01 +0000 | |
---|---|---|
committer | 2018-07-14 02:32:01 +0000 | |
commit | 0420b71eb8b07a2e32b2055305ec9c764a4ca8dc (patch) | |
tree | d32e45dddbe1709eba87d20530c43d7b4b607288 /engine-d | |
parent | 8490a957d5200419a0b8e60c35d8b2c7ecb1ba6e (diff) | |
parent | 90ab2ddaebb6056b8b5d4306a614ade5d2f1b56f (diff) |
Merge "Fixed issue in extracting package name from rule"
Diffstat (limited to 'engine-d')
-rw-r--r-- | engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java index b9875da..64d727e 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java @@ -24,6 +24,9 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.DELETE; @@ -51,7 +54,8 @@ import org.onap.holmes.engine.response.CorrelationRuleResponse; @Produces(MediaType.APPLICATION_JSON) @Slf4j public class EngineResources { - + private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*"); + @Inject DroolsEngine droolsEngine; @@ -70,6 +74,10 @@ public class EngineResources { Locale locale = LanguageUtil.getLocale(httpRequest); try { String packageName = getPackageName(deployRuleRequest.getContent()); + if(packageName == null) { + throw new CorrelationException("Could not find package name in rule: "+deployRuleRequest.getContent()); + } + DmaapService.loopControlNames .put(packageName, deployRuleRequest.getLoopControlName()); String packageNameRet = droolsEngine.deployRule(deployRuleRequest, locale); @@ -79,8 +87,8 @@ public class EngineResources { DmaapService.loopControlNames .put(packageNameRet, deployRuleRequest.getLoopControlName()); } - log.info("Rule deployed. Package name: " + packageName); - crResponse.setPackageName(packageName); + log.info("Rule deployed. Package name: " + packageNameRet); + crResponse.setPackageName(packageNameRet); } catch (CorrelationException correlationException) { log.error(correlationException.getMessage(), correlationException); @@ -131,10 +139,14 @@ public class EngineResources { } return true; } - + private String getPackageName(String contents){ - String ret = contents.trim(); - ret = ret.substring(7, ret.indexOf("import")).trim(); - return ret.endsWith(";") ? ret.substring(0, ret.length() - 1) : ret; + Matcher m = packagePattern.matcher(contents); + + if (m.find( )) { + return m.group(1); + }else { + return null; + } } } |