Repository: syncope
Updated Branches:
  refs/heads/2_0_X 6bc2cac16 -> f15408393
  refs/heads/master eb1cd3ff2 -> 08c1aa43b


[SYNCOPE-1262] Last matrix parameter still there


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

Branch: refs/heads/master
Commit: 7958ebd48fadf04ad4b6d4f8a10507b6d5d078a0
Parents: eb1cd3f
Author: Francesco Chicchiriccò <ilgro...@apache.org>
Authored: Tue Feb 13 17:15:41 2018 +0100
Committer: Francesco Chicchiriccò <ilgro...@apache.org>
Committed: Tue Feb 13 17:23:40 2018 +0100

----------------------------------------------------------------------
 .../panels/CamelRoutesDirectoryPanel.java       |  4 +--
 .../console/rest/CamelRoutesRestClient.java     |  8 +++---
 .../syncope/core/logic/CamelRouteLogic.java     | 19 +++++++++++--
 .../rest/api/service/CamelRouteService.java     | 16 ++++++-----
 .../rest/cxf/service/CamelRouteServiceImpl.java |  8 +++---
 .../syncope/fit/core/CamelRouteITCase.java      | 28 ++++++++++----------
 6 files changed, 51 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/panels/CamelRoutesDirectoryPanel.java
----------------------------------------------------------------------
diff --git 
a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/panels/CamelRoutesDirectoryPanel.java
 
