Subversion Repositories XServices

Rev

Rev 31 | Rev 42 | Go to most recent revision | Details | Compare with Previous | 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
 
31 brianR 22
import java.util.List;
30 brianR 23
import java.util.Set;
24
 
25
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
31 brianR 26
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
27
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes;
28
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
29
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
30 brianR 30
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
31
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
32
import net.brutex.sbm.wsclient.TTItem;
33
 
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IProgressMonitor;
36
import org.eclipse.mylyn.tasks.core.ITaskMapping;
37
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
38
import org.eclipse.mylyn.tasks.core.TaskRepository;
39
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
40
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
41
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
42
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
43
import org.eclipse.mylyn.tasks.core.data.TaskData;
44
 
45
/**
46
 * The Class SBMTicketDataHandler.
47
 */
48
public class SBMTicketDataHandler extends AbstractTaskDataHandler {
49
 
50
	/** The connector. */
51
	private final SBMRepositoryConnector connector;
52
 
53
	/**
54
	 * Instantiates a new SBM ticket data handler.
55
	 *
56
	 * @param connector the connector
57
	 */
58
	public SBMTicketDataHandler(SBMRepositoryConnector connector) {
59
		this.connector = connector;
60
	}
61
 
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository)
64
	 */
65
	@Override
66
	public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
67
		return new SBMTicketAttributeMapper(taskRepository);
68
	}
69
 
70
	/* (non-Javadoc)
71
	 * @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)
72
	 */
73
	@Override
74
	public boolean initializeTaskData(TaskRepository repository, TaskData taskData,
75
			ITaskMapping initializationData, IProgressMonitor monitor)
76
			throws CoreException {
77
 
78
		/*TaskAttribute attribute = taskData.getRoot().createAttribute(SBMStaticFields.TITLE);
79
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_SHORT_TEXT).setLabel("Summary:");
80
 
81
		/*attribute = taskData.getRoot().createAttribute(SBMStaticFields.DESCRIPTION);
82
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_LONG_TEXT).setLabel("Description:");
83
 
84
		attribute = taskData.getRoot().createAttribute(SBMStaticFields.SUBMITDATE);
85
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_DATETIME).setLabel("Create Date:");
86
 
87
 
88
		  if (!taskData.isNew()) {
89
			attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL);
90
			attribute.getMetaData().setReadOnly(true).setKind(TaskAttribute.KIND_DEFAULT).setType(
91
					TaskAttribute.TYPE_URL).setLabel("Location:");
92
			File file = client.getTask(taskData.getTaskId(), monitor);
93
			try {
94
				attribute.setValue(file.toURI().toURL().toString());
95
			} catch (MalformedURLException e) {
96
			}
97
		}
98
 
99
		attribute = taskData.getRoot().createAttribute(TaskAttribute.PRODUCT);
100
		attribute.getMetaData().setReadOnly(false).setKind(TaskAttribute.KIND_DEFAULT).setType(
101
				TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project");
102
				*/
103
		taskData.setPartial(true);
104
		return true;
105
	}
106
 
107
	/* (non-Javadoc)
108
	 * @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)
109
	 */
110
	@Override
111
	public RepositoryResponse postTaskData(TaskRepository repository,
112
			TaskData taskData, Set<TaskAttribute> oldAttributes,
113
			IProgressMonitor monitor) throws CoreException {
114
		// TODO Auto-generated method stub
115
		return null;
116
	}
117
 
118
	/**
119
	 * Convert.
120
	 *
121
	 * @param repository the repository
122
	 * @param ttitem the ttitem
123
	 * @param monitor the monitor
124
	 * @return the task data
125
	 * @throws CoreException the core exception
126
	 */
127
	public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor)
128
		throws CoreException {
31 brianR 129
		SBMClient client = SBMRepositoryConnector.getClient(repository);
30 brianR 130
		TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
131
				SBMConnectorPlugin.CONNECTOR_KIND,
132
				repository.getRepositoryUrl(),
34 brianR 133
				ttitem.getGenericItem().getValue().getItemName().getValue()+" ["+
134
				ttitem.getGenericItem().getValue().getItemID().getValue()+"]");
