Project

General

Profile

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
/**
18
 * The Class ModularObjectStoreService is the implementation of the ObjectStoreService interface.
19
 */
20
public class ModularObjectStoreService extends AbstractBaseService implements ObjectStoreService {
21

    
22
	/** The feeder. */
23
	private ModularObjectStoreFeeder feeder;
24

    
25
	/** The object store deliver. */
26
	private ModularObjectStoreDeliver objectStoreDeliver;
27

    
28
	/** The notification handler. */
29
	private NotificationHandler notificationHandler;
30

    
31
	/*
32
	 * (non-Javadoc)
33
	 *
34
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverObjects(java.lang.String, java.lang.Double, java.lang.Double)
35
	 */
36
	/**
37
	 * Deliver objects.
38
	 *
39
	 * @param obsId
40
	 *            the obs id
41
	 * @param from
42
	 *            the from
43
	 * @param until
44
	 *            the until
45
	 * @return the w3 c endpoint reference
46
	 * @throws ObjectStoreServiceException
47
	 *             the object store service exception
48
	 */
49
	@Override
50
	public W3CEndpointReference deliverObjects(final String obsId, final Long from, final Long until) throws ObjectStoreServiceException {
51

    
52
		return objectStoreDeliver.deliver(obsId, from, until);
53
	}
54

    
55
	/*
56
	 * (non-Javadoc)
57
	 *
58
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverObjectsByIds(java.lang.String,
59
	 * javax.xml.ws.wsaddressing.W3CEndpointReference)
60
	 */
61
	/**
62
	 * Deliver objects by ids.
63
	 *
64
	 * @param obsId
65
	 *            the obs id
66
	 * @param eprId
67
	 *            the epr id
68
	 * @return the w3 c endpoint reference
69
	 * @throws ObjectStoreServiceException
70
	 *             the object store service exception
71
	 */
72
	@Override
73
	public W3CEndpointReference deliverObjectsByIds(final String obsId, final W3CEndpointReference eprId) throws ObjectStoreServiceException {
74
		return objectStoreDeliver.deliverIds(obsId, eprId);
75
	}
76

    
77
	/*
78
	 * (non-Javadoc)
79
	 *
80
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverRecord(java.lang.String, java.lang.String)
81
	 */
82
	/**
83
	 * Deliver record.
84
	 *
85
	 * @param obsId
86
	 *            the obs id
87
	 * @param objectId
88
	 *            the object id
89
	 * @return the string
90
	 * @throws ObjectStoreServiceException
91
	 *             the object store service exception
92
	 */
93
	@Override
94
	public String deliverRecord(final String obsId, final String objectId) throws ObjectStoreServiceException {
95
		return objectStoreDeliver.deliverObject(obsId, objectId).toJSON();
96
	}
97

    
98
	/*
99
	 * (non-Javadoc)
100
	 *
101
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#getListOfObjectStores()
102
	 */
103
	/**
104
	 * Gets the list of object stores.
105
	 *
106
	 * @return the list of object stores
107
	 */
108
	@Override
109
	public List<String> getListOfObjectStores() {
110
		return objectStoreDeliver.getDao().listObjectStores();
111
	}
112

    
113
	/**
114
	 * Gets the feeder.
115
	 *
116
	 * @return the feeder
117
	 */
118
	public ModularObjectStoreFeeder getFeeder() {
119
		return feeder;
120
	}
121

    
122
	/**
123
	 * Sets the feeder.
124
	 *
125
	 * @param feeder
126
	 *            the new feeder
127
	 */
128
	@Required
129
	public void setFeeder(final ModularObjectStoreFeeder feeder) {
130
		this.feeder = feeder;
131
	}
132

    
133
	/**
134
	 * Gets the notification handler.
135
	 *
136
	 * @return the notification handler
137
	 */
138
	public NotificationHandler getNotificationHandler() {
139
		return notificationHandler;
140
	}
141

    
142
	/**
143
	 * Sets the notification handler.
144
	 *
145
	 * @param notificationHandler
146
	 *            the new notification handler
147
	 */
148
	@Required
149
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
150
		this.notificationHandler = notificationHandler;
151
	}
152

    
153
	/**
154
	 * {@inheritDoc}
155
	 *
156
	 * @see eu.dnetlib.enabling.tools.AbstractBaseService#notify(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
157
	 */
158
	@Override
159
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
160
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
161
	}
162

    
163
	/**
164
	 * Gets the object store deliver.
165
	 *
166
	 * @return the object store deliver
167
	 */
168
	public ModularObjectStoreDeliver getObjectStoreDeliver() {
169
		return objectStoreDeliver;
170
	}
171

    
172
	/**
173
	 * Sets the object store deliver.
174
	 *
175
	 * @param objectStoreDeliver
176
	 *            the new object store deliver
177
	 */
178
	@Required
179
	public void setObjectStoreDeliver(final ModularObjectStoreDeliver objectStoreDeliver) {
180
		this.objectStoreDeliver = objectStoreDeliver;
181
	}
182

    
183
	/*
184
	 * (non-Javadoc)
185
	 *
186
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#feedObject(java.lang.String, java.lang.String)
187
	 */
