You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2015/10/23 12:29:54 UTC
[53/54] [abbrv] syncope git commit: refactoring of the task stack ,
SYNCOPE-158
refactoring of the task stack , SYNCOPE-158
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/73f73f20
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/73f73f20
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/73f73f20
Branch: refs/heads/SYNCOPE-156
Commit: 73f73f20692910e6f0c2acf27d5d8bd7982e6b6c
Parents: 23d8047
Author: massi <ma...@tirasa.net>
Authored: Thu Oct 22 17:36:58 2015 +0200
Committer: massi <ma...@tirasa.net>
Committed: Thu Oct 22 17:37:31 2015 +0200
----------------------------------------------------------------------
.../org/apache/syncope/client/cli/Input.java | 4 +
.../client/cli/commands/TaskCommand.java | 585 -------------------
.../cli/commands/task/AbstractTaskCommand.java | 30 +
.../client/cli/commands/task/TaskCommand.java | 140 +++++
.../client/cli/commands/task/TaskDelete.java | 58 ++
.../client/cli/commands/task/TaskExecute.java | 66 +++
.../cli/commands/task/TaskExecutionDelete.java | 58 ++
.../cli/commands/task/TaskExecutionRead.java | 58 ++
.../client/cli/commands/task/TaskList.java | 59 ++
.../client/cli/commands/task/TaskRead.java | 60 ++
.../cli/commands/task/TaskResultManager.java | 222 +++++++
.../cli/commands/task/TaskRunningJobs.java | 34 ++
.../cli/commands/task/TaskScheduledJobs.java | 34 ++
13 files changed, 823 insertions(+), 585 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java b/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
index c53eefd..9314187 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
@@ -67,6 +67,10 @@ public class Input {
public String firstParameter() {
return parameters[0];
}
+
+ public String secondParameter() {
+ return parameters[1];
+ }
public String lastParameter() {
return parameters[parameters.length - 1];
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java
deleted file mode 100644
index deb00bf..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java
+++ /dev/null
@@ -1,585 +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.client.cli.commands;
-
-import org.apache.syncope.client.cli.commands.logger.LoggerCommand;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.xml.ws.WebServiceException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.client.cli.Command;
-import org.apache.syncope.client.cli.Input;
-import org.apache.syncope.client.cli.SyncopeServices;
-import org.apache.syncope.client.cli.messages.Messages;
-import org.apache.syncope.client.cli.util.CommandUtils;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AbstractTaskTO;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.NotificationTaskTO;
-import org.apache.syncope.common.lib.to.PropagationTaskTO;
-import org.apache.syncope.common.lib.to.PushTaskTO;
-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.JobStatusType;
-import org.apache.syncope.common.lib.types.TaskType;
-import org.apache.syncope.common.rest.api.beans.TaskQuery;
-import org.apache.syncope.common.rest.api.service.TaskService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Command(name = "task")
-public class TaskCommand extends AbstractCommand {
-
- private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class);
-
- private static final String HELP_MESSAGE = "Usage: task [options]\n"
- + " Options:\n"
- + " --help \n"
- + " --list-task \n"
- + " Syntax: --list-task {TASK-TYPE} \n"
- + " Task type: NOTIFICATION / PROPAGATION / PUSH / SCHEDULED / SYNCHRONIZATION\n"
- + " --list-running-jobs \n"
- + " --list-scheduled-jobs \n"
- + " --read \n"
- + " Syntax: --read {TASK-ID} {TASK-ID} [...]\n"
- + " --read-execution \n"
- + " Syntax: --read-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n"
- + " --delete \n"
- + " Syntax: --delete {TASK-ID} {TASK-ID} [...]\n"
- + " --delete-execution \n"
- + " Syntax: --delete-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n"
- + " --execute \n"
- + " Syntax: --execute {TASK-ID} {DRY-RUN}"
- + " Dry run: true / false";
-
- @Override
- public void execute(final Input input) {
- LOG.debug("Option: {}", input.getOption());
- LOG.debug("Parameters:");
- for (final String parameter : input.getParameters()) {
- LOG.debug(" > " + parameter);
- }
-
- final String[] parameters = input.getParameters();
-
- if (StringUtils.isBlank(input.getOption())) {
- input.setOption(Options.HELP.getOptionName());
- }
-
- final TaskService taskService = SyncopeServices.get(TaskService.class);
- switch (Options.fromName(input.getOption())) {
- case LIST_TASK:
- final String listTaskErrorMessage = "task --list-task {TASK-TYPE}\n"
- + " Task type: NOTIFICATION / PROPAGATION / PUSH / SCHEDULED / SYNCHRONIZATION";
- if (parameters.length == 1) {
- try {
- final TaskType taskType = TaskType.valueOf(parameters[0]);
- for (final AbstractTaskTO taskTO : taskService.list(taskType, new TaskQuery()).getResult()) {
- switch (taskType) {
- case NOTIFICATION:
- final NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Notification task key: " + notificationTaskTO.getKey());
- System.out.println(" executed: " + notificationTaskTO.isExecuted());
- System.out.println(" sender: " + notificationTaskTO.getSender());
- System.out.println(" subjetc: " + notificationTaskTO.getSubject());
- System.out.println(" text body: " + notificationTaskTO.getTextBody());
- System.out.println(" html body: " + notificationTaskTO.getHtmlBody());
- System.out.println(" latest execution status: "
- + notificationTaskTO.getLatestExecStatus());
- System.out.println(" start date: " + notificationTaskTO.getStartDate());
- System.out.println(" end date: " + notificationTaskTO.getEndDate());
- System.out.println(" recipients: " + notificationTaskTO.getRecipients());
- System.out.println(" trace level: " + notificationTaskTO.getTraceLevel());
- for (final TaskExecTO taskExecTO : notificationTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- break;
- case PROPAGATION:
- final PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Propagation task key: " + propagationTaskTO.getKey());
- System.out.println(" resource: " + propagationTaskTO.getResource());
- System.out.println(" any key: " + propagationTaskTO.getAnyKey());
- System.out.println(" any type kind: " + propagationTaskTO.getAnyTypeKind());
- System.out.println(" connector object key: "
- + propagationTaskTO.getConnObjectKey());
- System.out.println(" old connector object key: "
- + propagationTaskTO.getOldConnObjectKey());
- System.out.println(" latest execution status: "
- + propagationTaskTO.getLatestExecStatus());
- System.out.println(" class name: " + propagationTaskTO.getObjectClassName());
- System.out.println(" xml attribute: " + propagationTaskTO.getXmlAttributes());
- System.out.println(" start date: " + propagationTaskTO.getStartDate());
- System.out.println(" end date: " + propagationTaskTO.getEndDate());
- System.out.println(" operation: " + propagationTaskTO.getOperation());
- for (final TaskExecTO taskExecTO : propagationTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- break;
- case PUSH:
- final PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Push task key: " + pushTaskTO.getKey());
- System.out.println(" name: " + pushTaskTO.getName());
- System.out.println(" resource: " + pushTaskTO.getResource());
- System.out.println(" cron expression: " + pushTaskTO.getCronExpression());
- System.out.println(" description: " + pushTaskTO.getDescription());
- System.out.println(" is perform create: " + pushTaskTO.isPerformCreate());
- System.out.println(" is perform delete: " + pushTaskTO.isPerformDelete());
- System.out.println(" is perform update: " + pushTaskTO.isPerformUpdate());
- System.out.println(" is sync status: " + pushTaskTO.isSyncStatus());
- System.out.println(" start date: " + pushTaskTO.getStartDate());
- System.out.println(" end date: " + pushTaskTO.getEndDate());
- System.out.println(" last execution: " + pushTaskTO.getLastExec());
- System.out.println(" next execution: " + pushTaskTO.getNextExec());
- System.out.println(" latest execution status: "
- + pushTaskTO.getLatestExecStatus());
- System.out.println(" filters: " + pushTaskTO.getFilters());
- System.out.println(" delegate class: " + pushTaskTO.getJobDelegateClassName());
- System.out.println(" action class: " + pushTaskTO.getActionsClassNames());
- System.out.println(" matching rule: " + pushTaskTO.getMatchingRule());
- System.out.println(" not matching rule: " + pushTaskTO.getUnmatchingRule());
- for (final TaskExecTO taskExecTO : pushTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- break;
- case SCHEDULED:
- final SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Scheduled task key: " + schedTaskTO.getKey());
- System.out.println(" name: " + schedTaskTO.getName());
- System.out.println(" cron expression: " + schedTaskTO.getCronExpression());
- System.out.println(" description: " + schedTaskTO.getDescription());
- System.out.println(" start date: " + schedTaskTO.getStartDate());
- System.out.println(" end date: " + schedTaskTO.getEndDate());
- System.out.println(" last execution: " + schedTaskTO.getLastExec());
- System.out.println(" next execution: " + schedTaskTO.getNextExec());
- System.out.println(" latest execution status: "
- + schedTaskTO.getLatestExecStatus());
- System.out.println(" job delegate class: "
- + schedTaskTO.getJobDelegateClassName());
- for (final TaskExecTO taskExecTO : schedTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- break;
- case SYNCHRONIZATION:
- final SyncTaskTO syncTaskTO = (SyncTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Sync task key: " + syncTaskTO.getKey());
- System.out.println(" name: " + syncTaskTO.getName());
- System.out.println(" resource: " + syncTaskTO.getResource());
- System.out.println(" realm destination: " + syncTaskTO.getDestinationRealm());
- System.out.println(" cron expression: " + syncTaskTO.getCronExpression());
- System.out.println(" description: " + syncTaskTO.getDescription());
- System.out.println(" is full reconciliation: "
- + syncTaskTO.isFullReconciliation());
- System.out.println(" is perform create: " + syncTaskTO.isPerformCreate());
- System.out.println(" is perform delete: " + syncTaskTO.isPerformDelete());
- System.out.println(" is perform update: " + syncTaskTO.isPerformUpdate());
- System.out.println(" is sync status: " + syncTaskTO.isSyncStatus());
- System.out.println(" templates:");
- for (Map.Entry<String, AnyTO> entrySet : syncTaskTO.getTemplates().entrySet()) {
- final String key = entrySet.getKey();
- final AnyTO value = entrySet.getValue();
- System.out.println(" " + key + " key: " + value.getKey()
- + " of realm" + value.getRealm()
- + " on resource " + value.getResources());
-
- }
- System.out.println(" start date: " + syncTaskTO.getStartDate());
- System.out.println(" end date: " + syncTaskTO.getEndDate());
- System.out.println(" next execution: " + syncTaskTO.getNextExec());
- System.out.println(" last execution: " + syncTaskTO.getLastExec());
- System.out.println(" latest execution status: "
- + syncTaskTO.getLatestExecStatus());
- System.out.println(" job delegate class: "
- + syncTaskTO.getJobDelegateClassName());
- System.out.println(" action class name: " + syncTaskTO.getActionsClassNames());
- System.out.println(" matching rule: " + syncTaskTO.getMatchingRule());
- System.out.println(" unmatching rule: " + syncTaskTO.getUnmatchingRule());
- for (final TaskExecTO taskExecTO : syncTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- break;
- default:
- break;
- }
- }
- } catch (final SyncopeClientException ex) {
- Messages.printMessage(ex.getMessage());
- } catch (final IllegalArgumentException ex) {
- Messages.printTypeNotValidMessage(
- "task", parameters[0], CommandUtils.fromEnumToArray(TaskType.class));
- }
- } else {
- Messages.printCommandOptionMessage(listTaskErrorMessage);
- }
- break;
- case LIST_RUNNING_JOBS:
- try {
- for (final TaskExecTO taskExecTO : taskService.listJobs(JobStatusType.RUNNING)) {
- printTaskExecTO(taskExecTO);
- }
- } catch (final SyncopeClientException ex) {
- Messages.printMessage(ex.getMessage());
- }
- break;
- case LIST_SCHEDULED_JOBS:
- try {
- for (final TaskExecTO taskExecTO : taskService.listJobs(JobStatusType.SCHEDULED)) {
- printTaskExecTO(taskExecTO);
- }
- } catch (final SyncopeClientException ex) {
- Messages.printMessage(ex.getMessage());
- }
- break;
- case READ:
- final String readErrorMessage = "task --read {TASK-ID} {TASK-ID} [...]";
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- final AbstractTaskTO taskTO = taskService.read(Long.valueOf(parameter));
- if (taskTO instanceof NotificationTaskTO) {
- final NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Notification task key: " + notificationTaskTO.getKey());
- System.out.println(" executed: " + notificationTaskTO.isExecuted());
- System.out.println(" sender: " + notificationTaskTO.getSender());
- System.out.println(" subjetc: " + notificationTaskTO.getSubject());
- System.out.println(" text body: " + notificationTaskTO.getTextBody());
- System.out.println(" html body: " + notificationTaskTO.getHtmlBody());
- System.out.println(" latest execution status: "
- + notificationTaskTO.getLatestExecStatus());
- System.out.println(" start date: " + notificationTaskTO.getStartDate());
- System.out.println(" end date: " + notificationTaskTO.getEndDate());
- System.out.println(" recipients: " + notificationTaskTO.getRecipients());
- System.out.println(" trace level: " + notificationTaskTO.getTraceLevel());
- for (final TaskExecTO taskExecTO : notificationTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- } else if (taskTO instanceof PropagationTaskTO) {
- final PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Propagation task key: " + propagationTaskTO.getKey());
- System.out.println(" resource: " + propagationTaskTO.getResource());
- System.out.println(" any key: " + propagationTaskTO.getAnyKey());
- System.out.println(" any type kind: " + propagationTaskTO.getAnyTypeKind());
- System.out.println(" connector object key: "
- + propagationTaskTO.getConnObjectKey());
- System.out.println(" old connector object key: "
- + propagationTaskTO.getOldConnObjectKey());
- System.out.println(" latest execution status: "
- + propagationTaskTO.getLatestExecStatus());
- System.out.println(" class name: " + propagationTaskTO.getObjectClassName());
- System.out.println(" xml attribute: " + propagationTaskTO.getXmlAttributes());
- System.out.println(" start date: " + propagationTaskTO.getStartDate());
- System.out.println(" end date: " + propagationTaskTO.getEndDate());
- System.out.println(" operation: " + propagationTaskTO.getOperation());
- for (final TaskExecTO taskExecTO : propagationTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- } else if (taskTO instanceof PushTaskTO) {
- final PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Push task key: " + pushTaskTO.getKey());
- System.out.println(" name: " + pushTaskTO.getName());
- System.out.println(" resource: " + pushTaskTO.getResource());
- System.out.println(" cron expression: " + pushTaskTO.getCronExpression());
- System.out.println(" description: " + pushTaskTO.getDescription());
- System.out.println(" is perform create: " + pushTaskTO.isPerformCreate());
- System.out.println(" is perform delete: " + pushTaskTO.isPerformDelete());
- System.out.println(" is perform update: " + pushTaskTO.isPerformUpdate());
- System.out.println(" is sync status: " + pushTaskTO.isSyncStatus());
- System.out.println(" start date: " + pushTaskTO.getStartDate());
- System.out.println(" end date: " + pushTaskTO.getEndDate());
- System.out.println(" last execution: " + pushTaskTO.getLastExec());
- System.out.println(" next execution: " + pushTaskTO.getNextExec());
- System.out.println(" latest execution status: "
- + pushTaskTO.getLatestExecStatus());
- System.out.println(" filters: " + pushTaskTO.getFilters());
- System.out.println(" delegate class: " + pushTaskTO.getJobDelegateClassName());
- System.out.println(" action class: " + pushTaskTO.getActionsClassNames());
- System.out.println(" matching rule: " + pushTaskTO.getMatchingRule());
- System.out.println(" not matching rule: " + pushTaskTO.getUnmatchingRule());
- for (final TaskExecTO taskExecTO : pushTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- } else if (taskTO instanceof SchedTaskTO) {
- final SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Scheduled task key: " + schedTaskTO.getKey());
- System.out.println(" name: " + schedTaskTO.getName());
- System.out.println(" cron expression: " + schedTaskTO.getCronExpression());
- System.out.println(" description: " + schedTaskTO.getDescription());
- System.out.println(" start date: " + schedTaskTO.getStartDate());
- System.out.println(" end date: " + schedTaskTO.getEndDate());
- System.out.println(" last execution: " + schedTaskTO.getLastExec());
- System.out.println(" next execution: " + schedTaskTO.getNextExec());
- System.out.println(" latest execution status: "
- + schedTaskTO.getLatestExecStatus());
- System.out.println(" job delegate class: "
- + schedTaskTO.getJobDelegateClassName());
- for (final TaskExecTO taskExecTO : schedTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- } else if (taskTO instanceof SyncTaskTO) {
- final SyncTaskTO syncTaskTO = (SyncTaskTO) taskTO;
- System.out.println("");
- System.out.println(" - Sync task key: " + syncTaskTO.getKey());
- System.out.println(" name: " + syncTaskTO.getName());
- System.out.println(" resource: " + syncTaskTO.getResource());
- System.out.println(" realm destination: " + syncTaskTO.getDestinationRealm());
- System.out.println(" cron expression: " + syncTaskTO.getCronExpression());
- System.out.println(" description: " + syncTaskTO.getDescription());
- System.out.println(" is full reconciliation: "
- + syncTaskTO.isFullReconciliation());
- System.out.println(" is perform create: " + syncTaskTO.isPerformCreate());
- System.out.println(" is perform delete: " + syncTaskTO.isPerformDelete());
- System.out.println(" is perform update: " + syncTaskTO.isPerformUpdate());
- System.out.println(" is sync status: " + syncTaskTO.isSyncStatus());
- System.out.println(" templates:");
- for (Map.Entry<String, AnyTO> entrySet : syncTaskTO.getTemplates().entrySet()) {
- final String key = entrySet.getKey();
- final AnyTO value = entrySet.getValue();
- System.out.println(" " + key + "key : " + value.getKey()
- + " of realm" + value.getRealm()
- + " on resource " + value.getResources());
-
- }
- System.out.println(" start date: " + syncTaskTO.getStartDate());
- System.out.println(" end date: " + syncTaskTO.getEndDate());
- System.out.println(" next execution: " + syncTaskTO.getNextExec());
- System.out.println(" last execution: " + syncTaskTO.getLastExec());
- System.out.println(" latest execution status: "
- + syncTaskTO.getLatestExecStatus());
- System.out.println(" job delegate class: "
- + syncTaskTO.getJobDelegateClassName());
- System.out.println(" action class name: " + syncTaskTO.getActionsClassNames());
- System.out.println(" matching rule: " + syncTaskTO.getMatchingRule());
- System.out.println(" unmatching rule: " + syncTaskTO.getUnmatchingRule());
- for (final TaskExecTO taskExecTO : syncTaskTO.getExecutions()) {
- printTaskExecTO(taskExecTO);
- }
- System.out.println("");
- }
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("task", parameter);
- } catch (final SyncopeClientException | WebServiceException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Task", parameter);
- } else {
- Messages.printMessage("Error: " + ex.getMessage());
- }
- break;
- }
- }
- } else {
- Messages.printCommandOptionMessage(readErrorMessage);
- }
- break;
- case READ_EXECUTION:
- final String readExecutionErrorMessage = "task --read-execution {TASK-ID} {TASK-ID} [...]";
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- final TaskExecTO taskExecTO = taskService.readExecution(Long.valueOf(parameter));
- printTaskExecTO(taskExecTO);
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("task execution", parameter);
- } catch (final SyncopeClientException | WebServiceException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Task execution", parameter);
- } else {
- Messages.printMessage("Error: " + ex.getMessage());
- }
- break;
- }
- }
- } else {
- Messages.printCommandOptionMessage(readExecutionErrorMessage);
- }
- break;
- case DELETE:
- final String deleteErrorMessage = "task --delete {TASK-ID} {TASK-ID} [...]";
-
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- taskService.delete(Long.valueOf(parameter));
- Messages.printDeletedMessage("Task", parameter);
- } catch (final WebServiceException | SyncopeClientException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Task", parameter);
- } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
- Messages.printMessage("You cannot delete task " + parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("task", parameter);
- }
- }
- } else {
- Messages.printCommandOptionMessage(deleteErrorMessage);
- }
- break;
- case DELETE_EXECUTION:
- final String deleteExecutionErrorMessage = "task --delete-execution "
- + "{TASK-EXEC-ID} {TASK-EXEC-ID} [...]";
-
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- taskService.deleteExecution(Long.valueOf(parameter));
- Messages.printDeletedMessage("Task execution", parameter);
- } catch (final WebServiceException | SyncopeClientException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Task execution", parameter);
- } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
- Messages.printMessage("You cannot delete task execution" + parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("task execution", parameter);
- }
- }
- } else {
- Messages.printCommandOptionMessage(deleteExecutionErrorMessage);
- }
- break;
- case EXECUTE:
- final String executeErrorMessage = "task --execute {TASK-ID} {DRY-RUN}\n"
- + " Dry run: true / false";
-
- if (parameters.length == 2) {
-
- try {
- final Long taskIdToExecute = Long.valueOf(parameters[0]);
- boolean dryRun;
- if ("false".equalsIgnoreCase(parameters[1])) {
- dryRun = false;
- } else if ("true".equalsIgnoreCase(parameters[1])) {
- dryRun = true;
- } else {
- Messages.printNotBooleanDeletedMessage("dry run", parameters[1]);
- break;
- }
- final TaskExecTO taskExecTO = taskService.execute(taskIdToExecute, dryRun);
- printTaskExecTO(taskExecTO);
- } catch (final WebServiceException | SyncopeClientException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Task", parameters[0]);
- } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
- Messages.printMessage("You cannot delete task " + parameters[0]);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("task", parameters[0]);
- }
- } else {
- Messages.printCommandOptionMessage(executeErrorMessage);
- }
- break;
- case HELP:
- System.out.println(HELP_MESSAGE);
- break;
- default:
- Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE);
- }
-
- }
-
- private void printTaskExecTO(final TaskExecTO taskExecTO) {
- System.out.println(" EXECUTIONS: ");
- System.out.println(" - task execution key: " + taskExecTO.getKey());
- System.out.println(" task: " + taskExecTO.getTask());
- System.out.println(" message: ");
- System.out.println(" ############### <BEGIN MESSAGE> ###############");
- System.out.println(" message: " + taskExecTO.getMessage());
- System.out.println(" ############### <END MESSAGE> ###############");
- System.out.println(" status: " + taskExecTO.getStatus());
- System.out.println(" start date: " + taskExecTO.getStartDate());
- System.out.println(" end date: " + taskExecTO.getEndDate());
- System.out.println("");
- }
-
- @Override
- public String getHelpMessage() {
- return HELP_MESSAGE;
- }
-
- private enum Options {
-
- HELP("--help"),
- LIST_TASK("--list-task"),
- LIST_RUNNING_JOBS("--list-running-jobs"),
- LIST_SCHEDULED_JOBS("--list-scheduled-jobs"),
- READ("--read"),
- READ_EXECUTION("--read-execution"),
- DELETE("--delete"),
- DELETE_EXECUTION("--delete-execution"),
- EXECUTE("--execute");
-
- private final String optionName;
-
- Options(final String optionName) {
- this.optionName = optionName;
- }
-
- public String getOptionName() {
- return optionName;
- }
-
- public boolean equalsOptionName(final String otherName) {
- return (otherName == null) ? false : optionName.equals(otherName);
- }
-
- public static Options fromName(final String name) {
- Options optionToReturn = HELP;
- for (final Options option : Options.values()) {
- if (option.equalsOptionName(name)) {
- optionToReturn = option;
- }
- }
- return optionToReturn;
- }
-
- public static List<String> toList() {
- final List<String> options = new ArrayList<>();
- for (final Options value : values()) {
- options.add(value.getOptionName());
- }
- return options;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/AbstractTaskCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/AbstractTaskCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/AbstractTaskCommand.java
new file mode 100644
index 0000000..18e877a
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/AbstractTaskCommand.java
@@ -0,0 +1,30 @@
+/*
+ * 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.client.cli.commands.task;
+
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.common.rest.api.service.TaskService;
+
+public abstract class AbstractTaskCommand {
+
+ protected final TaskService taskService = SyncopeServices.get(TaskService.class);
+
+ protected final TaskResultManager taskResultManager = new TaskResultManager();
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskCommand.java
new file mode 100644
index 0000000..a616692
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskCommand.java
@@ -0,0 +1,140 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.cli.Command;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
+
+@Command(name = "task")
+public class TaskCommand extends AbstractCommand {
+
+ private static final String HELP_MESSAGE = "Usage: task [options]\n"
+ + " Options:\n"
+ + " --help \n"
+ + " --list-task \n"
+ + " Syntax: --list-task {TASK-TYPE} \n"
+ + " Task type: NOTIFICATION / PROPAGATION / PUSH / SCHEDULED / SYNCHRONIZATION\n"
+ + " --list-running-jobs \n"
+ + " --list-scheduled-jobs \n"
+ + " --read \n"
+ + " Syntax: --read {TASK-ID} {TASK-ID} [...]\n"
+ + " --read-execution \n"
+ + " Syntax: --read-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n"
+ + " --delete \n"
+ + " Syntax: --delete {TASK-ID} {TASK-ID} [...]\n"
+ + " --delete-execution \n"
+ + " Syntax: --delete-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n"
+ + " --execute \n"
+ + " Syntax: --execute {TASK-ID} {DRY-RUN}"
+ + " Dry run: true / false";
+
+ @Override
+ public void execute(final Input input) {
+ if (StringUtils.isBlank(input.getOption())) {
+ input.setOption(Options.HELP.getOptionName());
+ }
+
+ switch (Options.fromName(input.getOption())) {
+ case LIST_TASK:
+ new TaskList(input).list();
+ break;
+ case LIST_RUNNING_JOBS:
+ new TaskRunningJobs().list();
+ break;
+ case LIST_SCHEDULED_JOBS:
+ new TaskScheduledJobs().list();
+ break;
+ case READ:
+ new TaskRead(input).read();
+ break;
+ case READ_EXECUTION:
+ new TaskExecutionRead(input).read();
+ break;
+ case DELETE:
+ new TaskDelete(input).delete();
+ break;
+ case DELETE_EXECUTION:
+ new TaskExecutionDelete(input).delete();
+ break;
+ case EXECUTE:
+ new TaskExecute(input).execute();
+ break;
+ case HELP:
+ System.out.println(HELP_MESSAGE);
+ break;
+ default:
+ new TaskResultManager().defaultError(input.getOption(), HELP_MESSAGE);
+ }
+
+ }
+
+ @Override
+ public String getHelpMessage() {
+ return HELP_MESSAGE;
+ }
+
+ private enum Options {
+
+ HELP("--help"),
+ LIST_TASK("--list-task"),
+ LIST_RUNNING_JOBS("--list-running-jobs"),
+ LIST_SCHEDULED_JOBS("--list-scheduled-jobs"),
+ READ("--read"),
+ READ_EXECUTION("--read-execution"),
+ DELETE("--delete"),
+ DELETE_EXECUTION("--delete-execution"),
+ EXECUTE("--execute");
+
+ private final String optionName;
+
+ Options(final String optionName) {
+ this.optionName = optionName;
+ }
+
+ public String getOptionName() {
+ return optionName;
+ }
+
+ public boolean equalsOptionName(final String otherName) {
+ return (otherName == null) ? false : optionName.equals(otherName);
+ }
+
+ public static Options fromName(final String name) {
+ Options optionToReturn = HELP;
+ for (final Options option : Options.values()) {
+ if (option.equalsOptionName(name)) {
+ optionToReturn = option;
+ }
+ }
+ return optionToReturn;
+ }
+
+ public static List<String> toList() {
+ final List<String> options = new ArrayList<>();
+ for (final Options value : values()) {
+ options.add(value.getOptionName());
+ }
+ return options;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskDelete.java
new file mode 100644
index 0000000..655e112
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskDelete.java
@@ -0,0 +1,58 @@
+/*
+ * 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.client.cli.commands.task;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class TaskDelete extends AbstractTaskCommand {
+
+ private static final String DELETE_HELP_MESSAGE = "task --delete {TASK-ID} {TASK-ID} [...]";
+
+ private final Input input;
+
+ public TaskDelete(final Input input) {
+ this.input = input;
+ }
+
+ public void delete() {
+
+ if (input.parameterNumber() >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ taskService.delete(Long.valueOf(parameter));
+ taskResultManager.deletedMessage("Task", parameter);
+ } catch (final WebServiceException | SyncopeClientException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ taskResultManager.notFoundError("Task", parameter);
+ } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
+ taskResultManager.generic("You cannot delete task " + parameter);
+ } else {
+ taskResultManager.generic(ex.getMessage());
+ }
+ } catch (final NumberFormatException ex) {
+ taskResultManager.notBooleanDeletedError("task", parameter);
+ }
+ }
+ } else {
+ taskResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecute.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecute.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecute.java
new file mode 100644
index 0000000..9f53ece
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecute.java
@@ -0,0 +1,66 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.Arrays;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class TaskExecute extends AbstractTaskCommand {
+
+ private static final String EXECUTE_HELP_MESSAGE = "task --execute {TASK-ID} {DRY-RUN}\n"
+ + " Dry run: true / false";
+
+ private final Input input;
+
+ public TaskExecute(final Input input) {
+ this.input = input;
+ }
+
+ public void execute() {
+ if (input.parameterNumber() == 2) {
+ try {
+ final Long taskIdToExecute = Long.valueOf(input.firstParameter());
+ boolean dryRun = true;
+ if ("false".equalsIgnoreCase(input.secondParameter())) {
+ dryRun = false;
+ } else if ("true".equalsIgnoreCase(input.secondParameter())) {
+ dryRun = true;
+ } else {
+ taskResultManager.notBooleanDeletedError("dry run", input.secondParameter());
+ }
+ taskResultManager.printTaskExecTO(Arrays.asList(taskService.execute(taskIdToExecute, dryRun)));
+ } catch (final WebServiceException | SyncopeClientException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ taskResultManager.notFoundError("Task", input.firstParameter());
+ } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
+ taskResultManager.generic("You cannot delete task " + input.firstParameter());
+ } else {
+ taskResultManager.generic(ex.getMessage());
+ }
+ } catch (final NumberFormatException ex) {
+ taskResultManager.notBooleanDeletedError("task", input.firstParameter());
+ }
+ } else {
+ taskResultManager.commandOptionError(EXECUTE_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionDelete.java
new file mode 100644
index 0000000..a107716
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionDelete.java
@@ -0,0 +1,58 @@
+/*
+ * 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.client.cli.commands.task;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class TaskExecutionDelete extends AbstractTaskCommand {
+
+ private static final String DELETE_HELP_MESSAGE = "task --delete-execution "
+ + "{TASK-EXEC-ID} {TASK-EXEC-ID} [...]";
+
+ private final Input input;
+
+ public TaskExecutionDelete(final Input input) {
+ this.input = input;
+ }
+
+ public void delete() {
+ if (input.parameterNumber() >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ taskService.deleteExecution(Long.valueOf(parameter));
+ taskResultManager.deletedMessage("Task execution", parameter);
+ } catch (final WebServiceException | SyncopeClientException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ taskResultManager.notFoundError("Task execution", parameter);
+ } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
+ taskResultManager.generic("You cannot delete task execution" + parameter);
+ } else {
+ taskResultManager.generic(ex.getMessage());
+ }
+ } catch (final NumberFormatException ex) {
+ taskResultManager.notBooleanDeletedError("task execution", parameter);
+ }
+ }
+ } else {
+ taskResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionRead.java
new file mode 100644
index 0000000..d24641d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskExecutionRead.java
@@ -0,0 +1,58 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.Arrays;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class TaskExecutionRead extends AbstractTaskCommand {
+
+ private static final String EXECUTION_READ_HELP_MESSAGE = "task --read-execution {TASK-ID} {TASK-ID} [...]";
+
+ private final Input input;
+
+ public TaskExecutionRead(final Input input) {
+ this.input = input;
+ }
+
+ public void read() {
+ if (input.parameterNumber() >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ taskResultManager.printTaskExecTO(
+ Arrays.asList(taskService.readExecution(Long.valueOf(parameter))));
+ } catch (final NumberFormatException ex) {
+ taskResultManager.notBooleanDeletedError("task execution", parameter);
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ taskResultManager.notFoundError("Task execution", parameter);
+ } else {
+ taskResultManager.generic("Error: " + ex.getMessage());
+ }
+ break;
+ }
+ }
+ } else {
+ taskResultManager.commandOptionError(EXECUTION_READ_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskList.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskList.java
new file mode 100644
index 0000000..203dbcb
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskList.java
@@ -0,0 +1,59 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.LinkedList;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.util.CommandUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+
+public class TaskList extends AbstractTaskCommand {
+
+ private static final String LIST_HELP_MESSAGE = "task --list-task {TASK-TYPE}\n"
+ + " Task type: NOTIFICATION / PROPAGATION / PUSH / SCHEDULED / SYNCHRONIZATION";
+
+ private final Input input;
+
+ public TaskList(final Input input) {
+ this.input = input;
+ }
+
+ public void list() {
+ if (input.parameterNumber() == 1) {
+ try {
+ final TaskType taskType = TaskType.valueOf(input.firstParameter());
+ final LinkedList<AbstractTaskTO> taskTOs = new LinkedList<>();
+ for (final AbstractTaskTO taskTO : taskService.list(taskType, new TaskQuery()).getResult()) {
+ taskTOs.add(taskTO);
+ }
+ taskResultManager.fromList(taskType, taskTOs);
+ } catch (final SyncopeClientException ex) {
+ taskResultManager.generic(ex.getMessage());
+ } catch (final IllegalArgumentException ex) {
+ taskResultManager.typeNotValidError(
+ "task", input.firstParameter(), CommandUtils.fromEnumToArray(TaskType.class));
+ }
+ } else {
+ taskResultManager.commandOptionError(LIST_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRead.java
new file mode 100644
index 0000000..2538254
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRead.java
@@ -0,0 +1,60 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.LinkedList;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+
+public class TaskRead extends AbstractTaskCommand {
+
+ private static final String READ_HELP_MESSAGE = "task --read {TASK-ID} {TASK-ID} [...]";
+
+ private final Input input;
+
+ public TaskRead(final Input input) {
+ this.input = input;
+ }
+
+ public void read() {
+ if (input.parameterNumber() >= 1) {
+ final LinkedList<AbstractTaskTO> taskTOs = new LinkedList<>();
+ for (final String parameter : input.getParameters()) {
+ try {
+ taskTOs.add(taskService.read(Long.valueOf(parameter)));
+ } catch (final NumberFormatException ex) {
+ taskResultManager.notBooleanDeletedError("task", parameter);
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ taskResultManager.notFoundError("Task", parameter);
+ } else {
+ taskResultManager.generic("Error: " + ex.getMessage());
+ }
+ break;
+ }
+ }
+ taskResultManager.fromRead(taskTOs);
+ } else {
+ taskResultManager.commandOptionError(READ_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskResultManager.java
new file mode 100644
index 0000000..6075be7
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskResultManager.java
@@ -0,0 +1,222 @@
+/*
+ * 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.client.cli.commands.task;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+import org.apache.syncope.common.lib.to.AnyTO;
+import org.apache.syncope.common.lib.to.NotificationTaskTO;
+import org.apache.syncope.common.lib.to.PropagationTaskTO;
+import org.apache.syncope.common.lib.to.PushTaskTO;
+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.TaskType;
+
+public class TaskResultManager extends CommonsResultManager {
+
+ public void fromRead(final LinkedList<AbstractTaskTO> taskTOs) {
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ if (taskTO instanceof NotificationTaskTO) {
+ printNotificationTask((NotificationTaskTO) taskTO);
+ } else if (taskTO instanceof PropagationTaskTO) {
+ printPropagationTask((PropagationTaskTO) taskTO);
+ } else if (taskTO instanceof PushTaskTO) {
+ printPushTask((PushTaskTO) taskTO);
+ } else if (taskTO instanceof SchedTaskTO) {
+ printScheduledTask((SchedTaskTO) taskTO);
+ } else if (taskTO instanceof SyncTaskTO) {
+ printSyncTask((SyncTaskTO) taskTO);
+ }
+ }
+ }
+
+ public void fromList(final TaskType taskType, final LinkedList<AbstractTaskTO> taskTOs) {
+ switch (taskType) {
+ case NOTIFICATION:
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ printNotificationTask(((NotificationTaskTO) taskTO));
+ }
+ break;
+ case PROPAGATION:
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ printPropagationTask((PropagationTaskTO) taskTO);
+ }
+ break;
+ case PUSH:
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ printPushTask((PushTaskTO) taskTO);
+ }
+ break;
+ case SCHEDULED:
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ printScheduledTask((SchedTaskTO) taskTO);
+ }
+ break;
+ case SYNCHRONIZATION:
+ for (final AbstractTaskTO taskTO : taskTOs) {
+ printSyncTask((SyncTaskTO) taskTO);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void printNotificationTask(final NotificationTaskTO notificationTaskTO) {
+ System.out.println("");
+ System.out.println(" - Notification task key: " + notificationTaskTO.getKey());
+ System.out.println(" executed: " + notificationTaskTO.isExecuted());
+ System.out.println(" sender: " + notificationTaskTO.getSender());
+ System.out.println(" subjetc: " + notificationTaskTO.getSubject());
+ System.out.println(" text body: " + notificationTaskTO.getTextBody());
+ System.out.println(" html body: " + notificationTaskTO.getHtmlBody());
+ System.out.println(" latest execution status: "
+ + notificationTaskTO.getLatestExecStatus());
+ System.out.println(" start date: " + notificationTaskTO.getStartDate());
+ System.out.println(" end date: " + notificationTaskTO.getEndDate());
+ System.out.println(" recipients: " + notificationTaskTO.getRecipients());
+ System.out.println(" trace level: " + notificationTaskTO.getTraceLevel());
+ printTaskExecTO(notificationTaskTO.getExecutions());
+ System.out.println("");
+ }
+
+ private void printPropagationTask(final PropagationTaskTO propagationTaskTO) {
+ System.out.println("");
+ System.out.println(" - Propagation task key: " + propagationTaskTO.getKey());
+ System.out.println(" resource: " + propagationTaskTO.getResource());
+ System.out.println(" any key: " + propagationTaskTO.getAnyKey());
+ System.out.println(" any type kind: " + propagationTaskTO.getAnyTypeKind());
+ System.out.println(" connector object key: "
+ + propagationTaskTO.getConnObjectKey());
+ System.out.println(" old connector object key: "
+ + propagationTaskTO.getOldConnObjectKey());
+ System.out.println(" latest execution status: "
+ + propagationTaskTO.getLatestExecStatus());
+ System.out.println(" class name: " + propagationTaskTO.getObjectClassName());
+ System.out.println(" xml attribute: " + propagationTaskTO.getXmlAttributes());
+ System.out.println(" start date: " + propagationTaskTO.getStartDate());
+ System.out.println(" end date: " + propagationTaskTO.getEndDate());
+ System.out.println(" operation: " + propagationTaskTO.getOperation());
+ printTaskExecTO(propagationTaskTO.getExecutions());
+ System.out.println("");
+ }
+
+ private void printPushTask(final PushTaskTO pushTaskTO) {
+ System.out.println("");
+ System.out.println(" - Push task key: " + pushTaskTO.getKey());
+ System.out.println(" name: " + pushTaskTO.getName());
+ System.out.println(" resource: " + pushTaskTO.getResource());
+ System.out.println(" cron expression: " + pushTaskTO.getCronExpression());
+ System.out.println(" description: " + pushTaskTO.getDescription());
+ System.out.println(" is perform create: " + pushTaskTO.isPerformCreate());
+ System.out.println(" is perform delete: " + pushTaskTO.isPerformDelete());
+ System.out.println(" is perform update: " + pushTaskTO.isPerformUpdate());
+ System.out.println(" is sync status: " + pushTaskTO.isSyncStatus());
+ System.out.println(" start date: " + pushTaskTO.getStartDate());
+ System.out.println(" end date: " + pushTaskTO.getEndDate());
+ System.out.println(" last execution: " + pushTaskTO.getLastExec());
+ System.out.println(" next execution: " + pushTaskTO.getNextExec());
+ System.out.println(" latest execution status: "
+ + pushTaskTO.getLatestExecStatus());
+ System.out.println(" filters: " + pushTaskTO.getFilters());
+ System.out.println(" delegate class: " + pushTaskTO.getJobDelegateClassName());
+ System.out.println(" action class: " + pushTaskTO.getActionsClassNames());
+ System.out.println(" matching rule: " + pushTaskTO.getMatchingRule());
+ System.out.println(" not matching rule: " + pushTaskTO.getUnmatchingRule());
+ printTaskExecTO(pushTaskTO.getExecutions());
+
+ System.out.println("");
+ }
+
+ private void printScheduledTask(final SchedTaskTO schedTaskTO) {
+ System.out.println("");
+ System.out.println(" - Scheduled task key: " + schedTaskTO.getKey());
+ System.out.println(" name: " + schedTaskTO.getName());
+ System.out.println(" cron expression: " + schedTaskTO.getCronExpression());
+ System.out.println(" description: " + schedTaskTO.getDescription());
+ System.out.println(" start date: " + schedTaskTO.getStartDate());
+ System.out.println(" end date: " + schedTaskTO.getEndDate());
+ System.out.println(" last execution: " + schedTaskTO.getLastExec());
+ System.out.println(" next execution: " + schedTaskTO.getNextExec());
+ System.out.println(" latest execution status: "
+ + schedTaskTO.getLatestExecStatus());
+ System.out.println(" job delegate class: "
+ + schedTaskTO.getJobDelegateClassName());
+ printTaskExecTO(schedTaskTO.getExecutions());
+ System.out.println("");
+ }
+
+ private void printSyncTask(final SyncTaskTO syncTaskTO) {
+ System.out.println("");
+ System.out.println(" - Sync task key: " + syncTaskTO.getKey());
+ System.out.println(" name: " + syncTaskTO.getName());
+ System.out.println(" resource: " + syncTaskTO.getResource());
+ System.out.println(" realm destination: " + syncTaskTO.getDestinationRealm());
+ System.out.println(" cron expression: " + syncTaskTO.getCronExpression());
+ System.out.println(" description: " + syncTaskTO.getDescription());
+ System.out.println(" is full reconciliation: "
+ + syncTaskTO.isFullReconciliation());
+ System.out.println(" is perform create: " + syncTaskTO.isPerformCreate());
+ System.out.println(" is perform delete: " + syncTaskTO.isPerformDelete());
+ System.out.println(" is perform update: " + syncTaskTO.isPerformUpdate());
+ System.out.println(" is sync status: " + syncTaskTO.isSyncStatus());
+ System.out.println(" templates:");
+ for (Map.Entry<String, AnyTO> entrySet : syncTaskTO.getTemplates().entrySet()) {
+ final String key = entrySet.getKey();
+ final AnyTO value = entrySet.getValue();
+ System.out.println(" " + key + " key: " + value.getKey()
+ + " of realm" + value.getRealm()
+ + " on resource " + value.getResources());
+
+ }
+ System.out.println(" start date: " + syncTaskTO.getStartDate());
+ System.out.println(" end date: " + syncTaskTO.getEndDate());
+ System.out.println(" next execution: " + syncTaskTO.getNextExec());
+ System.out.println(" last execution: " + syncTaskTO.getLastExec());
+ System.out.println(" latest execution status: "
+ + syncTaskTO.getLatestExecStatus());
+ System.out.println(" job delegate class: "
+ + syncTaskTO.getJobDelegateClassName());
+ System.out.println(" action class name: " + syncTaskTO.getActionsClassNames());
+ System.out.println(" matching rule: " + syncTaskTO.getMatchingRule());
+ System.out.println(" unmatching rule: " + syncTaskTO.getUnmatchingRule());
+ printTaskExecTO(syncTaskTO.getExecutions());
+ System.out.println("");
+ }
+
+ public void printTaskExecTO(final List<TaskExecTO> taskExecTOs) {
+ for (final TaskExecTO taskExecTO : taskExecTOs) {
+ System.out.println(" EXECUTIONS: ");
+ System.out.println(" - task execution key: " + taskExecTO.getKey());
+ System.out.println(" task: " + taskExecTO.getTask());
+ System.out.println(" message: ");
+ System.out.println(" ############### <BEGIN MESSAGE> ###############");
+ System.out.println(" message: " + taskExecTO.getMessage());
+ System.out.println(" ############### <END MESSAGE> ###############");
+ System.out.println(" status: " + taskExecTO.getStatus());
+ System.out.println(" start date: " + taskExecTO.getStartDate());
+ System.out.println(" end date: " + taskExecTO.getEndDate());
+ System.out.println("");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRunningJobs.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRunningJobs.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRunningJobs.java
new file mode 100644
index 0000000..fdb886f
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskRunningJobs.java
@@ -0,0 +1,34 @@
+/*
+ * 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.client.cli.commands.task;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.types.JobStatusType;
+
+public class TaskRunningJobs extends AbstractTaskCommand {
+
+ public void list() {
+ try {
+ taskResultManager.printTaskExecTO(taskService.listJobs(JobStatusType.RUNNING));
+ } catch (final SyncopeClientException ex) {
+ taskResultManager.generic(ex.getMessage());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/73f73f20/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskScheduledJobs.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskScheduledJobs.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskScheduledJobs.java
new file mode 100644
index 0000000..d95f122
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/task/TaskScheduledJobs.java
@@ -0,0 +1,34 @@
+/*
+ * 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.client.cli.commands.task;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.types.JobStatusType;
+
+public class TaskScheduledJobs extends AbstractTaskCommand {
+
+ public void list() {
+ try {
+ taskResultManager.printTaskExecTO(taskService.listJobs(JobStatusType.SCHEDULED));
+ } catch (final SyncopeClientException ex) {
+ taskResultManager.generic(ex.getMessage());
+ }
+ }
+
+}