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-742] check applications when remove site
Date Mon, 07 Nov 2016 09:26:43 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 9f64be00e -> 300c457c0


[EAGLE-742] check applications when remove site

Author: wujinhu <wujinhu920@126.com>

Closes #615 from wujinhu/EAGLE-742.


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

Branch: refs/heads/master
Commit: 300c457c0392c81f6498d0796caa964e2cbcecb2
Parents: 9f64be0
Author: wujinhu <wujinhu920@126.com>
Authored: Mon Nov 7 17:26:32 2016 +0800
Committer: wujinhu <wujinhu920@126.com>
Committed: Mon Nov 7 17:26:32 2016 +0800

----------------------------------------------------------------------
 .../exceptions/SiteDeleteException.java         | 32 ++++++++++++++++++++
 .../eagle/metadata/resource/SiteResource.java   | 23 ++++++++++++--
 2 files changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/300c457c/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/SiteDeleteException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/SiteDeleteException.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/SiteDeleteException.java
new file mode 100644
index 0000000..96e065c
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/SiteDeleteException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eagle.metadata.exceptions;
+
+public class SiteDeleteException extends Exception {
+    public SiteDeleteException(Throwable cause) {
+        super(cause);
+    }
+
+    public SiteDeleteException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public SiteDeleteException(String message) {
+        super(message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/300c457c/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
index 64e19a3..5780f3f 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
@@ -16,7 +16,9 @@
  */
 package org.apache.eagle.metadata.resource;
 
+import org.apache.eagle.metadata.exceptions.SiteDeleteException;
 import org.apache.eagle.metadata.model.SiteEntity;
+import org.apache.eagle.metadata.service.ApplicationEntityService;
 import org.apache.eagle.metadata.service.SiteEntityService;
 
 import javax.inject.Inject;
@@ -29,10 +31,13 @@ import java.util.Collection;
 @Singleton
 public class SiteResource {
     private final SiteEntityService siteEntityService;
+    private final ApplicationEntityService entityService;
 
     @Inject
-    public SiteResource(SiteEntityService siteEntityService){
+    public SiteResource(SiteEntityService siteEntityService,
+                        ApplicationEntityService applicationEntityService){
         this.siteEntityService = siteEntityService;
+        this.entityService = applicationEntityService;
     }
 
     @GET
@@ -63,14 +68,26 @@ public class SiteResource {
     @Path("/{siteId}")
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<SiteEntity> deleteSiteBySiteId(@PathParam("siteId") String
siteId){
-        return RESTResponse.async(()->siteEntityService.deleteBySiteId(siteId)).get();
+        return RESTResponse.async(()-> {
+            int appCount = entityService.findBySiteId(siteId).size();
+            if (appCount > 0) {
+                throw new SiteDeleteException("This site has enabled applications, remove
them first");
+            }
+            return siteEntityService.deleteBySiteId(siteId);
+        }).get();
     }
 
     @DELETE
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<SiteEntity> deleteSiteByUUID(UUIDRequest uuidRequest){
-        return RESTResponse.async(()->siteEntityService.deleteByUUID(uuidRequest.getUuid())).get();
+        return RESTResponse.async(()-> {
+            int appCount = entityService.findBySiteId(siteEntityService.getByUUID(uuidRequest.getUuid()).getSiteId()).size();
+            if (appCount > 0) {
+                throw new SiteDeleteException("This site has enabled applications, remove
them first");
+            }
+            return siteEntityService.deleteByUUID(uuidRequest.getUuid());
+        }).get();
     }
 
     @PUT


Mime
View raw message