summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/main/java/org')
-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
3 files changed, 36 insertions, 43 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;
}
}