diff options
author | Guobiao Mo <guobiaomo@chinamobile.com> | 2018-05-08 14:31:26 -0700 |
---|---|---|
committer | Guobiao Mo <guobiaomo@chinamobile.com> | 2018-05-08 14:43:00 -0700 |
commit | 90ab2ddaebb6056b8b5d4306a614ade5d2f1b56f (patch) | |
tree | 66eb9a204a24c7dd78ac3f7ecb4a7cfa77343838 /engine-d/src/main/java | |
parent | 18bbb7722bccdf4fb572042eaf2ef43424d964de (diff) |
Fixed issue in extracting package name from rule
Issue-ID: HOLMES-133
Change-Id: I4db09e952e1e9dcba3d2d0398b26b4229aefef20
Signed-off-by: Guobiao Mo <guobiaomo@chinamobile.com>
Diffstat (limited to 'engine-d/src/main/java')
-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; + } } } |