188
	/**
189
	 * Feed object.
190
	 *
191
	 * @param obsId
192
	 *            the obs id
193
	 * @param objectMetadata
194
	 *            the object metadata
195
	 * @throws ObjectStoreServiceException
196
	 *             the object store service exception
197
	 */
198
	@Override
199
	public void feedObject(final String obsId, final String objectMetadata) throws ObjectStoreServiceException {
200
		Gson g = new Gson();
201
		try {
202
			ObjectStoreFile file = g.fromJson(objectMetadata, ObjectStoreFile.class);
203
			feeder.feedObject(obsId, file.getObjectID(), file.getURI(), file.getAccessProtocol(), file.getUsernameAuth(), file.getPasswordAuth(),
204
					file.getMimeType());
205

    
206
		} catch (Exception e) {
207
			throw new ObjectStoreServiceException(e.getMessage());
208
		}
209

    
210
	}
211

    
212
	/**
213
	 * Exist id starts with.
214
	 *
215
	 * @param obsId
216
	 *            the obs id
217
	 * @param startId
218
	 *            the start id
219
	 * @return true, if successful
220
	 * @throws ObjectStoreServiceException
221
	 *             the object store service exception
222
	 */
223
	public boolean existIDStartsWith(final String obsId, final String startId) throws ObjectStoreServiceException {
224
		return objectStoreDeliver.existIDStartsWith(obsId, startId);
225
	}
226

    
227
	/**
228
	 * Feed object.
229
	 *
230
	 * @param obsId
231
	 *            the obs id
232
	 * @param record
233
	 *            the record
234
	 * @return the string
235
	 * @throws ObjectStoreServiceException
236
	 *             the object store service exception
237
	 */
238
	public String feedObject(final String obsId, final ObjectStoreRecord record) throws ObjectStoreServiceException {
239

    
240
		try {
241

    
242
			return feeder.feedObjectRecord(obsId, record);
243

    
244
		} catch (Exception e) {
245
			throw new ObjectStoreServiceException(e.getMessage());
246
		}
247

    
248
	}
249

    
250
	/**
251
	 * Gets the size.
252
	 *
253
	 * @param obsId
254
	 *            the obs id
255
	 * @return the size
256
	 * @throws ObjectStoreServiceException
257
	 *             the object store service exception
258
	 */
259
	@Override
260
	public int getSize(final String obsId) throws ObjectStoreServiceException {
261
		return objectStoreDeliver.getDao().getObjectStore(obsId).getSize();
262

    
263
	}
264

    
265
	// ================================================================================
266
	// Tag Section
267
	// ================================================================================
268

    
269
	/*
270
	 * (non-Javadoc)
271
	 *
272
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#deliverRecordsByTag(java.lang.String, java.lang.Iterable)
273
	 */
274
	@Override
275
	public W3CEndpointReference deliverRecordsByTag(final String obsId, final List<String> tags) throws ObjectStoreServiceException {
276
		return objectStoreDeliver.deliverRecordsByTags(obsId, tags);
277
	}
278

    
279
	/*
280
	 * (non-Javadoc)
281
	 *
282
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#tagIds(java.lang.String, javax.xml.ws.wsaddressing.W3CEndpointReference,
283
	 * java.lang.String)
284
	 */
285
	@Override
286
	public int tagIds(final String objectStoreId, final W3CEndpointReference eprId, final String tag) {
287
		return feeder.tagIds(objectStoreId, eprId, tag);
288
	}
289

    
290
	/*
291
	 * (non-Javadoc)
292
	 *
293
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#untagIds(java.lang.String, javax.xml.ws.wsaddressing.W3CEndpointReference,
294
	 * java.lang.String)
295
	 */
296
	@Override
297
	public int untagIds(final String objectStoreId, final W3CEndpointReference eprId, final String tag) {
298
		return feeder.untagIds(objectStoreId, eprId, tag);
299
	}
300

    
301
	/*
302
	 * (non-Javadoc)
303
	 *
304
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#tagObjectstore(java.lang.String, java.lang.String)
305
	 */
306
	@Override
307
	public int tagObjectstore(final String objectStoreId, final String tag) {
308
		return feeder.tagObjectStore(objectStoreId, tag);
309
	}
310

    
311
	/*
312
	 * (non-Javadoc)
313
	 *
314
	 * @see eu.dnetlib.data.objectstore.rmi.ObjectStoreService#untagObjectstore(java.lang.String, java.lang.String)
315
	 */
316
	@Override
317
	public int untagObjectstore(final String objectStoreId, final String tag) {
318
		return feeder.untagObjectStore(objectStoreId, tag);
319
	}
320

    
321
	@Override
322
	public int tagIdsByList(final String objectStoreId, final List<String> ids, final String tag) {
323
		return feeder.tagObjectStorebyIds(objectStoreId, ids, tag);
324
	}
325

    
326
	@Override
327
	public int untagIdsByList(final String objectStoreId, final List<String> ids, final String tag) {
328
		return feeder.untagObjectStorebyIds(objectStoreId, ids, tag);
329
	}
330

    
331
}
(9-9/13)