]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-235: Added showRoles query param to /accounts/${csid} endpoint.
authorremillet <remillet@yahoo.com>
Wed, 24 Jan 2018 20:52:04 +0000 (12:52 -0800)
committerremillet <remillet@yahoo.com>
Wed, 24 Jan 2018 20:52:04 +0000 (12:52 -0800)
services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java

index aa0aa2793c4520cefe740cd544ff8debf35e4381..6f9f6d9c0b633c3456db491c4bd32ba7b8da4bbd 100644 (file)
@@ -48,6 +48,7 @@ public class AccountClient extends AbstractServiceClientImpl<AccountsCommonList,
     public final static String EMAIL_QUERY_PARAM = "email";
        public static final String PASSWORD_RESET_TOKEN_QP = "token";
        public static final String PASSWORD_RESET_PASSWORD_QP = "password";
+       public static final String INCLUDE_ROLES_QP = "showRoles";
 
        public AccountClient() throws Exception {
                super();
index ed4fc0a9bc3f9e69bad39ceb819cab01321c433d..5049b65038fb92c99c8c165c7580e6e85851c609 100644 (file)
@@ -35,12 +35,16 @@ import org.collectionspace.services.account.AccountListItem;
 import org.collectionspace.services.account.AccountRoleSubResource;
 import org.collectionspace.services.account.Status;
 import org.collectionspace.services.authorization.AccountRole;
+import org.collectionspace.services.authorization.PermissionRole;
+import org.collectionspace.services.authorization.PermissionRoleSubResource;
 import org.collectionspace.services.authorization.SubjectType;
 import org.collectionspace.services.account.RoleValue;
 import org.collectionspace.services.client.AccountClient;
 import org.collectionspace.services.client.AccountRoleFactory;
+import org.collectionspace.services.client.RoleClient;
 import org.collectionspace.services.common.storage.TransactionContext;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
+import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
@@ -185,12 +189,23 @@ public class AccountDocumentHandler
         getServiceContext().setOutput(getCommonPartList());
     }
 
-    @Override
-    public AccountsCommon extractCommonPart(
-            DocumentWrapper<AccountsCommon> wrapDoc)
-            throws Exception {
-        return wrapDoc.getWrappedObject();
-    }
+       @SuppressWarnings("unchecked")
+       @Override
+       public AccountsCommon extractCommonPart(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+               AccountsCommon account = wrapDoc.getWrappedObject();
+               
+               String includeRolesQueryParamValue = (String) getServiceContext().getQueryParams().getFirst(AccountClient.INCLUDE_ROLES_QP);
+               boolean includeRoles = Tools.isTrue(includeRolesQueryParamValue);
+               if (includeRoles) {
+                       AccountRoleSubResource accountRoleResource = new AccountRoleSubResource(
+                                       AccountRoleSubResource.ACCOUNT_ACCOUNTROLE_SERVICE);
+                       AccountRole accountRole = accountRoleResource.getAccountRole(getServiceContext(), account.getCsid(),
+                                       SubjectType.ROLE);
+                       account.setRole(AccountRoleFactory.convert(accountRole.getRole()));
+               }
+               
+               return wrapDoc.getWrappedObject();
+       }
 
     @Override
     public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)