Project

General

Profile

« Previous | Next » 

Revision 43652

objectStore rest controller doesn't use mongodb anymore to discover the basePath, it is instead passed and http parameter.

View differences:

modules/dnet-modular-objectstore-service/trunk/src/main/java/eu/dnetlib/data/objectstore/modular/ModularObjectStoreRESTService.java
1
package eu.dnetlib.data.objectstore.modular;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5

  
6
import javax.annotation.Resource;
7
import javax.servlet.ServletOutputStream;
8
import javax.servlet.http.HttpServletResponse;
9

  
10
import org.apache.commons.io.IOUtils;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.springframework.stereotype.Controller;
14
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestParam;
16

  
17
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
18
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
19
import eu.dnetlib.miscutils.datetime.HumanTime;
20

  
21
// TODO: Auto-generated Javadoc
22
/**
23
 * The Class ModularObjectStoreRESTService implement the controller REST of the object Store.
24
 */
25
@Controller
26
public class ModularObjectStoreRESTService {
27

  
28
	/** The object store deliver. */
29
	@Resource
30
	ModularObjectStoreDeliver objectStoreDeliver;
31

  
32
	private static final Log log = LogFactory.getLog(ModularObjectStoreRESTService.class); // NOPMD by marko on 11/24/08 5:02 PM
33

  
34
	/**
35
	 * Retrieve.
36
	 *
37
	 * @param res
38
	 *            the res
39
	 * @param objectStoreId
40
	 *            the object store id
41
	 * @param objectId
42
	 *            the object id
43
	 * @throws IOException
44
	 *             Signals that an I/O exception has occurred.
45
	 * @throws ObjectStoreServiceException
46
	 */
47
	@RequestMapping(value = "/**/objectStore/retrieve.do")
48
	public void retrieve(final HttpServletResponse res,
49
			@RequestParam(value = "objectStore", required = true) final String objectStoreId,
50
			@RequestParam(value = "objectId", required = true) final String objectId) throws IOException, ObjectStoreServiceException {
51

  
52
		final long start = System.currentTimeMillis();
53
		final ObjectStoreFile file = objectStoreDeliver.deliverObject(objectStoreId, objectId);
54

  
55
		log.debug(String.format("deliverObject completed in %s, objId: %s", HumanTime.exactly(System.currentTimeMillis() - start), objectId));
56

  
57
		if (file == null) throw new RuntimeException("The file with id " + objectId + " doesn't exist");
58

  
59
		// res.setContentType(file.getMimeType());
60

  
61
		InputStream is = objectStoreDeliver.deliverStream(objectStoreId, objectId);
62

  
63
		ServletOutputStream outputStream = res.getOutputStream();
64

  
65
		IOUtils.copy(is, outputStream);
66

  
67
		try {
68
			is.close();
69
			if (log.isDebugEnabled()) {
70
				log.debug(String.format("retrive.do completed in %s, objId: %s", HumanTime.exactly(System.currentTimeMillis() - start), objectId));
71
			}
72
		} catch (Throwable e) {
73
			log.error("unable to close input Stream", e);
74
		}
75

  
76
		/*
77
		 * while (true) { int readSize = is.read(buffer); if (readSize == -1) { break; } outputStream.write(buffer, 0, readSize); }
78
		 */
79
	}
80
}
modules/dnet-fs-objectstore/trunk/src/main/resources/eu/dnetlib/data/objectstore/modular/FS/applicationContext-FS-objectstore.properties
1
services.objectStore.mongodb.host=localhost
2
services.objectStore.mongodb.port=27017
3
services.objectStore.mongodb.db=objectStore
4
services.objectStore.mongodb.connectionsPerHost=20
5
services.objectStore.mongodb.upsert=true
6
services.objectStore.RESTURI=http://${container.hostname}:${container.port}/${container.context}/mvc/objectStore/retrieve.do
7
services.objectstore.dao=fSObjectstoreDao
modules/dnet-modular-objectstore-service/trunk/src/main/java/eu/dnetlib/data/objectstore/modular/connector/ObjectStore.java
1 1
package eu.dnetlib.data.objectstore.modular.connector;
2 2

  
3
import java.io.InputStream;
4

  
5 3
import eu.dnetlib.data.objectstore.modular.ObjectStoreRecord;
6 4
import eu.dnetlib.data.objectstore.rmi.MetadataObjectRecord;
7 5
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
......
89 87
	ObjectStoreFile deliverObject(String objectId) throws ObjectStoreServiceException;
