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 2013/02/20 17:57:32 UTC
svn commit: r1448292 - in /syncope/trunk:
client/src/main/java/org/apache/syncope/client/services/proxy/
client/src/test/java/org/apache/syncope/client/test/
common/src/main/java/org/apache/syncope/common/services/
core/src/main/java/org/apache/syncope...
Author: ilgrosso
Date: Wed Feb 20 16:57:32 2013
New Revision: 1448292
URL: http://svn.apache.org/r1448292
Log:
Refining some details about PolicyController (and related)
Modified:
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java
syncope/trunk/client/src/test/java/org/apache/syncope/client/test/JSONTest.java
syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ImplementationClassNamesLoader.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java
Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java Wed Feb 20 16:57:32 2013
@@ -55,27 +55,35 @@ public class PolicyServiceProxy extends
getRestTemplate().getForObject(baseUrl + "policy/delete/{id}", getTOClass(type), policyId);
}
+ @SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> List<T> list(final PolicyType type) {
+ List<T> result = null;
+
switch (type) {
case ACCOUNT:
case GLOBAL_ACCOUNT:
- return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+ result = (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
AccountPolicyTO[].class, type));
+ break;
case PASSWORD:
case GLOBAL_PASSWORD:
- return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+ result = (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
PasswordPolicyTO[].class, type));
+ break;
case SYNC:
case GLOBAL_SYNC:
- return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+ result = (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
SyncPolicyTO[].class, type));
+ break;
default:
throw new IllegalArgumentException("Policy Type not supported: " + type);
}
+
+ return result;
}
@Override
@@ -95,46 +103,56 @@ public class PolicyServiceProxy extends
typeToUrl(policyTO.getType()));
}
- private Class<? extends PolicyTO> getTOClass(final PolicyType type) {
+ @SuppressWarnings("unchecked")
+ private <T extends PolicyTO> Class<T> getTOClass(final PolicyType type) {
+ Class<T> result = null;
+
switch (type) {
case ACCOUNT:
case GLOBAL_ACCOUNT:
- return AccountPolicyTO.class;
+ result = (Class<T>) AccountPolicyTO.class;
+ break;
case PASSWORD:
case GLOBAL_PASSWORD:
- return PasswordPolicyTO.class;
+ result = (Class<T>) PasswordPolicyTO.class;
+ break;
case SYNC:
case GLOBAL_SYNC:
- return SyncPolicyTO.class;
+ result = (Class<T>) SyncPolicyTO.class;
+ break;
default:
throw new IllegalArgumentException("Policy Type not supported: " + type);
}
+
+ return result;
}
private String typeToUrl(final PolicyType type) {
String url = type.name().toLowerCase();
- int index = url.indexOf("_");
- if (index != -1) {
- return url.substring(index + 1);
- } else {
- return url;
- }
+ int index = url.indexOf('_');
+ return index == -1 ? url : url.substring(index + 1);
}
@Override
public Set<CorrelationRuleClassTO> getCorrelationRuleClasses(final PolicyType type) {
+ Set<CorrelationRuleClassTO> result = null;
+
switch (type) {
case SYNC:
case GLOBAL_SYNC:
final Set<String> classes = new HashSet<String>(Arrays.asList(getRestTemplate().getForObject(
baseUrl + "policy/correlationRuleClasses.json", String[].class)));
- return CollectionWrapper.wrapCorrelationRuleClasses(classes);
+ result = CollectionWrapper.wrapCorrelationRuleClasses(classes);
+ break;
+
default:
throw new NotFoundException();
}
+
+ return result;
}
}
Modified: syncope/trunk/client/src/test/java/org/apache/syncope/client/test/JSONTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/test/java/org/apache/syncope/client/test/JSONTest.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/client/src/test/java/org/apache/syncope/client/test/JSONTest.java (original)
+++ syncope/trunk/client/src/test/java/org/apache/syncope/client/test/JSONTest.java Wed Feb 20 16:57:32 2013
@@ -18,31 +18,31 @@
*/
package org.apache.syncope.client.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Test;
import org.apache.syncope.common.report.UserReportletConf;
import org.apache.syncope.common.search.AttributeCond;
import org.apache.syncope.common.search.MembershipCond;
import org.apache.syncope.common.search.NodeCond;
import org.apache.syncope.common.to.ConfigurationTO;
import org.apache.syncope.common.to.ReportTO;
-import org.apache.syncope.common.to.SchemaTO;
import org.apache.syncope.common.to.WorkflowFormPropertyTO;
import org.apache.syncope.common.types.AuditElements;
import org.apache.syncope.common.types.AuditLoggerName;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Test;
public class JSONTest {
@Test
public void testSearchCondition() throws IOException {
-
final AttributeCond usernameCond = new AttributeCond(AttributeCond.Type.LIKE);
usernameCond.setSchema("username");
usernameCond.setExpression("%o%");
@@ -66,7 +66,6 @@ public class JSONTest {
@Test
public void testLists() throws IOException {
-
List<ConfigurationTO> confList = new ArrayList<ConfigurationTO>();
ConfigurationTO configuration = new ConfigurationTO();
configuration.setKey("key1");
@@ -91,7 +90,6 @@ public class JSONTest {
@Test
public void testMap() throws IOException {
-
WorkflowFormPropertyTO prop = new WorkflowFormPropertyTO();
prop.putEnumValue("key1", "value1");
prop.putEnumValue("key2", "value2");
@@ -107,7 +105,6 @@ public class JSONTest {
@Test
public void testReportletConfImplementations() throws IOException {
-
ReportTO report = new ReportTO();
report.setName("testReportForCreate");
report.addReportletConf(new UserReportletConf("first"));
Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java Wed Feb 20 16:57:32 2013
@@ -37,6 +37,8 @@ public interface PolicyService {
/**
* @param type Creates a new policy with given type
* @param policyTO Policy to be created (needs to match type)
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
* @return Response containing URI location for created resource
*/
@POST
@@ -45,6 +47,8 @@ public interface PolicyService {
/**
* @param type Deletes policy with given type
* @param policyId Deletes policy with given id
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
*/
@DELETE
@Path("{policyId}")
@@ -52,6 +56,8 @@ public interface PolicyService {
/**
* @param type Type selector for requested policies
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
* @return List of policies with matching type.
*/
@GET
@@ -60,6 +66,8 @@ public interface PolicyService {
/**
* @param type Request for policy with given type
* @param policyId ID of requested policy
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
* @return Returns policy with matching id and type
*/
@GET
@@ -68,6 +76,8 @@ public interface PolicyService {
/**
* @param type PolicyType to read global policy from
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
* @return Global Policy for matching type
*/
@GET
@@ -78,6 +88,8 @@ public interface PolicyService {
* @param type PolicyType to be updated.
* @param policyId ID of policy to be updated
* @param policyTO Policy to replace existing policy
+ * @param <T> response type (extending PolicyTO)
+ * @see PolicyTO
*/
@PUT
@Path("{policyId}")
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ImplementationClassNamesLoader.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ImplementationClassNamesLoader.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ImplementationClassNamesLoader.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/init/ImplementationClassNamesLoader.java Wed Feb 20 16:57:32 2013
@@ -84,7 +84,7 @@ public class ImplementationClassNamesLoa
ClassMetadata metadata = factory.getMetadataReader(resource).getClassMetadata();
try {
- Class clazz = ClassUtils.forName(metadata.getClassName(), ClassUtils.getDefaultClassLoader());
+ Class<?> clazz = ClassUtils.forName(metadata.getClassName(), ClassUtils.getDefaultClassLoader());
Set<Class> interfaces = ClassUtils.getAllInterfacesForClassAsSet(clazz);
if (interfaces.contains(Reportlet.class) && !metadata.isAbstract()) {
@@ -102,7 +102,7 @@ public class ImplementationClassNamesLoa
if (interfaces.contains(SyncActions.class) && !metadata.isAbstract()) {
classNames.get(Type.SYNC_ACTIONS).add(metadata.getClassName());
}
-
+
if (interfaces.contains(SyncRule.class) && !metadata.isAbstract()) {
classNames.get(Type.SYNC_CORRELATION_RULES).add(metadata.getClassName());
}
@@ -121,7 +121,7 @@ public class ImplementationClassNamesLoa
}
}
} catch (IOException e) {
- LOG.error("While searching for class implementing {}", Reportlet.class.getName(), e);
+ LOG.error("While searching for implementatiom classes", e);
}
classNames = Collections.unmodifiableMap(classNames);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java Wed Feb 20 16:57:32 2013
@@ -32,7 +32,6 @@ import org.apache.syncope.common.types.A
import org.apache.syncope.common.types.AuditElements.PolicySubCategory;
import org.apache.syncope.common.types.AuditElements.Result;
import org.apache.syncope.common.types.PolicyType;
-import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
import org.apache.syncope.core.audit.AuditManager;
import org.apache.syncope.core.init.ImplementationClassNamesLoader;
import org.apache.syncope.core.persistence.beans.AccountPolicy;
@@ -69,26 +68,23 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/password/create")
- public PasswordPolicyTO create(final HttpServletResponse response, @RequestBody final PasswordPolicyTO policyTO)
- throws SyncopeClientCompositeErrorException {
- return (PasswordPolicyTO) createInternal(policyTO);
+ public PasswordPolicyTO create(final HttpServletResponse response, @RequestBody final PasswordPolicyTO policyTO) {
+ return createInternal(policyTO);
}
@PreAuthorize("hasRole('POLICY_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/account/create")
- public AccountPolicyTO create(final HttpServletResponse response, @RequestBody final AccountPolicyTO policyTO)
- throws SyncopeClientCompositeErrorException {
- return (AccountPolicyTO) createInternal(policyTO);
+ public AccountPolicyTO create(final HttpServletResponse response, @RequestBody final AccountPolicyTO policyTO) {
+ return createInternal(policyTO);
}
@PreAuthorize("hasRole('POLICY_CREATE')")
@RequestMapping(method = RequestMethod.POST, value = "/sync/create")
- public SyncPolicyTO create(final HttpServletResponse response, @RequestBody final SyncPolicyTO policyTO)
- throws SyncopeClientCompositeErrorException {
- return (SyncPolicyTO) createInternal(policyTO);
+ public SyncPolicyTO create(final HttpServletResponse response, @RequestBody final SyncPolicyTO policyTO) {
+ return createInternal(policyTO);
}
- public PolicyTO createInternal(final PolicyTO policyTO) {
+ public <T extends PolicyTO> T createInternal(final T policyTO) {
LOG.debug("Creating policy " + policyTO);
final Policy policy = binder.getPolicy(null, policyTO);
@@ -100,7 +96,6 @@ public class PolicyController extends Ab
}
private <T extends PolicyTO, K extends Policy> T update(final T policyTO, final K policy) {
-
LOG.debug("Updating policy " + policyTO);
binder.getPolicy(policy, policyTO);
@@ -114,9 +109,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_UPDATE')")
@RequestMapping(method = RequestMethod.POST, value = "/password/update")
- public PasswordPolicyTO update(@RequestBody final PasswordPolicyTO policyTO)
- throws NotFoundException {
-
+ public PasswordPolicyTO update(@RequestBody final PasswordPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof PasswordPolicy)) {
throw new NotFoundException("PasswordPolicy with id " + policyTO.getId());
@@ -127,9 +120,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_UPDATE')")
@RequestMapping(method = RequestMethod.POST, value = "/account/update")
- public AccountPolicyTO update(@RequestBody final AccountPolicyTO policyTO)
- throws NotFoundException, SyncopeClientCompositeErrorException {
-
+ public AccountPolicyTO update(@RequestBody final AccountPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof AccountPolicy)) {
throw new NotFoundException("AccountPolicy with id " + policyTO.getId());
@@ -140,9 +131,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_UPDATE')")
@RequestMapping(method = RequestMethod.POST, value = "/sync/update")
- public SyncPolicyTO update(@RequestBody final SyncPolicyTO policyTO)
- throws NotFoundException, SyncopeClientCompositeErrorException {
-
+ public SyncPolicyTO update(@RequestBody final SyncPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof SyncPolicy)) {
throw new NotFoundException("SyncPolicy with id " + policyTO.getId());
@@ -153,14 +142,13 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
- public List<PolicyTO> listByType(@PathVariable("kind") final String kind) {
-
+ public <T extends PolicyTO> List<T> listByType(@PathVariable("kind") final String kind) {
LOG.debug("Listing policies");
List<? extends Policy> policies = policyDAO.find(PolicyType.valueOf(kind.toUpperCase(Locale.ENGLISH)));
- final List<PolicyTO> policyTOs = new ArrayList<PolicyTO>();
+ final List<T> policyTOs = new ArrayList<T>();
for (Policy policy : policies) {
- policyTOs.add(binder.getPolicyTO(policy));
+ policyTOs.add((T) binder.getPolicyTO(policy));
}
auditManager.audit(Category.policy, PolicySubCategory.list, Result.success,
@@ -171,9 +159,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_READ')")
@RequestMapping(method = RequestMethod.GET, value = "/password/global/read")
- public PasswordPolicyTO getGlobalPasswordPolicy()
- throws NotFoundException {
-
+ public PasswordPolicyTO getGlobalPasswordPolicy() {
LOG.debug("Reading global password policy");
PasswordPolicy policy = policyDAO.getGlobalPasswordPolicy();
@@ -189,9 +175,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_READ')")
@RequestMapping(method = RequestMethod.GET, value = "/account/global/read")
- public AccountPolicyTO getGlobalAccountPolicy()
- throws NotFoundException {
-
+ public AccountPolicyTO getGlobalAccountPolicy() {
LOG.debug("Reading global account policy");
AccountPolicy policy = policyDAO.getGlobalAccountPolicy();
@@ -207,9 +191,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_READ')")
@RequestMapping(method = RequestMethod.GET, value = "/sync/global/read")
- public SyncPolicyTO getGlobalSyncPolicy()
- throws NotFoundException {
-
+ public SyncPolicyTO getGlobalSyncPolicy() {
LOG.debug("Reading global sync policy");
SyncPolicy policy = policyDAO.getGlobalSyncPolicy();
@@ -225,9 +207,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_READ')")
@RequestMapping(method = RequestMethod.GET, value = "/read/{id}")
- public PolicyTO read(@PathVariable("id") final Long id)
- throws NotFoundException {
-
+ public <T extends PolicyTO> T read(@PathVariable("id") final Long id) {
LOG.debug("Reading policy with id {}", id);
Policy policy = policyDAO.find(id);
@@ -243,8 +223,7 @@ public class PolicyController extends Ab
@PreAuthorize("hasRole('POLICY_DELETE')")
@RequestMapping(method = RequestMethod.GET, value = "/delete/{id}")
- public PolicyTO delete(@PathVariable("id") final Long id)
- throws NotFoundException {
+ public PolicyTO delete(@PathVariable("id") final Long id) {
Policy policy = policyDAO.find(id);
if (policy == null) {
throw new NotFoundException("Policy " + id + " not found");
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java?rev=1448292&r1=1448291&r2=1448292&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java Wed Feb 20 16:57:32 2013
@@ -21,19 +21,16 @@ package org.apache.syncope.core.services
import java.net.URI;
import java.util.List;
import java.util.Set;
-
import javax.ws.rs.BadRequestException;
-import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-
import org.apache.syncope.common.SyncopeConstants;
import org.apache.syncope.common.services.PolicyService;
import org.apache.syncope.common.to.AccountPolicyTO;
+import org.apache.syncope.common.to.CorrelationRuleClassTO;
import org.apache.syncope.common.to.PasswordPolicyTO;
import org.apache.syncope.common.to.PolicyTO;
import org.apache.syncope.common.to.SyncPolicyTO;
-import org.apache.syncope.common.to.CorrelationRuleClassTO;
import org.apache.syncope.common.types.PolicyType;
import org.apache.syncope.common.util.CollectionWrapper;
import org.apache.syncope.core.rest.controller.PolicyController;
@@ -60,37 +57,42 @@ public class PolicyServiceImpl implement
policyController.delete(policyId);
}
- @SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> List<T> list(final PolicyType type) {
- return (List<T>) policyController.listByType(type.toString());
+ return policyController.listByType(type.toString());
}
- @SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> T read(final PolicyType type, final Long policyId) {
- return (T) policyController.read(policyId);
+ return policyController.read(policyId);
}
@SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> T readGlobal(final PolicyType type) {
+ T result = null;
+
switch (type) {
case ACCOUNT:
case GLOBAL_ACCOUNT:
- return (T) policyController.getGlobalAccountPolicy();
+ result = (T) policyController.getGlobalAccountPolicy();
+ break;
case PASSWORD:
case GLOBAL_PASSWORD:
- return (T) policyController.getGlobalPasswordPolicy();
+ result = (T) policyController.getGlobalPasswordPolicy();
+ break;
case SYNC:
case GLOBAL_SYNC:
- return (T) policyController.getGlobalSyncPolicy();
+ result = (T) policyController.getGlobalSyncPolicy();
+ break;
default:
throw new BadRequestException();
}
+
+ return result;
}
@Override
@@ -122,18 +124,23 @@ public class PolicyServiceImpl implement
}
@Override
- public Set<CorrelationRuleClassTO> getCorrelationRuleClasses(PolicyType type) {
+ public Set<CorrelationRuleClassTO> getCorrelationRuleClasses(final PolicyType type) {
+ Set<CorrelationRuleClassTO> result = null;
+
switch (type) {
case SYNC:
case GLOBAL_SYNC:
@SuppressWarnings("unchecked")
- final Set<String> classes =
- (Set<String>) policyController.getCorrelationRuleClasses().getModel().values().iterator().next();
- return CollectionWrapper.wrapCorrelationRuleClasses(classes);
+ final Set<String> classes = (Set<String>) policyController.getCorrelationRuleClasses().getModel().
+ values().iterator().next();
+ result = CollectionWrapper.wrapCorrelationRuleClasses(classes);
+ break;
default:
- throw new NotFoundException();
+ throw new BadRequestException();
}
+
+ return result;
}
-}
+}
\ No newline at end of file