usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [1/2] incubator-usergrid git commit: simplify delete app
Date Tue, 07 Apr 2015 00:22:23 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-dev cac6e4b58 -> 3be95f98d


simplify delete app


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3ae2cbf1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3ae2cbf1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3ae2cbf1

Branch: refs/heads/two-dot-o-dev
Commit: 3ae2cbf1dc304288845ccc8ecdbe5476597e7394
Parents: cac6e4b
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Mon Apr 6 17:50:12 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Mon Apr 6 17:50:12 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 66 ++++++++++----------
 1 file changed, 33 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ae2cbf1/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 80aaafe..f48f6e9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -310,44 +310,44 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
         final Id managementAppId = new SimpleId(app.getUuid(), app.getType());
         final ApplicationScope managementAppScope = new ApplicationScopeImpl(managementAppId);
         final GraphManager managementGraphManager = managerCache.getGraphManager(managementAppScope);
-
-        Entity appInfoToDelete = managementEm.get(applicationId);
-        final Id deletedAppId = new SimpleId(appInfoToDelete.getUuid(), appInfoToDelete.getType());
+        final Id deletedAppId = new SimpleId(applicationId, CpNamingUtils.APPLICATION_INFO);
         final ApplicationScope deletedAppScope = new ApplicationScopeImpl(deletedAppId);
-        final ApplicationEntityIndex aei = entityIndexFactory.createApplicationEntityIndex(deletedAppScope);
-
-        // ensure that there is not already a deleted app with the same name
-
-        final EntityRef alias = managementEm.getAlias(
-            CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
-        if (alias != null) {
-            throw new ConflictException("Cannot delete app with same name as already deleted
app");
-        }
-        // make a copy of the app to delete application_info entity
-        // and put it in a deleted_application_info collection
-
-        final Entity deletedApp = managementEm.create(
-            CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
 
-        // copy its connections too
+        Entity appInfoToDelete = managementEm.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO,
applicationId));
+        Observable copyConnections = Observable.empty();
+        if(appInfoToDelete!=null) {
+            // ensure that there is not already a deleted app with the same name
 
-        final Set<String> connectionTypes = managementEm.getConnectionTypes(appInfoToDelete);
-        Observable copyConnections = Observable.from(connectionTypes).doOnNext(connType ->
{
-            try {
-                final Results connResults =
-                    managementEm.getConnectedEntities(appInfoToDelete, connType, null, Query.Level.ALL_PROPERTIES);
-                connResults.getEntities().forEach(entity -> {
-                    try {
-                        managementEm.createConnection(deletedApp, connType, entity);
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
-                    }
-                });
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+            final EntityRef alias = managementEm.getAlias(
+                CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
+            if (alias != null) {
+                throw new ConflictException("Cannot delete app with same name as already
deleted app");
             }
-        });
+            // make a copy of the app to delete application_info entity
+            // and put it in a deleted_application_info collection
 
+            final Entity deletedApp = managementEm.create(
+                CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
+            // copy its connections too
+
+            final Set<String> connectionTypes = managementEm.getConnectionTypes(appInfoToDelete);
+            copyConnections = Observable.from(connectionTypes).doOnNext(connType -> {
+                try {
+                    final Results connResults =
+                        managementEm.getConnectedEntities(appInfoToDelete, connType, null,
Query.Level.ALL_PROPERTIES);
+                    connResults.getEntities().forEach(entity -> {
+                        try {
+                            managementEm.createConnection(deletedApp, connType, entity);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                    });
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+        final ApplicationEntityIndex aei = entityIndexFactory.createApplicationEntityIndex(deletedAppScope);
         final Observable deleteNodeGraph = managementGraphManager.deleteNode(deletedAppId,
Long.MAX_VALUE);
         final Observable deleteAppFromIndex = aei.deleteApplication();
 


Mime
View raw message