90 88

  
91 89
	/**
92
	 * Deliver stream.
93
	 *
94
	 * @param objectId
95
	 *            the object id
96
	 * @return the input stream
97
	 */
98
	InputStream deliverStream(String objectId) throws ObjectStoreServiceException;
99

  
100
	/**
101 90
	 * Gets the size.
102 91
	 *
103 92
	 * @return the size
modules/dnet-modular-objectstore-service/trunk/src/main/java/eu/dnetlib/data/objectstore/modular/ModularObjectStoreDeliver.java
1 1
package eu.dnetlib.data.objectstore.modular;
2 2

  
3
import java.io.InputStream;
4

  
5 3
import javax.annotation.Resource;
6 4
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7 5

  
8
import org.springframework.beans.factory.annotation.Required;
9

  
10 6
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao;
11 7
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
12 8
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
13 9
import eu.dnetlib.enabling.resultset.ResultSetFactory;
14 10
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
11
import org.springframework.beans.factory.annotation.Required;
15 12

  
16 13
/**
17 14
 * The Class ModularObjectStoreDeliver is responsible of delivering data from the object Store.
......
109 106
	}
110 107

  
111 108
	/**
112
	 * Deliver stream.
113
	 *
114
	 * @param objectStoreID
115
	 *            the object store id
116
	 * @param objectId
117
	 *            the object id
118
	 * @return the input stream
119
	 * @throws ObjectStoreServiceException
120
	 */
121
	public InputStream deliverStream(final String objectStoreID, final String objectId) throws ObjectStoreServiceException {
122
		return dao.getObjectStore(objectStoreID).deliverStream(objectId);
123
	}
124

  
125
	/**
126 109
	 * Gets the result set client factory.
127 110
	 *
128 111
	 * @return the result set client factory
modules/dnet-modular-objectstore-service/trunk/pom.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 3
	<parent>
4 4
		<groupId>eu.dnetlib</groupId>
5 5
		<artifactId>dnet-parent</artifactId>
......
55 55
			<artifactId>commons-net-ftp</artifactId>
56 56
			<version>2.0</version>
57 57
		</dependency>
58
		<dependency>
59
			<groupId>javax.servlet</groupId>
60
			<artifactId>javax.servlet-api</artifactId>
61
			<version>${javax.servlet.version}</version>
62
			<scope>provided</scope>
63
		</dependency>
64 58

  
65 59
	</dependencies>
66 60
</project>
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/ModularObjectStoreRESTService.java
1
package eu.dnetlib.data.objectstore.filesystem;
2

  
3
import java.io.*;
4
import java.net.URLEncoder;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import javax.servlet.http.HttpServletResponse;
8

  
9
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
10
import eu.dnetlib.miscutils.datetime.HumanTime;
11
import org.apache.commons.io.IOUtils;
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14
import org.springframework.stereotype.Controller;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestParam;
17

  
18
/**
19
 * The Class ModularObjectStoreRESTService implement the controller REST of the object Store.
20
 */
