usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/8] usergrid git commit: queue up deletes
Date Fri, 04 Sep 2015 13:42:01 GMT
Repository: usergrid
Updated Branches:
  refs/heads/two-dot-o-dev 4c406edd8 -> e25f2c39c


queue up deletes


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

Branch: refs/heads/two-dot-o-dev
Commit: 09e81836121d57e293d853bcb1c2e284bf8322aa
Parents: 4450504
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Sep 3 13:53:28 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Sep 3 13:53:28 2015 -0600

----------------------------------------------------------------------
 .../usergrid/corepersistence/CoreModule.java    |   2 +
 .../service/ApplicationService.java             |  31 ++++++
 .../service/ApplicationServiceImpl.java         |  60 +++++++++++
 .../apache/usergrid/rest/SystemResource.java    |  45 +++++++-
 .../usergrid/management/ManagementService.java  |   8 ++
 .../cassandra/ManagementServiceImpl.java        | 108 +++++++++++--------
 6 files changed, 204 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 1a7f794..c032dcb 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -167,6 +167,8 @@ public class CoreModule  extends AbstractModule {
 
         bind( ConnectionService.class).to( ConnectionServiceImpl.class);
 
+        bind( ApplicationService.class ).to( ApplicationServiceImpl.class );
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationService.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationService.java
new file mode 100644
index 0000000..18b1e60
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationService.java
@@ -0,0 +1,31 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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
+ *  *
+ *  *     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,
+ *  * 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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.service;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import rx.Observable;
+
+/**
+ * Encapsulation of application operations.
+ */
+public interface ApplicationService {
+
+    Observable<Integer> deleteAllEntities(ApplicationScope applicationScope);
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
new file mode 100644
index 0000000..0becab4
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
@@ -0,0 +1,60 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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
+ *  *
+ *  *     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,
+ *  * 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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.service;
+
+import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
+import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
+import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import rx.Observable;
+
+/**
+ * implementation of application operations
+ */
+public class ApplicationServiceImpl  implements ApplicationService{
+
+    private final AllEntityIdsObservable allEntityIdsObservable;
+    private final AsyncEventService asyncEventService;
+    private final EventBuilder eventBuilder;
+
+    public ApplicationServiceImpl(AllEntityIdsObservable allEntityIdsObservable, AsyncEventService
asyncEventService, EventBuilder eventBuilder){
+
+        this.allEntityIdsObservable = allEntityIdsObservable;
+        this.asyncEventService = asyncEventService;
+        this.eventBuilder = eventBuilder;
+    }
+    @Override
+    public Observable<Integer> deleteAllEntities(ApplicationScope applicationScope)
{
+        if(applicationScope.getApplication().getUuid().equals(CpNamingUtils.MANAGEMENT_APPLICATION_ID)){
+            throw new IllegalArgumentException("Can't delete from management app");
+        }
+
+        //EventBuilder eventBuilder = injector.getInstance(EventBuilder.class);
+        Observable appObservable  = Observable.just(applicationScope);
+
+
+        Observable<Integer> countObservable = allEntityIdsObservable.getEntities(appObservable)
+            //.map(entity -> eventBuilder.buildEntityDelete(applicationScope, entity.getId()).getEntitiesCompacted())
+            .doOnNext(entity -> asyncEventService.queueEntityDelete(applicationScope,
entity.getId()))
+            .count();
+        return countObservable;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index 26f1149..ace8fd0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -17,11 +17,7 @@
 package org.apache.usergrid.rest;
 
 
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
@@ -35,6 +31,12 @@ import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 
 import com.sun.jersey.api.json.JSONWithPadding;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
 
 @Path( "/system" )
 @Component
@@ -77,6 +79,39 @@ public class SystemResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireSystemAccess
+    @DELETE
+    @Path( "applications/{applicationId}" )
+    public JSONWithPadding clearApplication( @Context UriInfo ui,
+                                               @PathParam("applicationId") UUID applicationId,
+                                               @QueryParam( "confirmApplicationId" ) UUID
confirmApplicationId,
+                                              @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        if(confirmApplicationId == null || !confirmApplicationId.equals(applicationId)){
+            throw new IllegalArgumentException("please make confirmApplicationId equal to
applicationId");
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "clear application" );
+
+        logger.info( "clearing up application" );
+        AtomicInteger itemsDeleted = new AtomicInteger(0);
+        try {
+             management.deleteAllEntities(applicationId)
+             .doOnNext(count -> itemsDeleted.set(count))
+             .toBlocking().lastOrDefault(0);
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to delete all items, deleted: " + itemsDeleted.get(), e
);
+        }
+        Map<String,Object> data = new HashMap<>();
+        data.put("count",itemsDeleted.get());
+        response.setData(data);
+        response.setSuccess();
+        return new JSONWithPadding( response, callback );
+    }
+
 
     @Path( "migrate" )
     public MigrateResource migrate() {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 43c1b30..4b05b94 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -35,6 +35,7 @@ import org.apache.usergrid.security.shiro.PrincipalCredentialsToken;
 import org.apache.usergrid.services.ServiceResults;
 
 import com.google.common.collect.BiMap;
+import rx.Observable;
 
 
 public interface ManagementService {
@@ -338,4 +339,11 @@ public interface ManagementService {
     long getCollectionSize(final UUID applicationId, final String collectionName);
 
     Map<String,Long> getEachCollectionSize(final UUID applicationId);
+
+    /**
+     * will delete all entities
+     * @param applicationId
+     * @return
+     */
+    Observable<Integer> deleteAllEntities(UUID applicationId);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/09e81836/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 73f18b1..437b1a4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -18,14 +18,19 @@ package org.apache.usergrid.management.cassandra;
 
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.inject.Injector;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.text.StrSubstitutor;
 import org.apache.shiro.UnavailableSecurityManagerException;
+import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
+import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
+import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.corepersistence.service.AggregationService;
 import org.apache.usergrid.corepersistence.service.AggregationServiceFactory;
+import org.apache.usergrid.corepersistence.service.ApplicationService;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.exception.ConflictException;
 import org.apache.usergrid.locking.Lock;
@@ -34,6 +39,7 @@ import org.apache.usergrid.management.*;
 import org.apache.usergrid.management.exceptions.*;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Group;
@@ -63,6 +69,8 @@ import org.apache.usergrid.utils.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import rx.*;
+import rx.Observable;
 
 import java.nio.ByteBuffer;
 import java.util.*;
@@ -1749,7 +1757,7 @@ public class ManagementServiceImpl implements ManagementService {
             return null;
         }
 
-        final EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
 
         Results r = em.getSourceEntities(
             new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
@@ -1771,7 +1779,7 @@ public class ManagementServiceImpl implements ManagementService {
             return null;
         }
         final BiMap<UUID, String> applications = HashBiMap.create();
-        final EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
 
         // query for application_info entities
         final Results results = em.getTargetEntities(
@@ -1829,7 +1837,7 @@ public class ManagementServiceImpl implements ManagementService {
             return null;
         }
 
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
         em.createConnection( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ), ORG_APP_RELATIONSHIP,
appInfo );
 
         return applicationId;
@@ -1869,7 +1877,7 @@ public class ManagementServiceImpl implements ManagementService {
             return null;
         }
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-        Entity entity = em.get( new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId)
);
+        Entity entity = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
 
         if ( entity != null ) {
             return new ApplicationInfo( applicationId, entity.getName() );
@@ -1966,19 +1974,19 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public String getClientSecretForOrganization( UUID organizationId ) throws Exception
{
-        return getSecret( smf.getManagementAppId(), AuthPrincipalType.ORGANIZATION, organizationId
);
+        return getSecret(smf.getManagementAppId(), AuthPrincipalType.ORGANIZATION, organizationId);
     }
 
 
     @Override
     public String getClientIdForApplication( UUID applicationId ) {
-        return ClientCredentialsInfo.getClientIdForTypeAndUuid( AuthPrincipalType.APPLICATION,
applicationId );
+        return ClientCredentialsInfo.getClientIdForTypeAndUuid(AuthPrincipalType.APPLICATION,
applicationId);
     }
 
 
     @Override
     public String getClientSecretForApplication( UUID applicationId ) throws Exception {
-        return getSecret( smf.getManagementAppId(), AuthPrincipalType.APPLICATION, applicationId
);
+        return getSecret(smf.getManagementAppId(), AuthPrincipalType.APPLICATION, applicationId);
     }
 
 
@@ -2135,7 +2143,7 @@ public class ManagementServiceImpl implements ManagementService {
         em.update( user );
 
         // revoke all access tokens for the app
-        revokeAccessTokensForAppUser( applicationId, userId );
+        revokeAccessTokensForAppUser(applicationId, userId);
 
         return user;
     }
@@ -2181,7 +2189,7 @@ public class ManagementServiceImpl implements ManagementService {
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
         em.setProperty( new SimpleEntityRef( User.ENTITY_TYPE, userId ), "disabled", true
);
 
-        revokeAccessTokensForAdminUser( userId );
+        revokeAccessTokensForAdminUser(userId);
     }
 
 
@@ -2360,7 +2368,7 @@ public class ManagementServiceImpl implements ManagementService {
             confirmAdminUser( user.getUuid() );
             if ( newAdminUsersNeedSysAdminApproval() ) {
                 sendAdminUserConfirmedAwaitingActivationEmail( user );
-                sendSysAdminRequestAdminActivationEmail( user );
+                sendSysAdminRequestAdminActivationEmail(user);
                 return ActivationState.CONFIRMED_AWAITING_ACTIVATION;
             }
             else {
@@ -2381,7 +2389,7 @@ public class ManagementServiceImpl implements ManagementService {
             activateAdminUser( principal.getUuid() );
             UserInfo user = getAdminUserByUuid( principal.getUuid() );
             sendAdminUserActivatedEmail( user );
-            sendSysAdminNewAdminActivatedNotificationEmail( user );
+            sendSysAdminNewAdminActivatedNotificationEmail(user);
             return ActivationState.ACTIVATED;
         }
         return ActivationState.UNKNOWN;
@@ -2389,7 +2397,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendAdminUserConfirmationEmail( UserInfo user ) throws Exception {
-        String token = getConfirmationTokenForAdminUser( user.getUuid(), 0 );
+        String token = getConfirmationTokenForAdminUser(user.getUuid(), 0);
         String confirmation_url =
                 String.format( properties.getProperty( PROPERTIES_ADMIN_CONFIRMATION_URL
), user.getUuid().toString() )
                         + "?token=" + token;
@@ -2400,16 +2408,16 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendSysAdminRequestAdminActivationEmail( UserInfo user ) throws Exception
{
-        String token = getActivationTokenForAdminUser( user.getUuid(), 0 );
+        String token = getActivationTokenForAdminUser(user.getUuid(), 0);
         //TODO: admin specific email
         String activation_url =
                 String.format( properties.getProperty( PROPERTIES_ADMIN_ACTIVATION_URL ),
user.getUuid().toString() )
                         + "?token=" + token;
-        sendHtmlMail( properties, getAdminSystemEmail(),
-                properties.getProperty( PROPERTIES_MAILER_EMAIL ),
-                "Request For Admin User Account Activation " + user.getEmail(), appendEmailFooter(
-                emailMsg( hashMap( "user_email", user.getEmail() ).map( "activation_url",
activation_url ),
-                        PROPERTIES_EMAIL_SYSADMIN_ADMIN_ACTIVATION ) ) );
+        sendHtmlMail(properties, getAdminSystemEmail(),
+            properties.getProperty(PROPERTIES_MAILER_EMAIL),
+            "Request For Admin User Account Activation " + user.getEmail(), appendEmailFooter(
+                emailMsg(hashMap("user_email", user.getEmail()).map("activation_url", activation_url),
+                    PROPERTIES_EMAIL_SYSADMIN_ADMIN_ACTIVATION)));
     }
 
 
@@ -2445,14 +2453,14 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public void sendAdminUserEmail( UserInfo user, String subject, String html ) throws Exception
{
-        sendHtmlMail( properties, user.getDisplayEmailAddress(), properties.getProperty(
PROPERTIES_MAILER_EMAIL ),
-                subject, appendEmailFooter( html ) );
+        sendHtmlMail(properties, user.getDisplayEmailAddress(), properties.getProperty(PROPERTIES_MAILER_EMAIL),
+            subject, appendEmailFooter(html));
     }
 
 
     @Override
     public void activateOrganization( OrganizationInfo organization ) throws Exception {
-        activateOrganization( organization, true );
+        activateOrganization(organization, true);
     }
 
 
@@ -2554,7 +2562,7 @@ public class ManagementServiceImpl implements ManagementService {
             throw new TokenException( "Could not match token : " + token );
         }
 
-        tokens.revokeToken( token );
+        tokens.revokeToken(token);
     }
 
 
@@ -2577,14 +2585,14 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public User getAppUserByIdentifier( UUID applicationId, Identifier identifier ) throws
Exception {
-        EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager(applicationId);
         return em.get( em.getUserByIdentifier( identifier ), User.class );
     }
 
 
     @Override
     public void startAppUserPasswordResetFlow( UUID applicationId, User user ) throws Exception
{
-        String token = getPasswordResetTokenForAppUser( applicationId, user.getUuid() );
+        String token = getPasswordResetTokenForAppUser(applicationId, user.getUuid());
         String reset_url =
                 buildUserAppUrl( applicationId, properties.getProperty( PROPERTIES_USER_RESETPW_URL
), user, token );
         Map<String, String> pageContext = hashMap( "reset_url", reset_url )
@@ -2603,7 +2611,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public boolean newAppUsersNeedAdminApproval( UUID applicationId ) throws Exception {
-        EntityManager em = emf.getEntityManager( applicationId );
+        EntityManager em = emf.getEntityManager(applicationId);
         Boolean registration_requires_admin_approval = ( Boolean ) em
                 .getProperty( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId
),
                         REGISTRATION_REQUIRES_ADMIN_APPROVAL );
@@ -2681,7 +2689,7 @@ public class ManagementServiceImpl implements ManagementService {
             EntityManager em = emf.getEntityManager( applicationId );
             User user = em.get( userId, User.class );
             sendAppUserActivatedEmail( applicationId, user );
-            sendAdminNewAppUserActivatedNotificationEmail( applicationId, user );
+            sendAdminNewAppUserActivatedNotificationEmail(applicationId, user);
             return ActivationState.ACTIVATED;
         }
         return ActivationState.UNKNOWN;
@@ -2689,7 +2697,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     public void sendAppUserConfirmationEmail( UUID applicationId, User user ) throws Exception
{
-        String token = getConfirmationTokenForAppUser( applicationId, user.getUuid() );
+        String token = getConfirmationTokenForAppUser(applicationId, user.getUuid());
         String confirmation_url =
                 buildUserAppUrl( applicationId, properties.getProperty( PROPERTIES_USER_CONFIRMATION_URL
), user,
                         token );
@@ -2705,17 +2713,17 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     protected String buildUserAppUrl(UUID applicationId, String url, User user, String token)
throws Exception {
-        ApplicationInfo ai = getApplicationInfo( applicationId );
-        OrganizationInfo oi = getOrganizationForApplication( applicationId );
+        ApplicationInfo ai = getApplicationInfo(applicationId);
+        OrganizationInfo oi = getOrganizationForApplication(applicationId);
         return String.format( url, oi.getName(), StringUtils.stringOrSubstringAfterFirst(
ai.getName(), '/' ),
                 user.getUuid().toString() ) + "?token=" + token;
     }
 
 
     public void sendAdminRequestAppUserActivationEmail( UUID applicationId, User user ) throws
Exception {
-        String token = getActivationTokenForAppUser( applicationId, user.getUuid() );
+        String token = getActivationTokenForAppUser(applicationId, user.getUuid());
         String activation_url =
-                buildUserAppUrl( applicationId, properties.getProperty( PROPERTIES_USER_ACTIVATION_URL
), user, token );
+                buildUserAppUrl(applicationId, properties.getProperty(PROPERTIES_USER_ACTIVATION_URL),
user, token);
     /*
      * String activation_url = String.format(
      * properties.getProperty(PROPERTIES_USER_ACTIVATION_URL),
@@ -2752,7 +2760,7 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public void activateAppUser( UUID applicationId, UUID userId ) throws Exception {
         EntityManager em = emf.getEntityManager( applicationId );
-        em.setProperty( new SimpleEntityRef( User.ENTITY_TYPE, userId ), "activated", true
);
+        em.setProperty(new SimpleEntityRef(User.ENTITY_TYPE, userId), "activated", true);
     }
 
 
@@ -2769,10 +2777,10 @@ public class ManagementServiceImpl implements ManagementService {
         }
 
         EntityManager em = emf.getEntityManager( applicationId );
-        User user = em.get( userId, User.class );
+        User user = em.get(userId, User.class);
 
-        writeUserPassword( applicationId, user,
-                encryptionService.defaultEncryptedCredentials( newPassword, user.getUuid(),
applicationId ) );
+        writeUserPassword(applicationId, user,
+            encryptionService.defaultEncryptedCredentials(newPassword, user.getUuid(), applicationId));
     }
 
 
@@ -2786,19 +2794,19 @@ public class ManagementServiceImpl implements ManagementService {
             throw new IllegalArgumentException( "oldpassword and newpassword are both required"
);
         }
         // TODO load the user, send the hashType down to maybeSaltPassword
-        User user = emf.getEntityManager( applicationId ).get( userId, User.class );
+        User user = emf.getEntityManager( applicationId ).get(userId, User.class);
         if ( !verify( applicationId, user.getUuid(), oldPassword ) ) {
             throw new IncorrectPasswordException( "Old password does not match" );
         }
 
-        setAppUserPassword( applicationId, userId, newPassword );
+        setAppUserPassword(applicationId, userId, newPassword);
     }
 
 
     @Override
     public User verifyAppUserPasswordCredentials( UUID applicationId, String name, String
password ) throws Exception {
 
-        User user = findUserEntity( applicationId, name );
+        User user = findUserEntity(applicationId, name);
         if ( user == null ) {
             return null;
         }
@@ -2861,16 +2869,16 @@ public class ManagementServiceImpl implements ManagementService {
         }
         String pin = getCredentialsSecret( readUserPin( applicationId, userId, user.getType()
) );
 
-        sendHtmlMail( properties, user.getDisplayEmailAddress(), properties.getProperty(
PROPERTIES_MAILER_EMAIL ),
-                "Your app pin",
-                appendEmailFooter( emailMsg( hashMap( USER_PIN, pin ), PROPERTIES_EMAIL_USER_PIN_REQUEST
) ) );
+        sendHtmlMail(properties, user.getDisplayEmailAddress(), properties.getProperty(PROPERTIES_MAILER_EMAIL),
+            "Your app pin",
+            appendEmailFooter(emailMsg(hashMap(USER_PIN, pin), PROPERTIES_EMAIL_USER_PIN_REQUEST)));
     }
 
 
     @Override
     public User verifyAppUserPinCredentials( UUID applicationId, String name, String pin
) throws Exception {
 
-        User user = findUserEntity( applicationId, name );
+        User user = findUserEntity(applicationId, name);
         if ( user == null ) {
             return null;
         }
@@ -2883,7 +2891,7 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public void countAdminUserAction( UserInfo user, String action ) throws Exception {
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
         em.incrementAggregateCounters( user.getUuid(), null, null, "admin_logins", 1 );
     }
 
@@ -2907,7 +2915,7 @@ public class ManagementServiceImpl implements ManagementService {
 
         org.setProperties( props );
 
-        em.update( org );
+        em.update(org);
     }
 
 
@@ -2991,7 +2999,7 @@ public class ManagementServiceImpl implements ManagementService {
         EntityManager em = emf.getEntityManager( appId );
         Entity owner = em.get( new SimpleEntityRef("user", ownerId ));
         return ( Set<CredentialsInfo> ) em
-                .getDictionaryElementValue( owner, DICTIONARY_CREDENTIALS, USER_PASSWORD_HISTORY
);
+                .getDictionaryElementValue(owner, DICTIONARY_CREDENTIALS, USER_PASSWORD_HISTORY);
     }
 
 
@@ -3058,6 +3066,16 @@ public class ManagementServiceImpl implements ManagementService {
         return null;
     }
 
+    @Override
+    public Observable<Integer> deleteAllEntities(UUID applicationId){
+        if(applicationId.equals(CpNamingUtils.MANAGEMENT_APPLICATION_ID)){
+            throw new IllegalArgumentException("Can't delete from management app");
+        }
+
+        ApplicationService service = injector.getInstance(ApplicationService.class);
+        return service.deleteAllEntities(CpNamingUtils.getApplicationScope(applicationId));
+    }
+
     private String getProperty(String key) {
         String obj = properties.getProperty(key);
         if(StringUtils.isEmpty(obj))


Mime
View raw message