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