1
|
package eu.dnetlib.data.objectstore;
|
2
|
|
3
|
import java.io.InputStream;
|
4
|
|
5
|
import eu.dnetlib.data.objectstore.connector.ObjectStoreDao;
|
6
|
import eu.dnetlib.enabling.resultset.client.ResultSetClient;
|
7
|
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
|
8
|
import eu.dnetlib.rmi.common.ResultSet;
|
9
|
import eu.dnetlib.rmi.data.ObjectStoreFile;
|
10
|
import eu.dnetlib.rmi.data.ObjectStoreServiceException;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.beans.factory.annotation.Required;
|
13
|
|
14
|
/**
|
15
|
* The Class ModularObjectStoreDeliver is responsible of delivering data from the object Store.
|
16
|
*/
|
17
|
public class ModularObjectStoreDeliver {
|
18
|
|
19
|
/**
|
20
|
* The dao.
|
21
|
*/
|
22
|
private ObjectStoreDao dao;
|
23
|
|
24
|
/**
|
25
|
* The result set factory.
|
26
|
*/
|
27
|
|
28
|
@Autowired
|
29
|
private ResultSetFactory resultSetFactory;
|
30
|
|
31
|
/**
|
32
|
* Gets the dao.
|
33
|
*
|
34
|
* @return the dao
|
35
|
*/
|
36
|
public ObjectStoreDao getDao() {
|
37
|
return dao;
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Sets the dao.
|
42
|
*
|
43
|
* @param dao the new dao
|
44
|
*/
|
45
|
@Required
|
46
|
public void setDao(final ObjectStoreDao dao) {
|
47
|
this.dao = dao;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Deliver.
|
52
|
*
|
53
|
* @param objectStoreID the object store id
|
54
|
* @param from the from
|
55
|
* @param until the until
|
56
|
* @return the w3 c endpoint reference
|
57
|
* @throws ObjectStoreServiceException
|
58
|
*/
|
59
|
public ResultSet<ObjectStoreFile> deliver(final String objectStoreID, final Long from, final Long until) throws ObjectStoreServiceException {
|
60
|
return resultSetFactory.createResultSet(dao.getObjectStore(objectStoreID).deliver(from, until));
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Deliver ids.
|
65
|
*
|
66
|
* @param objectStoreID the object store id
|
67
|
* @param eprId the epr id
|
68
|
* @return the w3 c endpoint reference
|
69
|
* @throws ObjectStoreServiceException
|
70
|
*/
|
71
|
public ResultSet<ObjectStoreFile> deliverIds(final String objectStoreID, final ResultSet<String> eprId) throws ObjectStoreServiceException {
|
72
|
|
73
|
final ResultSetClient resultSetClient = resultSetFactory.getResultSetClient();
|
74
|
Iterable<String> ids = resultSetClient.iter(eprId, String.class);
|
75
|
return resultSetFactory.createResultSet(dao.getObjectStore(objectStoreID).deliverIds(ids));
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Exist id starts with.
|
80
|
*
|
81
|
* @param obsId the obs id
|
82
|
* @param startId the start id
|
83
|
* @return true, if successful
|
84
|
* @throws ObjectStoreServiceException
|
85
|
*/
|
86
|
public boolean existIDStartsWith(final String obsId, final String startId) throws ObjectStoreServiceException {
|
87
|
return dao.getObjectStore(obsId).existIDStartsWith(startId);
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Deliver object.
|
92
|
*
|
93
|
* @param objectStoreID the object store id
|
94
|
* @param objectId the object id
|
95
|
* @return the object store file
|
96
|
* @throws ObjectStoreServiceException
|
97
|
*/
|
98
|
public ObjectStoreFile deliverObject(final String objectStoreID, final String objectId) throws ObjectStoreServiceException {
|
99
|
return dao.getObjectStore(objectStoreID).deliverObject(objectId);
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Deliver stream.
|
104
|
*
|
105
|
* @param objectStoreID the object store id
|
106
|
* @param objectId the object id
|
107
|
* @return the input stream
|
108
|
* @throws ObjectStoreServiceException
|
109
|
*/
|
110
|
public InputStream deliverStream(final String objectStoreID, final String objectId) throws ObjectStoreServiceException {
|
111
|
return dao.getObjectStore(objectStoreID).deliverStream(objectId);
|
112
|
}
|
113
|
|
114
|
}
|