Author: cschneider Date: Thu Jan 31 15:47:24 2013 New Revision: 1441024 URL: http://svn.apache.org/viewvc?rev=1441024&view=rev Log: SYNCOPE-231 Simplified PolicyService and TaskService
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java 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=1441024&r1=1441023&r2=1441024&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 Thu Jan 31 15:47:24 2013 @@ -66,43 +66,30 @@ public class PolicyController extends Ab @RequestMapping(method = RequestMethod.POST, value = "/password/create") public PasswordPolicyTO create(final HttpServletResponse response, @RequestBody final PasswordPolicyTO policyTO) throws SyncopeClientCompositeErrorException { - - LOG.debug("Creating policy " + policyTO); - - final PasswordPolicy policy = binder.getPolicy(null, policyTO); - - auditManager.audit(Category.policy, PolicySubCategory.create, Result.success, - "Successfully created password policy: " + policy.getId()); - - return binder.getPolicyTO(policyDAO.save(policy)); + return (PasswordPolicyTO) 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 { - - LOG.debug("Creating policy " + policyTO); - - final AccountPolicy policy = binder.getPolicy(null, policyTO); - - auditManager.audit(Category.policy, PolicySubCategory.create, Result.success, - "Successfully created account policy: " + policy.getId()); - - return binder.getPolicyTO(policyDAO.save(policy)); + return (AccountPolicyTO) 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 PolicyTO createInternal(final PolicyTO policyTO) { LOG.debug("Creating policy " + policyTO); - final SyncPolicy policy = binder.getPolicy(null, policyTO); + final Policy policy = binder.getPolicy(null, policyTO); auditManager.audit(Category.policy, PolicySubCategory.create, Result.success, - "Successfully created sync policy: " + policy.getId()); + "Successfully created " + policy.getType().toString() + " policy: " + policy.getId()); return binder.getPolicyTO(policyDAO.save(policy)); } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java?rev=1441024&r1=1441023&r2=1441024&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java Thu Jan 31 15:47:24 2013 @@ -111,7 +111,12 @@ public class TaskController extends Abst @RequestMapping(method = RequestMethod.POST, value = "/create/sched") public TaskTO createSchedTask(final HttpServletResponse response, @RequestBody final SchedTaskTO taskTO) throws NotFoundException { + TaskTO createdTaskTO = createSchedTaskInternal(taskTO); + response.setStatus(HttpServletResponse.SC_CREATED); + return createdTaskTO; + } + public TaskTO createSchedTaskInternal(final SchedTaskTO taskTO) { LOG.debug("Creating task " + taskTO); TaskUtil taskUtil = getTaskUtil(taskTO); @@ -135,7 +140,6 @@ public class TaskController extends Abst auditManager.audit(Category.task, TaskSubCategory.create, Result.success, "Successfully created task: " + task.getId() + "/" + taskUtil); - response.setStatus(HttpServletResponse.SC_CREATED); return binder.getTaskTO(task, taskUtil); } @@ -184,7 +188,11 @@ public class TaskController extends Abst @PreAuthorize("hasRole('TASK_LIST')") @RequestMapping(method = RequestMethod.GET, value = "/{kind}/count") public ModelAndView count(@PathVariable("kind") final String kind) { - return new ModelAndView().addObject(taskDAO.count(getTaskUtil(kind).taskClass())); + return new ModelAndView().addObject(countInternal(kind)); + } + + public int countInternal(final String kind) { + return taskDAO.count(getTaskUtil(kind).taskClass()); } @PreAuthorize("hasRole('TASK_LIST')") 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=1441024&r1=1441023&r2=1441024&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 Thu Jan 31 15:47:24 2013 @@ -46,23 +46,7 @@ public class PolicyServiceImpl implement @Override public <T extends PolicyTO> Response create(final PolicyType type, final T policyTO) { - PolicyTO policy; - switch (type) { - case ACCOUNT: - policy = policyController.create(new DummyHTTPServletResponse(), (AccountPolicyTO) policyTO); - break; - - case PASSWORD: - policy = policyController.create(new DummyHTTPServletResponse(), (PasswordPolicyTO) policyTO); - break; - - case SYNC: - policy = policyController.create(new DummyHTTPServletResponse(), (SyncPolicyTO) policyTO); - break; - - default: - throw new BadRequestException(); - } + PolicyTO policy = policyController.createInternal(policyTO); URI location = uriInfo.getAbsolutePathBuilder().path(policy.getId() + "").build(); return Response.created(location) .header(SyncopeConstants.REST_HEADER_ID, policy.getId()) Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java?rev=1441024&r1=1441023&r2=1441024&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/TaskServiceImpl.java Thu Jan 31 15:47:24 2013 @@ -37,7 +37,10 @@ import org.apache.syncope.common.to.Task import org.apache.syncope.common.types.PropagationTaskExecStatus; import org.apache.syncope.common.types.TaskType; import org.apache.syncope.common.util.CollectionWrapper; +import org.apache.syncope.core.persistence.dao.TaskDAO; import org.apache.syncope.core.rest.controller.TaskController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,18 +54,14 @@ public class TaskServiceImpl implements @Override public int count(final TaskType taskType) { - return (Integer) taskController.count(taskType.toString()).getModel().values().iterator().next(); + return taskController.countInternal(taskType.toString()); } @Override public Response create(final TaskTO taskTO) { TaskTO createdTask; - if (taskTO instanceof SyncTaskTO) { - createdTask = taskController.createSyncTask( - new DummyHTTPServletResponse(), (SyncTaskTO) taskTO); - } else if (taskTO instanceof SchedTaskTO) { - createdTask = taskController.createSchedTask( - new DummyHTTPServletResponse(), (SchedTaskTO) taskTO); + if (taskTO instanceof SyncTaskTO || taskTO instanceof SchedTaskTO) { + createdTask = taskController.createSchedTaskInternal((SchedTaskTO) taskTO); } else { throw new BadRequestException(); }