syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject syncope git commit: Fixing sched task update
Date Tue, 02 Feb 2016 15:53:06 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 5c5341346 -> f6924d05f


Fixing sched task update


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

Branch: refs/heads/master
Commit: f6924d05faed3763ebc6ec21dbed1c14d694be4f
Parents: 5c53413
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Feb 2 16:53:00 2016 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Tue Feb 2 16:53:00 2016 +0100

----------------------------------------------------------------------
 .../apache/syncope/core/logic/TaskLogic.java    |  8 +-----
 .../java/data/TaskDataBinderImpl.java           | 28 ++++++++------------
 .../core/rest/cxf/service/TaskServiceImpl.java  |  6 ++---
 .../syncope/fit/core/SchedTaskITCase.java       |  3 ++-
 4 files changed, 16 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/f6924d05/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
index 28206db..5101a98 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java
@@ -31,7 +31,6 @@ import org.apache.syncope.common.lib.to.AbstractExecTO;
 import org.apache.syncope.common.lib.to.AbstractTaskTO;
 import org.apache.syncope.common.lib.to.BulkActionResult;
 import org.apache.syncope.common.lib.to.SchedTaskTO;
-import org.apache.syncope.common.lib.to.SyncTaskTO;
 import org.apache.syncope.common.lib.to.TaskExecTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.ClientExceptionType;
@@ -119,12 +118,7 @@ public class TaskLogic extends AbstractJobLogic<AbstractTaskTO>
{
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_UPDATE + "')")
-    public SyncTaskTO updateSync(final SyncTaskTO taskTO) {
-        return updateSched(taskTO);
-    }
-
-    @PreAuthorize("hasRole('" + StandardEntitlement.TASK_UPDATE + "')")
-    public <T extends SchedTaskTO> T updateSched(final SchedTaskTO taskTO) {
+    public <T extends SchedTaskTO> T updateSchedTask(final SchedTaskTO taskTO) {
         SchedTask task = taskDAO.find(taskTO.getKey());
         if (task == null) {
             throw new NotFoundException("Task " + taskTO.getKey());

http://git-wip-us.apache.org/repos/asf/syncope/blob/f6924d05/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java
index 965e1b6..b07fffb 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/TaskDataBinderImpl.java
@@ -23,6 +23,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.core.provisioning.api.data.TaskDataBinder;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.AbstractProvisioningTaskTO;
 import org.apache.syncope.common.lib.to.AbstractTaskTO;
 import org.apache.syncope.common.lib.to.AnyTO;
@@ -193,8 +194,7 @@ public class TaskDataBinderImpl implements TaskDataBinder {
     public SchedTask createSchedTask(final SchedTaskTO taskTO, final TaskUtils taskUtils)
{
         Class<? extends AbstractTaskTO> taskTOClass = taskUtils.taskTOClass();
         if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) {
-            throw new IllegalArgumentException(
-                    String.format("taskUtils is type %s but task is not: %s", taskTOClass,
taskTO.getClass()));
+            throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass,
taskTO.getClass()));
         }
 
         SchedTask task = taskUtils.newTask();
@@ -223,26 +223,20 @@ public class TaskDataBinderImpl implements TaskDataBinder {
 
     @Override
     public void updateSchedTask(final SchedTask task, final SchedTaskTO taskTO, final TaskUtils
taskUtils) {
-        Class<? extends Task> taskClass = taskUtils.taskClass();
         Class<? extends AbstractTaskTO> taskTOClass = taskUtils.taskTOClass();
-
-        if (taskClass == null || !taskClass.isAssignableFrom(task.getClass())) {
-            throw new IllegalArgumentException(
-                    String.format("taskUtils is type %s but task is not: %s", taskClass,
task.getClass()));
-        }
-
         if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) {
-            throw new IllegalArgumentException(
-                    String.format("taskUtils is type %s but task is not: %s", taskTOClass,
taskTO.getClass()));
+            throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass,
taskTO.getClass()));
         }
 
-        task.setCronExpression(taskTO.getCronExpression());
-        if (StringUtils.isNotBlank(taskTO.getName())) {
-            task.setName(taskTO.getName());
-        }
-        if (StringUtils.isNotBlank(taskTO.getDescription())) {
-            task.setDescription(taskTO.getDescription());
+        if (StringUtils.isBlank(taskTO.getName())) {
+            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
+            sce.getElements().add("name");
+            throw sce;
         }
+        task.setName(taskTO.getName());
+        task.setDescription(taskTO.getDescription());
+        task.setCronExpression(taskTO.getCronExpression());
+        task.setActive(taskTO.isActive());
 
         if (task instanceof ProvisioningTask) {
             fill((ProvisioningTask) task, (AbstractProvisioningTaskTO) taskTO);

http://git-wip-us.apache.org/repos/asf/syncope/blob/f6924d05/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
index 5b33103..495fff8 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/TaskServiceImpl.java
@@ -102,10 +102,8 @@ public class TaskServiceImpl extends AbstractServiceImpl implements TaskService
 
     @Override
     public void update(final AbstractTaskTO taskTO) {
-        if (taskTO instanceof SyncTaskTO) {
-            logic.updateSync((SyncTaskTO) taskTO);
-        } else if (taskTO instanceof SchedTaskTO) {
-            logic.updateSched((SchedTaskTO) taskTO);
+        if (taskTO instanceof SchedTaskTO) {
+            logic.updateSchedTask((SchedTaskTO) taskTO);
         } else {
             throw new BadRequestException();
         }

http://git-wip-us.apache.org/repos/asf/syncope/blob/f6924d05/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
index b23866f..903093a 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
@@ -76,7 +76,8 @@ public class SchedTaskITCase extends AbstractTaskITCase {
         assertNotNull(task);
 
         SchedTaskTO taskMod = new SchedTaskTO();
-        taskMod.setKey(5L);
+        taskMod.setKey(SCHED_TASK_ID);
+        taskMod.setName(task.getName());
         taskMod.setCronExpression(null);
 
         taskService.update(taskMod);


Mime
View raw message