Subversion Repositories XServices

Rev

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

Rev 30 Rev 31
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
 
20
 
21
package net.brutex.mylyn.sbmconnector.core;
21
package net.brutex.mylyn.sbmconnector.core;
22
 
22
 
23
import java.math.BigInteger;
23
import java.math.BigInteger;
24
import java.net.URL;
24
import java.net.URL;
25
import java.util.ArrayList;
25
import java.util.ArrayList;
26
import java.util.Date;
26
import java.util.Date;
27
import java.util.Iterator;
27
import java.util.Iterator;
28
import java.util.List;
28
import java.util.List;
29
import java.util.StringTokenizer;
29
import java.util.StringTokenizer;
30
 
30
 
31
import javax.xml.namespace.QName;
31
import javax.xml.namespace.QName;
32
import javax.xml.ws.BindingProvider;
32
import javax.xml.ws.BindingProvider;
33
 
33
 
34
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
34
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
-
 
35
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
-
 
36
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
-
 
37
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
35
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
38
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
36
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
39
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
37
import net.brutex.sbm.wsclient.AEWebservicesFaultFault;
40
import net.brutex.sbm.wsclient.AEWebservicesFaultFault;
38
import net.brutex.sbm.wsclient.Aewebservices71;
41
import net.brutex.sbm.wsclient.Aewebservices71;
39
import net.brutex.sbm.wsclient.Aewebservices71PortType;
42
import net.brutex.sbm.wsclient.Aewebservices71PortType;
40
import net.brutex.sbm.wsclient.Auth;
43
import net.brutex.sbm.wsclient.Auth;
41
import net.brutex.sbm.wsclient.Field;
44
import net.brutex.sbm.wsclient.Field;
42
import net.brutex.sbm.wsclient.NameValue;
45
import net.brutex.sbm.wsclient.NameValue;
43
import net.brutex.sbm.wsclient.Note;
46
import net.brutex.sbm.wsclient.Note;
44
import net.brutex.sbm.wsclient.ObjectFactory;
47
import net.brutex.sbm.wsclient.ObjectFactory;
45
import net.brutex.sbm.wsclient.TTItem;
48
import net.brutex.sbm.wsclient.TTItem;
46
import net.brutex.sbm.wsclient.TableData;
49
import net.brutex.sbm.wsclient.TableData;
47
import net.brutex.sbm.wsclient.TableType;
50
import net.brutex.sbm.wsclient.TableType;
-
 
51
import net.brutex.sbm.wsclient.Value;
48
 
52
 
49
import org.eclipse.core.runtime.CoreException;
53
import org.eclipse.core.runtime.CoreException;
50
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
54
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
51
import org.eclipse.mylyn.commons.net.AuthenticationType;
55
import org.eclipse.mylyn.commons.net.AuthenticationType;
52
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
56
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
53
import org.eclipse.mylyn.tasks.core.TaskRepository;
57
import org.eclipse.mylyn.tasks.core.TaskRepository;
54
 
58
 
