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 2015/01/26 18:13:31 UTC

[5/9] syncope git commit: [SYNCOPE-630] Removing unused ResourceService#list(Long) and QueryResourceInfoComparator

[SYNCOPE-630] Removing unused ResourceService#list(Long) and QueryResourceInfoComparator


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

Branch: refs/heads/master
Commit: 60a62434e16a3a811d8f549e2d4351633667e90c
Parents: 4bdf7d7
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Mon Jan 26 17:51:45 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Jan 26 17:51:45 2015 +0100

----------------------------------------------------------------------
 .../common/services/ResourceService.java        |  11 --
 .../rest/controller/ResourceController.java     |  17 +--
 .../rest/utils/QueryResourceInfoComparator.java | 114 -------------------
 .../core/services/ResourceServiceImpl.java      |   7 +-
 core/src/main/resources/restContext.xml         |   3 -
 .../syncope/core/rest/ConnectorTestITCase.java  |  25 ++--
 .../syncope/core/rest/ResourceTestITCase.java   |  13 +--
 7 files changed, 22 insertions(+), 168 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/common/src/main/java/org/apache/syncope/common/services/ResourceService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/syncope/common/services/ResourceService.java b/common/src/main/java/org/apache/syncope/common/services/ResourceService.java
index f4d19f6..dae4622 100644
--- a/common/src/main/java/org/apache/syncope/common/services/ResourceService.java
+++ b/common/src/main/java/org/apache/syncope/common/services/ResourceService.java
@@ -23,7 +23,6 @@ import javax.validation.constraints.NotNull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 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;
@@ -94,16 +93,6 @@ public interface ResourceService extends JAXRSService {
     List<ResourceTO> list();
 
     /**
-     * Returns a list of resources using matching connector instance id.
-     *
-     * @param connInstanceId Connector id to filter for resources
-     * @return resources using matching connector instance id
-     */
-    @GET
-    @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    List<ResourceTO> list(@NotNull @MatrixParam("connectorId") Long connInstanceId);
-
-    /**
      * Creates a new resource.
      *
      * @param resourceTO Resource to be created

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java b/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java
index b61afcc..d3dc9d7 100644
--- a/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java
+++ b/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java
@@ -38,7 +38,6 @@ import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
 import org.apache.syncope.core.persistence.beans.AbstractSubject;
 import org.apache.syncope.core.persistence.beans.ConnInstance;
 import org.apache.syncope.core.persistence.beans.ExternalResource;
-import org.apache.syncope.core.persistence.dao.ConnInstanceDAO;
 import org.apache.syncope.core.persistence.dao.NotFoundException;
 import org.apache.syncope.core.persistence.dao.ResourceDAO;
 import org.apache.syncope.core.persistence.dao.RoleDAO;
@@ -66,9 +65,6 @@ public class ResourceController extends AbstractTransactionalController<Resource
     private ResourceDAO resourceDAO;
 
     @Autowired
-    private ConnInstanceDAO connInstanceDAO;
-
-    @Autowired
     private UserDAO userDAO;
 
     @Autowired
@@ -171,17 +167,8 @@ public class ResourceController extends AbstractTransactionalController<Resource
 
     @PreAuthorize("isAuthenticated()")
     @Transactional(readOnly = true)
-    public List<ResourceTO> list(final Long connInstanceId) {
-        List<ExternalResource> resources;
-
-        if (connInstanceId == null) {
-            resources = resourceDAO.findAll();
-        } else {
-            ConnInstance connInstance = connInstanceDAO.find(connInstanceId);
-            resources = connInstance.getResources();
-        }
-
-        return binder.getResourceTOs(resources);
+    public List<ResourceTO> list() {
+        return binder.getResourceTOs(resourceDAO.findAll());
     }
 
     @PreAuthorize("hasRole('RESOURCE_GETCONNECTOROBJECT')")

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java b/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
deleted file mode 100644
index bcc015d..0000000
--- a/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  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.
- */
-package org.apache.syncope.core.rest.utils;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cxf.jaxrs.ext.ResourceComparator;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
-import org.apache.cxf.jaxrs.model.Parameter;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-
-public class QueryResourceInfoComparator extends OperationResourceInfoComparator implements ResourceComparator {
-
-    public QueryResourceInfoComparator() {
-        super(null, null);
-    }
-
-    @Override
-    public int compare(final ClassResourceInfo cri1, final ClassResourceInfo cri2, final Message message) {
-        // Leave Class selection to CXF
-        return 0;
-    }
-
-    @Override
-    public int compare(final OperationResourceInfo oper1, final OperationResourceInfo oper2, final Message message) {
-        // Check if CXF can make a decision
-        int cxfResult = super.compare(oper1, oper2);
-        if (cxfResult != 0) {
-            return cxfResult;
-        }
-
-        int op1Counter = getMatchingRate(oper1, message);
-        int op2Counter = getMatchingRate(oper2, message);
-
-        return op1Counter == op2Counter
-                ? 0
-                : op1Counter < op2Counter
-                ? 1
-                : -1;
-    }
-
-    /**
-     * This method calculates a number indicating a good or bad match between values provided within the request and
-     * expected method parameters. A higher number means a better match.
-     *
-     * @param operation The operation to be rated, based on contained parameterInfo values.
-     * @param message A message containing query and header values from user request
-     * @return A positive or negative number, indicating a good match between query and method
-     */
-    protected int getMatchingRate(final OperationResourceInfo operation, final Message message) {
-        List<Parameter> params = operation.getParameters();
-        if (params == null || params.isEmpty()) {
-            return 0;
-        }
-
-        // Get Request QueryParams
-        String query = (String) message.get(Message.QUERY_STRING);
-        String path = (String) message.get(Message.REQUEST_URI);
-        Map<String, List<String>> qParams = JAXRSUtils.getStructuredParams(query, "&", true, false);
-        Map<String, List<String>> mParams = JAXRSUtils.getMatrixParams(path, true);
-        // Get Request Headers
-        Map<?, ?> qHeader = (java.util.Map<?, ?>) message.get(Message.PROTOCOL_HEADERS);
-
-        int rate = 0;
-        for (Parameter p : params) {
-            switch (p.getType()) {
-                case QUERY:
-                    if (qParams.containsKey(p.getName())) {
-                        rate += 2;
-                    } else if (p.getDefaultValue() == null) {
-                        rate -= 1;
-                    }
-                    break;
-                case MATRIX:
-                    if (mParams.containsKey(p.getName())) {
-                        rate += 2;
-                    } else if (p.getDefaultValue() == null) {
-                        rate -= 1;
-                    }
-                    break;
-                case HEADER:
-                    if (qHeader.containsKey(p.getName())) {
-                        rate += 2;
-                    } else if (p.getDefaultValue() == null) {
-                        rate -= 1;
-                    }
-                    break;
-                default:
-                    break;
-            }
-        }
-        return rate;
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java
index 674a674..dda5561 100644
--- a/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java
@@ -86,12 +86,7 @@ public class ResourceServiceImpl extends AbstractServiceImpl implements Resource
 
     @Override
     public List<ResourceTO> list() {
-        return controller.list(null);
-    }
-
-    @Override
-    public List<ResourceTO> list(final Long connInstanceId) {
-        return controller.list(connInstanceId);
+        return controller.list();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/main/resources/restContext.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/restContext.xml b/core/src/main/resources/restContext.xml
index 1b71e31..7b6fe30 100644
--- a/core/src/main/resources/restContext.xml
+++ b/core/src/main/resources/restContext.xml
@@ -100,9 +100,6 @@ under the License.
   <jaxrs:server id="restContainer" address="/" 
                 basePackages="org.apache.syncope.common.services, org.apache.syncope.core.services" 
                 staticSubresourceResolution="true">
-    <jaxrs:resourceComparator>
-      <bean id="queryResourceInfoComparator" class="org.apache.syncope.core.rest.utils.QueryResourceInfoComparator"/>
-    </jaxrs:resourceComparator>
     <jaxrs:properties> 
       <entry key="search.lax.property.match" value="true"/> 
     </jaxrs:properties> 

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/test/java/org/apache/syncope/core/rest/ConnectorTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/ConnectorTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/ConnectorTestITCase.java
index d1063f5..fc4e830 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/ConnectorTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/ConnectorTestITCase.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -265,6 +266,18 @@ public class ConnectorTestITCase extends AbstractTest {
         assertEquals(Integer.valueOf(20), actual.getConnRequestTimeout());
     }
 
+    private List<ResourceTO> filter(final List<ResourceTO> input, final Long connectorId) {
+        List<ResourceTO> result = new ArrayList<ResourceTO>();
+
+        for (ResourceTO resource : input) {
+            if (connectorId.equals(resource.getConnectorId())) {
+                result.add(resource);
+            }
+        }
+
+        return result;
+    }
+
     @Test
     public void issueSYNCOPE10() {
         // ----------------------------------
@@ -276,8 +289,7 @@ public class ConnectorTestITCase extends AbstractTest {
         assertNotNull(connInstanceTO);
 
         // check for resource
-        List<ResourceTO> resources = resourceService.list(Long.valueOf(103));
-
+        List<ResourceTO> resources = filter(resourceService.list(), 103L);
         assertEquals(4, resources.size());
 
         // Retrieve a resource TO template.
@@ -317,8 +329,7 @@ public class ConnectorTestITCase extends AbstractTest {
 
         assertNotNull(resourceTO);
 
-        resources = resourceService.list(connId);
-
+        resources = filter(resourceService.list(), connId);
         assertEquals(1, resources.size());
         // ----------------------------------
 
@@ -709,13 +720,13 @@ public class ConnectorTestITCase extends AbstractTest {
 
     @Test
     public void issueSYNCOPE605() {
-        
+
         ConnInstanceTO connectorInstanceTO = connectorService.read(103L);
         assertTrue(connectorInstanceTO.getCapabilities().isEmpty());
-        
+
         connectorInstanceTO.getCapabilities().add(ConnectorCapability.SEARCH);
         connectorService.update(connectorInstanceTO.getId(), connectorInstanceTO);
-        
+
         ConnInstanceTO updatedCapabilities = connectorService.read(connectorInstanceTO.getId());
         assertNotNull(updatedCapabilities.getCapabilities());
         assertTrue(updatedCapabilities.getCapabilities().size() == 1);

http://git-wip-us.apache.org/repos/asf/syncope/blob/60a62434/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
index 77f4c66..de4435b 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
@@ -406,17 +406,6 @@ public class ResourceTestITCase extends AbstractTest {
     }
 
     @Test
-    public void listByType() {
-        List<ResourceTO> actuals = resourceService.list(105L);
-        assertNotNull(actuals);
-
-        for (ResourceTO resourceTO : actuals) {
-            assertNotNull(resourceTO);
-            assertEquals(105L, resourceTO.getConnectorId().longValue());
-        }
-    }
-
-    @Test
     public void read() {
         ResourceTO actual = resourceService.read(RESOURCE_NAME_TESTDB);
         assertNotNull(actual);
@@ -507,7 +496,7 @@ public class ResourceTestITCase extends AbstractTest {
         item.setExtAttrName("cn");
         item.setPurpose(MappingPurpose.BOTH);
         mapping.setAccountIdItem(item);
-            
+
         item = new MappingItemTO();
         item.setIntMappingType(IntMappingType.RoleOwnerSchema);
         item.setExtAttrName("owner");