Subversion Repositories XServices

Rev

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

Rev 175 Rev 185
1
/*
1
/*
2
 *   Copyright 2014 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2014 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.ws.rs;
17
package net.brutex.xservices.ws.rs;
18
 
18
 
19
 
19
 
20
 
20
 
21
import java.io.File;
21
import java.io.File;
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.net.MalformedURLException;
23
import java.net.MalformedURLException;
24
import java.net.URI;
24
import java.net.URI;
25
import java.net.URL;
25
import java.net.URL;
26
import java.nio.file.FileVisitOption;
26
import java.nio.file.FileVisitOption;
27
import java.nio.file.Files;
27
import java.nio.file.Files;
28
import java.nio.file.Path;
28
import java.nio.file.Path;
29
import java.util.ArrayList;
29
import java.util.ArrayList;
30
import java.util.EnumSet;
30
import java.util.EnumSet;
31
import java.util.List;
31
import java.util.List;
32
import javax.ws.rs.core.HttpHeaders;
32
import javax.ws.rs.core.HttpHeaders;
33
import javax.ws.rs.core.Response;
33
import javax.ws.rs.core.Response;
34
import javax.ws.rs.core.UriInfo;
34
import javax.ws.rs.core.UriInfo;
-
 
35
 
-
 
36
import org.apache.commons.configuration2.PropertiesConfiguration;
-
 
37
import org.apache.commons.configuration2.builder.fluent.Configurations;
-
 
38
import org.apache.commons.configuration2.ex.ConfigurationException;
-
 
39
import org.apache.commons.jcs.JCS;
-
 
40
import org.apache.commons.jcs.access.CacheAccess;
-
 
41
import org.apache.commons.jcs.access.exception.CacheException;
-
 
42
import org.apache.logging.log4j.LogManager;
-
 
43
import org.apache.logging.log4j.Logger;
35
 
44
 
36
import net.brutex.xservices.cmtypes.ItemType;
45
import net.brutex.xservices.cmtypes.ItemType;
37
import net.brutex.xservices.cmtypes.ItemTypeList;
46
import net.brutex.xservices.cmtypes.ItemTypeList;
38
import net.brutex.xservices.types.FileInfoType;
47
import net.brutex.xservices.types.FileInfoType;
39
import net.brutex.xservices.util.FileWalker;
48
import net.brutex.xservices.util.FileWalker;
40
 
-
 
41
import org.apache.commons.configuration.ConfigurationException;
-
 
42
import org.apache.commons.configuration.PropertiesConfiguration;
-
 
43
import org.apache.jcs.JCS;
-
 
44
import org.apache.jcs.access.exception.CacheException;
-
 
45
import org.apache.log4j.Logger;
49
 
46
 
50
 
47
 
51
 
48
/*
52
/*
49
 * The Serena Dimensions CM Java API is required for these imports.
53
 * The Serena Dimensions CM Java API is required for these imports.
50
 * The API is not included in this package due to copyright reasons,
54
 * The API is not included in this package due to copyright reasons,
51
 * please get Dimensions CM from Serena Software Inc., Evaluation versions
55
 * please get Dimensions CM from Serena Software Inc., Evaluation versions
52
 * are available from http://www.serena.com
56
 * are available from http://www.serena.com
53
 * 
57
 * 
54
 * required Jars:
58
 * required Jars:
55
 * serena.darius-14.1.jar
59
 * serena.darius-14.1.jar
56
 * serena.dmclient-14.1.jar
60
 * serena.dmclient-14.1.jar
57
 * serena.dmfile-14.1.jar
61
 * serena.dmfile-14.1.jar
58
 * serena.dmnet-14.1.jar
62
 * serena.dmnet-14.1.jar
59
 * serena.dmtpi-14.1.jar
63
 * serena.dmtpi-14.1.jar
60
 * 
64
 * 
61
 */
65
 */
62
 
66
 
