Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2015-05-18 11:27:13 +0000
committerMarkus Tiede2015-05-18 11:27:23 +0000
commite66fc5be1788e4b63721a908f6fbd219d6ceffa0 (patch)
treef42fd10e8497a334d8578f56eb0320acb4526996 /org.eclipse.jubula.mylyn
parent9ec76298562e11ad4cc4f676dc6a519a5a38a462 (diff)
downloadorg.eclipse.jubula.core-e66fc5be1788e4b63721a908f6fbd219d6ceffa0.tar.gz
org.eclipse.jubula.core-e66fc5be1788e4b63721a908f6fbd219d6ceffa0.tar.xz
org.eclipse.jubula.core-e66fc5be1788e4b63721a908f6fbd219d6ceffa0.zip
Sprint task - refactor to provide infrastructure for (shareable; client independent) mylyn integration bundle : part 5 - relocate attribute update methods.
Diffstat (limited to 'org.eclipse.jubula.mylyn')
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/exceptions/InvalidALMAttributeException.java1
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java4
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties4
-rw-r--r--org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java129
4 files changed, 137 insertions, 1 deletions
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/exceptions/InvalidALMAttributeException.java b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/exceptions/InvalidALMAttributeException.java
index 705f92cd5..bf951f9d0 100644
--- a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/exceptions/InvalidALMAttributeException.java
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/exceptions/InvalidALMAttributeException.java
@@ -12,7 +12,6 @@ package org.eclipse.jubula.mylyn.exceptions;
/**
* @author BREDEX GmbH
- *
*/
public class InvalidALMAttributeException extends Exception {
/** serialVersionUID */
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java
index 6855fa9e7..d013a385f 100644
--- a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/Messages.java
@@ -22,6 +22,10 @@ public class Messages extends NLS {
public static String TaskRepositoryOffline;
public static String TaskRepositoryNoCredentialsStored;
public static String TaskRepositoryNoConnectorFound;
+ public static String InvalidAttributeID;
+ public static String BlankAttributeID;
+ public static String ReadOnlyAttributeID;
+ public static String InvalidValue;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties
index 37341af81..b25df0006 100644
--- a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/i18n/messages.properties
@@ -9,3 +9,7 @@ TaskRepositoryNotFound=No local task repository configuration "{0}" found.
TaskRepositoryOffline=The given task repository "{0}" is currently configured as offline.
TaskRepositoryNoCredentialsStored=There are no authentication credentials stored for "{0}".
TaskRepositoryNoConnectorFound=There is currently no connector available for the repository "{0}".
+InvalidValue=... value "{0}" is not allowed for attributeID "{1}";
+ReadOnlyAttributeID=... attributeID "{0}" is a read-only property;
+InvalidAttributeID=... attributeID "{0}" is invalid;
+BlankAttributeID=... blank attributeIDs are not allowed. \ No newline at end of file
diff --git a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java
index 23d0d9f31..8538388b1 100644
--- a/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java
+++ b/org.eclipse.jubula.mylyn/src/org/eclipse/jubula/mylyn/utils/MylynAccess.java
@@ -10,22 +10,32 @@
*******************************************************************************/
package org.eclipse.jubula.mylyn.utils;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jubula.mylyn.Activator;
+import org.eclipse.jubula.mylyn.exceptions.InvalidALMAttributeException;
import org.eclipse.jubula.mylyn.i18n.Messages;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryManager;
import org.eclipse.mylyn.tasks.core.IRepositoryModel;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
+import org.eclipse.mylyn.tasks.core.data.ITaskDataManager;
+import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.osgi.util.NLS;
import org.slf4j.Logger;
@@ -177,4 +187,123 @@ public final class MylynAccess {
}
return Status.OK_STATUS;
}
+
+ /**
+ * Updates fields in ALM system
+ * @param repo the task repository to perform the update in
+ * @param taskId task id
+ * @param attributeUpdates list of field updates
+ * @param monitor monitor
+ * @return OK if succeeded; WARNING when problems; ERROR otherwise
+ */
+ public static IStatus updateAttributes(TaskRepository repo, String taskId,
+ List<Map<String, String>> attributeUpdates, IProgressMonitor monitor) {
+
+ IStatus status = new Status(IStatus.ERROR, Activator.ID,
+ "No task data found in the given repository!"); //$NON-NLS-1$
+ try {
+ TaskData taskData = MylynAccess.getTaskDataByID(
+ repo, taskId, monitor);
+ if (taskData == null) {
+ return status;
+ }
+
+ ITask task = MylynAccess.getTaskByID(
+ repo, taskData.getTaskId(), monitor);
+ if (task != null) {
+ ITaskDataManager taskDataManager = TasksUi.getTaskDataManager();
+ ITaskDataWorkingCopy taskWorkingCopy = taskDataManager
+ .createWorkingCopy(task, taskData);
+ TaskDataModel taskModel = new TaskDataModel(repo, task,
+ taskWorkingCopy);
+
+ String connectorKind = repo.getConnectorKind();
+ AbstractRepositoryConnector connector = TasksUi
+ .getRepositoryConnector(connectorKind);
+ AbstractTaskDataHandler taskDataHandler = connector
+ .getTaskDataHandler();
+ TaskAttribute rootData = taskModel.getTaskData()
+ .getRoot();
+ List<TaskAttribute> changes = attributeUpdateHandling(
+ attributeUpdates, rootData);
+
+ if (changes.isEmpty()) {
+ return status;
+ }
+ for (TaskAttribute change : changes) {
+ taskModel.attributeChanged(change);
+ }
+
+ RepositoryResponse response = taskDataHandler.postTaskData(
+ taskModel.getTaskRepository(), taskModel.getTaskData(),
+ taskModel.getChangedOldAttributes(), monitor);
+
+ if (RepositoryResponse.ResponseKind.TASK_UPDATED
+ .equals(response.getReposonseKind())) {
+ status = new Status(IStatus.OK, Activator.ID,
+ "Task has been updated."); //$NON-NLS-1$
+ } else {
+ status = new Status(IStatus.WARNING, Activator.ID,
+ "Task has not been updated successfully."); //$NON-NLS-1$
+ }
+ }
+ } catch (InvalidALMAttributeException e) {
+ status = new Status(IStatus.ERROR, Activator.ID,
+ e.getMessage());
+ } catch (CoreException e) {
+ status = new Status(IStatus.ERROR, Activator.ID,
+ e.getLocalizedMessage());
+ } catch (IllegalArgumentException e) {
+ LOG.error(e.getLocalizedMessage(), e);
+ // This is necessary due to an IllegalArgumentException which might be
+ // thrown in the TaskDataHandler
+ status = new Status(IStatus.ERROR, Activator.ID,
+ e.getLocalizedMessage(), e);
+ }
+ return status;
+ }
+
+
+ /**
+ * Creates list of task attributes to change for default repository type
+ * @param attributeUpdates the attributes updates
+ * @param rootAttr root attribute
+ * @return list of task attributes to change
+ * @throws InvalidALMAttributeException
+ */
+ private static List<TaskAttribute> attributeUpdateHandling(
+ List<Map<String, String>> attributeUpdates, TaskAttribute rootAttr)
+ throws InvalidALMAttributeException {
+ List<TaskAttribute> changes = new ArrayList<TaskAttribute>();
+
+ for (Map<String, String> attributesToChange : attributeUpdates) {
+ for (String key : attributesToChange.keySet()) {
+ if (StringUtils.isBlank(key)) {
+ throw new InvalidALMAttributeException(
+ Messages.BlankAttributeID);
+ }
+ TaskAttribute attributeUpdate = rootAttr.getAttribute(key);
+ if (attributeUpdate == null) {
+ throw new InvalidALMAttributeException(NLS.bind(
+ Messages.InvalidAttributeID, key));
+ }
+ if (attributeUpdate.getMetaData().isReadOnly()) {
+ throw new InvalidALMAttributeException(NLS.bind(
+ Messages.ReadOnlyAttributeID, key));
+ }
+ String value = attributesToChange.get(key);
+ Map<String, String> options = attributeUpdate.getOptions();
+ if (options != null && !options.isEmpty()) {
+ if (!options.containsKey(value)) {
+ throw new InvalidALMAttributeException(NLS.bind(
+ Messages.InvalidValue, value, key));
+ }
+ }
+ attributeUpdate.setValue(value);
+
+ changes.add(attributeUpdate);
+ }
+ }
+ return changes;
+ }
} \ No newline at end of file

Back to the top