You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/02/13 21:26:41 UTC

[3/4] syncope git commit: [SYNCOPE-1262] Last matrix parameter still there

[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/f1540839
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/f1540839
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/f1540839

Branch: refs/heads/2_0_X
Commit: f154083938cf76e2f0835573c2c1a7d4614bcff5
Parents: 6bc2cac
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Feb 13 17:15:41 2018 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Feb 13 18:59:47 2018 +0100

----------------------------------------------------------------------
 .../syncope/common/lib/types/AuditElements.java |  7 +++--
 .../common/lib/types/AuditLoggerName.java       |  6 +----
 .../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 ++++++++++----------
 8 files changed, 55 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/f1540839/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditElements.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditElements.java b/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditElements.java
index 16f6d69..32e87a2 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditElements.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditElements.java
@@ -20,7 +20,6 @@ package org.apache.syncope.common.lib.types;
 
 import java.io.Serializable;
 import javax.xml.bind.annotation.XmlEnum;
-import org.apache.commons.lang3.StringUtils;
 
 public final class AuditElements implements Serializable {
 
@@ -33,12 +32,12 @@ public final class AuditElements implements Serializable {
     @XmlEnum
     public enum EventCategoryType {
 
-        LOGIC(StringUtils.EMPTY),
-        TASK(StringUtils.EMPTY),
+        LOGIC("LOGIC"),
+        TASK("TASK"),
         PROPAGATION("PropagationTask"),
         PULL("PullTask"),
         PUSH("PushTask"),
-        CUSTOM(StringUtils.EMPTY);
+        CUSTOM("CUSTOM");
 
         private final String value;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/f1540839/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditLoggerName.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditLoggerName.java b/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditLoggerName.java
index a595e9b..31622ec 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditLoggerName.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/types/AuditLoggerName.java
@@ -185,11 +185,7 @@ public class AuditLoggerName extends AbstractBaseBean {
 
         eventBuilder.append('[');
         if (type != null) {
-            if (StringUtils.isNotBlank(type.toString())) {
-                eventBuilder.append(type.toString());
-            } else {
-                eventBuilder.append(type.name());
-            }
+            eventBuilder.append(type.toString());
         }
         eventBuilder.append("]:[");
         if (StringUtils.isNotBlank(category)) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/f1540839/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 f6f37a6..353985f 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/f1540839/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/f1540839/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 2856daf..64a1914 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
@@ -30,10 +30,12 @@ import java.util.Map;
 import org.apache.commons.collections4.ComparatorUtils;
 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;
@@ -70,21 +72,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/f1540839/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 00a14d1..3e0913a 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
@@ -24,7 +24,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;
@@ -52,31 +51,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/f1540839/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/f1540839/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 4f4f475..1b9f7a5 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
@@ -63,19 +63,19 @@ public class CamelRouteITCase extends AbstractITCase {
         }
     }
 
-    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() {
         Assume.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"
@@ -98,10 +98,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());
         }
     }
 
@@ -109,7 +109,7 @@ public class CamelRouteITCase extends AbstractITCase {
     public void scriptingUpdate() {
         Assume.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 = ""
@@ -139,7 +139,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();
@@ -167,7 +167,7 @@ public class CamelRouteITCase extends AbstractITCase {
             assertNotNull(userTO);
             assertEquals("true", userTO.getPlainAttr("camelAttribute").getValues().get(0));
         } finally {
-            doUpdate(oldRoute.getKey(), oldRoute.getContent());
+            doUpdate(AnyTypeKind.USER, oldRoute.getKey(), oldRoute.getContent());
         }
     }
 
@@ -175,7 +175,7 @@ public class CamelRouteITCase extends AbstractITCase {
     public void issueSYNCOPE931() {
         Assume.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"
@@ -200,7 +200,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);
             Assert.fail("Error expected on an incorrect propagation type");
         } catch (Exception ex) {
             // Expected
@@ -209,10 +209,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());
         }
     }