63
import com.serena.dmclient.api.BulkOperator;
67
import com.serena.dmclient.api.BulkOperator;
64
import com.serena.dmclient.api.DimensionsConnection;
68
import com.serena.dmclient.api.DimensionsConnection;
65
import com.serena.dmclient.api.DimensionsConnectionDetails;
69
import com.serena.dmclient.api.DimensionsConnectionDetails;
66
import com.serena.dmclient.api.DimensionsConnectionManager;
70
import com.serena.dmclient.api.DimensionsConnectionManager;
67
import com.serena.dmclient.api.ItemRevision;
71
import com.serena.dmclient.api.ItemRevision;
68
import com.serena.dmclient.api.Project;
72
import com.serena.dmclient.api.Project;
69
import com.serena.dmclient.api.RepositoryFolder;
73
import com.serena.dmclient.api.RepositoryFolder;
70
import com.serena.dmclient.api.SystemAttributes;
74
import com.serena.dmclient.api.SystemAttributes;
71
 
75
 
72
/**
76
/**
73
 * The Class FileInfoImpl.
77
 * The Class FileInfoImpl.
74
 * 
78
 * 
75
 * @author Brian Rosenberger, bru(at)brutex.de
79
 * @author Brian Rosenberger, bru(at)brutex.de
76
 */
80
 */
