Revision 55492
Added by Alessia Bardi almost 5 years ago
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-objectstore-service/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-modular-objectstore-service"} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/DropContentObjectStoreAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
|
|
7 |
/** |
|
8 |
* Created by sandro on 2/26/16. |
|
9 |
*/ |
|
10 |
public class DropContentObjectStoreAction extends AbstractObjectStoreAction { |
|
11 |
|
|
12 |
@Override |
|
13 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException { |
|
14 |
try { |
|
15 |
final String objID = job.getParameters().get("obsID"); |
|
16 |
|
|
17 |
final boolean status = getDao().dropContent(objID); |
|
18 |
job.getParameters().put("dropStatus", "" + status); |
|
19 |
completeWithSuccess(handler, job); |
|
20 |
} catch (Exception e) { |
|
21 |
completeWithFail(handler, job, e); |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ObjectStoreActions.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
/** |
|
4 |
* The Enumeration of the blacboard action of the ObjectStore. |
|
5 |
*/ |
|
6 |
public enum ObjectStoreActions { |
|
7 |
|
|
8 |
/** The create. */ |
|
9 |
CREATE, |
|
10 |
/** |
|
11 |
* The delete. |
|
12 |
*/ |
|
13 |
DELETE, |
|
14 |
/** |
|
15 |
* The feed. |
|
16 |
*/ |
|
17 |
FEED, |
|
18 |
/** |
|
19 |
* The feedobject. |
|
20 |
*/ |
|
21 |
FEEDOBJECT, DROP_CONTENT |
|
22 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/DeleteObjectStoreAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
4 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
5 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
6 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
7 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
|
|
10 |
/** |
|
11 |
* The Class DeleteObjectStoreAction is responsible to execute the blacboard action of type DELETE. |
|
12 |
*/ |
|
13 |
public class DeleteObjectStoreAction extends AbstractObjectStoreAction { |
|
14 |
|
|
15 |
/** |
|
16 |
* The profile creator. |
|
17 |
*/ |
|
18 |
|
|
19 |
private ObjectStoreProfileCreator profileCreator; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private UniqueServiceLocator serviceLocator; |
|
23 |
|
|
24 |
@Override |
|
25 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException { |
|
26 |
try { |
|
27 |
final String objID = job.getParameters().get("obsID"); |
|
28 |
serviceLocator.getService(ISRegistryService.class).deleteProfile(objID); |
|
29 |
getDao().deleteObjectStore(objID); |
|
30 |
completeWithSuccess(handler, job); |
|
31 |
|
|
32 |
} catch (Exception e) { |
|
33 |
completeWithFail(handler, job, e); |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets the profile creator. |
|
39 |
* |
|
40 |
* @return the profile creator |
|
41 |
*/ |
|
42 |
public ObjectStoreProfileCreator getProfileCreator() { |
|
43 |
return profileCreator; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Sets the profile creator. |
|
48 |
* |
|
49 |
* @param profileCreator the new profile creator |
|
50 |
*/ |
|
51 |
public void setProfileCreator(ObjectStoreProfileCreator profileCreator) { |
|
52 |
this.profileCreator = profileCreator; |
|
53 |
} |
|
54 |
|
|
55 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ObjectStoreConsistency.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Set; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Lists; |
|
8 |
import com.google.common.collect.Sets; |
|
9 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
|
10 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
11 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
13 |
import org.apache.commons.lang3.StringUtils; |
|
14 |
import org.apache.commons.logging.Log; |
|
15 |
import org.apache.commons.logging.LogFactory; |
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.stereotype.Controller; |
|
18 |
import org.springframework.ui.ModelMap; |
|
19 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
20 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
21 |
|
|
22 |
|
|
23 |
@Controller |
|
24 |
public class ObjectStoreConsistency { |
|
25 |
|
|
26 |
private static final Log log = LogFactory.getLog(ObjectStoreConsistency.class); |
|
27 |
|
|
28 |
@Autowired |
|
29 |
private ObjectStoreDao objectStoreDao; |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private UniqueServiceLocator serviceLocator; |
|
33 |
|
|
34 |
private ObjectStoreIntegrityInfo integrityInfo; |
|
35 |
|
|
36 |
|
|
37 |
@RequestMapping(value = "/ui/objectStore/infoConsistency.do") |
|
38 |
@ResponseBody |
|
39 |
public ObjectStoreIntegrityInfo getConsistencyInfo(final ModelMap map) { |
|
40 |
return getIntegrityInfo(); |
|
41 |
} |
|
42 |
|
|
43 |
public void refreshConsistency() { |
|
44 |
try { |
|
45 |
Set<String> profiles = listProfileIds(); |
|
46 |
Set<String> objectStore = listObjectStoreIds(); |
|
47 |
Set<String> objectStoreNotInProfile = Sets.newHashSet(objectStore); |
|
48 |
objectStoreNotInProfile.removeAll(profiles); |
|
49 |
Set<String> profilesNotInObjectStore = Sets.newHashSet(profiles); |
|
50 |
profilesNotInObjectStore.removeAll(objectStore); |
|
51 |
ObjectStoreIntegrityInfo info = new ObjectStoreIntegrityInfo(); |
|
52 |
info.setObjectStoreWithoutProfile(objectStoreNotInProfile); |
|
53 |
info.setProfileWithoutObjectStore(profilesNotInObjectStore); |
|
54 |
this.integrityInfo = info; |
|
55 |
} catch (ISLookUpException e) { |
|
56 |
log.error("Error on refreshing consistency of objectStore ", e); |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
private Set<String> listObjectStoreIds() { |
|
64 |
return Sets.newHashSet( |
|
65 |
Lists.transform(objectStoreDao.listObjectStores(), new Function<String, String>() { |
|
66 |
@Override |
|
67 |
public String apply(String input) { |
|
68 |
return StringUtils.substringBefore(input, "_"); |
|
69 |
} |
|
70 |
})); |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
private Set<String> listProfileIds() throws ISLookUpException { |
|
75 |
|
|
76 |
final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class); |
|
77 |
final String query = "for $x in collection('/db/DRIVER/ObjectStoreDSResources/ObjectStoreDSResourceType') return $x//RESOURCE_IDENTIFIER/@value/string()"; |
|
78 |
|
|
79 |
List<String> resultList = lookupService.quickSearchProfile(query); |
|
80 |
|
|
81 |
|
|
82 |
return Sets.newHashSet(Lists.transform(resultList, new Function<String, String>() { |
|
83 |
@Override |
|
84 |
public String apply(String input) { |
|
85 |
return StringUtils.substringBefore(input, "_"); |
|
86 |
} |
|
87 |
})); |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
public ObjectStoreIntegrityInfo getIntegrityInfo() { |
|
93 |
if (integrityInfo == null) { |
|
94 |
refreshConsistency(); |
|
95 |
} |
|
96 |
return integrityInfo; |
|
97 |
} |
|
98 |
|
|
99 |
public void setIntegrityInfo(ObjectStoreIntegrityInfo integrityInfo) { |
|
100 |
this.integrityInfo = integrityInfo; |
|
101 |
} |
|
102 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/FeedObjectStoreAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
4 |
import eu.dnetlib.data.objectstore.rmi.Protocols; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
6 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
7 |
import org.springframework.beans.factory.annotation.Required; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* The Class FeedObjectStoreAction to execute the blacboard action of type FEED. |
|
12 |
*/ |
|
13 |
public class FeedObjectStoreAction extends AbstractObjectStoreAction { |
|
14 |
|
|
15 |
/** The profile creator. */ |
|
16 |
private ObjectStoreProfileCreator profileCreator; |
|
17 |
|
|
18 |
/** The store feeder. */ |
|
19 |
private ModularObjectStoreFeeder storeFeeder; |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException { |
|
23 |
try { |
|
24 |
final String objStoreID = job.getParameters().get("obsID"); |
|
25 |
final String objID = job.getParameters().get("objID"); |
|
26 |
final String URI = job.getParameters().get("URI"); |
|
27 |
final String eprRs = job.getParameters().get("epr"); |
|
28 |
final String protocolString = job.getParameters().get("protocol"); |
|
29 |
|
|
30 |
final Protocols protocol; |
|
31 |
if (protocolString == null) |
|
32 |
protocol = Protocols.None; |
|
33 |
else |
|
34 |
protocol = Protocols.valueOf(job.getParameters().get("protocol")); |
|
35 |
final String mime = job.getParameters().get("mime"); |
|
36 |
final String login = job.getParameters().get("login"); |
|
37 |
final String password = job.getParameters().get("password"); |
|
38 |
|
|
39 |
if (URI != null && URI.length() > 0) { |
|
40 |
storeFeeder.feedObject(objStoreID, objID, URI, protocol, login, |
|
41 |
password, mime); |
|
42 |
} else if (eprRs != null && eprRs.length() > 0) { |
|
43 |
storeFeeder |
|
44 |
.feed(objStoreID, eprRs, protocol, login, password, mime); |
|
45 |
} |
|
46 |
completeWithSuccess(handler, job); |
|
47 |
} catch (Exception e) { |
|
48 |
completeWithFail(handler, job, e); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
/** |
|
55 |
* Gets the profile creator. |
|
56 |
* |
|
57 |
* @return the profile creator |
|
58 |
*/ |
|
59 |
public ObjectStoreProfileCreator getProfileCreator() { |
|
60 |
return profileCreator; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Sets the profile creator. |
|
65 |
* |
|
66 |
* @param profileCreator the new profile creator |
|
67 |
*/ |
|
68 |
@Required |
|
69 |
public void setProfileCreator(ObjectStoreProfileCreator profileCreator) { |
|
70 |
this.profileCreator = profileCreator; |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Gets the store feeder. |
|
75 |
* |
|
76 |
* @return the store feeder |
|
77 |
*/ |
|
78 |
public ModularObjectStoreFeeder getStoreFeeder() { |
|
79 |
return storeFeeder; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Sets the store feeder. |
|
84 |
* |
|
85 |
* @param storeFeeder the new store feeder |
|
86 |
*/ |
|
87 |
@Required |
|
88 |
public void setStoreFeeder(ModularObjectStoreFeeder storeFeeder) { |
|
89 |
this.storeFeeder = storeFeeder; |
|
90 |
} |
|
91 |
|
|
92 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/CreateObjectStoreAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.apache.commons.logging.Log; |
|
8 |
import org.apache.commons.logging.LogFactory; |
|
9 |
|
|
10 |
/** |
|
11 |
* The Class CreateObjectStoreAction is responsible to execute the blacboard action of type CREATE. |
|
12 |
*/ |
|
13 |
public class CreateObjectStoreAction extends AbstractObjectStoreAction { |
|
14 |
|
|
15 |
private static final Log log = LogFactory.getLog(CreateObjectStoreAction.class); |
|
16 |
|
|
17 |
/** The profile creator. */ |
|
18 |
private ObjectStoreProfileCreator profileCreator; |
|
19 |
|
|
20 |
/** |
|
21 |
* Gets the profile creator. |
|
22 |
* |
|
23 |
* @return the profile creator |
|
24 |
*/ |
|
25 |
public ObjectStoreProfileCreator getProfileCreator() { |
|
26 |
return profileCreator; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Sets the profile creator. |
|
31 |
* |
|
32 |
* @param profileCreator the new profile creator |
|
33 |
*/ |
|
34 |
public void setProfileCreator(final ObjectStoreProfileCreator profileCreator) { |
|
35 |
this.profileCreator = profileCreator; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) { |
|
40 |
try { |
|
41 |
final String interpretation = job.getParameters().get("interpretation"); |
|
42 |
// final String basePath = job.getParameters().get("basePath"); |
|
43 |
// if (StringUtils.isBlank(basePath)) { |
|
44 |
// throw new ObjectStoreServiceException("missing basePath param"); |
|
45 |
// } |
|
46 |
|
|
47 |
final String objID = profileCreator.registerProfile(interpretation); |
|
48 |
try { |
|
49 |
getDao().createObjectStore(objID, interpretation, null); |
|
50 |
} catch (Throwable e) { |
|
51 |
log.warn("cannot created objectStore, deleting profile"); |
|
52 |
profileCreator.deleteProfile(objID); |
|
53 |
throw new ObjectStoreServiceException(e); |
|
54 |
} |
|
55 |
job.getParameters().put("objectStoreId", objID); |
|
56 |
completeWithSuccess(handler, job); |
|
57 |
} catch (Exception e) { |
|
58 |
completeWithFail(handler, job, e); |
|
59 |
} |
|
60 |
|
|
61 |
} |
|
62 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/AbstractObjectStoreAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import java.util.concurrent.Executor; |
|
4 |
import java.util.concurrent.Executors; |
|
5 |
|
|
6 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
|
7 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
9 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction; |
|
10 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
|
|
14 |
/** |
|
15 |
* The Class AbstractObjectStoreAction. |
|
16 |
*/ |
|
17 |
public abstract class AbstractObjectStoreAction implements BlackboardServerAction<ObjectStoreActions> { |
|
18 |
|
|
19 |
/** |
|
20 |
* Logger |
|
21 |
*/ |
|
22 |
private static final Log log = LogFactory.getLog(AbstractObjectStoreAction.class); |
|
23 |
private final Executor executor = Executors.newCachedThreadPool(); |
|
24 |
/** The object store dao. */ |
|
25 |
private ObjectStoreDao dao; |
|
26 |
|
|
27 |
protected abstract void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException; |
|
28 |
|
|
29 |
@Override |
|
30 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) { |
|
31 |
executor.execute(new Runnable() { |
|
32 |
|
|
33 |
@Override |
|
34 |
public void run() { |
|
35 |
try { |
|
36 |
handler.ongoing(job); |
|
37 |
executeAsync(handler, job); |
|
38 |
} catch (ObjectStoreServiceException e) { |
|
39 |
handler.failed(job, e); |
|
40 |
} |
|
41 |
} |
|
42 |
}); |
|
43 |
} |
|
44 |
|
|
45 |
protected void completeWithSuccess(final BlackboardServerHandler handler, final BlackboardJob job) { |
|
46 |
// Don't change this synchronization rule |
|
47 |
synchronized (this) { |
|
48 |
handler.done(job); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
protected void completeWithFail(final BlackboardServerHandler handler, final BlackboardJob job, final Throwable e) { |
|
53 |
// Don't change this synchronization rule |
|
54 |
synchronized (this) { |
|
55 |
handler.failed(job, e); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Gets the dao. |
|
61 |
* |
|
62 |
* @return the dao |
|
63 |
*/ |
|
64 |
public ObjectStoreDao getDao() { |
|
65 |
return dao; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Sets the dao. |
|
70 |
* |
|
71 |
* @param dao the new dao |
|
72 |
*/ |
|
73 |
public void setDao(ObjectStoreDao dao) { |
|
74 |
this.dao = dao; |
|
75 |
} |
|
76 |
|
|
77 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/connector/ObjectStore.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular.connector; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.modular.ObjectStoreRecord; |
|
4 |
import eu.dnetlib.data.objectstore.rmi.MetadataObjectRecord; |
|
5 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile; |
|
6 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
7 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
8 |
|
|
9 |
/** |
|
10 |
* The Interface ObjectStore. |
|
11 |
*/ |
|
12 |
public interface ObjectStore { |
|
13 |
|
|
14 |
/** |
|
15 |
* Gets the id of the objectStore. |
|
16 |
* |
|
17 |
* @return the id |
|
18 |
*/ |
|
19 |
String getId(); |
|
20 |
|
|
21 |
/** |
|
22 |
* Gets the interpretation the objectStore. |
|
23 |
* |
|
24 |
* @return the interpretation |
|
25 |
*/ |
|
26 |
String getInterpretation(); |
|
27 |
|
|
28 |
/** |
|
29 |
* Feed record into the objectstore. |
|
30 |
* |
|
31 |
* @param records |
|
32 |
* the records |
|
33 |
* @param incremental |
|
34 |
* the incremental |
|
35 |
* @return the int |
|
36 |
*/ |
|
37 |
int feed(Iterable<ObjectStoreRecord> records, boolean incremental) throws ObjectStoreServiceException; |
|
38 |
|
|
39 |
/** |
|
40 |
* Feed metadata record into the objectStore. |
|
41 |
* |
|
42 |
* @param records |
|
43 |
* the records |
|
44 |
* @param incremental |
|
45 |
* the incremental |
|
46 |
* @return the int |
|
47 |
*/ |
|
48 |
int feedMetadataRecord(Iterable<MetadataObjectRecord> records, boolean incremental) throws ObjectStoreServiceException; |
|
49 |
|
|
50 |
/** |
|
51 |
* Feed a single object record into the objectStore. |
|
52 |
* |
|
53 |
* @param record |
|
54 |
* the record |
|
55 |
* @return the string |
|
56 |
*/ |
|
57 |
String feedObjectRecord(ObjectStoreRecord record) throws ObjectStoreServiceException; |
|
58 |
|
|
59 |
/** |
|
60 |
* Deliver Object from the objectStore. |
|
61 |
* |
|
62 |
* @param from |
|
63 |
* : start date which you want to filter |
|
64 |
* @param until |
|
65 |
* : end date which you want to filter |
|
66 |
* @return the result set listener |
|
67 |
*/ |
|
68 |
ResultSetListener deliver(Long from, Long until) throws ObjectStoreServiceException; |
|
69 |
|
|
70 |
/** |
|
71 |
* Deliver ids. |
|
72 |
* |
|
73 |
* @param ids |
|
74 |
* the ids |
|
75 |
* @return the result set listener |
|
76 |
*/ |
|
77 |
ResultSetListener deliverIds(Iterable<String> ids) throws ObjectStoreServiceException; |
|
78 |
|
|
79 |
/** |
|
80 |
* Deliver object. |
|
81 |
* |
|
82 |
* @param objectId |
|
83 |
* the object id |
|
84 |
* @return the object store file |
|
85 |
* @throws ObjectStoreServiceException |
|
86 |
*/ |
|
87 |
ObjectStoreFile deliverObject(String objectId) throws ObjectStoreServiceException; |
|
88 |
|
|
89 |
/** |
|
90 |
* Gets the size. |
|
91 |
* |
|
92 |
* @return the size |
|
93 |
*/ |
|
94 |
int getSize() throws ObjectStoreServiceException; |
|
95 |
|
|
96 |
/** |
|
97 |
* Delete object. |
|
98 |
* |
|
99 |
* @param objectId |
|
100 |
* the object id |
|
101 |
*/ |
|
102 |
void deleteObject(String objectId) throws ObjectStoreServiceException; |
|
103 |
|
|
104 |
/** |
|
105 |
* Gets the object. |
|
106 |
* |
|
107 |
* @param recordId |
|
108 |
* the record id |
|
109 |
* @return the object |
|
110 |
*/ |
|
111 |
String getObject(String recordId) throws ObjectStoreServiceException; |
|
112 |
|
|
113 |
/** |
|
114 |
* Find if exist an ID startingwith the string startId. |
|
115 |
* |
|
116 |
* @param startId |
|
117 |
* the start id |
|
118 |
* @return if exist or less an id |
|
119 |
*/ |
|
120 |
boolean existIDStartsWith(String startId) throws ObjectStoreServiceException; |
|
121 |
|
|
122 |
/** |
|
123 |
* drop the content of the ObjectStore |
|
124 |
* THIS METHOD DELETE ALL THE CONTENT INSIDE THE OBJECTSTORE PAY ATTENTION WHEN YOU CALL IT |
|
125 |
* |
|
126 |
* @return if the content has been refreshed |
|
127 |
* @throws ObjectStoreServiceException |
|
128 |
*/ |
|
129 |
boolean dropContent() throws ObjectStoreServiceException; |
|
130 |
|
|
131 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/connector/ObjectStoreDao.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular.connector; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
6 |
|
|
7 |
/** |
|
8 |
* The Interface ObjectStoreDao. |
|
9 |
*/ |
|
10 |
public interface ObjectStoreDao { |
|
11 |
|
|
12 |
/** |
|
13 |
* Gets an Object Store with the given identifier. |
|
14 |
* <p> |
|
15 |
* If an Object Store with the given identifier does not exist, a new one is created. |
|
16 |
* </p> |
|
17 |
* |
|
18 |
* @param obsId |
|
19 |
* the object store identifier |
|
20 |
* @return the object store |
|
21 |
* @throws ObjectStoreServiceException |
|
22 |
*/ |
|
23 |
ObjectStore getObjectStore(String obsId) throws ObjectStoreServiceException; |
|
24 |
|
|
25 |
/** |
|
26 |
* List all the Object stores. |
|
27 |
* |
|
28 |
* @return the list of object store ids |
|
29 |
*/ |
|
30 |
List<String> listObjectStores(); |
|
31 |
|
|
32 |
/** |
|
33 |
* Creates an Object Store with the given identifier. |
|
34 |
* <p> |
|
35 |
* If an Object Store with the given identifier already exists this method does nothing. |
|
36 |
* </p> |
|
37 |
* |
|
38 |
* @param obsId the object store identifier |
|
39 |
* @param interpretation the interpretation of the store |
|
40 |
* @param basePath the base path to store the object Store in case of file system implementation |
|
41 |
* @return true, if successful |
|
42 |
* @throws ObjectStoreServiceException |
|
43 |
*/ |
|
44 |
boolean createObjectStore(String obsId, String interpretation, String basePath) throws ObjectStoreServiceException; |
|
45 |
|
|
46 |
/** |
|
47 |
* Upddate an Object Store metadata with the given identifier. |
|
48 |
* <p> |
|
49 |
* If an Object Store with the given identifier does not exist, a new one is created. |
|
50 |
* </p> |
|
51 |
* |
|
52 |
* @param obsId |
|
53 |
* the object store identifier |
|
54 |
* @param interpretation |
|
55 |
* the interpretation of the store |
|
56 |
* @return true, if successful |
|
57 |
*/ |
|
58 |
boolean updateObjectStore(String obsId, String interpretation); |
|
59 |
|
|
60 |
/** |
|
61 |
* Delete object store. |
|
62 |
* |
|
63 |
* @param obsId |
|
64 |
* the object store identifier |
|
65 |
* @return true, if successful |
|
66 |
* @throws ObjectStoreServiceException |
|
67 |
*/ |
|
68 |
boolean deleteObjectStore(String obsId) throws ObjectStoreServiceException; |
|
69 |
|
|
70 |
boolean dropContent(String obsId) throws ObjectStoreServiceException; |
|
71 |
|
|
72 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ObjectBroker.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
import java.io.IOException; |
|
7 |
import java.io.InputStream; |
|
8 |
import java.net.HttpURLConnection; |
|
9 |
import java.net.MalformedURLException; |
|
10 |
import java.net.SocketException; |
|
11 |
import java.net.URI; |
|
12 |
import java.net.URISyntaxException; |
|
13 |
import java.net.URL; |
|
14 |
|
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.apache.commons.net.ftp.FTPClient; |
|
18 |
|
|
19 |
import com.google.common.base.Function; |
|
20 |
|
|
21 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile; |
|
22 |
import eu.dnetlib.data.objectstore.rmi.Protocols; |
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
/** |
|
27 |
* The Class ObjectBroker is responsible to retrieve content from URL. |
|
28 |
*/ |
|
29 |
public class ObjectBroker implements Function<String, ObjectStoreRecord> { |
|
30 |
private static final Log log = LogFactory.getLog(ObjectBroker.class); |
|
31 |
|
|
32 |
/** The protocol. */ |
|
33 |
private Protocols protocol; |
|
34 |
|
|
35 |
/** The login. */ |
|
36 |
private String login; |
|
37 |
|
|
38 |
/** The password. */ |
|
39 |
private String password; |
|
40 |
|
|
41 |
/** The mime. */ |
|
42 |
private String mime; |
|
43 |
|
|
44 |
/** |
|
45 |
* Instantiates a new object broker. |
|
46 |
* |
|
47 |
* @param protocol |
|
48 |
* the protocol |
|
49 |
* @param login |
|
50 |
* the login |
|
51 |
* @param password |
|
52 |
* the password |
|
53 |
* @param mime |
|
54 |
* the mime |
|
55 |
*/ |
|
56 |
public ObjectBroker(final Protocols protocol, final String login, final String password, final String mime) { |
|
57 |
this.protocol = protocol; |
|
58 |
this.login = login; |
|
59 |
this.password = password; |
|
60 |
this.mime = mime; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Gets the protocol. |
|
65 |
* |
|
66 |
* @return the protocol |
|
67 |
*/ |
|
68 |
public Protocols getProtocol() { |
|
69 |
return protocol; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Sets the protocol. |
|
74 |
* |
|
75 |
* @param protocol |
|
76 |
* the new protocol |
|
77 |
*/ |
|
78 |
public void setProtocol(final Protocols protocol) { |
|
79 |
this.protocol = protocol; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Gets the login. |
|
84 |
* |
|
85 |
* @return the login |
|
86 |
*/ |
|
87 |
public String getLogin() { |
|
88 |
return login; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Sets the login. |
|
93 |
* |
|
94 |
* @param login |
|
95 |
* the new login |
|
96 |
*/ |
|
97 |
public void setLogin(final String login) { |
|
98 |
this.login = login; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Gets the password. |
|
103 |
* |
|
104 |
* @return the password |
|
105 |
*/ |
|
106 |
public String getPassword() { |
|
107 |
return password; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Sets the password. |
|
112 |
* |
|
113 |
* @param password |
|
114 |
* the new password |
|
115 |
*/ |
|
116 |
public void setPassword(final String password) { |
|
117 |
this.password = password; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Gets the mime. |
|
122 |
* |
|
123 |
* @return the mime |
|
124 |
*/ |
|
125 |
public String getMime() { |
|
126 |
return mime; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Sets the mime. |
|
131 |
* |
|
132 |
* @param mime |
|
133 |
* the new mime |
|
134 |
*/ |
|
135 |
public void setMime(final String mime) { |
|
136 |
this.mime = mime; |
|
137 |
} |
|
138 |
|
|
139 |
/* |
|
140 |
* (non-Javadoc) |
|
141 |
* |
|
142 |
* @see com.google.common.base.Function#apply(java.lang.Object) |
|
143 |
*/ |
|
144 |
@Override |
|
145 |
public ObjectStoreRecord apply(final String jsonInput) { |
|
146 |
if (jsonInput == null) return null; |
|
147 |
ObjectStoreRecord objectStorerecord = new ObjectStoreRecord(); |
|
148 |
|
|
149 |
objectStorerecord.setFileMetadata(ObjectStoreFile.createObject(jsonInput)); |
|
150 |
Protocols currentProtocol = (objectStorerecord.getFileMetadata().getAccessProtocol() == Protocols.None) ? protocol : objectStorerecord |
|
151 |
.getFileMetadata().getAccessProtocol(); |
|
152 |
objectStorerecord.getFileMetadata().setAccessProtocol(currentProtocol); |
|
153 |
if ((objectStorerecord.getFileMetadata().getMimeType() == null) || (objectStorerecord.getFileMetadata().getMimeType().length() == 0)) { |
|
154 |
objectStorerecord.getFileMetadata().setMimeType(mime); |
|
155 |
} |
|
156 |
|
|
157 |
switch (currentProtocol) { |
|
158 |
case FTP: |
|
159 |
FTPClient client = new FTPClient(); |
|
160 |
try { |
|
161 |
URI uri = new URI(objectStorerecord.getFileMetadata().getURI()); |
|
162 |
client.connect(uri.getHost()); |
|
163 |
if ((objectStorerecord.getFileMetadata().getUsernameAuth() != null) && (objectStorerecord.getFileMetadata().getUsernameAuth().length() > 0)) { |
|
164 |
client.login(objectStorerecord.getFileMetadata().getUsernameAuth(), objectStorerecord.getFileMetadata().getPasswordAuth()); |
|
165 |
} else { |
|
166 |
client.login("ftp", "a@a"); |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
final InputStream stream = client.retrieveFileStream(uri.getPath()); |
|
171 |
objectStorerecord.setInputStream(stream); |
|
172 |
return objectStorerecord; |
|
173 |
|
|
174 |
} catch (URISyntaxException e2) { |
|
175 |
log.error(e2); |
|
176 |
return null; |
|
177 |
} catch (SocketException e) { |
|
178 |
log.error(e); |
|
179 |
} catch (IOException e) { |
|
180 |
log.error(e); |
|
181 |
return null; |
|
182 |
} |
|
183 |
|
|
184 |
case HTTP: |
|
185 |
try { |
|
186 |
HttpURLConnection conn = (HttpURLConnection) new URL(objectStorerecord.getFileMetadata().getURI()).openConnection(); |
|
187 |
InputStream in; |
|
188 |
int http_status; |
|
189 |
try { |
|
190 |
|
|
191 |
http_status = conn.getResponseCode(); |
|
192 |
|
|
193 |
if ((http_status / 100) == 3) { |
|
194 |
String newURL = conn.getHeaderField("Location"); |
|
195 |
conn.disconnect(); |
|
196 |
conn = (HttpURLConnection) new URL(newURL).openConnection(); |
|
197 |
http_status = conn.getResponseCode(); |
|
198 |
if ((http_status / 100) != 2) return null; |
|
199 |
} |
|
200 |
in = conn.getInputStream(); |
|
201 |
objectStorerecord.setInputStream(in); |
|
202 |
return objectStorerecord; |
|
203 |
} catch (Exception e) { |
|
204 |
log.error(e); |
|
205 |
return null; |
|
206 |
} |
|
207 |
} catch (MalformedURLException e1) { |
|
208 |
log.error(e1); |
|
209 |
return null; |
|
210 |
} catch (IOException e1) { |
|
211 |
log.error(e1); |
|
212 |
return null; |
|
213 |
} |
|
214 |
|
|
215 |
case File_System: |
|
216 |
File f = new File(objectStorerecord.getFileMetadata().getURI()); |
|
217 |
try { |
|
218 |
InputStream myiInputStream = new FileInputStream(f); |
|
219 |
objectStorerecord.setInputStream(myiInputStream); |
|
220 |
return objectStorerecord; |
|
221 |
} catch (FileNotFoundException e) { |
|
222 |
try { |
|
223 |
Thread.sleep(5000); |
|
224 |
InputStream myiInputStream = new FileInputStream(f); |
|
225 |
objectStorerecord.setInputStream(myiInputStream); |
|
226 |
return objectStorerecord; |
|
227 |
} catch (Exception e1) { |
|
228 |
log.error(e1); |
|
229 |
return null; |
|
230 |
} |
|
231 |
} |
|
232 |
default: |
|
233 |
break; |
|
234 |
} |
|
235 |
|
|
236 |
return null; |
|
237 |
|
|
238 |
} |
|
239 |
|
|
240 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/FeedCompleteObjectAction.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
import org.springframework.beans.factory.annotation.Required; |
|
7 |
|
|
8 |
// TODO: Auto-generated Javadoc |
|
9 |
/** |
|
10 |
* The Class FeedCompleteObjectAction is responsible to execute the blacboard action of type FEED OBJECT which is Metadata created for WOS case of openaire. |
|
11 |
*/ |
|
12 |
public class FeedCompleteObjectAction extends AbstractObjectStoreAction { |
|
13 |
|
|
14 |
/** The store feeder. */ |
|
15 |
private ModularObjectStoreFeeder storeFeeder; |
|
16 |
|
|
17 |
@Override |
|
18 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException { |
|
19 |
try { |
|
20 |
final String objStoreID = job.getParameters().get("obsID"); |
|
21 |
final String eprRs = job.getParameters().get("epr"); |
|
22 |
final String mime = job.getParameters().get("mime"); |
|
23 |
int count = storeFeeder.feedMetadataObjectRecord(objStoreID, eprRs, mime); |
|
24 |
job.getParameters().put("total", "" + count); |
|
25 |
completeWithSuccess(handler, job); |
|
26 |
} catch (Exception e) { |
|
27 |
completeWithFail(handler, job, e); |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Gets the store feeder. |
|
33 |
* |
|
34 |
* @return the store feeder |
|
35 |
*/ |
|
36 |
public ModularObjectStoreFeeder getStoreFeeder() { |
|
37 |
return storeFeeder; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Sets the store feeder. |
|
42 |
* |
|
43 |
* @param storeFeeder the new store feeder |
|
44 |
*/ |
|
45 |
@Required |
|
46 |
public void setStoreFeeder(final ModularObjectStoreFeeder storeFeeder) { |
|
47 |
this.storeFeeder = storeFeeder; |
|
48 |
} |
|
49 |
|
|
50 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ObjectStoreRecord.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import java.io.InputStream; |
|
4 |
|
|
5 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile; |
|
6 |
|
|
7 |
/** |
|
8 |
* The Class ObjectStoreRecord is a serialization of the object to be ingested in the objectStore |
|
9 |
* metadata + inputstream of the data. |
|
10 |
*/ |
|
11 |
public class ObjectStoreRecord { |
|
12 |
|
|
13 |
/** The file metadata. */ |
|
14 |
private ObjectStoreFile fileMetadata; |
|
15 |
|
|
16 |
/** The input stream. */ |
|
17 |
private InputStream inputStream; |
|
18 |
|
|
19 |
/** |
|
20 |
* Gets the input stream. |
|
21 |
* |
|
22 |
* @return the input stream |
|
23 |
*/ |
|
24 |
public InputStream getInputStream() { |
|
25 |
return inputStream; |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Sets the input stream. |
|
30 |
* |
|
31 |
* @param inputStream the new input stream |
|
32 |
*/ |
|
33 |
public void setInputStream(final InputStream inputStream) { |
|
34 |
this.inputStream = inputStream; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets the file metadata. |
|
39 |
* |
|
40 |
* @return the file metadata |
|
41 |
*/ |
|
42 |
public ObjectStoreFile getFileMetadata() { |
|
43 |
return fileMetadata; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Sets the file metadata. |
|
48 |
* |
|
49 |
* @param fileMetadata the new file metadata |
|
50 |
*/ |
|
51 |
public void setFileMetadata(final ObjectStoreFile fileMetadata) { |
|
52 |
this.fileMetadata = fileMetadata; |
|
53 |
} |
|
54 |
|
|
55 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ModularObjectStoreFeeder.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import com.google.common.collect.Iterables; |
|
4 |
import com.google.common.collect.Lists; |
|
5 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStore; |
|
6 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
|
7 |
import eu.dnetlib.data.objectstore.rmi.MetadataObjectRecord; |
|
8 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile; |
|
9 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
10 |
import eu.dnetlib.data.objectstore.rmi.Protocols; |
|
11 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
13 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
14 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.springframework.beans.factory.annotation.Required; |
|
18 |
|
|
19 |
/** |
|
20 |
* The Class ModularObjectStoreFeeder, responsible to feed data into the object Store |
|
21 |
*/ |
|
22 |
public class ModularObjectStoreFeeder { |
|
23 |
|
|
24 |
private static final Log log = LogFactory.getLog(ModularObjectStoreFeeder.class); |
|
25 |
|
|
26 |
/** The dao of the objectStore. */ |
|
27 |
private ObjectStoreDao dao; |
|
28 |
|
|
29 |
/** The result set client factory. */ |
|
30 |
private ResultSetClientFactory resultSetClientFactory; |
|
31 |
|
|
32 |
/** The service locator. */ |
|
33 |
private UniqueServiceLocator serviceLocator; |
|
34 |
|
|
35 |
/** |
|
36 |
* Gets the dao. |
|
37 |
* |
|
38 |
* @return the dao |
|
39 |
*/ |
|
40 |
public ObjectStoreDao getDao() { |
|
41 |
return dao; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Sets the dao. |
|
46 |
* |
|
47 |
* @param dao |
|
48 |
* the new dao |
|
49 |
*/ |
|
50 |
@Required |
|
51 |
public void setDao(final ObjectStoreDao dao) { |
|
52 |
this.dao = dao; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Gets the result set client factory. |
|
57 |
* |
|
58 |
* @return the result set client factory |
|
59 |
*/ |
|
60 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
61 |
return resultSetClientFactory; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Sets the result set client factory. |
|
66 |
* |
|
67 |
* @param resultSetClientFactory |
|
68 |
* the new result set client factory |
|
69 |
*/ |
|
70 |
|
|
71 |
@Required |
|
72 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
73 |
this.resultSetClientFactory = resultSetClientFactory; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Feed metadata object record. |
|
78 |
* |
|
79 |
* @param objectStoreID |
|
80 |
* the object store id |
|
81 |
* @param rsEpr |
|
82 |
* the rs epr |
|
83 |
* @param mime |
|
84 |
* the mime |
|
85 |
* @throws ObjectStoreServiceException |
|
86 |
*/ |
|
87 |
public int feedMetadataObjectRecord(final String objectStoreID, final String rsEpr, final String mime) throws ObjectStoreServiceException { |
|
88 |
|
|
89 |
final Iterable<String> records = resultSetClientFactory.getClient(rsEpr); |
|
90 |
Iterable<MetadataObjectRecord> toIngest = Iterables.transform(records, input -> { |
|
91 |
MetadataObjectRecord record = MetadataObjectRecord.initFromJson(input); |
|
92 |
if (record != null) { |
|
93 |
record.setMime(mime); |
|
94 |
} else { |
|
95 |
log.error("An input record is null :" + input); |
|
96 |
} |
|
97 |
return record; |
|
98 |
}); |
|
99 |
ObjectStore store = dao.getObjectStore(objectStoreID); |
|
100 |
int size = store.feedMetadataRecord(toIngest, true); |
|
101 |
touch(objectStoreID, size); |
|
102 |
return size; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Feed object in the object store starting from an EPR of objectMetadata |
|
107 |
* |
|
108 |
* @param obsId |
|
109 |
* the objectStore id |
|
110 |
* @param rsEpr |
|
111 |
* the result set Endpoint-reference |
|
112 |
* @param protocol |
|
113 |
* the protocol |
|
114 |
* @param login |
|
115 |
* the login |
|
116 |
* @param password |
|
117 |
* the password |
|
118 |
* @param mime |
|
119 |
* the mime type |
|
120 |
* @throws ObjectStoreServiceException |
|
121 |
*/ |
|
122 |
public void feed(final String obsId, final String rsEpr, final Protocols protocol, final String login, final String password, final String mime) |
|
123 |
throws ObjectStoreServiceException { |
|
124 |
final Iterable<String> records = resultSetClientFactory.getClient(rsEpr); |
|
125 |
ObjectBroker objectBroker = new ObjectBroker(protocol, login, password, mime); |
|
126 |
Iterable<ObjectStoreRecord> toIngest = Iterables.transform(records, objectBroker); |
|
127 |
ObjectStore store = dao.getObjectStore(obsId); |
|
128 |
int size = store.feed(toIngest, true); |
|
129 |
touch(obsId, size); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Feed a single object in the object Stroe. |
|
134 |
* |
|
135 |
* @param objectStoreID |
|
136 |
* the object store id |
|
137 |
* @param objectID |
|
138 |
* the object id |
|
139 |
* @param URIObject |
|
140 |
* the URI of object |
|
141 |
* @param protocol |
|
142 |
* the protocol |
|
143 |
* @param login |
|
144 |
* the login |
|
145 |
* @param password |
|
146 |
* the password |
|
147 |
* @param mime |
|
148 |
* the mime type |
|
149 |
* @throws ObjectStoreServiceException |
|
150 |
*/ |
|
151 |
public void feedObject(final String objectStoreID, |
|
152 |
final String objectID, |
|
153 |
final String URIObject, |
|
154 |
final Protocols protocol, |
|
155 |
final String login, |
|
156 |
final String password, |
|
157 |
final String mime) throws ObjectStoreServiceException { |
|
158 |
ObjectStoreFile inputFile = new ObjectStoreFile(); |
|
159 |
inputFile.setURI(URIObject); |
|
160 |
inputFile.setObjectID(objectID); |
|
161 |
ObjectBroker objectBroker = new ObjectBroker(protocol, login, password, mime); |
|
162 |
Iterable<ObjectStoreRecord> toIngest = Iterables.transform(Lists.newArrayList(inputFile.toJSON()), objectBroker); |
|
163 |
ObjectStore store = dao.getObjectStore(objectStoreID); |
|
164 |
int size = store.feed(toIngest, true); |
|
165 |
touch(objectStoreID, size); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Feed object record. |
|
170 |
* |
|
171 |
* @param objectStoreID |
|
172 |
* the object store id |
|
173 |
* @param record |
|
174 |
* the record |
|
175 |
* @return the string |
|
176 |
* @throws ObjectStoreServiceException |
|
177 |
*/ |
|
178 |
public String feedObjectRecord(final String objectStoreID, final ObjectStoreRecord record) throws ObjectStoreServiceException { |
|
179 |
ObjectStore store = dao.getObjectStore(objectStoreID); |
|
180 |
return store.feedObjectRecord(record); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Sets the last modified date in the profile. |
|
185 |
* |
|
186 |
* @param obsId |
|
187 |
* the obs id |
|
188 |
* @param size |
|
189 |
* the size |
|
190 |
*/ |
|
191 |
public void touch(final String obsId, final int size) { |
|
192 |
try { |
|
193 |
final String now = DateUtils.now_ISO8601(); |
|
194 |
|
|
195 |
final String mdstoreXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + obsId + "']" |
|
196 |
+ "return update value $x//LAST_STORAGE_DATE with '" + now + "'"; |
|
197 |
|
|
198 |
serviceLocator.getService(ISRegistryService.class, true).executeXUpdate(mdstoreXUpdate); |
|
199 |
|
|
200 |
touchSize(obsId, size); |
|
201 |
} catch (final Exception e) { |
|
202 |
throw new IllegalStateException(e); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Touch size. |
|
208 |
* |
|
209 |
* @param obsId |
|
210 |
* the obs id |
|
211 |
* @param size |
|
212 |
* the size |
|
213 |
*/ |
|
214 |
public void touchSize(final String obsId, final int size) { |
|
215 |
try { |
|
216 |
final String mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + obsId + "']" |
|
217 |
+ "return update value $x//COUNT_STORE with '" + size + "'"; |
|
218 |
|
|
219 |
serviceLocator.getService(ISRegistryService.class, true).executeXUpdate(mdstoreNumberXUpdate); |
|
220 |
} catch (final Exception e) { |
|
221 |
throw new IllegalStateException(e); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
public UniqueServiceLocator getServiceLocator() { |
|
226 |
return serviceLocator; |
|
227 |
} |
|
228 |
|
|
229 |
@Required |
|
230 |
public void setServiceLocator(final UniqueServiceLocator serviceLocator) { |
|
231 |
this.serviceLocator = serviceLocator; |
|
232 |
} |
|
233 |
|
|
234 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ModularObjectStoreDeliver.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
5 |
|
|
6 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
|
7 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile; |
|
8 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
9 |
import eu.dnetlib.enabling.resultset.ResultSetFactory; |
|
10 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
11 |
import org.springframework.beans.factory.annotation.Required; |
|
12 |
|
|
13 |
/** |
|
14 |
* The Class ModularObjectStoreDeliver is responsible of delivering data from the object Store. |
|
15 |
*/ |
|
16 |
public class ModularObjectStoreDeliver { |
|
17 |
|
|
18 |
/** The dao. */ |
|
19 |
private ObjectStoreDao dao; |
|
20 |
|
|
21 |
/** The result set factory. */ |
|
22 |
@Resource |
|
23 |
private ResultSetFactory resultSetFactory; |
|
24 |
|
|
25 |
/** The result set client factory. */ |
|
26 |
private ResultSetClientFactory resultSetClientFactory; |
|
27 |
|
|
28 |
/** |
|
29 |
* Gets the dao. |
|
30 |
* |
|
31 |
* @return the dao |
|
32 |
*/ |
|
33 |
public ObjectStoreDao getDao() { |
|
34 |
return dao; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Sets the dao. |
|
39 |
* |
|
40 |
* @param dao |
|
41 |
* the new dao |
|
42 |
*/ |
|
43 |
@Required |
|
44 |
public void setDao(final ObjectStoreDao dao) { |
|
45 |
this.dao = dao; |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Deliver. |
|
50 |
* |
|
51 |
* @param objectStoreID |
|
52 |
* the object store id |
|
53 |
* @param from |
|
54 |
* the from |
|
55 |
* @param until |
|
56 |
* the until |
|
57 |
* @return the w3 c endpoint reference |
|
58 |
* @throws ObjectStoreServiceException |
|
59 |
*/ |
|
60 |
public W3CEndpointReference deliver(final String objectStoreID, final Long from, final Long until) throws ObjectStoreServiceException { |
|
61 |
return resultSetFactory.createResultSet(dao.getObjectStore(objectStoreID).deliver(from, until)); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Deliver ids. |
|
66 |
* |
|
67 |
* @param objectStoreID |
|
68 |
* the object store id |
|
69 |
* @param eprId |
|
70 |
* the epr id |
|
71 |
* @return the w3 c endpoint reference |
|
72 |
* @throws ObjectStoreServiceException |
|
73 |
*/ |
|
74 |
public W3CEndpointReference deliverIds(final String objectStoreID, final W3CEndpointReference eprId) throws ObjectStoreServiceException { |
|
75 |
|
|
76 |
Iterable<String> ids = resultSetClientFactory.getClient(eprId); |
|
77 |
return resultSetFactory.createResultSet(dao.getObjectStore(objectStoreID).deliverIds(ids)); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Exist id starts with. |
|
82 |
* |
|
83 |
* @param obsId |
|
84 |
* the obs id |
|
85 |
* @param startId |
|
86 |
* the start id |
|
87 |
* @return true, if successful |
|
88 |
* @throws ObjectStoreServiceException |
|
89 |
*/ |
|
90 |
public boolean existIDStartsWith(final String obsId, final String startId) throws ObjectStoreServiceException { |
|
91 |
return dao.getObjectStore(obsId).existIDStartsWith(startId); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Deliver object. |
|
96 |
* |
|
97 |
* @param objectStoreID |
|
98 |
* the object store id |
|
99 |
* @param objectId |
|
100 |
* the object id |
|
101 |
* @return the object store file |
|
102 |
* @throws ObjectStoreServiceException |
|
103 |
*/ |
|
104 |
public ObjectStoreFile deliverObject(final String objectStoreID, final String objectId) throws ObjectStoreServiceException { |
|
105 |
return dao.getObjectStore(objectStoreID).deliverObject(objectId); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Gets the result set client factory. |
|
110 |
* |
|
111 |
* @return the result set client factory |
|
112 |
*/ |
|
113 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
114 |
return resultSetClientFactory; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Sets the result set client factory. |
|
119 |
* |
|
120 |
* @param resultSetClientFactory |
|
121 |
* the new result set client factory |
|
122 |
*/ |
|
123 |
@Required |
|
124 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
125 |
this.resultSetClientFactory = resultSetClientFactory; |
|
126 |
} |
|
127 |
|
|
128 |
} |
modules/dnet-modular-objectstore-service/tags/dnet-modular-objectstore-service-5.0.0/src/main/java/eu/dnetlib/data/objectstore/modular/ObjectStoreProfileCreator.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.modular; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
4 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
5 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
6 |
import eu.dnetlib.soap.EndpointReferenceBuilder; |
|
7 |
import org.antlr.stringtemplate.StringTemplate; |
|
8 |
import org.springframework.beans.factory.annotation.Required; |
|
9 |
|
|
10 |
import javax.xml.ws.Endpoint; |
|
11 |
|
|
12 |
// TODO: Auto-generated Javadoc |
|
13 |
|
|
14 |
/** |
|
15 |
* The Class ObjectStoreProfileCreator is responsible of creating profile of the ObjectStore |
|
16 |
*/ |
|
17 |
public class ObjectStoreProfileCreator { |
|
18 |
|
|
19 |
/** |
|
20 |
* service locator. |
|
21 |
*/ |
|
22 |
private UniqueServiceLocator serviceLocator; |
|
23 |
|
|
24 |
/** |
|
25 |
* objectstore ds template. |
|
26 |
*/ |
|
27 |
private StringTemplate objectstoreDsTemplate; |
|
28 |
|
|
29 |
/** |
|
30 |
* service endpoint. |
|
31 |
*/ |
|
32 |
private Endpoint endpoint; |
|
33 |
|
|
34 |
/** |
|
35 |
* endpoint builder. |
|
36 |
*/ |
|
37 |
private EndpointReferenceBuilder<Endpoint> eprBuilder; |
|
38 |
|
|
39 |
/** |
|
40 |
* Register profile. |
|
41 |
* |
|
42 |
* @param interpretation the interpretation |
|
43 |
* @return the string |
|
44 |
* @throws ISRegistryException the IS registry exception |
|
45 |
*/ |
|
46 |
public String registerProfile(final String interpretation) |
|
47 |
throws ISRegistryException { |
|
48 |
// XXX: mini hack |
|
49 |
StringTemplate template = new StringTemplate( |
|
50 |
objectstoreDsTemplate.getTemplate()); |
|
51 |
template.setAttribute("serviceUri", eprBuilder.getAddress(endpoint)); |
|
52 |
template.setAttribute("interpretation", interpretation); |
|
53 |
|
|
54 |
return serviceLocator.getService(ISRegistryService.class, true).registerProfile(template.toString()); |
|
55 |
} |
|
56 |
|
|
57 |
public void deleteProfile(final String profileId) throws ISRegistryException { |
|
58 |
serviceLocator.getService(ISRegistryService.class).deleteProfile(profileId); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Gets the endpoint. |
|
63 |
* |
|
64 |
* @return the endpoint |
|
65 |
*/ |
|
66 |
public Endpoint getEndpoint() { |
|
67 |
return endpoint; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Sets the endpoint. |
|
72 |
* |
|
73 |
* @param endpoint the new endpoint |
|
74 |
*/ |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-modular-objectstore-service-5.0.0