21
@Controller
22
public class ModularObjectStoreRESTService {
23

  
24
	private static final Log log = LogFactory.getLog(ModularObjectStoreRESTService.class); // NOPMD by marko on 11/24/08 5:02 PM
25

  
26
	public static String retrieveURL(final String baseURI, final String basePath, final String objectStoreId, final String objectId)
27
			throws UnsupportedEncodingException {
28
		final StringBuilder sb = new StringBuilder(baseURI)
29
				.append("?objectStore=" + encode(objectStoreId))
30
				.append("&objectId=" + encode(objectId))
31
				.append("&basePath=" + encode(basePath));
32
		return sb.toString();
33
	}
34

  
35
	private static String encode(final String s) throws UnsupportedEncodingException {
36
		return URLEncoder.encode(s, "UTF-8");
37
	}
38

  
39
	/**
40
	 *
41
	 * @param res
42
	 * @param basePath
43
	 * @param objectStoreId
44
	 * @param objectId
45
	 * @throws IOException
46
	 * @throws ObjectStoreServiceException
47
	 */
48
	@RequestMapping(value = "/**/objectStore/retrieve.do")
49
	public void retrieve(final HttpServletResponse res,
50
			@RequestParam(value = "basePath", required = true) final String basePath,
51
			@RequestParam(value = "objectStore", required = true) final String objectStoreId,
52
			@RequestParam(value = "objectId", required = true) final String objectId) throws IOException, ObjectStoreServiceException {
53

  
54
		final long start = System.currentTimeMillis();
55
		final Path path = FileSystemUtility.objectStoreFilePath(basePath, objectStoreId, objectId);
56

  
57
		if (!Files.exists(path) || !Files.isReadable(path)) {
58
			final String msg = String.format("Object with identifier: %s not found the in %s", objectId, path);
59
			res.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
60
			log.warn(msg);
61
		} else {
62
			try (final InputStream is = new BufferedInputStream(new FileInputStream(path.toFile()))) {
63

  
64
				IOUtils.copy(is, res.getOutputStream());
65

  
66
				if (log.isDebugEnabled()) {
67
					log.debug(String.format("retrive.do completed in %s, objId: %s", HumanTime.exactly(System.currentTimeMillis() - start), objectId));
68
				}
69
			} catch (IOException e) {
70
				final String msg = "unable to close input Stream";
71
				res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
72
				log.error(msg, e);
73
			}
74
		}
75
	}
76
}
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/ObjectStoreFileUtility.java
1 1
package eu.dnetlib.data.objectstore.filesystem;
2 2

  
3 3
import java.io.UnsupportedEncodingException;
4
import java.net.URLEncoder;
5 4

  
6 5
import com.mongodb.DBObject;
7 6
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
......
21 20
	/** The Constant log. */
22 21
	private static final Log log = LogFactory.getLog(ObjectStoreFileUtility.class);
23 22

  
24
	public static ObjectStoreFile build(final DBObject metadata, final String baseURI, final String objectStoreID) {
23
	public static ObjectStoreFile build(final DBObject metadata, final String baseURI, final String objectStoreID, final String basePath) {
25 24

  
26 25
		String originalFile = (String) metadata.get("originalObject");
27 26
		ObjectStoreFile original = ObjectStoreFile.createObject(originalFile);
......
44 43
			}
45 44
		}
46 45
		try {
47
			newFile.setURI(baseURI + "?objectStore=" + URLEncoder.encode(objectStoreID, "UTF-8") + "&objectId="
48
					+ URLEncoder.encode(newFile.getObjectID(), "UTF-8"));
46
			newFile.setURI(ModularObjectStoreRESTService.retrieveURL(baseURI, basePath, objectStoreID, newFile.getObjectID()));
49 47
		} catch (UnsupportedEncodingException e) {
50 48
			log.error("Error on Build objectStoreFile ", e);
51 49
		}
52 50
		return newFile;
53 51
	}