77
public class DIMCMInfoImpl implements DIMCMInfo {
81
public class DIMCMInfoImpl implements DIMCMInfo {
78
 
82
 
79
	Logger logger = Logger.getLogger(DIMCMInfoImpl.class);
83
	Logger logger = LogManager.getLogger();
80
 
84
 
81
	/*
85
	/*
82
	 * (non-Javadoc)
86
	 * (non-Javadoc)
83
	 * 
87
	 * 
84
	 * @see
88
	 * @see
85
	 * net.brutex.xservices.ws.rs.FileInfo#getFiles(javax.ws.rs.core.HttpHeaders
89
	 * net.brutex.xservices.ws.rs.FileInfo#getFiles(javax.ws.rs.core.HttpHeaders
86
	 * , java.lang.String, boolean, boolean, int, java.lang.String, int, int)
90
	 * , java.lang.String, boolean, boolean, int, java.lang.String, int, int)
87
	 */
91
	 */
88
	public Response getFiles(HttpHeaders h, UriInfo uriInfo, String projSpec,
92
	public Response getFiles(HttpHeaders h, UriInfo uriInfo, String projSpec,
89
			String directory, boolean recursive, boolean withFiles, int level,
93
			String directory, boolean recursive, boolean withFiles, int level,
90
			String search, int count, int page, boolean useCache) throws CacheException {
94
			String search, int count, int page, boolean useCache) throws CacheException {
91
 
95
 
92
		
96
		
93
		/*
97
		/*
94
		 * try to hit cache first
98
		 * try to hit cache first
95
		 */
99
		 */
96
		JCS cache = JCS.getInstance("DIMCM");
100
		CacheAccess<Object, Object> cache = JCS.getInstance("DIMCM");
97
		String cachekey = projSpec + directory + String.valueOf(recursive);
101
		String cachekey = projSpec + directory + String.valueOf(recursive);
98
		if(useCache) {
102
		if(useCache) {
99
				ItemTypeList cacheresult = (ItemTypeList) cache.get(cachekey);
103
				ItemTypeList cacheresult = (ItemTypeList) cache.get(cachekey);
100
				if(cacheresult != null) return Response.ok(cacheresult).build();
104
				if(cacheresult != null) return Response.ok(cacheresult).build();
101
		}
105
		}
102
		
106
		
103
		//Reject when project has not the form "PRODUCT:PROJECT"
107
		//Reject when project has not the form "PRODUCT:PROJECT"
104
		if(! projSpec.contains(":")) return Response.noContent().build();
108
		if(! projSpec.contains(":")) return Response.noContent().build();
105
		
109
		
106
		Project project = getDIMCMConnection().getObjectFactory().getProject(projSpec);
110
		Project project = getDIMCMConnection().getObjectFactory().getProject(projSpec);
107
		RepositoryFolder folder = null;
111
		RepositoryFolder folder = null;
108
		
112
		
109
		if (directory == null) {
113
		if (directory == null) {
110
			folder = project.getRootFolder();
114
			folder = project.getRootFolder();
111
		} else {
115
		} else {
112
			while(directory.startsWith("/") || directory.startsWith("\\")) {
116
			while(directory.startsWith("/") || directory.startsWith("\\")) {
113
				directory = directory.substring(1);
117
				directory = directory.substring(1);
114
			}
118
			}
115
			if(directory.equals("")) {
119
			if(directory.equals("")) {
116
				folder = project.getRootFolder();
120
				folder = project.getRootFolder();
117
			} else {
121
			} else {
118
				folder = project.findRepositoryFolderByPath(directory);
122
				folder = project.findRepositoryFolderByPath(directory);
119
			}
123
			}
120
		}
124
		}
121
 
125
 
122
		
126
		
123
		ItemTypeList resultlist = new ItemTypeList();
127
		ItemTypeList resultlist = new ItemTypeList();
124
		resultlist.list = getItems(folder, recursive);
128
		resultlist.list = getItems(folder, recursive);
125
		if(cache!=null) cache.put(cachekey, resultlist);
129
		if(cache!=null) cache.put(cachekey, resultlist);
126
		
130
		
127
		//does this help?
131
		//does this help?
128
		DimensionsConnectionManager.unregisterThreadConnection();
132
		DimensionsConnectionManager.unregisterThreadConnection();
129
		
133
		
130
		return Response.ok(resultlist).build();
134
		return Response.ok(resultlist).build();
131
 
135
 
132
	}
136
	}
133
 
137
 
134
	
138
	
135
	
139
	
136
	
140
	
137
	List<ItemType> getItems(RepositoryFolder f, boolean recursive) {
141
	List<ItemType> getItems(RepositoryFolder f, boolean recursive) {
138
		DimensionsConnection conn = getDIMCMConnection();
142
		DimensionsConnection conn = getDIMCMConnection();
139
		List<ItemType> result = new ArrayList<>();
143
		List<ItemType> result = new ArrayList<>();
140
 
144
 
141
		/* get Items from current folder */
145
		/* get Items from current folder */
142
		/* latest revision only */
146
		/* latest revision only */
143
		List<ItemRevision> revisions = f.getLatestItemRevisions();
147
		List<ItemRevision> revisions = f.getLatestItemRevisions();
144
 
148
 
145
		int[] attr = { SystemAttributes.FULL_PATH_NAME,
149
		int[] attr = { SystemAttributes.FULL_PATH_NAME,
146
				SystemAttributes.ITEMFILE_DIR,
150
				SystemAttributes.ITEMFILE_DIR,
147
				SystemAttributes.ITEMFILE_FILENAME,
151
				SystemAttributes.ITEMFILE_FILENAME,
148
				SystemAttributes.ITEMFILE_DIR, SystemAttributes.OBJECT_SPEC,
152
				SystemAttributes.ITEMFILE_DIR, SystemAttributes.OBJECT_SPEC,
149
				SystemAttributes.OBJECT_ID, SystemAttributes.OBJECT_SPEC_UID,
153
				SystemAttributes.OBJECT_ID, SystemAttributes.OBJECT_SPEC_UID,
150
				SystemAttributes.OBJECT_UID, SystemAttributes.CREATION_DATE,
154
				SystemAttributes.OBJECT_UID, SystemAttributes.CREATION_DATE,
151
				SystemAttributes.CREATION_USER, SystemAttributes.ITEM_FORMAT,
155
				SystemAttributes.CREATION_USER, SystemAttributes.ITEM_FORMAT,
152
				SystemAttributes.LAST_UPDATED_DATE,
156
				SystemAttributes.LAST_UPDATED_DATE,
153
				SystemAttributes.LAST_UPDATED_USER };
157
				SystemAttributes.LAST_UPDATED_USER };
154
		BulkOperator bulk = conn.getObjectFactory().getBulkOperator(revisions);
158
		BulkOperator bulk = conn.getObjectFactory().getBulkOperator(revisions);
155
		bulk.queryAttribute(attr);
159
		bulk.queryAttribute(attr);
156
 
160
 
157
		// Copy into JAXB object
161
		// Copy into JAXB object
158
		for (ItemRevision r : revisions) {
162
		for (ItemRevision r : revisions) {
159
			ItemType item = new ItemType();
163
			ItemType item = new ItemType();
160
			item.setLongFilename((String) r
164
			item.setLongFilename((String) r
161
					.getAttribute(SystemAttributes.FULL_PATH_NAME));
165
					.getAttribute(SystemAttributes.FULL_PATH_NAME));
162
			item.setDirName((String) r
166
			item.setDirName((String) r
163
					.getAttribute(SystemAttributes.ITEMFILE_DIR));
167
					.getAttribute(SystemAttributes.ITEMFILE_DIR));
164
			item.setShortFilename((String) r
168
			item.setShortFilename((String) r
165
					.getAttribute(SystemAttributes.ITEMFILE_FILENAME));
169
					.getAttribute(SystemAttributes.ITEMFILE_FILENAME));
166
			item.setObject_id((String) r
170
			item.setObject_id((String) r
167
					.getAttribute(SystemAttributes.OBJECT_ID));
171
					.getAttribute(SystemAttributes.OBJECT_ID));
168
			item.setObject_uid((String.valueOf(r
172
			item.setObject_uid((String.valueOf(r
169
					.getAttribute(SystemAttributes.OBJECT_UID))));
173
					.getAttribute(SystemAttributes.OBJECT_UID))));
170
			item.setObject_spec((String) r
174
			item.setObject_spec((String) r
171
					.getAttribute(SystemAttributes.OBJECT_SPEC));
175
					.getAttribute(SystemAttributes.OBJECT_SPEC));
172
			item.setObject_spec_uid(String.valueOf(r
176
			item.setObject_spec_uid(String.valueOf(r
173
					.getAttribute(SystemAttributes.OBJECT_SPEC_UID)));
177
					.getAttribute(SystemAttributes.OBJECT_SPEC_UID)));
174
			item.setObject_spec_uid(String.valueOf(r
178
			item.setObject_spec_uid(String.valueOf(r
175
					.getAttribute(SystemAttributes.OBJECT_SPEC_UID)));
179
					.getAttribute(SystemAttributes.OBJECT_SPEC_UID)));
176
			item.setCreatedDate(String.valueOf(r
180
			item.setCreatedDate(String.valueOf(r
177
					.getAttribute(SystemAttributes.CREATION_DATE)));
181
					.getAttribute(SystemAttributes.CREATION_DATE)));
178
			item.setCreatedUser(String.valueOf(r
182
			item.setCreatedUser(String.valueOf(r
179
					.getAttribute(SystemAttributes.CREATION_USER)));
183
					.getAttribute(SystemAttributes.CREATION_USER)));
180
			item.setItemFormat(String.valueOf(r
184
			item.setItemFormat(String.valueOf(r
181
					.getAttribute(SystemAttributes.ITEM_FORMAT)));
185
					.getAttribute(SystemAttributes.ITEM_FORMAT)));
182
			item.setUpdatedDate(String.valueOf(r
186
			item.setUpdatedDate(String.valueOf(r
183
					.getAttribute(SystemAttributes.LAST_UPDATED_DATE)));
187
					.getAttribute(SystemAttributes.LAST_UPDATED_DATE)));
184
			item.setUpdatedUser(String.valueOf(r
188
			item.setUpdatedUser(String.valueOf(r
185
					.getAttribute(SystemAttributes.LAST_UPDATED_USER)));
189
					.getAttribute(SystemAttributes.LAST_UPDATED_USER)));
186
 
190
 
187
			try {
191
			try {
188
				item.setUrl(new URL(getBaseURL()
192
				item.setUrl(new URL(getBaseURL()
189
						+ "?jsp=api&command=openi&object_id="
193
						+ "?jsp=api&command=openi&object_id="
190
						+ item.getObject_spec() + "&DB_CONN="
194
						+ item.getObject_spec() + "&DB_CONN="
191
						+ conn.getConnectionDetails().getDbConn() + "&DB_NAME="
195
						+ conn.getConnectionDetails().getDbConn() + "&DB_NAME="
192
						+ conn.getConnectionDetails().getDbName()));
196
						+ conn.getConnectionDetails().getDbName()));
193
			} catch (MalformedURLException e) {
197
			} catch (MalformedURLException e) {
194
				// TODO Auto-generated catch block
198
				// TODO Auto-generated catch block
195
				e.printStackTrace();
199
				e.printStackTrace();
196
			}
200
			}
197
			result.add(item);
201
			result.add(item);
198
		}
202
		}
199
		
203
		
200
		/*
204
		/*
201
		 * for recursive add other folders
205
		 * for recursive add other folders
202
		 */
206
		 */
203
		if(recursive) {
207
		if(recursive) {
204
			List<RepositoryFolder> folders = f.getAllChildFolders();
208
			List<RepositoryFolder> folders = f.getAllChildFolders();
205
			for(RepositoryFolder ff : folders) {
209
			for(RepositoryFolder ff : folders) {
206
				result.addAll(getItems(ff, false));
210
				result.addAll(getItems(ff, false));
207
			}
211
			}
208
		}
212
		}
209
		
213
		
210
		return result;
214
		return result;
211
	}
215
	}
212
 
216
 
213
	/**
217
	/**
214
	 * Sets the directory.
218
	 * Sets the directory.
215
	 * 
219
	 * 
216
	 * @param list
220
	 * @param list
217
	 *            the list
221
	 *            the list
218
	 * @param dir
222
	 * @param dir
219
	 *            the dir
223
	 *            the dir
220
	 * @param withDirectories
224
	 * @param withDirectories
221
	 *            the with directories
225
	 *            the with directories
222
	 * @param withFiles
226
	 * @param withFiles
223
	 *            the with files
227
	 *            the with files
224
	 * @param depth
228
	 * @param depth
225
	 *            the depth
229
	 *            the depth
226
	 * @param search
230
	 * @param search
227
	 *            the search
231
	 *            the search
228
	 */
232
	 */
229
	private void setDirectory(final URI baseuri, final List<FileInfoType> list,
233
	private void setDirectory(final URI baseuri, final List<FileInfoType> list,
230
			File dir, boolean withDirectories, boolean withFiles,
234
			File dir, boolean withDirectories, boolean withFiles,
231
			final int depth, String search) {
235
			final int depth, String search) {
232
		if (depth <= 0)
236
		if (depth <= 0)
233
			return;
237
			return;
234
 
238
 
235
		if (search == null || search.equals("")) {
239
		if (search == null || search.equals("")) {
236
			search = "*";
240
			search = "*";
237
			logger.info("No search pattern supplied, using default '*'.");
241
			logger.info("No search pattern supplied, using default '*'.");
238
		}
242
		}
239
 
243
 
240
		FileWalker finder = new FileWalker(search);
244
		FileWalker finder = new FileWalker(search);
241
		try {
245
		try {
242
			Files.walkFileTree(dir.toPath(),
246
			Files.walkFileTree(dir.toPath(),
243
					EnumSet.of(FileVisitOption.FOLLOW_LINKS), depth, finder);
247
					EnumSet.of(FileVisitOption.FOLLOW_LINKS), depth, finder);
244
			logger.info("FileWalker returned '" + finder.getCount()
248
			logger.info("FileWalker returned '" + finder.getCount()
245
					+ "' hits. '" + finder.getTotal()
249
					+ "' hits. '" + finder.getTotal()
246
					+ "' files have been scanned.");
250
					+ "' files have been scanned.");
247
			List<Path> result = finder.getResult();
251
			List<Path> result = finder.getResult();
248
			for (Path f : result) {
252
			for (Path f : result) {
249
				if (!withDirectories) {
253
				if (!withDirectories) {
250
					if (f.toFile().isDirectory())
254
					if (f.toFile().isDirectory())
251
						continue;
255
						continue;
252
				}
256
				}
253
				if (!withFiles) {
257
				if (!withFiles) {
254
					if (f.toFile().isFile())
258
					if (f.toFile().isFile())
255
						continue;
259
						continue;
256
				}
260
				}
257
				list.add(new FileInfoType(f, baseuri));
261
				list.add(new FileInfoType(f, baseuri));
258
			}
262
			}
259
		} catch (IOException e2) {
263
		} catch (IOException e2) {
260
			logger.error(e2.getMessage(), e2);
264
			logger.error(e2.getMessage(), e2);
261
			;
265
			;
262
		}
266
		}
263
	}
267
	}
264
 
268
 
265
	/**
269
	/**
266
	 * Sets the directory.
270
	 * Sets the directory.
267
	 * 
271
	 * 
268
	 * @param dir
272
	 * @param dir
269
	 *            the dir
273
	 *            the dir
270
	 * @param withDirectories
274
	 * @param withDirectories
271
	 *            the with directories
275
	 *            the with directories
272
	 * @param withFiles
276
	 * @param withFiles
273
	 *            the with files
277
	 *            the with files
274
	 * @param depth
278
	 * @param depth
275
	 *            the depth
279
	 *            the depth
276
	 * @param search
280
	 * @param search
277
	 *            the search
281
	 *            the search
278
	 * @return the list
282
	 * @return the list
279
	 */
283
	 */
280
	private List<FileInfoType> setDirectory(URI baseuri, String dir,
284
	private List<FileInfoType> setDirectory(URI baseuri, String dir,
281
			boolean withDirectories, boolean withFiles, int depth, String search) {
285
			boolean withDirectories, boolean withFiles, int depth, String search) {
282
		List<FileInfoType> list = new ArrayList<FileInfoType>();
286
		List<FileInfoType> list = new ArrayList<FileInfoType>();
283
		setDirectory(baseuri, list, new File(dir), withDirectories, withFiles,
287
		setDirectory(baseuri, list, new File(dir), withDirectories, withFiles,
284
				depth, search);
288
				depth, search);
285
		return list;
289
		return list;
286
	}
290
	}
287
 
291
 
288
	private boolean isPermitted(String dir) {
292
	private boolean isPermitted(String dir) {
289
		/*
293
		/*
290
		 * 
294
		 * 
291
		 * logger.warn(String.format(
295
		 * logger.warn(String.format(
292
		 * "User '%s' does not have permission to access '%s'."
296
		 * "User '%s' does not have permission to access '%s'."
293
		 * ,SecurityUtils.getSubject().getPrincipal(), dir )); throw new
297
		 * ,SecurityUtils.getSubject().getPrincipal(), dir )); throw new
294
		 * NotAuthorizedException(new
298
		 * NotAuthorizedException(new
295
		 * UnauthorizedException("User does not have permission to access "+
299
		 * UnauthorizedException("User does not have permission to access "+
296
		 * dir)); }
300
		 * dir)); }
297
		 */
301
		 */
298
		return true;
302
		return true;
299
	}
303
	}
300
 
304
 
301
	// http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
305
	// http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
302
	private static String humanReadableByteCount(long bytes, boolean si) {
306
	private static String humanReadableByteCount(long bytes, boolean si) {
303
		int unit = si ? 1000 : 1024;
307
		int unit = si ? 1000 : 1024;
304
		if (bytes < unit)
308
		if (bytes < unit)
305
			return bytes + " B";
309
			return bytes + " B";
306
		int exp = (int) (Math.log(bytes) / Math.log(unit));
310
		int exp = (int) (Math.log(bytes) / Math.log(unit));
307
		String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1)
311
		String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1)
308
				+ (si ? "" : "i");
312
				+ (si ? "" : "i");
309
		return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
313
		return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
310
	}
314
	}
