Subversion Repositories XServices

Rev

Rev 31 | Rev 39 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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