syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/3] git commit: [SYNCOPE-578] Missing role bulk delete implementation on core side
Date Thu, 30 Oct 2014 16:21:06 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X 8fc6e9e54 -> f44df5bfd
  refs/heads/master 7530ea211 -> 366395b12


[SYNCOPE-578] Missing role bulk delete implementation on core side


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

Branch: refs/heads/1_2_X
Commit: f44df5bfdf83112b5ecfa033a3710495e03df151
Parents: 8fc6e9e
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Oct 30 17:20:47 2014 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Oct 30 17:20:47 2014 +0100

----------------------------------------------------------------------
 .../syncope/common/services/RoleService.java    | 14 ++++++++++
 .../console/pages/BulkActionModalPage.java      |  6 ++++-
 .../syncope/console/rest/RoleRestClient.java    |  2 +-
 .../core/rest/controller/RoleController.java    | 27 +++++++++++++++++---
 .../syncope/core/services/RoleServiceImpl.java  |  6 +++++
 5 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/f44df5bf/common/src/main/java/org/apache/syncope/common/services/RoleService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/syncope/common/services/RoleService.java b/common/src/main/java/org/apache/syncope/common/services/RoleService.java
index bd2091a..1f4e45b 100644
--- a/common/src/main/java/org/apache/syncope/common/services/RoleService.java
+++ b/common/src/main/java/org/apache/syncope/common/services/RoleService.java
@@ -37,6 +37,8 @@ import org.apache.cxf.jaxrs.model.wadl.Descriptions;
 import org.apache.cxf.jaxrs.model.wadl.DocTarget;
 import org.apache.syncope.common.reqres.PagedResult;
 import org.apache.syncope.common.mod.RoleMod;
+import org.apache.syncope.common.reqres.BulkAction;
+import org.apache.syncope.common.reqres.BulkActionResult;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.types.ResourceAssociationActionType;
 import org.apache.syncope.common.types.ResourceDeassociationActionType;
@@ -296,4 +298,16 @@ public interface RoleService extends JAXRSService {
     Response bulkAssociation(@NotNull @PathParam("roleId") Long roleId,
             @NotNull @PathParam("type") ResourceAssociationActionType type,
             @NotNull List<ResourceName> resourceNames);
+
+    /**
+     * Executes the provided bulk action.
+     *
+     * @param bulkAction list of role ids against which the bulk action will be performed.
+     * @return Bulk action result
+     */
+    @POST
+    @Path("bulk")
+    @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+    @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+    BulkActionResult bulk(@NotNull BulkAction bulkAction);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/f44df5bf/console/src/main/java/org/apache/syncope/console/pages/BulkActionModalPage.java
----------------------------------------------------------------------
diff --git a/console/src/main/java/org/apache/syncope/console/pages/BulkActionModalPage.java
b/console/src/main/java/org/apache/syncope/console/pages/BulkActionModalPage.java
index c5d9524..f76570c 100644
--- a/console/src/main/java/org/apache/syncope/console/pages/BulkActionModalPage.java
+++ b/console/src/main/java/org/apache/syncope/console/pages/BulkActionModalPage.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import org.apache.syncope.common.reqres.BulkAction;
 import org.apache.syncope.common.reqres.BulkActionResult;
+import org.apache.syncope.console.commons.Constants;
 import org.apache.syncope.console.rest.BaseRestClient;
 import org.apache.syncope.console.wicket.ajax.markup.html.ClearIndicatingAjaxButton;
 import org.apache.syncope.console.wicket.markup.html.form.ActionLink;
@@ -83,6 +84,7 @@ public class BulkActionModalPage<T, S> extends BaseModalPage {
                 dataProvider,
                 Integer.MAX_VALUE).setVisible(items != null && !items.isEmpty()));
 
+        @SuppressWarnings("rawtypes")
         final ActionLinksPanel actionPanel = new ActionLinksPanel("actions", new Model(),
getPageReference());
         add(actionPanel);
 