311
 
315
 
312
	private DimensionsConnection getDIMCMConnection() {
316
	private DimensionsConnection getDIMCMConnection() {
313
		/*
317
		/*
314
		 * Do we have a registered connection already?
318
		 * Do we have a registered connection already?
315
		 */
319
		 */
316
		DimensionsConnection conn = null;
320
		DimensionsConnection conn = null;
317
		
321
		
318
		try {
322
		try {
319
			conn = DimensionsConnectionManager.getThreadConnection();
323
			conn = DimensionsConnectionManager.getThreadConnection();
320
			if (conn != null)
324
			if (conn != null)
321
				return conn;
325
				return conn;
322
		} catch (Exception e) {
326
		} catch (Exception e) {
323
			logger.error(e.getMessage());
327
			logger.error(e.getMessage());
324
		}
328
		}
325
 
329
 
326
		/*
330
		/*
327
		 * Create a new connection from property file
331
		 * Create a new connection from property file
328
		 */
332
		 */
329
		PropertiesConfiguration props;
333
		PropertiesConfiguration props;
330
		try {
334
		try {
-
 
335
			
331
			props = new PropertiesConfiguration(this.getClass()
336
			props = new Configurations().properties(this.getClass()
332
					.getClassLoader().getResource("/../dimcm.properties"));
337
					.getClassLoader().getResource("/../dimcm.properties"));
333
		} catch (ConfigurationException e) {
338
		} catch (ConfigurationException e) {
334
			e.printStackTrace();
339
			e.printStackTrace();
335
			return null;
340
			return null;
336
		}
341
		}
337
 
342
 
338
		DimensionsConnectionDetails details = new DimensionsConnectionDetails();
343
		DimensionsConnectionDetails details = new DimensionsConnectionDetails();
339
		details.setUsername(props.getString("user"));
344
		details.setUsername(props.getString("user"));
340
		details.setPassword(props.getString("password"));
345
		details.setPassword(props.getString("password"));
341
		details.setDbName(props.getString("dbname"));
346
		details.setDbName(props.getString("dbname"));
342
		details.setDbConn(props.getString("dbconn"));
347
		details.setDbConn(props.getString("dbconn"));
343
		details.setServer(props.getString("server"));
348
		details.setServer(props.getString("server"));
344
		conn = DimensionsConnectionManager.getConnection(details);
349
		conn = DimensionsConnectionManager.getConnection(details);
345
		DimensionsConnectionManager.registerThreadConnection(conn);
350
		DimensionsConnectionManager.registerThreadConnection(conn);
346
		return conn;
351
		return conn;
347
	}
352
	}
