eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinh...@apache.org
Subject incubator-eagle git commit: [EAGLE-700] API /policies/{policyId} throws exception if policy does not exist
Date Fri, 28 Oct 2016 08:07:17 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master cbf6d3c10 -> 38d46c8bb


[EAGLE-700] API /policies/{policyId} throws exception if policy does not exist

Author: wujinhu <wujinhu920@126.com>

Closes #579 from wujinhu/EAGLE-693.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/38d46c8b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/38d46c8b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/38d46c8b

Branch: refs/heads/master
Commit: 38d46c8bb549c9d6673c48f00a07bb82f57ad43a
Parents: cbf6d3c
Author: wujinhu <wujinhu920@126.com>
Authored: Fri Oct 28 16:07:12 2016 +0800
Committer: wujinhu <wujinhu920@126.com>
Committed: Fri Oct 28 16:07:12 2016 +0800

----------------------------------------------------------------------
 .../service/metadata/resource/MetadataResource.java      | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/38d46c8b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
index 05455f0..5110766 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
@@ -306,12 +306,9 @@ public class MetadataResource {
 
     @Path("/policies/{policyId}")
     @GET
-    public PolicyDefinition getPolicyByID(@PathParam("policyId") String policyId) {
-        Preconditions.checkNotNull(policyId,"policyId");
-        return dao.listPolicies().stream().filter(pc -> pc.getName().equals(policyId)).findAny().orElseGet(()
-> {
-            LOG.error("Policy (policyId " + policyId + ") not found");
-            throw new IllegalArgumentException("Policy (policyId " + policyId + ") not found");
-        });
+    public List<PolicyDefinition> getPolicyByID(@PathParam("policyId") String policyId)
{
+        Preconditions.checkNotNull(policyId, "policyId");
+        return dao.listPolicies().stream().filter(pc -> pc.getName().equals(policyId)).collect(Collectors.toList());
     }
 
     @Path("/policies/{policyId}/status/{status}")
@@ -319,7 +316,7 @@ public class MetadataResource {
     public OpResult updatePolicyStatusByID(@PathParam("policyId") String policyId, @PathParam("status")
PolicyDefinition.PolicyStatus status) {
         OpResult result = new OpResult();
         try {
-            PolicyDefinition policyDefinition = getPolicyByID(policyId);
+            PolicyDefinition policyDefinition = getPolicyByID(policyId).get(0);
             policyDefinition.setPolicyStatus(status);
             OpResult updateResult  = addPolicy(policyDefinition);
             result.code = updateResult.code;


Mime
View raw message