You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/04/07 15:20:51 UTC
[10/14] incubator-usergrid git commit: simplify delete app
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/USERGRID-533-create-app-test
Commit: 3ae2cbf1dc304288845ccc8ecdbe5476597e7394
Parents: cac6e4b
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Apr 6 17:50:12 2015 -0600
Committer: Shawn Feldman <sf...@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();