348
 
353
 
349
	private String getBaseURL() {
354
	private String getBaseURL() {
350
		final String CACHE_BASEURL = "DIMCM.conf.baseurl";
355
		final String CACHE_BASEURL = "DIMCM.conf.baseurl";
351
	try {
356
	try {
352
		JCS cache = JCS.getInstance("DIMCM");
357
		CacheAccess<Object, Object> cache = JCS.getInstance("DIMCM");
353
		String baseurl = (String) cache.get(CACHE_BASEURL);
358
		String baseurl = (String) cache.get(CACHE_BASEURL);
354
		if(baseurl != null) return baseurl;
359
		if(baseurl != null) return baseurl;
-
 
360
		
-
 
361
		Configurations configs = new Configurations();
355
		
362
		
356
		PropertiesConfiguration	props = new PropertiesConfiguration(this.getClass().getClassLoader().getResource("/../dimcm.properties"));
363
		PropertiesConfiguration	props = configs.properties((this.getClass().getClassLoader().getResource("/../dimcm.properties")));
357
		baseurl = props.getString("baseurl");
364
		baseurl = props.getString("baseurl");
358
		cache.put(CACHE_BASEURL, baseurl);
365
		cache.put(CACHE_BASEURL, baseurl);
359
		return baseurl;
366
		return baseurl;
360
		
367
		
361
	} catch (CacheException e1) {
368
	} catch (CacheException e1) {
362
		// TODO Auto-generated catch block
369
		// TODO Auto-generated catch block
363
		e1.printStackTrace();
370
		e1.printStackTrace();
364
		return null;
371
		return null;
365
	} catch (ConfigurationException e) {
372
	} catch (ConfigurationException e) {
366
		e.printStackTrace();
373
		e.printStackTrace();
367
		return null;
374
		return null;
368
		
375
		
369
	}
376
	}
370
}
377
}
371
}
378
}
372
 
379
 
373
Generated by GNU Enscript 1.6.5.90.
380
Generated by GNU Enscript 1.6.5.90.
374
 
381
 
375
 
382