55
public class SBMClient {
59
public class SBMClient {
56
 
60
 
57
	private Aewebservices71PortType port;
61
	private Aewebservices71PortType port;
58
	private static final QName SERVICE_NAME = new QName("http://localhost:80/gsoap/aewebservices71.wsdl", "aewebservices71");
62
	private static final QName SERVICE_NAME = new QName("http://localhost:80/gsoap/aewebservices71.wsdl", "aewebservices71");
59
	private TaskRepository repository;
63
	private TaskRepository repository;
60
	private ObjectFactory of;
64
	private ObjectFactory of;
61
	private List<TableData> tables = new ArrayList<TableData>();
65
	private List<TableData> tables = new ArrayList<TableData>();
62
	
66
	
63
	public SBMClient(TaskRepository repository) {
67
	public SBMClient(TaskRepository repository) {
64
		this.repository = repository;
68
		this.repository = repository;
65
		this.of = new ObjectFactory();
69
		this.of = new ObjectFactory();
66
		
70
		
67
        URL wsdlURL = Aewebservices71.WSDL_LOCATION;
71
        URL wsdlURL = Aewebservices71.WSDL_LOCATION;
68
		wsdlURL = this.getClass().getResource("/META-INF/aewebservices71.wsdl");
72
		wsdlURL = this.getClass().getResource("/META-INF/aewebservices71.wsdl");
69
        Aewebservices71 ss = new Aewebservices71(wsdlURL, SERVICE_NAME);
73
        Aewebservices71 ss = new Aewebservices71(wsdlURL, SERVICE_NAME);
70
        port = ss.getAewebservices71();
74
        port = ss.getAewebservices71();
71
        ((BindingProvider)port).getRequestContext().put(
75
        ((BindingProvider)port).getRequestContext().put(
72
        		BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
76
        		BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
73
        		repository.getRepositoryUrl());
77
        		repository.getRepositoryUrl());
74
	}
78
	}
75
	
79
	
76
	public boolean canAuthenticate() throws CoreException {
80
	public boolean canAuthenticate() throws CoreException {
77
		try {
81
		try {
78
			port.getUser(getAuth(), repository.getCredentials(AuthenticationType.REPOSITORY).getUserName());
82
			port.getUser(getAuth(), repository.getCredentials(AuthenticationType.REPOSITORY).getUserName());
79
		} catch (AEWebservicesFaultFault e) {
83
		} catch (AEWebservicesFaultFault e) {
80
			new CoreException(RepositoryStatus.createLoginError(
84
			new CoreException(RepositoryStatus.createLoginError(
81
					repository.getRepositoryUrl(), SBMConnectorPlugin.PLUGIN_ID));
85
					repository.getRepositoryUrl(), SBMConnectorPlugin.PLUGIN_ID));
82
			return false;
86
			return false;
83
		}
87
		}
84
		return true;
88
		return true;
85
	}
89
	}
86
	
90
	
87
	public List<TTItem> getTTItemsByTable(String tablename, String sql_where) throws CoreException {
91
	public List<TTItem> getTTItemsByTable(String tablename, String sql_where) throws CoreException {
88
		List<TTItem> list = new ArrayList<TTItem>();
92
		List<TTItem> list = new ArrayList<TTItem>();
89
		if(sql_where==null || sql_where.isEmpty()) sql_where = "TS_ID>0";
93
		if(sql_where==null || sql_where.isEmpty()) sql_where = "TS_ID>0";
90
		try {
94
		try {
91
			list = port.getItemsByQueryWithName(
95
			list = port.getItemsByQueryWithName(
92
					getAuth(), 
96
					getAuth(), 
93
					tablename, 
97
					tablename, 
94
					"("+sql_where+")",
98
					"("+sql_where+")",
95
					"TS_SUBMITDATE desc",
99
					"TS_SUBMITDATE desc",
96
					BigInteger.valueOf(500l), null);
100
					BigInteger.valueOf(500l), null);
97
		} catch (AEWebservicesFaultFault e) {
101
		} catch (AEWebservicesFaultFault e) {
98
			new CoreException(
102
			new CoreException(
99
					RepositoryStatus.createInternalError(
103
					RepositoryStatus.createInternalError(
100
							SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
104
							SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
101
		}
105
		}
102
		return list;
106
		return list;
103
	}
107
	}
104
	
108
	
105
	public TTItem getTTItem(String itemid) {
109
	public TTItem getTTItem(String itemid) {
106
		TTItem item = of.createTTItem();
110
		TTItem item = of.createTTItem();
107
			try {
111
			try {
108
				item = port.getItem(getAuth(), itemid, null);
112
				item = port.getItem(getAuth(), itemid, null);
109
			} catch (AEWebservicesFaultFault e) {
113
			} catch (AEWebservicesFaultFault e) {
110
				new CoreException(
114
				new CoreException(
111
						RepositoryStatus.createInternalError(
115
						RepositoryStatus.createInternalError(
112
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
116
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
113
			}
117
			}
114
			return item;
118
			return item;
115
	}
119
	}
116
	
120
	
117
 
121
 
118
	
122
	
119
	private Auth getAuth() {
123
	private Auth getAuth() {
120
		Auth auth = of.createAuth();
124
		Auth auth = of.createAuth();
121
		AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY);
125
		AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY);
122
		auth.setUserId(of.createAuthUserId(credentials.getUserName()));
126
		auth.setUserId(of.createAuthUserId(credentials.getUserName()));
123
		auth.setPassword(of.createAuthPassword(credentials.getPassword()));	
127
		auth.setPassword(of.createAuthPassword(credentials.getPassword()));	
124
		return auth;
128
		return auth;
125
	}
129
	}
-
 
130
 
-
 
131
	/**
-
 
132
	 * Gets the field value for a system generic field.
-
 
133
	 *
-
 
134
	 * @param ttitem the ttitem
-
 
135
	 * @param fieldname the fieldname
-
 
136
	 * @return the static field value
126
 
137
	 */
127
	public String getFieldValue(TTItem ttitem, String fieldname) {
138
	public String getStaticFieldValue(TTItem ttitem, String fieldname) {
128
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
139
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
129
			Date date = ttitem.getCreateDate().getValue().toGregorianCalendar().getTime();
140
			Date date = ttitem.getCreateDate().getValue().toGregorianCalendar().getTime();
130
			return String.valueOf(date.getTime());
141
			return String.valueOf(date.getTime());
131
		}
142
		}
132
		if(fieldname.equals(SBMStaticFields.LASTMODIFIEDDATE.getValue())) {
143
		if(fieldname.equals(SBMStaticFields.LASTMODIFIEDDATE.getValue())) {
133
			return String.valueOf(ttitem.getModifiedDate().getValue().toGregorianCalendar().getTimeInMillis());
144
			return String.valueOf(ttitem.getModifiedDate().getValue().toGregorianCalendar().getTimeInMillis());
134
		}
145
		}
135
		if(fieldname.equals("TITLE")) {
146
		if(fieldname.equals("TITLE")) {
136
			if(ttitem.getTitle()==null || ttitem.getTitle().isNil()) return "";
147
			if(ttitem.getTitle()==null || ttitem.getTitle().isNil()) return "";
137
			return ttitem.getTitle().getValue();
148
			return ttitem.getTitle().getValue();
138
		}
149
		}
139
		if(fieldname.equals(SBMStaticFields.ISSUEID.getValue())) {
150
		if(fieldname.equals(SBMStaticFields.ISSUEID.getValue())) {
140
			if(ttitem.getGenericItem()==null || ttitem.getGenericItem().getValue().getItemName()==null) {
151
			if(ttitem.getGenericItem()==null || ttitem.getGenericItem().getValue().getItemName()==null) {
141
				return "";
152
				return "";
142
			}
153
			}
143
			return ttitem.getGenericItem().getValue().getItemName().getValue();
154
			return ttitem.getGenericItem().getValue().getItemName().getValue();
144
		}
155
		}
145
		if(fieldname.equals("ISSUETYPE")) {
156
		if(fieldname.equals("ISSUETYPE")) {
146
			if(ttitem.getItemType()==null || ttitem.getItemType().isNil()) return "";
157
			if(ttitem.getItemType()==null || ttitem.getItemType().isNil()) return "";
147
			return ttitem.getItemType().getValue();
158
			return ttitem.getItemType().getValue();
148
		}
159
		}
149
		if(fieldname.equals(SBMStaticFields.STATE.getValue())) {
160
		if(fieldname.equals(SBMStaticFields.STATE.getValue())) {
150
			if(ttitem.getState()==null || ttitem.getState().isNil()) return "";
161
			if(ttitem.getState()==null || ttitem.getState().isNil()) return "";
151
			return ttitem.getState().getValue();
162
			return ttitem.getState().getValue();
152
		}
163
		}
153
		if(fieldname.equals(SBMStaticFields.ID.getValue())) {
164
		if(fieldname.equals(SBMStaticFields.ID.getValue())) {
154
			return ttitem.getGenericItem().getValue().getItemID().getValue();
165
			return ttitem.getGenericItem().getValue().getItemID().getValue();
155
		}
166
		}
156
		if(fieldname.equals(SBMStaticFields.PROJECTID.getValue())) {
167
		if(fieldname.equals(SBMStaticFields.PROJECTID.getValue())) {
157
			if(ttitem.getClassification() ==null || ttitem.getClassification().isNil()) return "";
168
			if(ttitem.getClassification() ==null || ttitem.getClassification().isNil()) return "";
158
			return ttitem.getClassification().getValue();
169
			return ttitem.getClassification().getValue();
159
		}
170
		}
160
		if(fieldname.equals(SBMStaticFields.PROJECTUUID.getValue())) {
171
		if(fieldname.equals(SBMStaticFields.PROJECTUUID.getValue())) {
161
			if(ttitem.getClassificationUUID()==null || ttitem.getClassificationUUID().isNil()) return "";
172
			if(ttitem.getClassificationUUID()==null || ttitem.getClassificationUUID().isNil()) return "";
162
			return ttitem.getClassificationUUID().getValue();
173
			return ttitem.getClassificationUUID().getValue();
163
		}
174
		}
164
		if(fieldname.equals("DESCRIPTION")) {
175
		if(fieldname.equals("DESCRIPTION")) {
165
			if(ttitem.getDescription() == null || ttitem.getDescription().isNil()) return "";
176
			if(ttitem.getDescription() == null || ttitem.getDescription().isNil()) return "";
166
			return ttitem.getDescription().getValue();
177
			return ttitem.getDescription().getValue();
167
		} 
178
		} 
168
		if(fieldname.equals(SBMStaticFields.SUBMITTER.getValue())) {
179
		if(fieldname.equals(SBMStaticFields.SUBMITTER.getValue())) {
169
			if(ttitem.getCreatedBy()==null || ttitem.getCreatedBy().isNil()) return "";
180
			if(ttitem.getCreatedBy()==null || ttitem.getCreatedBy().isNil()) return "";
170
			return ttitem.getCreatedBy().getValue();
181
			return ttitem.getCreatedBy().getValue();
171
		}
182
		}
172
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
183
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
173
			return String.valueOf(ttitem.getCreateDate().getValue().toGregorianCalendar().getTimeInMillis());
184
			return String.valueOf(ttitem.getCreateDate().getValue().toGregorianCalendar().getTimeInMillis());
174
		}
185
		}
175
		if(fieldname.equals(SBMStaticFields.LASTMODIFIER.getValue())) {
186
		if(fieldname.equals(SBMStaticFields.LASTMODIFIER.getValue())) {
176
			if(ttitem.getModifiedBy()==null || ttitem.getModifiedBy().isNil()) return "";
187
			if(ttitem.getModifiedBy()==null || ttitem.getModifiedBy().isNil()) return "";
177
			return ttitem.getModifiedBy().getValue();
188
			return ttitem.getModifiedBy().getValue();
178
		}
189
		}
179
		if(fieldname.equals(SBMStaticFields.LASTMODIFIEDDATE.getValue())) {
190
		if(fieldname.equals(SBMStaticFields.LASTMODIFIEDDATE.getValue())) {
180
			return String.valueOf(ttitem.getModifiedDate().getValue().toGregorianCalendar().getTimeInMillis());
191
			return String.valueOf(ttitem.getModifiedDate().getValue().toGregorianCalendar().getTimeInMillis());
181
		}
192
		}
182
		if(fieldname.equals(SBMStaticFields.ACTIVEINACTIVE.getValue())) {
193
		if(fieldname.equals(SBMStaticFields.ACTIVEINACTIVE.getValue())) {
183
			return ttitem.getActiveInactive().getValue();
194
			return ttitem.getActiveInactive().getValue();
184
		}
195
		}
185
		if(fieldname.equals(SBMStaticFields.OWNER.getValue())) {
196
		if(fieldname.equals(SBMStaticFields.OWNER.getValue())) {
186
			return ttitem.getOwner().getValue();
197
			return ttitem.getOwner().getValue();
187
		}
198
		}
188
		if(fieldname.equals(SBMStaticFields.ITEMURL.getValue())) {
199
		if(fieldname.equals(SBMStaticFields.ITEMURL.getValue())) {
189
			return ttitem.getUrl().getValue();
200
			return ttitem.getUrl().getValue();
190
		}
201
		}
191
		if(fieldname.equals(SBMStaticFields.UUID.getValue())) {
202
		if(fieldname.equals(SBMStaticFields.UUID.getValue())) {
192
			return ttitem.getGenericItem().getValue().getItemUUID().getValue();
203
			return ttitem.getGenericItem().getValue().getItemUUID().getValue();
193
		}
204
		}
194
		if(fieldname.equals(SBMStaticFields.CLOSEDATE.getValue())) {
205
		if(fieldname.equals(SBMStaticFields.CLOSEDATE.getValue())) {
195
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
206
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
196
			while (list.hasNext()) {
207
			while (list.hasNext()) {
197
				NameValue field = list.next();
208
				NameValue field = list.next();
198
				if(field.getName().getValue().equals("CLOSEDATE")) {
209
				if(field.getName().getValue().equals("CLOSEDATE")) {
199
					return field.getValue().getValue().getInternalValue().getValue();
210
					return field.getValue().getValue().getInternalValue().getValue();
200
				}
211
				}
201
			}
212
			}
202
		}
213
		}
203
		if(fieldname.equals(SBMStaticFields.LASTSTATECHANGEDATE.getValue())) {
214
		if(fieldname.equals(SBMStaticFields.LASTSTATECHANGEDATE.getValue())) {
204
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
215
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
205
			while (list.hasNext()) {
216
			while (list.hasNext()) {
206
				NameValue field = list.next();
217
				NameValue field = list.next();
207
				if(field.getName().getValue().equals("LASTSTATECHANGEDATE")) {
218
				if(field.getName().getValue().equals("LASTSTATECHANGEDATE")) {
208
					return field.getValue().getValue().getInternalValue().getValue();
219
					return field.getValue().getValue().getInternalValue().getValue();
209
				}
220
				}
210
			}
221
			}
211
		}
222
		}
212
		if(fieldname.equals(SBMStaticFields.SECONDARYOWNER.getValue())) {
223
		if(fieldname.equals(SBMStaticFields.SECONDARYOWNER.getValue())) {
213
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
224
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
214
			while (list.hasNext()) {
225
			while (list.hasNext()) {
215
				NameValue field = list.next();
226
				NameValue field = list.next();
216
				if(field.getName().getValue().equals("SECONDARYOWNER")) {
227
				if(field.getName().getValue().equals("SECONDARYOWNER")) {
217
					return field.getValue().getValue().getInternalValue().getValue();
228
					return field.getValue().getValue().getInternalValue().getValue();
218
				}
229
				}
219
			}
230
			}
220
		}
231
		}
221
		if(fieldname.equals(SBMStaticFields.LASTSTATECHANGER.getValue())) {
232
		if(fieldname.equals(SBMStaticFields.LASTSTATECHANGER.getValue())) {
222
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
233
			Iterator<NameValue> list = ttitem.getExtendedFieldList().iterator();
223
			while (list.hasNext()) {
234
			while (list.hasNext()) {
224
				NameValue field = list.next();
235
				NameValue field = list.next();
225
				if(field.getName().getValue().equals("LASTSTATECHANGER")) {
236
				if(field.getName().getValue().equals("LASTSTATECHANGER")) {
226
					return field.getValue().getValue().getDisplayValue().getValue();
237
					return field.getValue().getValue().getDisplayValue().getValue();
227
				}
238
				}
228
			}
239
			}
229
		}
240
		}
230
 
241
 
231
		return "UNKNOWN";
242
		return "UNKNOWN";
232
	}
243
	}
233
	
-
 
234
	//Todo caching
244
	
235
	public String getFieldLabel(TTItem ttitem, String fieldname) {
-
 
-
 
245
	public String getFieldLabel(TTItem ttitem, String fieldname) {
236
		
246
		refreshTables();
237
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
247
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
238
		String tableid = new StringTokenizer(itemid, ":").nextToken();
-
 
239
		if (tables.isEmpty()) {
-
 
240
			try {
-
 
241
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
-
 
242
			} catch (AEWebservicesFaultFault e) {
-
 
243
				new CoreException(
-
 
244
						RepositoryStatus.createInternalError(
-
 
245
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
-
 
246
			}
-
 
247
		}
248
		String tableid = new StringTokenizer(itemid, ":").nextToken();
248
		for (TableData table : tables) {
249
		for (TableData table : tables) {
249
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
250
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
250
				Iterator<Field> iter = table.getFieldList().iterator();
251
				Iterator<Field> iter = table.getFieldList().iterator();
251
				while(iter.hasNext()) {
252
				while(iter.hasNext()) {
252
					Field f = iter.next();
253
					Field f = iter.next();
253
					if(f.getName().getValue().equals(fieldname)) {
254
					if(f.getName().getValue().equals(fieldname)) {
254
						return f.getDisplayName().getValue();
255
						return f.getDisplayName().getValue();
255
					}
256
					}
256
				}
257
				}
257
				break;
258
				break;
258
			}
259
			}
259
		}
260
		}
260
	return "label_UNKNOWN";
261
	return "label_UNKNOWN";
261
	}
262
	}
-
 
263
	
-
 
264
	/**
-
 
265
	 * Gets the table database name.
-
 
266
	 *
-
 
267
	 * @param ttitem the ttitem
-
 
268
	 * @return the table name or null in case table is not found
-
 
269
	 */
-
 
270
	public String getTableName(TTItem ttitem) {
-
 
271
		refreshTables();
-
 
272
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
-
 
273
		String tableid = new StringTokenizer(itemid, ":").nextToken();
-
 
274
		for (TableData table : tables) {
-
 
275
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
-
 
276
				return table.getName().getValue();
-
 
277
			}
-
 
278
		}
-
 
279
		return null;
-
 
280
	}
262
	
281
	
263
	public List<SBMNote> getNotes(TTItem ttitem) {
282
	public List<SBMNote> getNotes(TTItem ttitem) {
264
		List<SBMNote> notes = new ArrayList<SBMNote>();
283
		List<SBMNote> notes = new ArrayList<SBMNote>();
265
		Iterator<Note> iter = ttitem.getNoteList().iterator();
284
		Iterator<Note> iter = ttitem.getNoteList().iterator();
266
		while(iter.hasNext()) {
285
		while(iter.hasNext()) {
267
			Note n = iter.next();
286
			Note n = iter.next();
268
			SBMNote note = new SBMNote("sbm_user", 
287
			SBMNote note = new SBMNote("sbm_user", 
269
					n.getTitle().getValue()+"\n"+n.getNote().getValue(),
288
					n.getTitle().getValue()+"\n"+n.getNote().getValue(),
270
					n.getModificationDateTime().toGregorianCalendar().getTime(),
289
					n.getModificationDateTime().toGregorianCalendar().getTime(),
271
					n.getId().toString());
290
					n.getId().toString());
272
			notes.add(note);
291
			notes.add(note);
273
		}
292
		}
274
		return notes;
293
		return notes;
275
	}
294
	}
-
 
295
 
-
 
296
	
-
 
297
	/**
-
 
298
	 * Gets the names of all available primary tables.
-
 
299
	 * A table name is a unique reference within one SBM environment, thus can be
-
 
300
	 * used as a key.
-
 
301
	 *
-
 
302
	 * @return the primary table names as a list
276
 
303
	 */
-
 
304
	public List<String> getPrimaryTables() {
277
	public List<String> getPrimaryTables() {
305
		refreshTables();
-
 
306
		List<String> table_names = new ArrayList<String>();
-
 
307
		for (TableData table : tables) {
-
 
308
			table_names.add(table.getName().getValue());
-
 
309
		}
-
 
310
		return table_names;
-
 
311
	}
-
 
312
	
-
 
313
	/**
-
 
314
	 * Refresh table specifications from SBM web service. This
-
 
315
	 * is only done once per SBMClient instance.
-
 
316
	 */
278
		List<String> table_names = new ArrayList<String>();
317
	private void refreshTables() {
279
		if (tables.isEmpty()) {
318
		if (tables.isEmpty()) {
-
 
319
			try {
280
			try {
320
				//currently we limit this to primary tables
281
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
321
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
282
			} catch (AEWebservicesFaultFault e) {
322
			} catch (AEWebservicesFaultFault e) {
283
				new CoreException(
323
				new CoreException(
284
						RepositoryStatus.createInternalError(
324
						RepositoryStatus.createInternalError(
285
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
325
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
286
			}
326
			}
287
		}
327
		}
-
 
328
	}
-
 
329
	
-
 
330
	/**
-
 
331
	 * Gets the fields for a primary table
-
 
332
	 *
-
 
333
	 * @param tablename the table database name
-
 
334
	 * @return the fields, empty when table does not exist
-
 
335
	 */
-
 
336
	public List<SBMField> getFields(String tablename) {
-
 
337
		refreshTables();
-
 
338
		List<SBMField> fields = new ArrayList<SBMField>();
288
		for (TableData table : tables) {
339
		for (TableData table : tables) {
-
 
340
			if(table.getName().getValue().equals(tablename)) {
-
 
341
				Iterator<Field> iter = table.getFieldList().iterator();
-
 
342
				while(iter.hasNext()) {
-
 
343
					Field f = iter.next();
-
 
344
					SBMField nf = new SBMField(
-
 
345
							SBMFieldTypes.fromValue(f.getFieldType().value()),
-
 
346
							tablename,
-
 
347
							f.getDisplayName().getValue(),
289
			table_names.add(table.getName().getValue());
348
							f.getName().getValue());
-
 
349
					fields.add(nf);
-
 
350
				}
-
 
351
				break;
-
 
352
			}
290
		}
353
		}
-
 
354
		return fields;
-
 
355
	}
-
 
356
	
-
 
357
	/**
-
 
358
	 * Gets the field value for custom defined field.
-
 
359
	 * (those from &lt;extendedFieldList&gt;)
-
 
360
	 *
-
 
361
	 * @param ttitem the ttitem
-
 
362
	 * @param fieldname the fieldname
-
 
363
	 * @return the field value or null if the field is not found
-
 
364
	 */
-
 
365
	public SBMFieldValue getFieldValue(TTItem ttitem, String fieldname) {
-
 
366
		SBMFieldValue value;
-
 
367
		Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator();
-
 
368
		while(fs.hasNext()) {
-
 
369
			NameValue nv = fs.next();
-
 
370
			if(nv.getName().getValue().equals(fieldname)) {
-
 
371
				if (nv.getValue()!=null && !nv.getValue().isNil()) {
-
 
372
					value = new SBMFieldValue(
-
 
373
							nv.getValue().getValue().getInternalValue().getValue(),
-
 
374
							nv.getValue().getValue().getDisplayValue().getValue());
-
 
375
					return value;
-
 
376
				}
-
 
377
			}
-
 
378
		}
-
 
379
		return null;
-
 
380
	}
-
 
381
	
-
 
382
	/**
-
 
383
	 * Gets the field values for custom defined, multi type field.
-
 
384
	 * (those from &lt;extendedFieldList&gt;)
-
 
385
	 *
-
 
386
	 * @param ttitem the ttitem
-
 
387
	 * @param fieldname the fieldname
-
 
388
	 * @return the list of field values
-
 
389
	 */
-
 
390
	public List<SBMFieldValue> getFieldValues(TTItem ttitem, String fieldname) {
-
 
391
		List<SBMFieldValue> values = new ArrayList<SBMFieldValue>();
-
 
392
		Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator();
-
 
393
		while(fs.hasNext()) {
-
 
394
			NameValue nv = fs.next();
-
 
395
			if(nv.getName().getValue().equals(fieldname)) {
-
 
396
				if (nv.getValues()!=null && !nv.getValues().isEmpty()) {
-
 
397
					Iterator<Value> nvv = nv.getValues().iterator();
-
 
398
					while(nvv.hasNext()) {
-
 
399
						Value nvv_value = nvv.next();			
-
 
400
						SBMFieldValue value = new SBMFieldValue(
-
 
401
							nvv_value.getInternalValue().getValue(),
-
 
402
							nvv_value.getDisplayValue().getValue());
-
 
403
						values.add(value);
-
 
404
					}
-
 
405
					return values;
-
 
406
				}
-
 
407
			}
-
 
408
		}
291
		return table_names;
409
		return values;
292
	}
410
	}
293
}
411
}