Revision 32708
Added by Michele Artini over 9 years ago
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/BlackboardJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import org.apache.commons.lang.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
import com.googlecode.sarasvati.Engine; |
|
10 |
import com.googlecode.sarasvati.NodeToken; |
|
11 |
|
|
12 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
13 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
14 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardClientHandler; |
|
15 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
16 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJobImpl; |
|
17 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJobRegistry; |
|
18 |
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener; |
|
19 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
20 |
|
|
21 |
public abstract class BlackboardJobNode extends SarasvatiJobNode { |
|
22 |
|
|
23 |
@Resource |
|
24 |
private UniqueServiceLocator serviceLocator; |
|
25 |
|
|
26 |
/** |
|
27 |
* logger. |
|
28 |
*/ |
|
29 |
private static final Log log = LogFactory.getLog(BlackboardJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
30 |
|
|
31 |
/** |
|
32 |
* blackboard handler. |
|
33 |
*/ |
|
34 |
@Resource |
|
35 |
private BlackboardClientHandler blackboardClientHandler; |
|
36 |
|
|
37 |
/** |
|
38 |
* blackboard job registry. |
|
39 |
*/ |
|
40 |
@Resource |
|
41 |
private BlackboardJobRegistry jobRegistry; |
|
42 |
|
|
43 |
@Override |
|
44 |
public void execute(final Engine engine, final NodeToken token) { |
|
45 |
super.execute(engine, token); |
|
46 |
|
|
47 |
log.info("executing blackboard node"); |
|
48 |
|
|
49 |
try { |
|
50 |
token.getEnv().setAttribute(WorkflowsConstants.BLACKBOARD_IS_BLACKBOARD, true); |
|
51 |
final String query = getXqueryForServiceId(token); |
|
52 |
final String serviceId = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query); |
|
53 |
if (StringUtils.isBlank(serviceId)) { |
|
54 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED, true); |
|
55 |
final String msg = "cannot locate target service profile, using query: " + query; |
|
56 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR, msg); |
|
57 |
log.error(msg); |
|
58 |
engine.complete(token, "failed"); |
|
59 |
return; |
|
60 |
} |
|
61 |
|
|
62 |
final BlackboardJob job = blackboardClientHandler.newJob(serviceId); |
|
63 |
|
|
64 |
token.getEnv().setTransientAttribute(WorkflowsConstants.BLACKBOARD_JOB, job); |
|
65 |
token.getEnv().setAttribute(WorkflowsConstants.BLACKBOARD_SERVICE_ID, ((BlackboardJobImpl) job).getServiceId()); |
|
66 |
prepareJob(job, token); |
|
67 |
|
|
68 |
jobRegistry.registerJobListener(job, generateBlackboardListener(engine, token)); |
|
69 |
|
|
70 |
blackboardClientHandler.assign(job); |
|
71 |
|
|
72 |
} catch (final Throwable e) { |
|
73 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED, true); |
|
74 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR, "cannot prepare blackboard job: " + e); |
|
75 |
engine.complete(token, "failed"); |
|
76 |
log.error("cannot prepare blackboard job", e); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
abstract protected String getXqueryForServiceId(NodeToken token); |
|
81 |
|
|
82 |
abstract protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception; |
|
83 |
|
|
84 |
protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) { |
|
85 |
return new BlackboardWorkflowJobListener(engine, token); |
|
86 |
} |
|
87 |
|
|
88 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/repobye/DeleteObjectStoreJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repobye; |
|
2 |
|
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.NodeToken; |
|
7 |
|
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
9 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
10 |
|
|
11 |
public class DeleteObjectStoreJobNode extends BlackboardJobNode { |
|
12 |
|
|
13 |
private static final Log log = LogFactory.getLog(DeleteObjectStoreJobNode.class); |
|
14 |
|
|
15 |
private String objectstoreId; |
|
16 |
|
|
17 |
@Override |
|
18 |
protected String getXqueryForServiceId(final NodeToken token) { |
|
19 |
return "//RESOURCE_IDENTIFIER[../RESOURCE_TYPE/@value='ObjectStoreServiceResourceType']/@value/string()"; |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
24 |
log.info("preparing blackboard job: delete of mdstore " + getObjectstoreId()); |
|
25 |
job.setAction("DELETE"); |
|
26 |
job.getParameters().put("obsID", getObjectstoreId()); |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* @return the objectstoreId |
|
31 |
*/ |
|
32 |
public String getObjectstoreId() { |
|
33 |
return objectstoreId; |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* @param objectstoreId |
|
38 |
* the objectstoreId to set |
|
39 |
*/ |
|
40 |
public void setObjectstoreId(final String objectstoreId) { |
|
41 |
this.objectstoreId = objectstoreId; |
|
42 |
} |
|
43 |
|
|
44 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/SuccessFailureNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import org.antlr.stringtemplate.StringTemplate; |
|
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.apache.commons.lang.StringEscapeUtils; |
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
import org.springframework.beans.factory.annotation.Required; |
|
14 |
|
|
15 |
import com.google.common.collect.Maps; |
|
16 |
import com.googlecode.sarasvati.Arc; |
|
17 |
import com.googlecode.sarasvati.NodeToken; |
|
18 |
|
|
19 |
import eu.dnetlib.common.logging.DnetLogger; |
|
20 |
import eu.dnetlib.common.logging.LogMessage; |
|
21 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
22 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
23 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
24 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
25 |
|
|
26 |
/** |
|
27 |
* The success node sets the "isCompletedSuccessfully" env var. |
|
28 |
* |
|
29 |
*/ |
|
30 |
public class SuccessFailureNode extends SimpleJobNode { |
|
31 |
|
|
32 |
/** |
|
33 |
* is completed successfully. |
|
34 |
*/ |
|
35 |
private boolean success; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private UniqueServiceLocator serviceLocator; |
|
39 |
|
|
40 |
@Resource(name = "msroWorkflowLogger") |
|
41 |
private DnetLogger dnetLogger; |
|
42 |
|
|
43 |
private static final Log log = LogFactory.getLog(SuccessFailureNode.class); |
|
44 |
|
|
45 |
@Override |
|
46 |
protected String execute(final NodeToken token) { |
|
47 |
final String profileId = token.getFullEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_ID).trim(); |
|
48 |
|
|
49 |
final long now = DateUtils.now(); |
|
50 |
final String date = DateUtils.calculate_ISO8601(now); |
|
51 |
|
|
52 |
token.getProcess().getEnv().setAttribute(WorkflowsConstants.SYSTEM_END_DATE, now); |
|
53 |
token.getProcess().getEnv().setAttribute(WorkflowsConstants.SYSTEM_END_HUMAN_DATE, date); |
|
54 |
|
|
55 |
final Map<String, String> params = mergeEnvAttributes(token); |
|
56 |
final LogMessage logMessage = dnetLogger.newLogMessage().addDetails(params); |
|
57 |
|
|
58 |
try { |
|
59 |
final String template = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/msro/workflows/templates/workflow_status.xml.st")); |
|
60 |
final StringTemplate st = new StringTemplate(template); |
|
61 |
st.setAttribute("procId", StringEscapeUtils.escapeXml(params.get(WorkflowsConstants.SYSTEM_WF_PROCESS_ID))); |
|
62 |
st.setAttribute("date", StringEscapeUtils.escapeXml(date)); |
|
63 |
st.setAttribute("params", filterOutputParams(params)); |
|
64 |
if (!isSuccess()) { |
|
65 |
st.setAttribute("error", StringEscapeUtils.escapeXml(params.get(WorkflowsConstants.SYSTEM_ERROR))); |
|
66 |
} |
|
67 |
|
|
68 |
serviceLocator.getService(ISRegistryService.class).updateProfileNode(profileId, "//STATUS", st.toString()); |
|
69 |
|
|
70 |
token.getProcess().getEnv().setAttribute(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY, isSuccess()); |
|
71 |
|
|
72 |
logMessage.addDetail(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY, Boolean.toString(isSuccess())); |
|
73 |
} catch (Exception e) { |
|
74 |
log.error("Error updating workflow profile: " + profileId, e); |
|
75 |
token.getProcess().getEnv().setAttribute(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY, false); |
|
76 |
logMessage.addDetail(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY, Boolean.toString(false)); |
|
77 |
} |
|
78 |
|
|
79 |
logMessage.flush(); |
|
80 |
|
|
81 |
return Arc.DEFAULT_ARC; |
|
82 |
} |
|
83 |
|
|
84 |
private Map<String, String> filterOutputParams(final Map<String, String> map) { |
|
85 |
final Map<String, String> res = Maps.newHashMap(); |
|
86 |
|
|
87 |
if (map != null) { |
|
88 |
for (String k : map.keySet()) { |
|
89 |
if (!StringUtils.isBlank(k) && (k.startsWith(WorkflowsConstants.DATAPROVIDER_PREFIX) || k.startsWith(WorkflowsConstants.MAIN_LOG_PREFIX))) { |
|
90 |
final String key = StringEscapeUtils.escapeXml(k); |
|
91 |
final String v = map.get(k); |
|
92 |
res.put(key, v != null ? StringEscapeUtils.escapeXml(v) : "null"); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
return res; |
|
98 |
} |
|
99 |
|
|
100 |
private Map<String, String> mergeEnvAttributes(final NodeToken token) { |
|
101 |
final Map<String, String> map = Maps.newHashMap(); |
|
102 |
|
|
103 |
for (String s : token.getEnv().getAttributeNames()) { |
|
104 |
map.put(s, token.getEnv().getAttribute(s)); |
|
105 |
} |
|
106 |
for (String s : token.getFullEnv().getAttributeNames()) { |
|
107 |
map.put(s, token.getFullEnv().getAttribute(s)); |
|
108 |
} |
|
109 |
return map; |
|
110 |
} |
|
111 |
|
|
112 |
public boolean isSuccess() { |
|
113 |
return success; |
|
114 |
} |
|
115 |
|
|
116 |
@Required |
|
117 |
public void setSuccess(final boolean success) { |
|
118 |
this.success = success; |
|
119 |
} |
|
120 |
|
|
121 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/transform/GroovyJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.transform; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.beans.factory.annotation.Required; |
|
12 |
|
|
13 |
import com.google.common.collect.Maps; |
|
14 |
import com.googlecode.sarasvati.Arc; |
|
15 |
import com.googlecode.sarasvati.NodeToken; |
|
16 |
|
|
17 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
18 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
19 |
import eu.dnetlib.enabling.resultset.MappedResultSetFactory; |
|
20 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
21 |
import eu.dnetlib.msro.rmi.MSROException; |
|
22 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
23 |
import groovy.lang.GroovyShell; |
|
24 |
import groovy.util.GroovyScriptEngine; |
|
25 |
|
|
26 |
public class GroovyJobNode extends SimpleJobNode { |
|
27 |
|
|
28 |
private static final Log log = LogFactory.getLog(GroovyJobNode.class); |
|
29 |
|
|
30 |
/** |
|
31 |
* used to transform the records using Groovy. |
|
32 |
*/ |
|
33 |
|
|
34 |
private MappedResultSetFactory mappedResultSetFactory; |
|
35 |
|
|
36 |
private String inputEprParam; |
|
37 |
private String outputEprParam; |
|
38 |
private String transformationRuleId; |
|
39 |
// private String groovyParams; |
|
40 |
|
|
41 |
@Resource |
|
42 |
private UniqueServiceLocator serviceLocator; |
|
43 |
|
|
44 |
private Map<String, String> retrieveGroovyParameter() { |
|
45 |
Map<String, String> out = Maps.newHashMap(); |
|
46 |
|
|
47 |
String query = "for $x in collection('/db/DRIVER/GroovyProcessingDSResource/GroovyProcessingDSResourceType')" |
|
48 |
+ "where $x[.//RESOURCE_IDENTIFIER/@value='" + transformationRuleId + "']" |
|
49 |
+ "return concat($x//GROOVY_CLASSPATH/text(),':::',$x//GROOVY_DNETCLASS/text())"; |
|
50 |
try { |
|
51 |
String result = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query).get(0); |
|
52 |
if (result == null) { return null; } |
|
53 |
String[] data = result.trim().split(":::"); |
|
54 |
if (data.length == 2) { |
|
55 |
out.put("classpath", data[0]); |
|
56 |
out.put("mainClass", data[1]); |
|
57 |
} |
|
58 |
|
|
59 |
return out; |
|
60 |
} catch (Exception e) { |
|
61 |
log.error(e); |
|
62 |
return null; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
protected String execute(final NodeToken token) throws Exception { |
|
68 |
final String inputEprString = token.getEnv().getAttribute(inputEprParam); |
|
69 |
if (inputEprString == null || inputEprString.isEmpty()) { throw new MSROException("InputEprParam (" + inputEprParam + ") not found in ENV"); } |
|
70 |
final W3CEndpointReference inputEpr = new EPRUtils().getEpr(inputEprString); |
|
71 |
String groovyClasspath, groovyDnetClass; |
|
72 |
Map<String, String> prop = retrieveGroovyParameter(); |
|
73 |
groovyClasspath = prop.get("classpath"); |
|
74 |
groovyDnetClass = prop.get("mainClass"); |
|
75 |
W3CEndpointReference epr = transformGroovy(inputEpr, groovyClasspath, groovyDnetClass, parseJsonParameters(token)); |
|
76 |
token.getEnv().setAttribute(outputEprParam, epr.toString()); |
|
77 |
return Arc.DEFAULT_ARC; |
|
78 |
} |
|
79 |
|
|
80 |
private W3CEndpointReference transformGroovy(final W3CEndpointReference source, |
|
81 |
final String groovyClasspath, |
|
82 |
final String groovyDnetClass, |
|
83 |
final Map<String, String> params) throws ClassNotFoundException, IOException { |
|
84 |
|
|
85 |
GroovyScriptEngine gse = new GroovyScriptEngine(groovyClasspath); |
|
86 |
gse.getGroovyClassLoader().loadClass(groovyDnetClass); |
|
87 |
log.info("***********************************************"); |
|
88 |
log.info("Loaded Groovy classes:"); |
|
89 |
for (Class<?> c : gse.getGroovyClassLoader().getLoadedClasses()) { |
|
90 |
log.info(c.getCanonicalName()); |
|
91 |
} |
|
92 |
log.info("***********************************************"); |
|
93 |
GroovyShell groovyShell = new GroovyShell(gse.getGroovyClassLoader()); |
|
94 |
|
|
95 |
Object go = groovyShell.evaluate("new " + groovyDnetClass + "()"); |
|
96 |
if (go instanceof GroovyUnaryFunction) { |
|
97 |
GroovyUnaryFunction groovyUnaryFunction = (GroovyUnaryFunction) go; |
|
98 |
if (params != null) { |
|
99 |
groovyUnaryFunction.setParams(params); |
|
100 |
} |
|
101 |
return mappedResultSetFactory.createMappedResultSet(source, groovyUnaryFunction); |
|
102 |
} else { |
|
103 |
throw new RuntimeException("Groovy object " + go + " is not supported"); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
public MappedResultSetFactory getMappedResultSetFactory() { |
|
108 |
return mappedResultSetFactory; |
|
109 |
} |
|
110 |
|
|
111 |
@Required |
|
112 |
public void setMappedResultSetFactory(final MappedResultSetFactory mappedResultSetFactory) { |
|
113 |
this.mappedResultSetFactory = mappedResultSetFactory; |
|
114 |
} |
|
115 |
|
|
116 |
public String getInputEprParam() { |
|
117 |
return inputEprParam; |
|
118 |
} |
|
119 |
|
|
120 |
public void setInputEprParam(final String inputEprParam) { |
|
121 |
this.inputEprParam = inputEprParam; |
|
122 |
} |
|
123 |
|
|
124 |
public String getOutputEprParam() { |
|
125 |
return outputEprParam; |
|
126 |
} |
|
127 |
|
|
128 |
public void setOutputEprParam(final String outputEprParam) { |
|
129 |
this.outputEprParam = outputEprParam; |
|
130 |
} |
|
131 |
|
|
132 |
public String getTransformationRuleId() { |
|
133 |
return transformationRuleId; |
|
134 |
} |
|
135 |
|
|
136 |
public void setTransformationRuleId(final String transformationRuleId) { |
|
137 |
this.transformationRuleId = transformationRuleId; |
|
138 |
} |
|
139 |
|
|
140 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/index/DeleteIndexJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.index; |
|
2 |
|
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.NodeToken; |
|
7 |
|
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
9 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
10 |
|
|
11 |
public class DeleteIndexJobNode extends BlackboardJobNode { |
|
12 |
|
|
13 |
private static final Log log = LogFactory.getLog(DeleteIndexJobNode.class); |
|
14 |
|
|
15 |
private String indexId; |
|
16 |
private String defaultIndexId; |
|
17 |
|
|
18 |
@Override |
|
19 |
protected String getXqueryForServiceId(final NodeToken token) { |
|
20 |
return "collection('/db/DRIVER/ServiceResources/IndexServiceResourceType')//RESOURCE_IDENTIFIER/@value/string()"; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
25 |
log.info("deleting index id = " + getIndexId()); |
|
26 |
|
|
27 |
job.setAction("DELETE"); |
|
28 |
job.getParameters().put("id", getIndexId()); |
|
29 |
job.getParameters().put("backend_Id", defaultIndexId); |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
public String getIndexId() { |
|
34 |
return indexId; |
|
35 |
} |
|
36 |
|
|
37 |
public void setIndexId(final String indexId) { |
|
38 |
this.indexId = indexId; |
|
39 |
} |
|
40 |
|
|
41 |
public String getDefaultIndexId() { |
|
42 |
return defaultIndexId; |
|
43 |
} |
|
44 |
|
|
45 |
public void setDefaultIndexId(final String defaultIndexId) { |
|
46 |
this.defaultIndexId = defaultIndexId; |
|
47 |
} |
|
48 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/transform/CleanJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.transform; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.Arc; |
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
|
|
9 |
import eu.dnetlib.data.utility.cleaner.rmi.CleanerService; |
|
10 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
11 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
12 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
13 |
|
|
14 |
public class CleanJobNode extends SimpleJobNode { |
|
15 |
|
|
16 |
private String inputEprParam; |
|
17 |
private String outputEprParam; |
|
18 |
private String ruleId; |
|
19 |
|
|
20 |
@Resource |
|
21 |
private UniqueServiceLocator serviceLocator; |
|
22 |
|
|
23 |
@Override |
|
24 |
protected String execute(final NodeToken token) throws Exception { |
|
25 |
|
|
26 |
final W3CEndpointReference inputEpr = new EPRUtils().getEpr(token.getEnv().getAttribute(inputEprParam)); |
|
27 |
final W3CEndpointReference outputEpr = ruleId == null || ruleId.isEmpty() ? inputEpr : serviceLocator.getService(CleanerService.class).clean(inputEpr, |
|
28 |
ruleId); |
|
29 |
|
|
30 |
token.getEnv().setAttribute(outputEprParam, outputEpr.toString()); |
|
31 |
|
|
32 |
return Arc.DEFAULT_ARC; |
|
33 |
} |
|
34 |
|
|
35 |
public String getInputEprParam() { |
|
36 |
return inputEprParam; |
|
37 |
} |
|
38 |
|
|
39 |
public void setInputEprParam(final String inputEprParam) { |
|
40 |
this.inputEprParam = inputEprParam; |
|
41 |
} |
|
42 |
|
|
43 |
public String getOutputEprParam() { |
|
44 |
return outputEprParam; |
|
45 |
} |
|
46 |
|
|
47 |
public void setOutputEprParam(final String outputEprParam) { |
|
48 |
this.outputEprParam = outputEprParam; |
|
49 |
} |
|
50 |
|
|
51 |
public String getRuleId() { |
|
52 |
return ruleId; |
|
53 |
} |
|
54 |
|
|
55 |
public void setRuleId(final String ruleId) { |
|
56 |
this.ruleId = ruleId; |
|
57 |
} |
|
58 |
|
|
59 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/transform/ApplyXsltJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.transform; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
7 |
|
|
8 |
import org.springframework.beans.factory.annotation.Required; |
|
9 |
import org.springframework.core.io.ClassPathResource; |
|
10 |
|
|
11 |
import com.googlecode.sarasvati.Arc; |
|
12 |
import com.googlecode.sarasvati.NodeToken; |
|
13 |
|
|
14 |
import eu.dnetlib.enabling.resultset.XSLTMappedResultSetFactory; |
|
15 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
16 |
import eu.dnetlib.msro.rmi.MSROException; |
|
17 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
18 |
|
|
19 |
public class ApplyXsltJobNode extends SimpleJobNode { |
|
20 |
|
|
21 |
private String inputEprParam; |
|
22 |
private String outputEprParam; |
|
23 |
private String xsltClasspath; |
|
24 |
|
|
25 |
private XSLTMappedResultSetFactory xsltMappedResultSetFactory; |
|
26 |
|
|
27 |
@Override |
|
28 |
protected String execute(final NodeToken token) throws Exception { |
|
29 |
final String inputEpr = token.getEnv().getAttribute(inputEprParam); |
|
30 |
if ((inputEpr == null) || inputEpr.isEmpty()) throw new MSROException("InputEprParam (" + inputEprParam + ") not found in ENV"); |
|
31 |
|
|
32 |
final Map<String, String> xsltParams = new HashMap<String, String>(); |
|
33 |
|
|
34 |
for (String name : token.getFullEnv().getAttributeNames()) { |
|
35 |
xsltParams.put(name.replaceAll(":", "_"), token.getFullEnv().getAttribute(name)); |
|
36 |
} |
|
37 |
for (String name : token.getEnv().getAttributeNames()) { |
|
38 |
xsltParams.put(name.replaceAll(":", "_"), token.getEnv().getAttribute(name)); |
|
39 |
} |
|
40 |
|
|
41 |
xsltParams.putAll(parseJsonParameters(token)); |
|
42 |
|
|
43 |
final W3CEndpointReference epr = xsltMappedResultSetFactory.createMappedResultSet(new EPRUtils().getEpr(inputEpr), |
|
44 |
(new ClassPathResource(xsltClasspath)), xsltParams); |
|
45 |
|
|
46 |
token.getEnv().setAttribute(outputEprParam, epr.toString()); |
|
47 |
|
|
48 |
return Arc.DEFAULT_ARC; |
|
49 |
} |
|
50 |
|
|
51 |
public String getInputEprParam() { |
|
52 |
return inputEprParam; |
|
53 |
} |
|
54 |
|
|
55 |
public void setInputEprParam(final String inputEprParam) { |
|
56 |
this.inputEprParam = inputEprParam; |
|
57 |
} |
|
58 |
|
|
59 |
public String getOutputEprParam() { |
|
60 |
return outputEprParam; |
|
61 |
} |
|
62 |
|
|
63 |
public void setOutputEprParam(final String outputEprParam) { |
|
64 |
this.outputEprParam = outputEprParam; |
|
65 |
} |
|
66 |
|
|
67 |
public String getXsltClasspath() { |
|
68 |
return xsltClasspath; |
|
69 |
} |
|
70 |
|
|
71 |
public void setXsltClasspath(final String xsltClasspath) { |
|
72 |
this.xsltClasspath = xsltClasspath; |
|
73 |
} |
|
74 |
|
|
75 |
public XSLTMappedResultSetFactory getXsltMappedResultSetFactory() { |
|
76 |
return xsltMappedResultSetFactory; |
|
77 |
} |
|
78 |
|
|
79 |
@Required |
|
80 |
public void setXsltMappedResultSetFactory(final XSLTMappedResultSetFactory xsltMappedResultSetFactory) { |
|
81 |
this.xsltMappedResultSetFactory = xsltMappedResultSetFactory; |
|
82 |
} |
|
83 |
|
|
84 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/transform/TransformJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.transform; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.Arc; |
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
|
|
9 |
import eu.dnetlib.data.transformation.service.rmi.TransformationService; |
|
10 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
11 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
12 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
13 |
|
|
14 |
public class TransformJobNode extends SimpleJobNode { |
|
15 |
|
|
16 |
private String inputEprParam; |
|
17 |
private String outputEprParam; |
|
18 |
private String ruleId; |
|
19 |
|
|
20 |
@Resource |
|
21 |
private UniqueServiceLocator serviceLocator; |
|
22 |
|
|
23 |
@Override |
|
24 |
protected String execute(final NodeToken token) throws Exception { |
|
25 |
final W3CEndpointReference inputEpr = new EPRUtils().getEpr(token.getEnv().getAttribute(inputEprParam)); |
|
26 |
final W3CEndpointReference outputEpr = serviceLocator.getService(TransformationService.class).transform(ruleId, inputEpr); |
|
27 |
|
|
28 |
token.getEnv().setAttribute(outputEprParam, outputEpr.toString()); |
|
29 |
|
|
30 |
return Arc.DEFAULT_ARC; |
|
31 |
} |
|
32 |
|
|
33 |
public String getInputEprParam() { |
|
34 |
return inputEprParam; |
|
35 |
} |
|
36 |
|
|
37 |
public void setInputEprParam(final String inputEprParam) { |
|
38 |
this.inputEprParam = inputEprParam; |
|
39 |
} |
|
40 |
|
|
41 |
public String getOutputEprParam() { |
|
42 |
return outputEprParam; |
|
43 |
} |
|
44 |
|
|
45 |
public void setOutputEprParam(final String outputEprParam) { |
|
46 |
this.outputEprParam = outputEprParam; |
|
47 |
} |
|
48 |
|
|
49 |
public String getRuleId() { |
|
50 |
return ruleId; |
|
51 |
} |
|
52 |
|
|
53 |
public void setRuleId(final String ruleId) { |
|
54 |
this.ruleId = ruleId; |
|
55 |
} |
|
56 |
|
|
57 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/mdstore/MultipleMdStoreIterator.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.mdstore; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
7 |
|
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
|
|
10 |
import eu.dnetlib.data.mdstore.MDStoreService; |
|
11 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
13 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
14 |
|
|
15 |
// TODO: Auto-generated Javadoc |
|
16 |
/** |
|
17 |
* The Class MultipleMdStoreIterator. |
|
18 |
*/ |
|
19 |
public class MultipleMdStoreIterator implements Iterable<String>, Iterator<String> { |
|
20 |
|
|
21 |
/** The service locator. */ |
|
22 |
private UniqueServiceLocator serviceLocator; |
|
23 |
|
|
24 |
/** The md i ds. */ |
|
25 |
private List<String> mdIDs; |
|
26 |
|
|
27 |
/** The current id. */ |
|
28 |
private String currentId = null; |
|
29 |
|
|
30 |
/** The current iterator. */ |
|
31 |
private Iterator<String> currentIterator; |
|
32 |
|
|
33 |
/** The result set client factory. */ |
|
34 |
@Autowired |
|
35 |
private ResultSetClientFactory resultSetClientFactory; |
|
36 |
|
|
37 |
/** |
|
38 |
* Instantiates a new multiple md store iterator. |
|
39 |
* |
|
40 |
* @param mdstoreLocator |
|
41 |
* the mdstore locator |
|
42 |
* @param mdIds |
|
43 |
* the md ids |
|
44 |
*/ |
|
45 |
public MultipleMdStoreIterator(final UniqueServiceLocator serviceLocator, final List<String> mdIds, |
|
46 |
final ResultSetClientFactory resultSetClientFactory) { |
|
47 |
this.serviceLocator = serviceLocator; |
|
48 |
this.mdIDs = mdIds; |
|
49 |
this.resultSetClientFactory = resultSetClientFactory; |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
/* |
|
54 |
* (non-Javadoc) |
|
55 |
* |
|
56 |
* @see java.lang.Iterable#iterator() |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public Iterator<String> iterator() { |
|
60 |
getNextMDStoreRecords(); |
|
61 |
return this; |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
/* |
|
66 |
* (non-Javadoc) |
|
67 |
* |
|
68 |
* @see java.util.Iterator#hasNext() |
|
69 |
*/ |
|
70 |
@Override |
|
71 |
public boolean hasNext() { |
|
72 |
if (currentId == null || currentIterator == null) { return false; } |
|
73 |
if (!currentIterator.hasNext()) { |
|
74 |
getNextMDStoreRecords(); |
|
75 |
} |
|
76 |
return currentIterator.hasNext(); |
|
77 |
} |
|
78 |
|
|
79 |
/* |
|
80 |
* (non-Javadoc) |
|
81 |
* |
|
82 |
* @see java.util.Iterator#next() |
|
83 |
*/ |
|
84 |
@Override |
|
85 |
public String next() { |
|
86 |
return currentIterator.next(); |
|
87 |
} |
|
88 |
|
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* |
|
92 |
* @see java.util.Iterator#remove() |
|
93 |
*/ |
|
94 |
@Override |
|
95 |
public void remove() { |
|
96 |
currentIterator.remove(); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Gets the next md store records. |
|
101 |
* |
|
102 |
* @return the next md store records |
|
103 |
*/ |
|
104 |
private void getNextMDStoreRecords() { |
|
105 |
if (mdIDs.size() > 0) { |
|
106 |
currentId = mdIDs.remove(0); |
|
107 |
currentIterator = getIterableResultset(currentId); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Gets the iterable resultset. |
|
113 |
* |
|
114 |
* @param id |
|
115 |
* the id |
|
116 |
* @return the iterable resultset |
|
117 |
*/ |
|
118 |
private Iterator<String> getIterableResultset(final String id) { |
|
119 |
try { |
|
120 |
W3CEndpointReference epr = serviceLocator.getService(MDStoreService.class).deliverMDRecords(id, "", "", ""); |
|
121 |
Iterable<String> input = resultSetClientFactory.getClient(epr); |
|
122 |
return input.iterator(); |
|
123 |
} catch (MDStoreServiceException e) { |
|
124 |
return null; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/mdstore/StoreMDStoreRecordsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.mdstore; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
import org.springframework.beans.factory.annotation.Required; |
|
8 |
|
|
9 |
import com.googlecode.sarasvati.Engine; |
|
10 |
import com.googlecode.sarasvati.NodeToken; |
|
11 |
import com.googlecode.sarasvati.env.Env; |
|
12 |
|
|
13 |
import eu.dnetlib.enabling.resultset.rmi.ResultSetException; |
|
14 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
15 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
16 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
17 |
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener; |
|
18 |
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory; |
|
19 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
20 |
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider; |
|
21 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
22 |
|
|
23 |
public class StoreMDStoreRecordsJobNode extends BlackboardJobNode implements ProgressJobNode { |
|
24 |
|
|
25 |
private static final Log log = LogFactory.getLog(StoreMDStoreRecordsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
26 |
|
|
27 |
private String eprParam; |
|
28 |
private String mdId; |
|
29 |
private String storingType; |
|
30 |
private ProcessCountingResultSetFactory processCountingResultSetFactory; |
|
31 |
private ResultsetProgressProvider progressProvider; |
|
32 |
|
|
33 |
@Override |
|
34 |
protected String getXqueryForServiceId(final NodeToken token) { |
|
35 |
return "//RESOURCE_IDENTIFIER[../RESOURCE_TYPE/@value='MDStoreServiceResourceType']/@value/string()"; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws ResultSetException { |
|
40 |
job.setAction("FEED"); |
|
41 |
|
|
42 |
final String eprS = token.getEnv().getAttribute(getEprParam()); |
|
43 |
|
|
44 |
this.progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), eprS); |
|
45 |
|
|
46 |
job.getParameters().put("epr", progressProvider.getEpr().toString()); |
|
47 |
job.getParameters().put("storingType", getStoringType()); |
|
48 |
job.getParameters().put("mdId", getMdId()); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) { |
|
53 |
return new BlackboardWorkflowJobListener(engine, token) { |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void populateEnv(final Env env, final Map<String, String> responseParams) { |
|
57 |
log.info("Number of stored records: " + responseParams.get("total")); |
|
58 |
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "total", responseParams.get("total")); |
|
59 |
} |
|
60 |
}; |
|
61 |
} |
|
62 |
|
|
63 |
public String getEprParam() { |
|
64 |
return eprParam; |
|
65 |
} |
|
66 |
|
|
67 |
public void setEprParam(final String eprParam) { |
|
68 |
this.eprParam = eprParam; |
|
69 |
} |
|
70 |
|
|
71 |
public String getMdId() { |
|
72 |
return mdId; |
|
73 |
} |
|
74 |
|
|
75 |
public void setMdId(final String mdId) { |
|
76 |
this.mdId = mdId; |
|
77 |
} |
|
78 |
|
|
79 |
public String getStoringType() { |
|
80 |
return storingType; |
|
81 |
} |
|
82 |
|
|
83 |
public void setStoringType(final String storingType) { |
|
84 |
this.storingType = storingType; |
|
85 |
} |
|
86 |
|
|
87 |
public ProcessCountingResultSetFactory getProcessCountingResultSetFactory() { |
|
88 |
return processCountingResultSetFactory; |
|
89 |
} |
|
90 |
|
|
91 |
@Required |
|
92 |
public void setProcessCountingResultSetFactory(final ProcessCountingResultSetFactory processCountingResultSetFactory) { |
|
93 |
this.processCountingResultSetFactory = processCountingResultSetFactory; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public ProgressProvider getProgressProvider() { |
|
98 |
return progressProvider; |
|
99 |
} |
|
100 |
|
|
101 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/pom.xml | ||
---|---|---|
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"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
<relativePath /> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<groupId>eu.dnetlib</groupId> |
|
11 |
<artifactId>dnet-msro-service</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>2.0.1</version> |
|
14 |
<scm> |
|
15 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-msro-service/tags/dnet-msro-service-2.0.1</developerConnection> |
|
16 |
</scm> |
|
17 |
<dependencies> |
|
18 |
<dependency> |
|
19 |
<groupId>opensymphony</groupId> |
|
20 |
<artifactId>quartz</artifactId> |
|
21 |
<version>1.6.6</version> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>dnet-msro-service-api</artifactId> |
|
26 |
<version>[2.0.0,3.0.0)</version> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>eu.dnetlib</groupId> |
|
30 |
<artifactId>cnr-resultset-service</artifactId> |
|
31 |
<version>[2.0.0,3.0.0)</version> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>eu.dnetlib</groupId> |
|
35 |
<artifactId>cnr-data-utility-cleaner-rmi</artifactId> |
|
36 |
<version>[2.0.0,3.0.0)</version> |
|
37 |
</dependency> |
|
38 |
<dependency> |
|
39 |
<groupId>eu.dnetlib</groupId> |
|
40 |
<artifactId>cnr-resultset-client</artifactId> |
|
41 |
<version>[2.0.0,3.0.0)</version> |
|
42 |
</dependency> |
|
43 |
<dependency> |
|
44 |
<groupId>eu.dnetlib</groupId> |
|
45 |
<artifactId>dnet-download-service-rmi</artifactId> |
|
46 |
<version>[1.0.0,2.0.0)</version> |
|
47 |
</dependency> |
|
48 |
|
|
49 |
<dependency> |
|
50 |
<groupId>eu.dnetlib</groupId> |
|
51 |
<artifactId>cnr-blackboard-common</artifactId> |
|
52 |
<version>[2.1.0,3.0.0)</version> |
|
53 |
</dependency> |
|
54 |
<dependency> |
|
55 |
<groupId>eu.dnetlib</groupId> |
|
56 |
<artifactId>dnet-mongo-logging</artifactId> |
|
57 |
<version>[1.0.0,2.0.0)</version> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>eu.dnetlib</groupId> |
|
61 |
<artifactId>dnet-datasource-common</artifactId> |
|
62 |
<version>[3.0.0,4.0.0)</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>com.googlecode</groupId> |
|
66 |
<artifactId>sarasvati</artifactId> |
|
67 |
<version>1.0.3</version> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>com.googlecode</groupId> |
|
71 |
<artifactId>sarasvati-visual</artifactId> |
|
72 |
<version>1.0.3</version> |
|
73 |
</dependency> |
|
74 |
<dependency> |
|
75 |
<groupId>eu.dnetlib</groupId> |
|
76 |
<artifactId>dnet-modular-collector-service-rmi</artifactId> |
|
77 |
<version>[1.2.0,2.0.0)</version> |
|
78 |
</dependency> |
|
79 |
<dependency> |
|
80 |
<groupId>eu.dnetlib</groupId> |
|
81 |
<artifactId>cnr-enabling-database-api</artifactId> |
|
82 |
<version>[1.0.0,2.0.0)</version> |
|
83 |
</dependency> |
|
84 |
<dependency> |
|
85 |
<groupId>eu.dnetlib</groupId> |
|
86 |
<artifactId>dnet-objectstore-rmi</artifactId> |
|
87 |
<version>[2.0.0,3.0.0)</version> |
|
88 |
</dependency> |
|
89 |
<dependency> |
|
90 |
<groupId>eu.dnetlib</groupId> |
|
91 |
<artifactId>dnet-data-transformation-service-rmi</artifactId> |
|
92 |
<version>[1.0.0,2.0.0)</version> |
|
93 |
</dependency> |
|
94 |
<dependency> |
|
95 |
<groupId>eu.dnetlib</groupId> |
|
96 |
<artifactId>dnet-runtime</artifactId> |
|
97 |
<version>[1.0.0,2.0.0)</version> |
|
98 |
</dependency> |
|
99 |
<dependency> |
|
100 |
<groupId>javax.mail</groupId> |
|
101 |
<artifactId>mail</artifactId> |
|
102 |
<version>1.4</version> |
|
103 |
</dependency> |
|
104 |
<dependency> |
|
105 |
<groupId>org.codehaus.groovy</groupId> |
|
106 |
<artifactId>groovy-all</artifactId> |
|
107 |
<version>2.1.6</version> |
|
108 |
</dependency> |
|
109 |
<dependency> |
|
110 |
<groupId>junit</groupId> |
|
111 |
<artifactId>junit</artifactId> |
|
112 |
<version>${junit.version}</version> |
|
113 |
<scope>test</scope> |
|
114 |
</dependency> |
|
115 |
<dependency> |
|
116 |
<groupId>joda-time</groupId> |
|
117 |
<artifactId>joda-time</artifactId> |
|
118 |
<version>2.3</version> |
|
119 |
</dependency> |
|
120 |
</dependencies> |
|
121 |
|
|
122 |
<properties> |
|
123 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
124 |
</properties> |
|
125 |
|
|
126 |
</project> |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/blackboard/BlackboardSubscriber.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.blackboard; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
import javax.xml.ws.Endpoint; |
|
5 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
6 |
|
|
7 |
import org.apache.commons.logging.Log; |
|
8 |
import org.apache.commons.logging.LogFactory; |
|
9 |
import org.springframework.beans.factory.annotation.Required; |
|
10 |
|
|
11 |
import eu.dnetlib.enabling.is.sn.rmi.ISSNException; |
|
12 |
import eu.dnetlib.enabling.is.sn.rmi.ISSNService; |
|
13 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
14 |
import eu.dnetlib.soap.EndpointReferenceBuilder; |
|
15 |
|
|
16 |
public class BlackboardSubscriber { |
|
17 |
|
|
18 |
/** |
|
19 |
* Logger. |
|
20 |
*/ |
|
21 |
private static final Log log = LogFactory.getLog(BlackboardSubscriber.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
/** |
|
24 |
* service locator. |
|
25 |
*/ |
|
26 |
@Resource |
|
27 |
private UniqueServiceLocator serviceLocator; |
|
28 |
|
|
29 |
/** |
|
30 |
* injected EPR builder. |
|
31 |
*/ |
|
32 |
@Resource(name = "jaxwsEndpointReferenceBuilder") |
|
33 |
private EndpointReferenceBuilder<Endpoint> eprBuilder; |
|
34 |
|
|
35 |
/** |
|
36 |
* notification endpoint (normally the msro service). |
|
37 |
*/ |
|
38 |
private Endpoint endpoint; |
|
39 |
|
|
40 |
/** |
|
41 |
* performs the subscription. |
|
42 |
* |
|
43 |
* @throws ISSNException |
|
44 |
* could happen |
|
45 |
*/ |
|
46 |
public void subscribeAll() throws ISSNException { |
|
47 |
log.info("Subscribing msro service"); |
|
48 |
|
|
49 |
final W3CEndpointReference endpointReference = eprBuilder.getEndpointReference(getEndpoint()); |
|
50 |
serviceLocator.getService(ISSNService.class).subscribe(endpointReference, "UPDATE/*/*/RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_RESPONSE", 0); |
|
51 |
} |
|
52 |
|
|
53 |
public Endpoint getEndpoint() { |
|
54 |
return endpoint; |
|
55 |
} |
|
56 |
|
|
57 |
@Required |
|
58 |
public void setEndpoint(final Endpoint endpoint) { |
|
59 |
this.endpoint = endpoint; |
|
60 |
} |
|
61 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/AsyncJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import java.util.concurrent.ExecutorService; |
|
4 |
import java.util.concurrent.Executors; |
|
5 |
|
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
import com.googlecode.sarasvati.Engine; |
|
10 |
import com.googlecode.sarasvati.NodeToken; |
|
11 |
|
|
12 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
13 |
|
|
14 |
public abstract class AsyncJobNode extends SarasvatiJobNode { |
|
15 |
|
|
16 |
/** |
|
17 |
* logger. |
|
18 |
*/ |
|
19 |
private static final Log log = LogFactory.getLog(AsyncJobNode.class); |
|
20 |
|
|
21 |
private final ExecutorService executor = Executors.newCachedThreadPool(); |
|
22 |
|
|
23 |
@Override |
|
24 |
public void execute(final Engine engine, final NodeToken token) { |
|
25 |
super.execute(engine, token); |
|
26 |
|
|
27 |
log.info("executing async node"); |
|
28 |
|
|
29 |
executor.execute(new Runnable() { |
|
30 |
|
|
31 |
@Override |
|
32 |
public void run() { |
|
33 |
try { |
|
34 |
log.debug("START NODE: " + getBeanName()); |
|
35 |
beforeStart(token); |
|
36 |
String arc = execute(token); |
|
37 |
beforeCompleted(token); |
|
38 |
log.debug("END NODE (SUCCESS): " + getBeanName()); |
|
39 |
engine.complete(token, arc); |
|
40 |
} catch (Throwable e) { |
|
41 |
log.error("got exception while executing workflow node", e); |
|
42 |
log.debug("END NODE (FAILED): " + getBeanName()); |
|
43 |
beforeFailed(token); |
|
44 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED, true); |
|
45 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR, e.getMessage()); |
|
46 |
engine.complete(token, "failed"); |
|
47 |
} |
|
48 |
} |
|
49 |
}); |
|
50 |
} |
|
51 |
|
|
52 |
abstract protected String execute(final NodeToken token) throws Exception; |
|
53 |
|
|
54 |
protected void beforeStart(final NodeToken token) {} |
|
55 |
|
|
56 |
protected void beforeCompleted(final NodeToken token) {} |
|
57 |
|
|
58 |
protected void beforeFailed(final NodeToken token) {} |
|
59 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/harvest/fs/StartHarvestFSJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.harvest.fs; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
|
|
8 |
import com.googlecode.sarasvati.Engine; |
|
9 |
import com.googlecode.sarasvati.NodeToken; |
|
10 |
import com.googlecode.sarasvati.env.Env; |
|
11 |
|
|
12 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
13 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
14 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
15 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
16 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
17 |
import eu.dnetlib.msro.rmi.MSROException; |
|
18 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
19 |
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener; |
|
20 |
import eu.dnetlib.msro.workflows.nodes.blackboard.OngoingBlackboardWorkflowJobListener; |
|
21 |
|
|
22 |
public class StartHarvestFSJobNode extends BlackboardJobNode { |
|
23 |
|
|
24 |
/** |
|
25 |
* Logger. |
|
26 |
*/ |
|
27 |
private static final Log log = LogFactory.getLog(StartHarvestFSJobNode.class); |
|
28 |
|
|
29 |
/** |
|
30 |
* service locator. |
|
31 |
*/ |
|
32 |
private UniqueServiceLocator serviceLocator; |
|
33 |
|
|
34 |
private static final String protocol = "filesystem"; |
|
35 |
|
|
36 |
private String datasourceId; |
|
37 |
private String username; |
|
38 |
private String password; |
|
39 |
private String filter; |
|
40 |
private String eprParam; |
|
41 |
private String datasourceInterface; |
|
42 |
private String format; |
|
43 |
|
|
44 |
@Override |
|
45 |
protected String getXqueryForServiceId(final NodeToken token) { |
|
46 |
return "collection('/db/DRIVER/ServiceResources/HarvestingServiceResourceType')/RESOURCE_PROFILE" |
|
47 |
+ "[.//SERVICE_PROPERTIES/PROPERTY[@key='protocol']/@value = '" + protocol + "']//RESOURCE_IDENTIFIER/@value/string()"; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
52 |
job.setAction("LISTRECORDS"); |
|
53 |
|
|
54 |
if (datasourceId == null || datasourceId.isEmpty()) { |
|
55 |
throw new MSROException("Missing field datasourceId"); |
|
56 |
} else { |
|
57 |
job.getParameters().put("repository_id", getDatasourceId()); |
|
58 |
} |
|
59 |
|
|
60 |
if (datasourceInterface == null || datasourceInterface.isEmpty()) { |
|
61 |
throw new MSROException("Missing field datasourceInterface"); |
|
62 |
} else { |
|
63 |
job.getParameters().put("base_url", obtainBaseUrl()); |
|
64 |
} |
|
65 |
|
|
66 |
if (format == null || format.isEmpty()) { |
|
67 |
throw new MSROException("Missing field format"); |
|
68 |
} else { |
|
69 |
job.getParameters().put("inputFormat", format); |
|
70 |
} |
|
71 |
|
|
72 |
if (username != null && !username.isEmpty()) { |
|
73 |
job.getParameters().put("username", getUsername()); |
|
74 |
} |
|
75 |
|
|
76 |
if (password != null && !password.isEmpty()) { |
|
77 |
job.getParameters().put("password", getPassword()); |
|
78 |
} |
|
79 |
|
|
80 |
if (filter != null && !filter.isEmpty()) { |
|
81 |
job.getParameters().put("filter", getFilter()); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
private String obtainBaseUrl() throws ISLookUpDocumentNotFoundException, ISLookUpException { |
|
87 |
String query = "/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + getDatasourceId() + "']" + |
|
88 |
"//INTERFACE[@label='" + getDatasourceInterface() + |
|
89 |
"' and ./ACCESS_PROTOCOL = '" + protocol + |
|
90 |
"' and .//FORMAT = '" + getFormat() + "']/BASE_URL/text()"; |
|
91 |
|
|
92 |
log.info("Executing query: " + query); |
|
93 |
|
|
94 |
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query); |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) { |
|
99 |
return new OngoingBlackboardWorkflowJobListener(engine, token) { |
|
100 |
|
|
101 |
@Override |
|
102 |
protected void populateEnv(final Env env, final Map<String, String> responseParams) { |
|
103 |
log.info("Obtained epr: " + responseParams.get("rs_epr")); |
|
104 |
env.setAttribute(getEprParam(), responseParams.get("rs_epr")); |
|
105 |
} |
|
106 |
}; |
|
107 |
} |
|
108 |
|
|
109 |
public String getUsername() { |
|
110 |
return username; |
|
111 |
} |
|
112 |
|
|
113 |
public void setUsername(final String username) { |
|
114 |
this.username = username; |
|
115 |
} |
|
116 |
|
|
117 |
public String getPassword() { |
|
118 |
return password; |
|
119 |
} |
|
120 |
|
|
121 |
public void setPassword(final String password) { |
|
122 |
this.password = password; |
|
123 |
} |
|
124 |
|
|
125 |
public String getFilter() { |
|
126 |
return filter; |
|
127 |
} |
|
128 |
|
|
129 |
public void setFilter(final String filter) { |
|
130 |
this.filter = filter; |
|
131 |
} |
|
132 |
|
|
133 |
public String getDatasourceId() { |
|
134 |
return datasourceId; |
|
135 |
} |
|
136 |
|
|
137 |
public void setDatasourceId(final String datasourceId) { |
|
138 |
this.datasourceId = datasourceId; |
|
139 |
} |
|
140 |
|
|
141 |
public String getEprParam() { |
|
142 |
return eprParam; |
|
143 |
} |
|
144 |
|
|
145 |
public void setEprParam(final String eprParam) { |
|
146 |
this.eprParam = eprParam; |
|
147 |
} |
|
148 |
|
|
149 |
public String getFormat() { |
|
150 |
return format; |
|
151 |
} |
|
152 |
|
|
153 |
public void setFormat(final String format) { |
|
154 |
this.format = format; |
|
155 |
} |
|
156 |
|
|
157 |
public String getDatasourceInterface() { |
|
158 |
return datasourceInterface; |
|
159 |
} |
|
160 |
|
|
161 |
public void setDatasourceInterface(final String datasourceInterface) { |
|
162 |
this.datasourceInterface = datasourceInterface; |
|
163 |
} |
|
164 |
|
|
165 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/blackboard/BlackboardWorkflowJobListener.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.blackboard; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
import java.util.Map.Entry; |
|
5 |
|
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 |
import com.googlecode.sarasvati.Arc; |
|
10 |
import com.googlecode.sarasvati.Engine; |
|
11 |
import com.googlecode.sarasvati.NodeToken; |
|
12 |
import com.googlecode.sarasvati.env.Env; |
|
13 |
|
|
14 |
import eu.dnetlib.enabling.tools.blackboard.AbstractBlackboardJobListener; |
|
15 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
16 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
17 |
|
|
18 |
public class BlackboardWorkflowJobListener extends AbstractBlackboardJobListener { |
|
19 |
|
|
20 |
/** |
|
21 |
* logger. |
|
22 |
*/ |
|
23 |
private static final Log log = LogFactory.getLog(BlackboardWorkflowJobListener.class); |
|
24 |
|
|
25 |
/** |
|
26 |
* workflow engine. |
|
27 |
*/ |
|
28 |
private Engine engine; |
|
29 |
|
|
30 |
/** |
|
31 |
* workflow node token. |
|
32 |
*/ |
|
33 |
private NodeToken token; |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void onDone(final BlackboardJob job) { |
|
37 |
log.debug("Blackboard workflow node DONE"); |
|
38 |
complete(job, Arc.DEFAULT_ARC); |
|
39 |
} |
|
40 |
|
|
41 |
public BlackboardWorkflowJobListener(final Engine engine, final NodeToken token) { |
|
42 |
super(); |
|
43 |
this.engine = engine; |
|
44 |
this.token = token; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
final public void processJob(final BlackboardJob job) { |
|
49 |
token.getEnv().setTransientAttribute(WorkflowsConstants.BLACKBOARD_JOB, job); |
|
50 |
super.processJob(job); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
final protected void onFailed(final BlackboardJob job) { |
|
55 |
log.warn("Blackboard workflow node FAILED: " + job.getError()); |
|
56 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_HAS_FAILED, true); |
|
57 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR, job.getError()); |
|
58 |
complete(job, "failed"); |
|
59 |
} |
|
60 |
|
|
61 |
final protected void complete(final BlackboardJob job, final String arc) { |
|
62 |
final Env env = token.getEnv(); |
|
63 |
|
|
64 |
populateEnv(env, job.getParameters()); |
|
65 |
|
|
66 |
engine.complete(token, arc); |
|
67 |
engine.executeQueuedArcTokens(token.getProcess()); |
|
68 |
} |
|
69 |
|
|
70 |
protected void populateEnv(final Env env, Map<String, String> responseParams) { |
|
71 |
for (Entry<String, String> entry : responseParams.entrySet()) { |
|
72 |
env.setAttribute(WorkflowsConstants.BLACKBOARD_PARAM_PREFIX + entry.getKey(), entry.getValue()); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
protected void onOngoing(final BlackboardJob job) { |
|
78 |
token.getEnv().setAttribute(WorkflowsConstants.BLACKBOARD_IS_GOING, true); |
|
79 |
} |
|
80 |
|
|
81 |
public Engine getEngine() { |
|
82 |
return engine; |
|
83 |
} |
|
84 |
|
|
85 |
public void setEngine(final Engine engine) { |
|
86 |
this.engine = engine; |
|
87 |
} |
|
88 |
|
|
89 |
public NodeToken getToken() { |
|
90 |
return token; |
|
91 |
} |
|
92 |
|
|
93 |
public void setToken(final NodeToken token) { |
|
94 |
this.token = token; |
|
95 |
} |
|
96 |
|
|
97 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/blackboard/OngoingBlackboardWorkflowJobListener.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.blackboard; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.Arc; |
|
4 |
import com.googlecode.sarasvati.Engine; |
|
5 |
import com.googlecode.sarasvati.NodeToken; |
|
6 |
|
|
7 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
8 |
|
|
9 |
public class OngoingBlackboardWorkflowJobListener extends BlackboardWorkflowJobListener { |
|
10 |
|
|
11 |
public OngoingBlackboardWorkflowJobListener(Engine engine, NodeToken token) { |
|
12 |
super(engine, token); |
|
13 |
} |
|
14 |
|
|
15 |
@Override |
|
16 |
protected void onOngoing(BlackboardJob job) { |
|
17 |
super.onOngoing(job); |
|
18 |
complete(job, Arc.DEFAULT_ARC); |
|
19 |
} |
|
20 |
|
|
21 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-2.0.1/src/main/java/eu/dnetlib/msro/workflows/nodes/mdstore/FetchMDStoreRecordsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.mdstore; |
|
2 |
|
|
3 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
4 |
|
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
|
|
8 |
import com.googlecode.sarasvati.Arc; |
|
9 |
import com.googlecode.sarasvati.NodeToken; |
|
10 |
|
|
11 |
import eu.dnetlib.data.mdstore.MDStoreService; |
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
13 |
import eu.dnetlib.msro.rmi.MSROException; |
|
14 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
15 |
|
|
16 |
public class FetchMDStoreRecordsJobNode extends SimpleJobNode { |
|
17 |
|
|
18 |
private static final Log log = LogFactory.getLog(FetchMDStoreRecordsJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-msro-service-2.0.1