@@ -128,7 +130,9 @@ public class BulkActionModalPage<T, S> extends BaseModalPage {
 
                         setResponsePage(new BulkActionResultModalPage<T, S>(window,
items, columns, res, idFieldName));
                     } catch (Exception e) {
-                        LOG.error("Operation {} not supported", bulkAction.getOperation(),
e);
+                        error(getString(Constants.ERROR)
+                                + ": Operation " + bulkAction.getOperation() + " not supported");
+                        feedbackPanel.refresh(target);
                     }
 
                 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/f44df5bf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
----------------------------------------------------------------------
diff --git a/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java b/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
index ed60460..e5a7587 100644
--- a/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
+++ b/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
@@ -108,7 +108,7 @@ public class RoleRestClient extends AbstractSubjectRestClient {
 
     @Override
     public BulkActionResult bulkAction(final BulkAction action) {
-        return getService(RoleRestClient.class).bulkAction(action);
+        return getService(RoleService.class).bulk(action);
     }
 
     public void unlink(final String etag, final long roleId, final List<StatusBean>
statuses) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/f44df5bf/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
b/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
index 0276122..71723b4 100644
--- a/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
+++ b/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
@@ -18,6 +18,8 @@
  */
 package org.apache.syncope.core.rest.controller;
 
+import static org.apache.syncope.core.rest.controller.AbstractController.LOG;
+
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -32,6 +34,8 @@ import org.apache.syncope.core.persistence.dao.search.SearchCond;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.types.ClientExceptionType;
 import org.apache.syncope.common.SyncopeClientException;
+import org.apache.syncope.common.reqres.BulkAction;
+import org.apache.syncope.common.reqres.BulkActionResult;
 import org.apache.syncope.common.types.SubjectType;
 import org.apache.syncope.core.persistence.beans.PropagationTask;
 import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
@@ -344,6 +348,26 @@ public class RoleController extends AbstractSubjectController<RoleTO,
RoleMod> {
         return roleTO;
     }
 
+    @PreAuthorize("(hasRole('ROLE_DELETE') and #bulkAction.operation == #bulkAction.operation.DELETE)")
+    public BulkActionResult bulk(final BulkAction bulkAction) {
+        BulkActionResult res = new BulkActionResult();
+
+        if (bulkAction.getOperation() == BulkAction.Type.DELETE) {
+            for (String roleId : bulkAction.getTargets()) {
+                try {
+                    res.add(delete(Long.valueOf(roleId)).getId(), BulkActionResult.Status.SUCCESS);
+                } catch (Exception e) {
+                    LOG.error("Error performing delete for role {}", roleId, e);
+                    res.add(roleId, BulkActionResult.Status.FAILURE);
+                }
+            }
+        } else {
+            LOG.warn("Unsupported bulk action: {}", bulkAction.getOperation());
+        }
+
+        return res;
+    }
+
     @PreAuthorize("hasRole('ROLE_UPDATE')")
     @Transactional(rollbackFor = { Throwable.class })
     @Override
@@ -426,9 +450,6 @@ public class RoleController extends AbstractSubjectController<RoleTO,
RoleMod> {
         return original;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected RoleTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException
{
         Long id = null;

http://git-wip-us.apache.org/repos/asf/syncope/blob/f44df5bf/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
index 3c6281a..91466a5 100644
--- a/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import javax.ws.rs.core.Response;
 import org.apache.syncope.common.mod.RoleMod;
+import org.apache.syncope.common.reqres.BulkAction;
 import org.apache.syncope.common.reqres.BulkActionResult;
 import org.apache.syncope.common.services.RoleService;
 import org.apache.syncope.common.reqres.PagedResult;
@@ -219,4 +220,9 @@ public class RoleServiceImpl extends AbstractServiceImpl implements RoleService
 
         return modificationResponse(res);
     }
+
+    @Override
+    public BulkActionResult bulk(final BulkAction bulkAction) {
+        return controller.bulk(bulkAction);
+    }
 }


Mime
View raw message