54 52

  
55
	public static UnaryFunction<String, DBObject> asJSON(final String baseURI, final String objectStoreID) {
53
	public static UnaryFunction<String, DBObject> asJSON(final String baseURI, final String objectStoreID, final String basePath) {
56 54
		return new UnaryFunction<String, DBObject>() {
57 55

  
58 56
			@Override
59 57
			public String evaluate(final DBObject input) {
60
				return build(input, baseURI, objectStoreID).toJSON();
58
				return build(input, baseURI, objectStoreID, basePath).toJSON();
61 59

  
62 60
			}
63 61
		};
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/FileSystemObjectStore.java
1
/**
2
 *
3
 */
4 1
package eu.dnetlib.data.objectstore.filesystem;
5 2

  
6
import java.io.*;
7
import java.net.URLEncoder;
3
import java.io.ByteArrayInputStream;
4
import java.io.IOException;
8 5
import java.nio.file.FileSystems;
9 6
import java.nio.file.Files;
10 7
import java.nio.file.Path;
......
27 24
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
28 25
import eu.dnetlib.enabling.resultset.ResultSetListener;
29 26
import eu.dnetlib.miscutils.collections.Pair;
30
import eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions;
31 27
import org.apache.commons.lang.StringUtils;
32 28
import org.apache.commons.logging.Log;
33 29
import org.apache.commons.logging.LogFactory;
......
111 107
		return this.interpretation;
112 108
	}
113 109

  
114

  
115
	private Path createObjectStorePath(final String objectIdentifier, final String basePath){
116
		final Path baseDirPath = FileSystems.getDefault().getPath(basePath).resolve(id);
117
		final String md5id = DnetXsltFunctions.md5(objectIdentifier);
118
		final String firstLevel = StringUtils.substring(md5id, 0, 2);
119
		final String secondLevel = StringUtils.substring(md5id, 2, 4);
120
		return baseDirPath.resolve(firstLevel).resolve(secondLevel);
121
	}
122

  
123
	private String getFileName(final String objectIdentifier){
124
		final String md5id = DnetXsltFunctions.md5(objectIdentifier);
125
		return StringUtils.substring(md5id, 4)+ ".obj";
126
	}
127

  
128 110
	/**
129 111
	 * {@inheritDoc}
130 112
	 *
......
135 117
		if (records == null)
136 118
			return 0;
137 119

  
138
		Path baseDirPath = FileSystems.getDefault().getPath(basePath).resolve(id);
120
		Path baseDirPath = FileSystems.getDefault().getPath(getBasePath()).resolve(getId());
139 121
		if (!Files.exists(baseDirPath))
140 122
			throw new ObjectStoreServiceException("Error can't feed objects because the folder " + baseDirPath + " does not exist");
141 123

  
142 124
		int addedCounter = 0;
143 125
		for (ObjectStoreRecord record : records) {
144 126
			String url = feedObject(record);
145
			if (StringUtils.isNotBlank(url))
127
			if (StringUtils.isNotBlank(url)) {
146 128
				addedCounter++;
129
			}
147 130
		}
148 131
		return addedCounter;
149 132
	}
......
186 169
		if (record != null) {
187 170
			String objectIdentifier = record.getFileMetadata().getObjectID();
188 171
			if (StringUtils.isNotBlank(objectIdentifier)) {
189
				Path objectStoreFilePath = createObjectStorePath(objectIdentifier, basePath);
190
				final Path objResolvedPath = objectStoreFilePath.resolve(getFileName(objectIdentifier));
172
				final Path objResolvedPath = FileSystemUtility.objectStoreFilePath(basePath, id, objectIdentifier);
173

  
191 174
				if (Files.notExists(objResolvedPath)) {
192 175
					try {
193
						log.debug("Creation of folder " + objectStoreFilePath);
194
						Files.createDirectories(objectStoreFilePath);
195
						log.debug("Folder " + objectStoreFilePath + " created");
176
						log.debug("Creation of folder " + objResolvedPath.getParent());
177
						Files.createDirectories(objResolvedPath.getParent());
178
						log.debug("Folder " + objResolvedPath.getParent() + " created");
196 179
						String md5Sum = null;
197 180
						Integer size = 0;
198 181
						if (record.getInputStream() != null) {
......
200 183
							md5Sum = infos.getKey();
201 184
							size = infos.getValue();
202 185
						}
203
						String url = getBaseURI() + "?objectStore=" + URLEncoder.encode(id, "UTF-8") + "&objectId="
204
								+ URLEncoder.encode(record.getFileMetadata().getObjectID(), "UTF-8");
186
						final String url =
187
								ModularObjectStoreRESTService.retrieveURL(getBaseURI(), getBasePath(), getId(), record.getFileMetadata().getObjectID());
205 188
						if (StringUtils.isNotBlank(md5Sum)) {
206 189
							double timestamp = System.currentTimeMillis();
207 190
							BasicDBObject metadata = new BasicDBObject();
......
230 213
						}
231 214
					}
232 215
				} else {
233
					log.debug("The File in the path" + objectStoreFilePath + "exists ");
216
					log.debug("The File in the path" + objResolvedPath.getParent() + "exists ");
234 217
				}
235 218
			}
236

  
237 219
		}
238 220
		log.warn("Record for object store is null");
239 221
		return null;
......
247 229
	@Override
248 230
	public ResultSetListener deliver(final Long from, final Long until) throws ObjectStoreServiceException {
249 231
		FileSystemObjectStoreResultSetListener resultSet = new FileSystemObjectStoreResultSetListener();
250
		resultSet.setBaseURI(baseURI);
232
		resultSet.setBaseURI(getBaseURI());
251 233
		resultSet.setMongoCollection(mongoMetadata);
252
		resultSet.setObjectStoreID(id);
234
		resultSet.setObjectStoreID(getId());
253 235
		resultSet.setFromDate(from);
254 236
		resultSet.setUntilDate(until);
237
		resultSet.setBasePath(getBasePath());
255 238
		return resultSet;
256 239
	}
257 240

  
......
263 246
	@Override
264 247
	public ResultSetListener deliverIds(final Iterable<String> ids) throws ObjectStoreServiceException {
265 248
		FileSystemObjectStoreResultSetListener resultSet = new FileSystemObjectStoreResultSetListener();
266
		resultSet.setBaseURI(baseURI);
249
		resultSet.setBaseURI(getBaseURI());
267 250
		resultSet.setMongoCollection(mongoMetadata);
268
		resultSet.setObjectStoreID(id);
251
		resultSet.setObjectStoreID(getId());
269 252
		resultSet.setRecords(Lists.newArrayList(ids));
253
		resultSet.setBasePath(basePath);
270 254
		return resultSet;
271 255
	}
272 256

  
......
280 264
		Bson query = Filters.eq("id", objectId);
281 265
		DBObject resultQuery = mongoMetadata.find(query).first();
282 266
		checkAndGetFsPathField(resultQuery, objectId);
283
		return ObjectStoreFileUtility.build(resultQuery, baseURI, id);
267
		return ObjectStoreFileUtility.build(resultQuery, getBaseURI(), getId(), basePath);
284 268
	}
285 269

  
286
	/**
287
	 * {@inheritDoc}
288
	 *
289
	 * @see eu.dnetlib.data.objectstore.modular.connector.ObjectStore#deliverStream(java.lang.String)
290
	 */
291
	@Override
292
	public InputStream deliverStream(final String objectId) throws ObjectStoreServiceException {
293
		Bson query = Filters.eq("id", objectId);
294
		DBObject resultQuery = mongoMetadata.find(query).first();
295
		String pathStr = checkAndGetFsPathField(resultQuery, objectId);
296
		Path path = FileSystems.getDefault().getPath(pathStr);
297
		if (!Files.exists(path))
298
			throw new ObjectStoreFileNotFoundException("Object with identifier :" + objectId + " not found the in the path: " + path);
299
		try {
300
			FileInputStream is = new FileInputStream(path.toFile());
301
			return is;
302
		} catch (FileNotFoundException e) {
303
			throw new ObjectStoreServiceException("something wrong happened on getting data stream ", e);
304
		}
305

  
306
	}
307

  
308 270
	private String checkAndGetFsPathField(final DBObject resultQuery, final String objectId) throws ObjectStoreServiceException {
309 271
		if (resultQuery == null || !resultQuery.containsField(FS_PATH_FIELD))
310 272
			throw new ObjectStoreFileNotFoundException("Object with identifier :" + objectId + " not found or missing " + FS_PATH_FIELD + " field");
......
314 276
		return pathStr;
315 277
	}
316 278

  
317

  
318 279
	/**
319 280
	 * {@inheritDoc}
320 281
	 *
......
373 334

  
374 335
	@Override
375 336
	public boolean dropContent() throws ObjectStoreServiceException {
376
		if (basePath == null) {
337
		if (getBasePath() == null) {
377 338
			throw new ObjectStoreServiceException("Error on dropping object store base_path required");
378 339
		}
379
		final Path baseDirPath = FileSystems.getDefault().getPath(basePath).resolve(id);
340
		final Path baseDirPath = FileSystems.getDefault().getPath(getBasePath()).resolve(getId());
380 341
		try {
381 342
			FileSystemUtility.deleteFolderRecursive(baseDirPath);
382 343
		} catch (IOException e) {
......
399 360
	@Override
400 361
	public String toString() {
401 362
		return "FileSystemObjectStore{" +
402
				"id='" + id + '\'' +
403
				", interpretation='" + interpretation + '\'' +
404
				", basePath='" + basePath + '\'' +
405
				", baseURI='" + baseURI + '\'' +
363
				"id='" + getId() + '\'' +
364
				", interpretation='" + getInterpretation() + '\'' +
365
				", basePath='" + getBasePath() + '\'' +
366
				", baseURI='" + getBaseURI() + '\'' +
406 367
				'}';
407 368
	}
408 369

  
......
415 376
		return baseURI;
416 377
	}
417 378

  
379
	public String getBasePath() {
380
		return basePath;
381
	}
418 382
}
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/FileSystemUtility.java
6 6
import java.io.FileInputStream;
7 7
import java.io.IOException;
8 8
import java.io.InputStream;
9
import java.nio.file.FileVisitResult;
10
import java.nio.file.Files;
11
import java.nio.file.Path;
12
import java.nio.file.SimpleFileVisitor;
9
import java.nio.file.*;
13 10
import java.nio.file.attribute.BasicFileAttributes;
14 11

  
15 12
import eu.dnetlib.miscutils.collections.Pair;
13
import eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions;
14
import org.apache.commons.lang.StringUtils;
16 15
import org.apache.commons.logging.Log;
17 16
import org.apache.commons.logging.LogFactory;
18 17

  
......
70 69
		return true;
71 70
	}
72 71

  
72
	public static Path objectStoreFilePath(final String basePath, final String objectStoreId, final String objectIdentifier) {
73
		final Path baseDirPath = FileSystems.getDefault().getPath(basePath).resolve(objectStoreId);
74
		final String md5id = DnetXsltFunctions.md5(objectIdentifier);
75
		final String firstLevel = StringUtils.substring(md5id, 0, 2);
76
		final String secondLevel = StringUtils.substring(md5id, 2, 4);
77
		final String fileName = StringUtils.substring(md5id, 4) + ".obj";
78
		return baseDirPath.resolve(firstLevel).resolve(secondLevel).resolve(fileName);
79
	}
73 80

  
74

  
75 81
}
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/FileSystemObjectStoreResultSetListener.java
58 58
	/** The base uri. */
59 59
	private String baseURI;
60 60

  
61
	/**
62
	 * The base path
63
	 */
64
	private String basePath;
65

  
61 66
	/** The current size. */
62 67
	private int currentSize = -1;
63 68

  
......
67 72
	/** The cursor position. */
68 73
	private long cursorPosition;
69 74

  
70

  
71

  
72 75
	/**
73 76
	 * {@inheritDoc}
74 77
	 * @see eu.dnetlib.enabling.resultset.TypedResultSetListener#getResult(int, int)
......
83 86
			}
84 87
			Bson q = Filters.in("id", ids);
85 88
			FindIterable<DBObject> res = getMongoCollection().find(q);
86
			return MappedCollection.listMap(res, ObjectStoreFileUtility.asJSON(baseURI, objectStoreID));
89
			return MappedCollection.listMap(res, ObjectStoreFileUtility.asJSON(getBaseURI(), getObjectStoreID(), getBasePath()));
87 90
		} else if ((fromDate != null) && (untilDate != null)) {
88 91
			if ((currentCursor == null) || (cursorPosition > from)) {
89 92
				createCurrentCursor();
......
99 102
					cursorPosition++;
100 103
				}
101 104
			}
102
			return MappedCollection.listMap(result, ObjectStoreFileUtility.asJSON(baseURI, objectStoreID));
105
			return MappedCollection.listMap(result, ObjectStoreFileUtility.asJSON(getBaseURI(), getObjectStoreID(), getBasePath()));
103 106
		}
104 107

  
105 108
		throw new IllegalArgumentException("Missing parameters on Delivery must provide either from, to, or ObjectStoreIDs");
......
339 342
		this.mongoCollection = mongoCollection;
340 343
	}
341 344

  
345
	public String getBasePath() {
346
		return basePath;
347
	}
348

  
349
	public void setBasePath(final String basePath) {
350
		this.basePath = basePath;
351
	}
342 352
}
modules/dnet-fs-objectstore/trunk/src/main/java/eu/dnetlib/data/objectstore/filesystem/FileSystemObjectStoreDao.java
26 26
import org.apache.commons.logging.Log;
27 27
import org.apache.commons.logging.LogFactory;
28 28
import org.bson.conversions.Bson;
29
import org.springframework.beans.factory.annotation.Autowired;
30 29

  
31 30
/**
32 31
 * @author sandro
......
36 35

  
37 36
	private static final Log log = LogFactory.getLog(FileSystemObjectStoreDao.class); // NOPMD by marko on 11/24/08 5:02 PM
38 37

  
38
	private static final String OBJECTSTORE_PROFILE_SUFFIX = "_T2JqZWN0U3RvcmVEU1Jlc291cmNlcy9PYmplY3RTdG9yZURTUmVzb3VyY2VUeXBl";
39

  
39 40
	private static final String INTERPRETATION_FIELD = "interpretation";
40 41

  
41 42
	private final static String OBJECTSTORE_METADATA_NAME_FIELD = "metadataObjectStore";
......
47 48
	@Resource(name="objectstoreMongoDB")
48 49
	private MongoDatabase db;
49 50

  
50
	@Autowired
51
	private FileSystemUtility fsUtility;
52

  
53 51
	private boolean upsert;
54 52

  
55 53
	private String objectStoreRESTURI;
56 54

  
57

  
58

  
59 55
	/**
60 56
	 * {@inheritDoc}
61 57
	 * @throws ObjectStoreServiceException
......
64 60
	 */
65 61
	@Override
66 62
	public ObjectStore getObjectStore(final String obsId) throws ObjectStoreServiceException {
67
		String currentId =obsId.substring(0, 36);
63
		String currentId = obsId.substring(0, 36);
68 64
		String find_id = obsId;
69
		if(find_id.length()==36) {
70
			find_id+="_T2JqZWN0U3RvcmVEU1Jlc291cmNlcy9PYmplY3RTdG9yZURTUmVzb3VyY2VUeXBl";
65
		if (find_id.length() == 36) {
66
			find_id += OBJECTSTORE_PROFILE_SUFFIX;
71 67
		}
72 68

  
73 69
		MongoCollection<DBObject> coll = getDb().getCollection(OBJECTSTORE_METADATA_NAME_FIELD, DBObject.class);
......
76 72
		DBObject resultQuery = coll.find(query).first();
77 73
		log.debug("result "+resultQuery);
78 74
		if ((resultQuery == null)) throw new ObjectStoreFileNotFoundException("the objectStore with identifier: "+obsId+" was not found");
79
		if (!resultQuery.containsField(BASE_PATH_FIELD) || StringUtils.isBlank(resultQuery.get(BASE_PATH_FIELD).toString()))
75

  
76
		final String basePath = resultQuery.get(BASE_PATH_FIELD).toString();
77
		final String interpretation = resultQuery.get("interpretation").toString();
78

  
79
		if (!resultQuery.containsField(BASE_PATH_FIELD) || StringUtils.isBlank(basePath))
80 80
			throw new ObjectStoreServiceException("Can't Get Objectstore, the metadata doesn't contain info about the basepath");
81
		return new FileSystemObjectStore(currentId, resultQuery.get("interpretation").toString(), resultQuery.get(BASE_PATH_FIELD).toString(),
82
				getDb().getCollection(currentId, DBObject.class), objectStoreRESTURI);
81

  
82
		final MongoCollection<DBObject> collection = getDb().getCollection(currentId, DBObject.class);
83
		return new FileSystemObjectStore(currentId, interpretation, basePath, collection, objectStoreRESTURI);
83 84
	}
84 85

  
85 86
	/**
modules/dnet-fs-objectstore/trunk/src/main/resources/eu/dnetlib/data/objectstore/filesystem/applicationContext-filesystem-objectstore.properties
1
services.objectStore.mongodb.host=localhost
2
services.objectStore.mongodb.port=27017
3
services.objectStore.mongodb.db=objectStore
4
services.objectStore.mongodb.connectionsPerHost=20
5
services.objectStore.mongodb.upsert=true
6
services.objectStore.RESTURI=http://${container.hostname}:${container.port}/${container.context}/mvc/objectStore/retrieve.do
7
services.objectstore.dao=fSObjectstoreDao
modules/dnet-fs-objectstore/trunk/pom.xml
38 38
			<artifactId>mongo-java-driver</artifactId>
39 39
			<version>${mongodb.driver.version}</version>
40 40
		</dependency>
41
  
41
	  <dependency>
42
		  <groupId>javax.servlet</groupId>
43
		  <artifactId>javax.servlet-api</artifactId>
44
		  <version>${javax.servlet.version}</version>
45
		  <scope>provided</scope>
46
	  </dependency>
47

  
42 48
  </dependencies>
43
</project>
49
</project>

Also available in: Unified diff