1
|
package eu.dnetlib.data.objectstore.modular;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
6
|
|
7
|
import org.springframework.beans.factory.annotation.Required;
|
8
|
|
9
|
import com.google.gson.Gson;
|
10
|
|
11
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
|
12
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
|
13
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
|
14
|
import eu.dnetlib.enabling.tools.AbstractBaseService;
|
15
|
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
|
16
|
|
17
|
// TODO: Auto-generated Javadoc
|
18
|
/**
|
19
|
* The Class ModularObjectStoreService is the implementation of the ObjectStoreService interface.
|
20
|
*/
|
21
|
public class ModularObjectStoreService extends AbstractBaseService implements ObjectStoreService {
|
22
|
|
23
|
/** The feeder. */
|
24
|
private ModularObjectStoreFeeder feeder;
|
25
|
|
26
|
/** The object store deliver. */
|
27
|
private ModularObjectStoreDeliver objectStoreDeliver;
|
28
|
|
29
|
/** The notification handler. */
|
30
|
private NotificationHandler notificationHandler;
|
31
|
|
32
|
/*
|
33
|
* (non-Javadoc)
|
34
|
*
|
35
|
* @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverObjects(java.lang.String, java.lang.Double, java.lang.Double)
|
36
|
*/
|
37
|
/**
|
38
|
* Deliver objects.
|
39
|
*
|
40
|
* @param obsId
|
41
|
* the obs id
|
42
|
* @param from
|
43
|
* the from
|
44
|
* @param until
|
45
|
* the until
|
46
|
* @return the w3 c endpoint reference
|
47
|
* @throws ObjectStoreServiceException
|
48
|
* the object store service exception
|
49
|
*/
|
50
|
@Override
|
51
|
public W3CEndpointReference deliverObjects(final String obsId, final Double from, final Double until) throws ObjectStoreServiceException {
|
52
|
|
53
|
return objectStoreDeliver.deliver(obsId, from, until);
|
54
|
}
|
55
|
|
56
|
/*
|
57
|
* (non-Javadoc)
|
58
|
*
|
59
|
* @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverObjectsByIds(java.lang.String,
|
60
|
* javax.xml.ws.wsaddressing.W3CEndpointReference)
|
61
|
*/
|
62
|
/**
|
63
|
* Deliver objects by ids.
|
64
|
*
|
65
|
* @param obsId
|
66
|
* the obs id
|
67
|
* @param eprId
|
68
|
* the epr id
|
69
|
* @return the w3 c endpoint reference
|
70
|
* @throws ObjectStoreServiceException
|
71
|
* the object store service exception
|
72
|
*/
|
73
|
@Override
|
74
|
public W3CEndpointReference deliverObjectsByIds(final String obsId, final W3CEndpointReference eprId) throws ObjectStoreServiceException {
|
75
|
return objectStoreDeliver.deliverIds(obsId, eprId);
|
76
|
}
|
77
|
|
78
|
/*
|
79
|
* (non-Javadoc)
|
80
|
*
|
81
|
* @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverRecord(java.lang.String, java.lang.String)
|
82
|
*/
|
83
|
/**
|
84
|
* Deliver record.
|
85
|
*
|
86
|
* @param obsId
|
87
|
* the obs id
|
88
|
* @param objectId
|
89
|
* the object id
|
90
|
* @return the string
|
91
|
* @throws ObjectStoreServiceException
|
92
|
* the object store service exception
|
93
|
*/
|
94
|
@Override
|
95
|
public String deliverRecord(final String obsId, final String objectId) throws ObjectStoreServiceException {
|
96
|
return objectStoreDeliver.deliverObject(obsId, objectId).toJSON();
|
97
|
}
|
98
|
|
99
|
/*
|
100
|
* (non-Javadoc)
|
101
|
*
|
102
|
* @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#getListOfObjectStores()
|
103
|
*/
|
104
|
/**
|
105
|
* Gets the list of object stores.
|
106
|
*
|
107
|
* @return the list of object stores
|
108
|
*/
|
109
|
@Override
|
110
|
public List<String> getListOfObjectStores() {
|
111
|
return objectStoreDeliver.getDao().listObjectStores();
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Gets the feeder.
|
116
|
*
|
117
|
* @return the feeder
|
118
|
*/
|
119
|
public ModularObjectStoreFeeder getFeeder() {
|
120
|
return feeder;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Sets the feeder.
|
125
|
*
|
126
|
* @param feeder
|
127
|
* the new feeder
|
128
|
*/
|
129
|
@Required
|
130
|
public void setFeeder(final ModularObjectStoreFeeder feeder) {
|
131
|
this.feeder = feeder;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Gets the notification handler.
|
136
|
*
|
137
|
* @return the notification handler
|
138
|
*/
|
139
|
public NotificationHandler getNotificationHandler() {
|
140
|
return notificationHandler;
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* Sets the notification handler.
|
145
|
*
|
146
|
* @param notificationHandler
|
147
|
* the new notification handler
|
148
|
*/
|
149
|
@Required
|
150
|
public void setNotificationHandler(final NotificationHandler notificationHandler) {
|
151
|
this.notificationHandler = notificationHandler;
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* {@inheritDoc}
|
156
|
*
|
157
|
* @see eu.dnetlib.enabling.tools.AbstractBaseService#notify(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
158
|
*/
|
159
|
@Override
|
160
|
public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
|
161
|
getNotificationHandler().notified(subscriptionId, topic, isId, message);
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Gets the object store deliver.
|
166
|
*
|
167
|
* @return the object store deliver
|
168
|
*/
|
169
|
public ModularObjectStoreDeliver getObjectStoreDeliver() {
|
170
|
return objectStoreDeliver;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Sets the object store deliver.
|
175
|
*
|
176
|
* @param objectStoreDeliver
|
177
|
* the new object store deliver
|
178
|
*/
|
179
|
@Required
|
180
|
public void setObjectStoreDeliver(final ModularObjectStoreDeliver objectStoreDeliver) {
|
181
|
this.objectStoreDeliver = objectStoreDeliver;
|
182
|
}
|
183
|
|
184
|
/*
|
185
|
* (non-Javadoc)
|
186
|
*
|
187
|
* @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#feedObject(java.lang.String, java.lang.String)
|
188
|
*/
|
189
|
/**
|
190
|
* Feed object.
|
191
|
*
|
192
|
* @param obsId
|
193
|
* the obs id
|
194
|
* @param objectMetadata
|
195
|
* the object metadata
|
196
|
* @throws ObjectStoreServiceException
|
197
|
* the object store service exception
|
198
|
*/
|
199
|
@Override
|
200
|
public void feedObject(final String obsId, final String objectMetadata) throws ObjectStoreServiceException {
|
201
|
Gson g = new Gson();
|
202
|
try {
|
203
|
ObjectStoreFile file = g.fromJson(objectMetadata, ObjectStoreFile.class);
|
204
|
feeder.feedObject(obsId, file.getObjectID(), file.getURI(), file.getAccessProtocol(), file.getUsernameAuth(), file.getPasswordAuth(),
|
205
|
file.getMimeType());
|
206
|
|
207
|
} catch (Exception e) {
|
208
|
throw new ObjectStoreServiceException(e.getMessage());
|
209
|
}
|
210
|
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* Exist id starts with.
|
215
|
*
|
216
|
* @param obsId
|
217
|
* the obs id
|
218
|
* @param startId
|
219
|
* the start id
|
220
|
* @return true, if successful
|
221
|
* @throws ObjectStoreServiceException
|
222
|
* the object store service exception
|
223
|
*/
|
224
|
public boolean existIDStartsWith(final String obsId, final String startId) throws ObjectStoreServiceException {
|
225
|
return objectStoreDeliver.existIDStartsWith(obsId, startId);
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* Feed object.
|
230
|
*
|
231
|
* @param obsId
|
232
|
* the obs id
|
233
|
* @param record
|
234
|
* the record
|
235
|
* @return the string
|
236
|
* @throws ObjectStoreServiceException
|
237
|
* the object store service exception
|
238
|
*/
|
239
|
public String feedObject(final String obsId, final ObjectStoreRecord record) throws ObjectStoreServiceException {
|
240
|
|
241
|
try {
|
242
|
|
243
|
return feeder.feedObjectRecord(obsId, record);
|
244
|
|
245
|
} catch (Exception e) {
|
246
|
throw new ObjectStoreServiceException(e.getMessage());
|
247
|
}
|
248
|
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* Gets the size.
|
253
|
*
|
254
|
* @param obsId
|
255
|
* the obs id
|
256
|
* @return the size
|
257
|
* @throws ObjectStoreServiceException
|
258
|
* the object store service exception
|
259
|
*/
|
260
|
@Override
|
261
|
public int getSize(final String obsId) throws ObjectStoreServiceException {
|
262
|
return objectStoreDeliver.getDao().getObjectStore(obsId).getSize();
|
263
|
|
264
|
}
|
265
|
}
|