b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/panels/CamelRoutesDirectoryPanel.java
index 007dda8..6b32959 100644
--- 
a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/panels/CamelRoutesDirectoryPanel.java
+++ 
b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/panels/CamelRoutesDirectoryPanel.java
@@ -115,7 +115,7 @@ public class CamelRoutesDirectoryPanel extends 
DirectoryPanel<
 
             @Override
             public void onClick(final AjaxRequestTarget target, final 
CamelRouteTO ignore) {
-                final CamelRouteTO route = 
restClient.read(model.getObject().getKey());
+                final CamelRouteTO route = restClient.read(anyTypeKind, 
model.getObject().getKey());
 
                 utilityModal.header(Model.of(route.getKey()));
                 utilityModal.setContent(new XMLEditorPanel(
@@ -126,7 +126,7 @@ public class CamelRoutesDirectoryPanel extends 
DirectoryPanel<
                     @Override
                     public void onSubmit(final AjaxRequestTarget target, final 
Form<?> form) {
                         try {
-                            restClient.update(route);
+                            restClient.update(anyTypeKind, route);
                             info(getString(Constants.OPERATION_SUCCEEDED));
                             modal.close(target);
                         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
----------------------------------------------------------------------
diff --git 
a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
 
b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
index 92d6118..aac5498 100644
--- 
a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
+++ 
b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
@@ -36,12 +36,12 @@ public class CamelRoutesRestClient extends BaseRestClient {
                 : Collections.<CamelRouteTO>emptyList();
     }
 
-    public CamelRouteTO read(final String key) {
-        return getService(CamelRouteService.class).read(key);
+    public CamelRouteTO read(final AnyTypeKind anyTypeKind, final String key) {
+        return getService(CamelRouteService.class).read(anyTypeKind, key);
     }
 
-    public void update(final CamelRouteTO routeTO) {
-        getService(CamelRouteService.class).update(routeTO);
+    public void update(final AnyTypeKind anyTypeKind, final CamelRouteTO 
routeTO) {
+        getService(CamelRouteService.class).update(anyTypeKind, routeTO);
     }
 
     public boolean isCamelEnabledFor(final AnyTypeKind anyTypeKind) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java
----------------------------------------------------------------------
diff --git 
a/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java
 
b/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java
index 0969e13..bb3d20b 100644
--- 
a/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java
+++ 
b/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java
@@ -27,10 +27,12 @@ import java.util.List;
 import org.apache.camel.component.metrics.routepolicy.MetricsRegistryService;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.CamelMetrics;
 import org.apache.syncope.common.lib.to.CamelRouteTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.CamelEntitlement;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
 import org.apache.syncope.core.persistence.api.dao.CamelRouteDAO;
 import org.apache.syncope.core.persistence.api.dao.NotFoundException;
 import org.apache.syncope.core.persistence.api.entity.CamelRoute;
@@ -67,21 +69,34 @@ public class CamelRouteLogic extends 
AbstractTransactionalLogic<CamelRouteTO> {
 
     @PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_READ + "')")
     @Transactional(readOnly = true)
-    public CamelRouteTO read(final String key) {
+    public CamelRouteTO read(final AnyTypeKind anyTypeKind, final String key) {
         CamelRoute route = routeDAO.find(key);
         if (route == null) {
             throw new NotFoundException("CamelRoute with key=" + key);
         }
 
+        if (route.getAnyTypeKind() != anyTypeKind) {
+            SyncopeClientException sce = 
SyncopeClientException.build(ClientExceptionType.InvalidRequest);
+            sce.getElements().add("Found " + anyTypeKind + ", expected " + 
route.getAnyTypeKind());
+            throw sce;
+        }
+
         return binder.getRouteTO(route);
     }
 
     @PreAuthorize("hasRole('" + CamelEntitlement.ROUTE_UPDATE + "')")
-    public void update(final CamelRouteTO routeTO) {
+    public void update(final AnyTypeKind anyTypeKind, final CamelRouteTO 
routeTO) {
         CamelRoute route = routeDAO.find(routeTO.getKey());
         if (route == null) {
             throw new NotFoundException("CamelRoute with key=" + 
routeTO.getKey());
         }
+
+        if (route.getAnyTypeKind() != anyTypeKind) {
+            SyncopeClientException sce = 
SyncopeClientException.build(ClientExceptionType.InvalidRequest);
+            sce.getElements().add("Found " + anyTypeKind + ", expected " + 
route.getAnyTypeKind());
+            throw sce;
+        }
+
         String originalContent = route.getContent();
 
         LOG.debug("Updating route {} with content {}", routeTO.getKey(), 
routeTO.getContent());

http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
----------------------------------------------------------------------
diff --git 
a/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
 
b/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
index 1de6313..9dd5bca 100644
--- 
a/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
+++ 
b/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
@@ -25,7 +25,6 @@ import java.util.List;
 import javax.validation.constraints.NotNull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
-import javax.ws.rs.MatrixParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
@@ -54,31 +53,36 @@ public interface CamelRouteService extends JAXRSService {
      * @return all routes for the given any type kind
      */
     @GET
+    @Path("{anyTypeKind}")
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    List<CamelRouteTO> list(@NotNull @MatrixParam("anyTypeKind") AnyTypeKind 
anyTypeKind);
+    List<CamelRouteTO> list(@NotNull @PathParam("anyTypeKind") AnyTypeKind 
anyTypeKind);
 
     /**
      * Read the route with the given key.
      *
+     * @param anyTypeKind any type kind
      * @param key route key
      * @return route with given key
      */
     @GET
-    @Path("{key}")
+    @Path("{anyTypeKind}/{key}")
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    CamelRouteTO read(@NotNull @PathParam("key") String key);
+    CamelRouteTO read(
+            @NotNull @PathParam("anyTypeKind") AnyTypeKind anyTypeKind,
+            @NotNull @PathParam("key") String key);
 
     /**
      * Update the given route.
      *
+     * @param anyTypeKind any type kind
      * @param route to be updated
      * @return an empty response if operation was successful
      */
     @PUT
-    @Path("{key}")
+    @Path("{anyTypeKind}/{key}")
     @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    Response update(@NotNull CamelRouteTO route);
+    Response update(@NotNull @PathParam("anyTypeKind") AnyTypeKind 
anyTypeKind, @NotNull CamelRouteTO route);
 
     /**
      * Restart the underlying Apache Camel context.

http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java
 
b/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java
index a7f6fbd..eb1db19 100644
--- 
a/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java
+++ 
b/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java
@@ -40,13 +40,13 @@ public class CamelRouteServiceImpl extends 
AbstractServiceImpl implements CamelR
     }
 
     @Override
-    public CamelRouteTO read(final String key) {
-        return logic.read(key);
+    public CamelRouteTO read(final AnyTypeKind anyTypeKind, final String key) {
+        return logic.read(anyTypeKind, key);
     }
 
     @Override
-    public Response update(final CamelRouteTO route) {
-        logic.update(route);
+    public Response update(final AnyTypeKind anyTypeKind, final CamelRouteTO 
route) {
+        logic.update(anyTypeKind, route);
         return Response.noContent().build();
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/7958ebd4/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
index 95516a8..9316ad2 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
@@ -59,19 +59,19 @@ public class CamelRouteITCase extends AbstractITCase {
         groupRoutes.forEach(route -> assertNotNull(route.getContent()));
     }
 
-    private CamelRouteTO doUpdate(final String key, final String content) {
-        CamelRouteTO route = camelRouteService.read(key);
+    private CamelRouteTO doUpdate(final AnyTypeKind anyTypeKind, final String 
key, final String content) {
+        CamelRouteTO route = camelRouteService.read(anyTypeKind, key);
         route.setContent(content);
-        camelRouteService.update(route);
+        camelRouteService.update(anyTypeKind, route);
         // getting new route definition
-        return camelRouteService.read(key);
+        return camelRouteService.read(anyTypeKind, key);
     }
 
     @Test
     public void update() {
         assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
 
-        CamelRouteTO oldRoute = camelRouteService.read("createUser");
+        CamelRouteTO oldRoute = camelRouteService.read(AnyTypeKind.USER, 
"createUser");
         assertNotNull(oldRoute);
         String routeContent = "<route id=\"createUser\">\n"
                 + "  <from uri=\"direct:createUser\"/>\n"
@@ -94,10 +94,10 @@ public class CamelRouteITCase extends AbstractITCase {
                 + "  </doTry>\n"
                 + "</route>";
         try {
-            CamelRouteTO route = doUpdate("createUser", routeContent);
+            CamelRouteTO route = doUpdate(AnyTypeKind.USER, "createUser", 
routeContent);
             assertEquals(routeContent, route.getContent());
         } finally {
-            doUpdate(oldRoute.getKey(), oldRoute.getContent());
+            doUpdate(AnyTypeKind.USER, oldRoute.getKey(), 
oldRoute.getContent());
         }
     }
 
@@ -105,7 +105,7 @@ public class CamelRouteITCase extends AbstractITCase {
     public void scriptingUpdate() {
         assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
 
-        CamelRouteTO oldRoute = camelRouteService.read("createUser");
+        CamelRouteTO oldRoute = camelRouteService.read(AnyTypeKind.USER, 
"createUser");
         // updating route content including new attribute management
 
         String routeContent = ""
@@ -135,7 +135,7 @@ public class CamelRouteITCase extends AbstractITCase {
                 + "    </doTry>\n"
                 + "  </route> ";
         try {
-            doUpdate("createUser", routeContent);
+            doUpdate(AnyTypeKind.USER, "createUser", routeContent);
 
             // creating new schema attribute for user
             PlainSchemaTO schemaTO = new PlainSchemaTO();
@@ -163,7 +163,7 @@ public class CamelRouteITCase extends AbstractITCase {
             assertNotNull(userTO);
             assertEquals("true", 
userTO.getPlainAttr("camelAttribute").get().getValues().get(0));
         } finally {
-            doUpdate(oldRoute.getKey(), oldRoute.getContent());
+            doUpdate(AnyTypeKind.USER, oldRoute.getKey(), 
oldRoute.getContent());
         }
     }
 
@@ -171,7 +171,7 @@ public class CamelRouteITCase extends AbstractITCase {
     public void issueSYNCOPE931() {
         assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
 
-        CamelRouteTO oldRoute = camelRouteService.read("createUser");
+        CamelRouteTO oldRoute = camelRouteService.read(AnyTypeKind.USER, 
"createUser");
         assertNotNull(oldRoute);
         String routeContent = "<route id=\"createUser\">\n"
                 + "  <from uri=\"direct:createUser\"/>\n"
@@ -196,7 +196,7 @@ public class CamelRouteITCase extends AbstractITCase {
 
         // Try to update a route with an incorrect propagation type
         try {
-            doUpdate("createUser", routeContent);
+            doUpdate(AnyTypeKind.USER, "createUser", routeContent);
             fail("Error expected on an incorrect propagation type");
         } catch (Exception ex) {
             // Expected
@@ -205,10 +205,10 @@ public class CamelRouteITCase extends AbstractITCase {
         // Now update the route again with the correct propagation type
         routeContent = routeContent.replaceFirst("create123", "create");
         try {
-            CamelRouteTO route = doUpdate("createUser", routeContent);
+            CamelRouteTO route = doUpdate(AnyTypeKind.USER, "createUser", 
routeContent);
             assertEquals(routeContent, route.getContent());
         } finally {
-            doUpdate(oldRoute.getKey(), oldRoute.getContent());
+            doUpdate(AnyTypeKind.USER, oldRoute.getKey(), 
oldRoute.getContent());
         }
     }
 

Reply via email to