Subversion Repositories XServices

Rev

Rev 31 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 brianR 1
/*
2
 *   Mylyn Connector for Serena Business Mashups
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
4
 *
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
6
 *   you may not use this file except in compliance with the License.
7
 *   You may obtain a copy of the License at
8
 *
9
 *       http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *   Unless required by applicable law or agreed to in writing, software
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *   See the License for the specific language governing permissions and
15
 *   limitations under the License.
16
 *
17
 *   Serena, TeamTrack and Serena Business Mashup are
18
 * 	 registered trademarks of SERENA Software Inc.
19
 */
20
package net.brutex.mylyn.sbmconnector.core;
21
 
22
import java.util.Set;
23
 
24
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
25
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
26
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
27
import net.brutex.sbm.wsclient.TTItem;
28
 
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.mylyn.tasks.core.ITaskMapping;
32
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
33
import org.eclipse.mylyn.tasks.core.TaskRepository;
34
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
35
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
36
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
37
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
38
import org.eclipse.mylyn.tasks.core.data.TaskData;
39
 
40
/**
41
 * The Class SBMTicketDataHandler.
42
 */
43
public class SBMTicketDataHandler extends AbstractTaskDataHandler {
44
 
45
	/** The connector. */
46
	private final SBMRepositoryConnector connector;
47
 
48
	/**
49
	 * Instantiates a new SBM ticket data handler.
50
	 *
51
	 * @param connector the connector
52
	 */
53
	public SBMTicketDataHandler(SBMRepositoryConnector connector) {
54
		this.connector = connector;
55
	}
56
 
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository)
59
	 */
60
	@Override
61
	public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
62
		return new SBMTicketAttributeMapper(taskRepository);
63
	}
64
 
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, org.eclipse.mylyn.tasks.core.ITaskMapping, org.eclipse.core.runtime.IProgressMonitor)
67
	 */
68
	@Override
69
	public boolean initializeTaskData(TaskRepository repository, TaskData taskData,
70
			ITaskMapping initializationData, IProgressMonitor monitor)
71
			throws CoreException {
72
 
73
		/*TaskAttribute attribute = taskData.getRoot().createAttribute(SBMStaticFields.TITLE);
74
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_SHORT_TEXT).setLabel("Summary:");
75
 
76
		/*attribute = taskData.getRoot().createAttribute(SBMStaticFields.DESCRIPTION);
77
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_LONG_TEXT).setLabel("Description:");
78
 
79
		attribute = taskData.getRoot().createAttribute(SBMStaticFields.SUBMITDATE);
80
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_DATETIME).setLabel("Create Date:");
81
 
82
 
83
		  if (!taskData.isNew()) {
84
			attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL);
85
			attribute.getMetaData().setReadOnly(true).setKind(TaskAttribute.KIND_DEFAULT).setType(
86
					TaskAttribute.TYPE_URL).setLabel("Location:");
87
			File file = client.getTask(taskData.getTaskId(), monitor);
88
			try {
89
				attribute.setValue(file.toURI().toURL().toString());
90
			} catch (MalformedURLException e) {
91
			}
92
		}
93
 
94
		attribute = taskData.getRoot().createAttribute(TaskAttribute.PRODUCT);
95
		attribute.getMetaData().setReadOnly(false).setKind(TaskAttribute.KIND_DEFAULT).setType(
96
				TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project");
97
				*/
98
		taskData.setPartial(true);
99
		return true;
100
	}
101
 
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set, org.eclipse.core.runtime.IProgressMonitor)
104
	 */
105
	@Override
106
	public RepositoryResponse postTaskData(TaskRepository repository,
107
			TaskData taskData, Set<TaskAttribute> oldAttributes,
108
			IProgressMonitor monitor) throws CoreException {
109
		// TODO Auto-generated method stub
110
		return null;
111
	}
112
 
113
	/**
114
	 * Convert.
115
	 *
116
	 * @param repository the repository
117
	 * @param ttitem the ttitem
118
	 * @param monitor the monitor
119
	 * @return the task data
120
	 * @throws CoreException the core exception
121
	 */
122
	public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor)
123
		throws CoreException {
124
		TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
125
				SBMConnectorPlugin.CONNECTOR_KIND,
126
				repository.getRepositoryUrl(),
127
				ttitem.getGenericItem().getValue().getItemID().getValue());
128
		initializeTaskData(repository, data, null, monitor);
129
		// Create Fields for all the generic SBM (system) fields
130
		for (SBMTicketAttribute f : SBMTicketAttribute.values()) {
131
			TaskAttribute attr;
132
			if(f.getTaskName()!=null) {
133
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
134
			} else {
135
				attr = data.getRoot().createAttribute(f.getSBMName());
136
			}
137
			try {
138
				SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list
139
				attr.getMetaData().setReadOnly(true);
140
			} catch (IllegalArgumentException e) {
141
				attr.getMetaData().setReadOnly(false);
142
			}
143
			attr.getMetaData().setType(f.getTaskType());
144
			attr.getMetaData().setLabel(SBMRepositoryConnector.getClient(repository).getFieldLabel(ttitem, f.getSBMName()));
145
			if(f.isVisible()) {
146
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
147
			} else {
148
				attr.getMetaData().setKind(null);
149
			}
150
			attr.setValue(SBMRepositoryConnector.getClient(repository).getFieldValue(ttitem, f.getSBMName()));
151
		}
152
 
153
		//Custom fields
154
		TaskAttribute custom = data.getRoot().createAttribute("BLIBLABLUB");
155
		custom.getMetaData().setType(TaskAttribute.TYPE_BOOLEAN);
156
		custom.getMetaData().setLabel("BIILLALLLLLLLL");
157
		custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
158
		custom.setValue("roger");
159
 
160
		//Notes
161
		for(SBMNote n : SBMRepositoryConnector.getClient(repository).getNotes(ttitem)) {
162
			TaskCommentMapper mapper = new TaskCommentMapper();
163
			mapper.setCommentId(n.getId());
164
			mapper.setNumber(Integer.valueOf(n.getId()));
165
			mapper.setText(n.getText());
166
			mapper.setCreationDate(n.getCreation());
167
 
168
			TaskAttribute a = data.getRoot().createAttribute("NOTE"+n.getId());
169
			mapper.applyTo(a);
170
		}
171
 
172
		data.setPartial(false);
173
		return data;
174
	}
175
}