30 brianR 135
		initializeTaskData(repository, data, null, monitor);
136
		// Create Fields for all the generic SBM (system) fields
137
		for (SBMTicketAttribute f : SBMTicketAttribute.values()) {
138
			TaskAttribute attr;
139
			if(f.getTaskName()!=null) {
140
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
141
			} else {
142
				attr = data.getRoot().createAttribute(f.getSBMName());
143
			}
144
			try {
145
				SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list
146
				attr.getMetaData().setReadOnly(true);
147
			} catch (IllegalArgumentException e) {
148
				attr.getMetaData().setReadOnly(false);
149
			}
150
			attr.getMetaData().setType(f.getTaskType());
31 brianR 151
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName()));
30 brianR 152
			if(f.isVisible()) {
153
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
154
			} else {
155
				attr.getMetaData().setKind(null);
156
			}
34 brianR 157
			/*
158
			if(f.getTaskType()==TaskAttribute.TYPE_SINGLE_SELECT) {
159
				List<SBMFieldValue> options =
160
					client.getValidSet(client.getTableName(ttitem), f.getSBMName());
161
				for( SBMFieldValue optionvalue: options) {
162
					attr.putOption(optionvalue.getValue(), optionvalue.getValue());
163
				}
164
			}
165
			*/
31 brianR 166
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName()));
34 brianR 167
 
30 brianR 168
		}
169
 
31 brianR 170
		//Custom fields
171
		List<SBMField> customfields = client.getFields(client.getTableName(ttitem));
172
		for(SBMField f : customfields) {
173
			if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) {
174
				continue;
175
			}
176
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
177
			custom.getMetaData().setType(
178
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType()));
179
			custom.getMetaData().setLabel(f.getLabel());
180
			custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
34 brianR 181
			custom.getMetaData().setReadOnly(false);
31 brianR 182
			if(f.getType()==SBMFieldTypes.SELECTION &&
183
					client.getFieldValue(ttitem, f.getName())!=null) {
34 brianR 184
				List<SBMFieldValue> options =
185
					client.getValidSet(client.getTableName(ttitem), f.getName());
186
				for( SBMFieldValue optionvalue: options) {
187
					custom.putOption(optionvalue.getInternalValue(), optionvalue.getValue());
188
				}
31 brianR 189
				String val = client.getFieldValue(ttitem, f.getName()).getValue();
190
				custom.setValue(val);
191
			} else if(f.getType()==SBMFieldTypes.MULTIPLE_SELECTION
192
					|| f.getType()==SBMFieldTypes.MULTIPLE_RELATIONAL
193
					|| f.getType()==SBMFieldTypes.MULTIPLE_GROUP
194
					|| f.getType()==SBMFieldTypes.MULTIPLE_USERGROUP) {
195
				List<SBMFieldValue> values = client.getFieldValues(ttitem, f.getName());
196
				for(SBMFieldValue val : values) {
197
					custom.putOption(val.getInternalValue(), val.getValue());
198
					custom.addValue(val.getValue());
199
				}
200
			} else if(client.getFieldValue(ttitem, f.getName())!=null) {
201
					custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue());
202
			}
203
		}
30 brianR 204
 
205
		//Notes
31 brianR 206
		for(SBMNote n : client.getNotes(ttitem)) {
30 brianR 207
			TaskCommentMapper mapper = new TaskCommentMapper();
208
			mapper.setCommentId(n.getId());
209
			mapper.setNumber(Integer.valueOf(n.getId()));
210
			mapper.setText(n.getText());
211
			mapper.setCreationDate(n.getCreation());
212
 
213
			TaskAttribute a = data.getRoot().createAttribute("NOTE"+n.getId());
214
			mapper.applyTo(a);
215
		}
216
 
217
		data.setPartial(false);
218
		return data;
219
	}
220
}