summaryrefslogtreecommitdiffstats
path: root/rulemgt/src
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java8
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java21
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java50
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java5
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java3
5 files changed, 41 insertions, 46 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
index 17903ab..aab6dc5 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
@@ -15,20 +15,18 @@
*/
package org.onap.holmes.rulemgt.bean.response;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
-@JsonInclude(JsonInclude.Include.ALWAYS)
@Getter
@Setter
public class RuleQueryListResponse {
- @JsonProperty(value = "rules")
+ @SerializedName(value = "rules")
private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();
- @JsonProperty(value = "totalcount")
+ @SerializedName(value = "totalcount")
private int totalCount;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
index 97da7ee..d0513ca 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
@@ -13,7 +13,6 @@
*/
package org.onap.holmes.rulemgt.dcae;
-import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -27,7 +26,7 @@ import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.JacksonUtil;
+import org.onap.holmes.common.utils.GsonUtil;
import org.onap.holmes.common.utils.Md5Util;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
@@ -56,7 +55,7 @@ public class DcaeConfigurationPolling implements Runnable {
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevResult && prevConfigMd5.equals(md5)){
+ if (prevResult && prevConfigMd5.equals(md5)) {
log.info("Operation aborted due to identical Configurations.");
return;
}
@@ -64,8 +63,6 @@ public class DcaeConfigurationPolling implements Runnable {
prevResult = false;
} catch (CorrelationException e) {
log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
- } catch (JsonProcessingException e) {
- log.info("Failed to generate the MD5 information for new configurations.", e);
}
if (dcaeConfigurations != null) {
RuleQueryListResponse ruleQueryListResponse = getAllCorrelationRules();
@@ -87,17 +84,13 @@ public class DcaeConfigurationPolling implements Runnable {
.readEntity(RuleQueryListResponse.class);
}
- private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations) throws CorrelationException {
+ private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations)
+ throws CorrelationException {
boolean suc = false;
for (Rule rule : dcaeConfigurations.getDefaultRules()) {
RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule);
Client client = ClientBuilder.newClient(new ClientConfig());
- String content = null;
- try {
- content = JacksonUtil.beanToJson(ruleCreateRequest);
- } catch (JsonProcessingException e) {
- throw new CorrelationException("Failed to convert the message object to a json string.", e);
- }
+ String content = GsonUtil.beanToJson(ruleCreateRequest);
WebTarget webTarget = client.target(url);
Response response = webTarget.request(MediaType.APPLICATION_JSON)
.put(Entity.entity(content, MediaType.APPLICATION_JSON));
@@ -109,8 +102,8 @@ public class DcaeConfigurationPolling implements Runnable {
return suc;
}
- private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs){
- ruleResult4APIs.forEach(correlationRule ->{
+ private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) {
+ ruleResult4APIs.forEach(correlationRule -> {
Client client = ClientBuilder.newClient(new ClientConfig());
WebTarget webTarget = client.target(url + "/" + correlationRule.getRuleId());
webTarget.request(MediaType.APPLICATION_JSON).delete();
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
index dc21e0d..041377f 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
-import java.io.IOException;
import java.util.Locale;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
@@ -39,7 +38,7 @@ import net.sf.json.JSONObject;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
-import org.onap.holmes.common.utils.JacksonUtil;
+import org.onap.holmes.common.utils.GsonUtil;
import org.onap.holmes.common.utils.LanguageUtil;
import org.onap.holmes.common.utils.UserUtil;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
@@ -68,9 +67,10 @@ public class RuleMgtResources {
response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "The request entity of the HTTP call, which comprises \"rulename\"(required), "
- + "\"loopcontrolname\"(required), \"content\"(required), \"enabled\"(required) "
- + "and \"description\"(optional)", required = true)
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"rulename\"(required), "
+ + "\"loopcontrolname\"(required), \"content\"(required), \"enabled\"(required) "
+ + "and \"description\"(optional)", required = true)
RuleCreateRequest ruleCreateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
@@ -90,13 +90,15 @@ public class RuleMgtResources {
@ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleid\"(required), "
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ @ApiParam(value =
+ "The request entity of the HTTP call, which comprises \"ruleid\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
RuleUpdateRequest ruleUpdateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
try {
- ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
+ ruleChangeResponse = ruleMgtWrapper
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");
return ruleChangeResponse;
} catch (CorrelationException e) {
@@ -128,9 +130,10 @@ public class RuleMgtResources {
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
@Timed
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value = "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
- + "\"rulename\"(optional), \"creator\"(optional), "
- + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
+ @ApiParam(value =
+ "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "
+ + "\"rulename\"(optional), \"creator\"(optional), "
+ + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
required = false) @QueryParam("queryrequest") String ruleQueryRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleQueryListResponse ruleQueryListResponse;
@@ -138,7 +141,8 @@ public class RuleMgtResources {
try {
ruleQueryListResponse = ruleMgtWrapper
.getCorrelationRuleByCondition(ruleQueryCondition);
- log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));
+ log.info("query rule successful by condition:" + JSONObject
+ .fromObject(ruleQueryCondition));
return ruleQueryListResponse;
} catch (CorrelationException e) {
log.error("query rule failed,cause query condition conversion failure", e);
@@ -149,18 +153,16 @@ public class RuleMgtResources {
private RuleQueryCondition getRuleQueryCondition(String queryRequest,
HttpServletRequest request) {
Locale locale = LanguageUtil.getLocale(request);
- try {
- RuleQueryCondition ruleQueryCondition = JacksonUtil
- .jsonToBean(queryRequest, RuleQueryCondition.class);
- if (queryRequest == null) {
- ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);
- } else if (queryRequest.indexOf("enabled") == -1) {
- ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);
+
+ RuleQueryCondition ruleQueryCondition = GsonUtil.jsonToBean(queryRequest, RuleQueryCondition.class);
+ if (queryRequest == null) {
+ if(ruleQueryCondition==null){
+ ruleQueryCondition = new RuleQueryCondition();
}
- return ruleQueryCondition;
- } catch (IOException e) {
- log.warn("queryRequest convert to json failed", e);
- throw ExceptionUtil.buildExceptionResponse("The request format is invalid!");
+ ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);
+ } else if (queryRequest.indexOf("enabled") == -1) {
+ ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);
}
+ return ruleQueryCondition;
}
}
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
index a330306..8d16198 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
@@ -21,6 +21,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
+import com.alibaba.fastjson.JSONException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.ProcessingException;
import org.junit.Before;
@@ -57,13 +58,13 @@ public class DcaeConfigurationPollingTest {
public void testDaceConfigurationPolling_getDcaeConfigurations_exception() throws Exception {
PowerMock.resetAll();
thrown.expect(CorrelationException.class);
- thrown.expectMessage("host");
+ thrown.expectMessage("syntax error, pos 1");
PowerMockito.mockStatic(MicroServiceConfig.class);
when(MicroServiceConfig.getServiceConfigInfoFromCBS("holmes-rule-mgmt"))
.thenReturn("host");
PowerMock.createMock(DcaeConfigurationParser.class);
PowerMock.expectPrivate(DcaeConfigurationParser.class, "parse", "host")
- .andThrow(new CorrelationException("tests")).anyTimes();
+ .andThrow(new CorrelationException("")).anyTimes();
PowerMock.replayAll();
Whitebox.invokeMethod(daceConfigurationPolling, "getDcaeConfigurations");
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
index 692cc19..0c3bd89 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java
@@ -16,6 +16,7 @@
package org.onap.holmes.rulemgt.resources;
+import com.google.gson.JsonSyntaxException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import org.easymock.EasyMock;
@@ -147,7 +148,7 @@ public class RuleMgtResourcesTest {
@Test
public void getCorrelationRules_param_translate_exception() {
- thrown.expect(WebApplicationException.class);
+ thrown.expect(JsonSyntaxException.class);
String queryRequest = "this is error param";
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);