Revision 49538
Added by Michele Artini over 6 years ago
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/db/ExecuteSqlFromEnvJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.db; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import com.googlecode.sarasvati.Arc; |
|
6 |
import com.googlecode.sarasvati.NodeToken; |
|
7 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
8 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
9 |
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode; |
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
|
|
12 |
public class ExecuteSqlFromEnvJobNode extends AsyncJobNode { |
|
13 |
|
|
14 |
private String db; |
|
15 |
private String dbParam; |
|
16 |
private String dbProperty; |
|
17 |
|
|
18 |
private String sqlParamName; |
|
19 |
|
|
20 |
@Resource |
|
21 |
private UniqueServiceLocator serviceLocator; |
|
22 |
|
|
23 |
@Override |
|
24 |
protected String execute(final NodeToken token) throws Exception { |
|
25 |
String sql = token.getEnv().getAttribute(sqlParamName); |
|
26 |
if (StringUtils.isBlank(sql)) throw new IllegalArgumentException("Missing value in env attribute named: " + sqlParamName); |
|
27 |
serviceLocator.getService(DatabaseService.class).updateSQL(findDb(token), sql); |
|
28 |
|
|
29 |
return Arc.DEFAULT_ARC; |
|
30 |
} |
|
31 |
|
|
32 |
private String findDb(final NodeToken token) { |
|
33 |
if (dbParam != null && !dbParam.isEmpty()) { |
|
34 |
return token.getEnv().getAttribute(dbParam); |
|
35 |
} else if (dbProperty != null && !dbProperty.isEmpty()) { |
|
36 |
return getPropertyFetcher().getProperty(dbProperty); |
|
37 |
} else { |
|
38 |
return db; |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
public String getDb() { |
|
43 |
return db; |
|
44 |
} |
|
45 |
|
|
46 |
public void setDb(final String db) { |
|
47 |
this.db = db; |
|
48 |
} |
|
49 |
|
|
50 |
public String getDbParam() { |
|
51 |
return dbParam; |
|
52 |
} |
|
53 |
|
|
54 |
public void setDbParam(final String dbParam) { |
|
55 |
this.dbParam = dbParam; |
|
56 |
} |
|
57 |
|
|
58 |
public String getDbProperty() { |
|
59 |
return dbProperty; |
|
60 |
} |
|
61 |
|
|
62 |
public void setDbProperty(final String dbProperty) { |
|
63 |
this.dbProperty = dbProperty; |
|
64 |
} |
|
65 |
|
|
66 |
public String getSqlParamName() { |
|
67 |
return sqlParamName; |
|
68 |
} |
|
69 |
|
|
70 |
public void setSqlParamName(final String sqlParamName) { |
|
71 |
this.sqlParamName = sqlParamName; |
|
72 |
} |
|
73 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/db/QueryDbJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.db; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import javax.annotation.Resource; |
|
6 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
7 |
|
|
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.apache.commons.lang.StringUtils; |
|
10 |
|
|
11 |
import com.googlecode.sarasvati.Arc; |
|
12 |
import com.googlecode.sarasvati.NodeToken; |
|
13 |
|
|
14 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
15 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
16 |
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode; |
|
17 |
|
|
18 |
public class QueryDbJobNode extends AsyncJobNode { |
|
19 |
|
|
20 |
private String db; |
|
21 |
private String dbParam; |
|
22 |
private String dbProperty; |
|
23 |
|
|
24 |
private String sql; |
|
25 |
private String sqlForSize; |
|
26 |
private String xslt; |
|
27 |
private String outputEprParam; |
|
28 |
|
|
29 |
@Resource |
|
30 |
private UniqueServiceLocator serviceLocator; |
|
31 |
|
|
32 |
@Override |
|
33 |
protected String execute(final NodeToken token) throws Exception { |
|
34 |
final String sqlText = fetchSqlAsText(sql); |
|
35 |
|
|
36 |
W3CEndpointReference epr = null; |
|
37 |
|
|
38 |
final DatabaseService dbService = serviceLocator.getService(DatabaseService.class); |
|
39 |
|
|
40 |
if (StringUtils.isNotBlank(xslt)) { |
|
41 |
final String xsltText = IOUtils.toString(getClass().getResourceAsStream(xslt)); |
|
42 |
|
|
43 |
if (StringUtils.isBlank(sqlForSize)) { |
|
44 |
epr = dbService.xsltSearchSQL(findDb(token), sqlText, xsltText); |
|
45 |
} else { |
|
46 |
epr = dbService.alternativeXsltSearchSQL(findDb(token), sqlText, fetchSqlAsText(sqlForSize), xsltText); |
|
47 |
} |
|
48 |
} else { |
|
49 |
if (StringUtils.isBlank(sqlForSize)) { |
|
50 |
epr = dbService.searchSQL(findDb(token), sqlText); |
|
51 |
} else { |
|
52 |
epr = dbService.alternativeSearchSQL(findDb(token), sqlText, fetchSqlAsText(sqlForSize)); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
token.getEnv().setAttribute(outputEprParam, epr.toString()); |
|
57 |
|
|
58 |
return Arc.DEFAULT_ARC; |
|
59 |
} |
|
60 |
|
|
61 |
private String fetchSqlAsText(final String path) throws IOException { |
|
62 |
return IOUtils.toString(getClass().getResourceAsStream(path)); |
|
63 |
} |
|
64 |
|
|
65 |
private String findDb(final NodeToken token) { |
|
66 |
if (dbParam != null && !dbParam.isEmpty()) { |
|
67 |
return token.getEnv().getAttribute(dbParam); |
|
68 |
} else if (dbProperty != null && !dbProperty.isEmpty()) { |
|
69 |
return getPropertyFetcher().getProperty(dbProperty); |
|
70 |
} else { |
|
71 |
return db; |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
public String getDb() { |
|
76 |
return db; |
|
77 |
} |
|
78 |
|
|
79 |
public void setDb(final String db) { |
|
80 |
this.db = db; |
|
81 |
} |
|
82 |
|
|
83 |
public String getDbParam() { |
|
84 |
return dbParam; |
|
85 |
} |
|
86 |
|
|
87 |
public void setDbParam(final String dbParam) { |
|
88 |
this.dbParam = dbParam; |
|
89 |
} |
|
90 |
|
|
91 |
public String getSql() { |
|
92 |
return sql; |
|
93 |
} |
|
94 |
|
|
95 |
public void setSql(final String sql) { |
|
96 |
this.sql = sql; |
|
97 |
} |
|
98 |
|
|
99 |
public String getXslt() { |
|
100 |
return xslt; |
|
101 |
} |
|
102 |
|
|
103 |
public void setXslt(final String xslt) { |
|
104 |
this.xslt = xslt; |
|
105 |
} |
|
106 |
|
|
107 |
public String getOutputEprParam() { |
|
108 |
return outputEprParam; |
|
109 |
} |
|
110 |
|
|
111 |
public void setOutputEprParam(final String outputEprParam) { |
|
112 |
this.outputEprParam = outputEprParam; |
|
113 |
} |
|
114 |
|
|
115 |
public String getDbProperty() { |
|
116 |
return dbProperty; |
|
117 |
} |
|
118 |
|
|
119 |
public void setDbProperty(final String dbProperty) { |
|
120 |
this.dbProperty = dbProperty; |
|
121 |
} |
|
122 |
|
|
123 |
public String getSqlForSize() { |
|
124 |
return sqlForSize; |
|
125 |
} |
|
126 |
|
|
127 |
public void setSqlForSize(final String sqlForSize) { |
|
128 |
this.sqlForSize = sqlForSize; |
|
129 |
} |
|
130 |
|
|
131 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/repobye/DeleteObjectStoreJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repobye; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.NodeToken; |
|
4 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
7 |
import org.apache.commons.logging.Log; |
|
8 |
import org.apache.commons.logging.LogFactory; |
|
9 |
|
|
10 |
public class DeleteObjectStoreJobNode extends BlackboardJobNode { |
|
11 |
|
|
12 |
private static final Log log = LogFactory.getLog(DeleteObjectStoreJobNode.class); |
|
13 |
|
|
14 |
private String objectstoreId; |
|
15 |
|
|
16 |
@Override |
|
17 |
protected String obtainServiceId(final NodeToken token) { |
|
18 |
return getServiceLocator().getServiceId(ObjectStoreService.class); |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
23 |
log.info("preparing blackboard job: delete of objectstore " + getObjectstoreId()); |
|
24 |
job.setAction("DELETE"); |
|
25 |
job.getParameters().put("obsID", getObjectstoreId()); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* @return the objectstoreId |
|
30 |
*/ |
|
31 |
public String getObjectstoreId() { |
|
32 |
return objectstoreId; |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* @param objectstoreId |
|
37 |
* the objectstoreId to set |
|
38 |
*/ |
|
39 |
public void setObjectstoreId(final String objectstoreId) { |
|
40 |
this.objectstoreId = objectstoreId; |
|
41 |
} |
|
42 |
|
|
43 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/VerifyDatasourceJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repohi; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import com.google.common.base.Splitter; |
|
6 |
import com.googlecode.sarasvati.Arc; |
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
|
|
9 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
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 eu.dnetlib.msro.rmi.MSROException; |
|
14 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
15 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
16 |
|
|
17 |
public class VerifyDatasourceJobNode extends SimpleJobNode { |
|
18 |
|
|
19 |
@Resource |
|
20 |
private UniqueServiceLocator serviceLocator; |
|
21 |
|
|
22 |
private String expectedInterfaceTypologyPrefixes; |
|
23 |
|
|
24 |
private String expectedCompliancePrefixes; |
|
25 |
|
|
26 |
@Override |
|
27 |
protected String execute(final NodeToken token) throws Exception { |
|
28 |
final String dsId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID); |
|
29 |
final String ifaceId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE); |
|
30 |
final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class); |
|
31 |
|
|
32 |
String compliance; |
|
33 |
try { |
|
34 |
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId |
|
35 |
+ "']/INTERFACE_EXTRA_FIELD[@name='overriding_compliance']/text()"); |
|
36 |
} catch (ISLookUpDocumentNotFoundException e) { |
|
37 |
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId |
|
38 |
+ "']/@compliance/string()"); |
|
39 |
} |
|
40 |
|
|
41 |
final String typology = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId |
|
42 |
+ "']/@typology/string()"); |
|
43 |
|
|
44 |
verifyValue(compliance, expectedCompliancePrefixes); |
|
45 |
verifyValue(typology, expectedInterfaceTypologyPrefixes); |
|
46 |
token.getFullEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE_COMPLIANCE, compliance); |
|
47 |
|
|
48 |
if (isPending(dsId)) { |
|
49 |
return "validateDs"; |
|
50 |
} else { |
|
51 |
return Arc.DEFAULT_ARC; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
private void verifyValue(final String value, final String expected) throws Exception { |
|
56 |
if (expected != null && !expected.isEmpty()) { |
|
57 |
for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(expected)) { |
|
58 |
if (value.toLowerCase().startsWith(s.toLowerCase())) { return; } |
|
59 |
} |
|
60 |
throw new MSROException("Invalid value: " + value + ", Valid term prefixes are: [" + expected + "]"); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
private boolean isPending(final String id) throws ISLookUpDocumentNotFoundException, ISLookUpException { |
|
65 |
final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//RESOURCE_KIND/@value/string()"; |
|
66 |
final String res = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query); |
|
67 |
return res.trim().equals("PendingRepositoryResources"); |
|
68 |
} |
|
69 |
|
|
70 |
public String getExpectedInterfaceTypologyPrefixes() { |
|
71 |
return expectedInterfaceTypologyPrefixes; |
|
72 |
} |
|
73 |
|
|
74 |
public void setExpectedInterfaceTypologyPrefixes(final String expectedInterfaceTypologyPrefixes) { |
|
75 |
this.expectedInterfaceTypologyPrefixes = expectedInterfaceTypologyPrefixes; |
|
76 |
} |
|
77 |
|
|
78 |
public String getExpectedCompliancePrefixes() { |
|
79 |
return expectedCompliancePrefixes; |
|
80 |
} |
|
81 |
|
|
82 |
public void setExpectedCompliancePrefixes(final String expectedCompliancePrefixes) { |
|
83 |
this.expectedCompliancePrefixes = expectedCompliancePrefixes; |
|
84 |
} |
|
85 |
|
|
86 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/repobye/DeleteMetaWfJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repobye; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.io.StringWriter; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
|
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.dom4j.Document; |
|
11 |
import org.dom4j.Node; |
|
12 |
import org.dom4j.io.SAXReader; |
|
13 |
|
|
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.is.registry.rmi.ISRegistryService; |
|
19 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
20 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
21 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
22 |
|
|
23 |
public class DeleteMetaWfJobNode extends SimpleJobNode { |
|
24 |
|
|
25 |
private String metaWfId; |
|
26 |
|
|
27 |
@Resource |
|
28 |
private UniqueServiceLocator serviceLocator; |
|
29 |
|
|
30 |
private static final Log log = LogFactory.getLog(DeleteMetaWfJobNode.class); |
|
31 |
|
|
32 |
@Override |
|
33 |
protected String execute(final NodeToken token) throws Exception { |
|
34 |
final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(metaWfId); |
|
35 |
final Document doc = new SAXReader().read(new StringReader(profile)); |
|
36 |
|
|
37 |
final String dsId = doc.valueOf("//DATAPROVIDER/@id"); |
|
38 |
final String dsName = doc.valueOf("//DATAPROVIDER/text()"); |
|
39 |
final String ifaceId = doc.valueOf("//DATAPROVIDER/@interface"); |
|
40 |
final String destroyWfId = doc.valueOf("//CONFIGURATION/@destroyWorkflow"); |
|
41 |
|
|
42 |
log.info("Removing a MetaWf of dataprovider: " + dsId); |
|
43 |
|
|
44 |
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_ID, dsId); |
|
45 |
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_NAME, dsName); |
|
46 |
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE, ifaceId); |
|
47 |
|
|
48 |
final ISRegistryService registry = serviceLocator.getService(ISRegistryService.class); |
|
49 |
|
|
50 |
for (Object o : doc.selectNodes("//WORKFLOW")) { |
|
51 |
final String wfId = ((Node) o).valueOf("@id"); |
|
52 |
try { |
|
53 |
registry.deleteProfile(wfId); |
|
54 |
log.info(" - Deleted Workflow: " + wfId); |
|
55 |
} catch (Exception e) { |
|
56 |
log.error(" - (ERR) Error deleting profile " + wfId); |
|
57 |
} |
|
58 |
} |
|
59 |
registry.deleteProfile(metaWfId); |
|
60 |
log.info(" - Deleted MetaWorkflow: " + metaWfId); |
|
61 |
|
|
62 |
registry.deleteProfile(destroyWfId); |
|
63 |
log.info(" - Deleted destroy workflow: " + destroyWfId); |
|
64 |
|
|
65 |
verifyDatasource(dsId, ifaceId); |
|
66 |
|
|
67 |
return Arc.DEFAULT_ARC; |
|
68 |
} |
|
69 |
|
|
70 |
private void verifyDatasource(final String dsId, final String ifaceId) throws Exception { |
|
71 |
final StringWriter sw = new StringWriter(); |
|
72 |
|
|
73 |
sw.append("for $x in collection('/db/DRIVER/MetaWorkflowDSResources/MetaWorkflowDSResourceType') where"); |
|
74 |
sw.append(" $x//DATAPROVIDER/@id = '" + dsId + "' and "); |
|
75 |
sw.append(" $x//DATAPROVIDER/@interface = '" + ifaceId + "' and "); |
|
76 |
sw.append(" $x//RESOURCE_IDENTIFIER/@value != '" + metaWfId + "' "); |
|
77 |
sw.append("return $x//RESOURCE_IDENTIFIER/@value/string()"); |
|
78 |
|
|
79 |
final boolean active = !serviceLocator.getService(ISLookUpService.class).quickSearchProfile(sw.toString()).isEmpty(); |
|
80 |
|
|
81 |
log.info(" - Updating iface, active status: " + active); |
|
82 |
|
|
83 |
updateIfaceActivationStatus(dsId, ifaceId, active); |
|
84 |
} |
|
85 |
|
|
86 |
protected void updateIfaceActivationStatus(final String dsId, final String ifaceId, final boolean active) throws Exception { |
|
87 |
serviceLocator.getService(ISRegistryService.class).updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@active", "'" + active + "'"); |
|
88 |
} |
|
89 |
|
|
90 |
public String getMetaWfId() { |
|
91 |
return metaWfId; |
|
92 |
} |
|
93 |
|
|
94 |
public void setMetaWfId(final String metaWfId) { |
|
95 |
this.metaWfId = metaWfId; |
|
96 |
} |
|
97 |
|
|
98 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/RegisterMetaWfJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repohi; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringWriter; |
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import com.googlecode.sarasvati.Arc; |
|
8 |
import com.googlecode.sarasvati.NodeToken; |
|
9 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
10 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
11 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
12 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
13 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
14 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus; |
|
15 |
import org.antlr.stringtemplate.StringTemplate; |
|
16 |
import org.apache.commons.io.IOUtils; |
|
17 |
import org.apache.commons.lang.StringEscapeUtils; |
|
18 |
|
|
19 |
public class RegisterMetaWfJobNode extends SimpleJobNode { |
|
20 |
|
|
21 |
@Resource |
|
22 |
private UniqueServiceLocator serviceLocator; |
|
23 |
private String adminEmail; |
|
24 |
|
|
25 |
private String wfName; |
|
26 |
|
|
27 |
@Override |
|
28 |
protected String execute(final NodeToken token) throws Exception { |
|
29 |
final String dsId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID); |
|
30 |
final String dsName = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME); |
|
31 |
final String ifaceId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE); |
|
32 |
|
|
33 |
final String metaWfId = registerDatasourceWorkflow(dsId, dsName, ifaceId); |
|
34 |
|
|
35 |
token.getFullEnv().setAttribute("META_WORKFLOW_ID", metaWfId); |
|
36 |
token.getFullEnv().setAttribute("META_WORKFLOW_STATUS", WorkflowStatus.ASSIGNED.toString()); |
|
37 |
|
|
38 |
return Arc.DEFAULT_ARC; |
|
39 |
} |
|
40 |
|
|
41 |
public String registerDatasourceWorkflow(final String dsId, final String dsName, final String ifaceId) throws ISRegistryException, IOException { |
|
42 |
final StringWriter sw = new StringWriter(); |
|
43 |
IOUtils.copy(getClass().getResourceAsStream("/eu/dnetlib/msro/workflows/templates/meta-workflow.xml.st"), sw); |
|
44 |
|
|
45 |
final StringTemplate st = new StringTemplate(sw.toString()); |
|
46 |
st.setAttribute("dsId", dsId); |
|
47 |
st.setAttribute("ifaceId", ifaceId); |
|
48 |
st.setAttribute("dsName", StringEscapeUtils.escapeXml(dsName)); |
|
49 |
st.setAttribute("section", "dataproviders"); |
|
50 |
st.setAttribute("wfName", StringEscapeUtils.escapeXml(getWfName())); |
|
51 |
st.setAttribute("wfFamily", StringEscapeUtils.escapeXml(getWfName())); |
|
52 |
st.setAttribute("adminEmail", adminEmail); |
|
53 |
st.setAttribute("status", WorkflowStatus.ASSIGNED.toString()); |
|
54 |
|
|
55 |
return serviceLocator.getService(ISRegistryService.class).registerProfile(st.toString()); |
|
56 |
} |
|
57 |
|
|
58 |
public String getWfName() { |
|
59 |
return wfName; |
|
60 |
} |
|
61 |
|
|
62 |
public void setWfName(final String wfName) { |
|
63 |
this.wfName = wfName; |
|
64 |
} |
|
65 |
|
|
66 |
public String getAdminEmail() { |
|
67 |
return adminEmail; |
|
68 |
} |
|
69 |
|
|
70 |
public void setAdminEmail(final String adminEmail) { |
|
71 |
this.adminEmail = adminEmail; |
|
72 |
} |
|
73 |
} |
modules/dnet-msro-service/branches/dsm/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/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/CreateObjectStoreJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.repohi; |
|
2 |
|
|
3 |
import java.util.Map; |
|
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 |
import com.googlecode.sarasvati.env.Env; |
|
12 |
|
|
13 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService; |
|
14 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
15 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
16 |
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener; |
|
17 |
|
|
18 |
public class CreateObjectStoreJobNode extends BlackboardJobNode { |
|
19 |
|
|
20 |
private static final Log log = LogFactory.getLog(CreateObjectStoreJobNode.class); |
|
21 |
|
|
22 |
private String interpretation; |
|
23 |
private String outputPrefix = "objectStore_"; |
|
24 |
|
|
25 |
@Override |
|
26 |
protected String obtainServiceId(final NodeToken token) { |
|
27 |
return getServiceLocator().getServiceId(ObjectStoreService.class); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) { |
|
32 |
log.info("preparing blackboard job for the creation of the objectStore "); |
|
33 |
String basePath = token.getEnv().getAttribute("objectStoreBasePath"); |
|
34 |
job.setAction("CREATE"); |
|
35 |
job.getParameters().put("interpretation", interpretation); |
|
36 |
if (!StringUtils.isEmpty(basePath)) { |
|
37 |
job.getParameters().put("basePath", basePath); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
public String getInterpretation() { |
|
42 |
return interpretation; |
|
43 |
} |
|
44 |
|
|
45 |
public void setInterpretation(final String interpretation) { |
|
46 |
this.interpretation = interpretation; |
|
47 |
} |
|
48 |
|
|
49 |
public String getOutputPrefix() { |
|
50 |
return outputPrefix; |
|
51 |
} |
|
52 |
|
|
53 |
public void setOutputPrefix(final String outputPrefix) { |
|
54 |
this.outputPrefix = outputPrefix; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) { |
|
59 |
return new BlackboardWorkflowJobListener(engine, token) { |
|
60 |
|
|
61 |
@Override |
|
62 |
protected void populateEnv(final Env env, final Map<String, String> responseParams) { |
|
63 |
|
|
64 |
env.setAttribute(getOutputPrefix() + "interpretation", interpretation); |
|
65 |
env.setAttribute(getOutputPrefix() + "id", responseParams.get("objectStoreId")); |
|
66 |
} |
|
67 |
}; |
|
68 |
} |
|
69 |
|
|
70 |
} |
modules/dnet-msro-service/branches/dsm/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/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/index/PrepareCreateIndexJobNode.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.msro.workflows.nodes.SimpleJobNode; |
|
9 |
|
|
10 |
public class PrepareCreateIndexJobNode extends SimpleJobNode { |
|
11 |
|
|
12 |
private static final Log log = LogFactory.getLog(PrepareCreateIndexJobNode.class); |
|
13 |
|
|
14 |
private String layout; |
|
15 |
private String format; |
|
16 |
private String interpretation; |
|
17 |
|
|
18 |
@Override |
|
19 |
protected String execute(final NodeToken token) throws Exception { |
|
20 |
log.info("Preparing env for CreateIndexJobNode"); |
|
21 |
token.getEnv().setAttribute("layout", layout); |
|
22 |
token.getEnv().setAttribute("format", format); |
|
23 |
token.getEnv().setAttribute("interpretation", interpretation); |
|
24 |
return null; |
|
25 |
} |
|
26 |
|
|
27 |
public String getLayout() { |
|
28 |
return layout; |
|
29 |
} |
|
30 |
|
|
31 |
public void setLayout(final String layout) { |
|
32 |
this.layout = layout; |
|
33 |
} |
|
34 |
|
|
35 |
public String getFormat() { |
|
36 |
return format; |
|
37 |
} |
|
38 |
|
|
39 |
public void setFormat(final String format) { |
|
40 |
this.format = format; |
|
41 |
} |
|
42 |
|
|
43 |
public String getInterpretation() { |
|
44 |
return interpretation; |
|
45 |
} |
|
46 |
|
|
47 |
public void setInterpretation(final String interpretation) { |
|
48 |
this.interpretation = interpretation; |
|
49 |
} |
|
50 |
|
|
51 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/transform/GroovyUnaryFunction.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.transform; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
6 |
|
|
7 |
public abstract class GroovyUnaryFunction implements UnaryFunction<String, String> { |
|
8 |
|
|
9 |
private Map<String, String> params; |
|
10 |
|
|
11 |
@Override |
|
12 |
abstract public String evaluate(String input); |
|
13 |
|
|
14 |
public Map<String, String> getParams() { |
|
15 |
return params; |
|
16 |
} |
|
17 |
|
|
18 |
public void setParams(final Map<String, String> params) { |
|
19 |
this.params = params; |
|
20 |
} |
|
21 |
|
|
22 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/is/ValidateProfilesJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.is; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
import javax.xml.XMLConstants; |
|
8 |
import javax.xml.transform.stream.StreamSource; |
|
9 |
import javax.xml.validation.Schema; |
|
10 |
import javax.xml.validation.SchemaFactory; |
|
11 |
import javax.xml.validation.Validator; |
|
12 |
|
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
|
|
16 |
import com.googlecode.sarasvati.Arc; |
|
17 |
import com.googlecode.sarasvati.NodeToken; |
|
18 |
|
|
19 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
20 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
21 |
import eu.dnetlib.msro.rmi.MSROException; |
|
22 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
23 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
24 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
25 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
26 |
|
|
27 |
public class ValidateProfilesJobNode extends SimpleJobNode implements ProgressJobNode { |
|
28 |
|
|
29 |
@Resource |
|
30 |
private UniqueServiceLocator serviceLocator; |
|
31 |
|
|
32 |
private int total = 0; |
|
33 |
private int current = 0; |
|
34 |
|
|
35 |
private static final Log log = LogFactory.getLog(ValidateProfilesJobNode.class); |
|
36 |
|
|
37 |
@Override |
|
38 |
protected String execute(final NodeToken token) throws Exception { |
|
39 |
|
|
40 |
final ISLookUpService lookup = serviceLocator.getService(ISLookUpService.class); |
|
41 |
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
|
42 |
|
|
43 |
int invalidTotals = 0; |
|
44 |
|
|
45 |
final List<String> list = lookup.listResourceTypes(); |
|
46 |
|
|
47 |
this.total = list.size(); |
|
48 |
this.current = 0; |
|
49 |
for (String resourceType : list) { |
|
50 |
int valid = 0; |
|
51 |
int invalid = 0; |
|
52 |
|
|
53 |
final String schemaSource = lookup.getResourceTypeSchema(resourceType); |
|
54 |
final Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(schemaSource))); |
|
55 |
final Validator validator = schema.newValidator(); |
|
56 |
|
|
57 |
for (String profile : lookup.quickSearchProfile("/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='" + resourceType + "']")) { |
|
58 |
try { |
|
59 |
validator.validate(new StreamSource(new StringReader(profile))); |
|
60 |
valid++; |
|
61 |
} catch (Exception e) { |
|
62 |
invalid++; |
|
63 |
} |
|
64 |
} |
|
65 |
invalidTotals += invalid; |
|
66 |
|
|
67 |
final String message = String.format("Valid: %s, Invalid: %s, Total: %s", valid, invalid, valid + invalid); |
|
68 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + resourceType, message); |
|
69 |
log.info("Validation of " + resourceType + " profiles: " + message); |
|
70 |
} |
|
71 |
|
|
72 |
if (invalidTotals > 0) { throw new MSROException("Validation wf has found " + invalidTotals + " invalid profiles"); } |
|
73 |
|
|
74 |
return Arc.DEFAULT_ARC; |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public ProgressProvider getProgressProvider() { |
|
79 |
return new ProgressProvider() { |
|
80 |
|
|
81 |
@Override |
|
82 |
public boolean isInaccurate() { |
|
83 |
return false; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public int getTotalValue() { |
|
88 |
return total; |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public int getCurrentValue() { |
|
93 |
return current; |
|
94 |
} |
|
95 |
}; |
|
96 |
} |
|
97 |
|
|
98 |
} |
modules/dnet-msro-service/branches/dsm/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/branches/dsm/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.data.provision.index.rmi.IndexService; |
|
9 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
10 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
11 |
|
|
12 |
public class DeleteIndexJobNode extends BlackboardJobNode { |
|
13 |
|
|
14 |
private static final Log log = LogFactory.getLog(DeleteIndexJobNode.class); |
|
15 |
|
|
16 |
private String indexId; |
|
17 |
private String defaultIndexId; |
|
18 |
|
|
19 |
@Override |
|
20 |
protected String obtainServiceId(final NodeToken token) { |
|
21 |
return getServiceLocator().getServiceId(IndexService.class); |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
26 |
log.info("deleting index id = " + getIndexId()); |
|
27 |
|
|
28 |
job.setAction("DELETE"); |
|
29 |
job.getParameters().put("id", getIndexId()); |
|
30 |
job.getParameters().put("backend_Id", defaultIndexId); |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
public String getIndexId() { |
|
35 |
return indexId; |
|
36 |
} |
|
37 |
|
|
38 |
public void setIndexId(final String indexId) { |
|
39 |
this.indexId = indexId; |
|
40 |
} |
|
41 |
|
|
42 |
public String getDefaultIndexId() { |
|
43 |
return defaultIndexId; |
|
44 |
} |
|
45 |
|
|
46 |
public void setDefaultIndexId(final String defaultIndexId) { |
|
47 |
this.defaultIndexId = defaultIndexId; |
|
48 |
} |
|
49 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/db/ExecuteSqlJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.db; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import org.apache.commons.io.IOUtils; |
|
8 |
|
|
9 |
import com.googlecode.sarasvati.Arc; |
|
10 |
import com.googlecode.sarasvati.NodeToken; |
|
11 |
|
|
12 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
13 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
14 |
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode; |
|
15 |
|
|
16 |
public class ExecuteSqlJobNode extends AsyncJobNode { |
|
17 |
|
|
18 |
private String db; |
|
19 |
private String dbParam; |
|
20 |
private String dbProperty; |
|
21 |
|
|
22 |
private String sql; |
|
23 |
|
|
24 |
@Resource |
|
25 |
private UniqueServiceLocator serviceLocator; |
|
26 |
|
|
27 |
@Override |
|
28 |
protected String execute(final NodeToken token) throws Exception { |
|
29 |
serviceLocator.getService(DatabaseService.class).updateSQL(findDb(token), fetchSqlAsText(sql)); |
|
30 |
|
|
31 |
return Arc.DEFAULT_ARC; |
|
32 |
} |
|
33 |
|
|
34 |
private String fetchSqlAsText(final String path) throws IOException { |
|
35 |
return IOUtils.toString(getClass().getResourceAsStream(path)); |
|
36 |
} |
|
37 |
|
|
38 |
private String findDb(final NodeToken token) { |
|
39 |
if (dbParam != null && !dbParam.isEmpty()) { |
|
40 |
return token.getEnv().getAttribute(dbParam); |
|
41 |
} else if (dbProperty != null && !dbProperty.isEmpty()) { |
|
42 |
return getPropertyFetcher().getProperty(dbProperty); |
|
43 |
} else { |
|
44 |
return db; |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public String getDb() { |
|
49 |
return db; |
|
50 |
} |
|
51 |
|
|
52 |
public void setDb(final String db) { |
|
53 |
this.db = db; |
|
54 |
} |
|
55 |
|
|
56 |
public String getDbParam() { |
|
57 |
return dbParam; |
|
58 |
} |
|
59 |
|
|
60 |
public void setDbParam(final String dbParam) { |
|
61 |
this.dbParam = dbParam; |
|
62 |
} |
|
63 |
|
|
64 |
public String getDbProperty() { |
|
65 |
return dbProperty; |
|
66 |
} |
|
67 |
|
|
68 |
public void setDbProperty(final String dbProperty) { |
|
69 |
this.dbProperty = dbProperty; |
|
70 |
} |
|
71 |
|
|
72 |
public String getSql() { |
|
73 |
return sql; |
|
74 |
} |
|
75 |
|
|
76 |
public void setSql(final String sql) { |
|
77 |
this.sql = sql; |
|
78 |
} |
|
79 |
|
|
80 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/SetEnvParameterJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.Arc; |
|
4 |
import com.googlecode.sarasvati.NodeToken; |
|
5 |
|
|
6 |
public class SetEnvParameterJobNode extends SimpleJobNode { |
|
7 |
|
|
8 |
private String parameterName; |
|
9 |
private String parameterValue; |
|
10 |
|
|
11 |
@Override |
|
12 |
protected String execute(final NodeToken token) throws Exception { |
|
13 |
token.getEnv().setAttribute(parameterName, parameterValue); |
|
14 |
return Arc.DEFAULT_ARC; |
|
15 |
} |
|
16 |
|
|
17 |
public String getParameterName() { |
|
18 |
return parameterName; |
|
19 |
} |
|
20 |
|
|
21 |
public void setParameterName(final String parameterName) { |
|
22 |
this.parameterName = parameterName; |
|
23 |
} |
|
24 |
|
|
25 |
public String getParameterValue() { |
|
26 |
return parameterValue; |
|
27 |
} |
|
28 |
|
|
29 |
public void setParameterValue(final String parameterValue) { |
|
30 |
this.parameterValue = parameterValue; |
|
31 |
} |
|
32 |
|
|
33 |
} |
modules/dnet-msro-service/branches/dsm/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/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/unpack/UnpackJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.unpack; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.Queue; |
|
6 |
import java.util.concurrent.PriorityBlockingQueue; |
|
7 |
|
|
8 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
9 |
|
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.dom4j.Document; |
|
13 |
import org.dom4j.Node; |
|
14 |
import org.dom4j.io.SAXReader; |
|
15 |
import org.springframework.beans.factory.annotation.Required; |
|
16 |
|
|
17 |
import com.googlecode.sarasvati.Arc; |
|
18 |
import com.googlecode.sarasvati.NodeToken; |
|
19 |
|
|
20 |
import eu.dnetlib.enabling.resultset.IterableResultSetFactory; |
|
21 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
22 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
23 |
|
|
24 |
public class UnpackJobNode extends SimpleJobNode { |
|
25 |
|
|
26 |
/** |
|
27 |
* logger. |
|
28 |
*/ |
|
29 |
private static final Log log = LogFactory.getLog(UnpackJobNode.class); |
|
30 |
|
|
31 |
private String inputEprParam; |
|
32 |
private String outputEprParam; |
|
33 |
private String xpath; |
|
34 |
|
|
35 |
private IterableResultSetFactory iterableResultSetFactory; |
|
36 |
private ResultSetClientFactory resultSetClientFactory; |
|
37 |
|
|
38 |
@Override |
|
39 |
protected String execute(final NodeToken token) throws Exception { |
|
40 |
final Iterator<String> client = resultSetClientFactory.getClient(token.getEnv().getAttribute(inputEprParam)).iterator(); |
|
41 |
final Queue<String> queue = new PriorityBlockingQueue<String>(); |
|
42 |
|
|
43 |
while (queue.isEmpty() && client.hasNext()) { |
|
44 |
populateQueue(queue, client.next(), xpath); |
|
45 |
} |
|
46 |
|
|
47 |
final W3CEndpointReference epr = iterableResultSetFactory.createIterableResultSet(new Iterable<String>() { |
|
48 |
|
|
49 |
@Override |
|
50 |
public Iterator<String> iterator() { |
|
51 |
return new Iterator<String>() { |
|
52 |
|
|
53 |
@Override |
|
54 |
public boolean hasNext() { |
|
55 |
synchronized (queue) { |
|
56 |
return !queue.isEmpty(); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String next() { |
|
62 |
synchronized (queue) { |
|
63 |
final String res = queue.poll(); |
|
64 |
while (queue.isEmpty() && client.hasNext()) { |
|
65 |
populateQueue(queue, client.next(), xpath); |
|
66 |
} |
|
67 |
return res; |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void remove() {} |
|
73 |
}; |
|
74 |
} |
|
75 |
}); |
|
76 |
|
|
77 |
token.getEnv().setAttribute(outputEprParam, epr.toString()); |
|
78 |
|
|
79 |
return Arc.DEFAULT_ARC; |
|
80 |
} |
|
81 |
|
|
82 |
private void populateQueue(final Queue<String> queue, final String record, final String xpath) { |
|
83 |
try { |
|
84 |
final SAXReader reader = new SAXReader(); |
|
85 |
final Document doc = reader.read(new StringReader(record)); |
|
86 |
for (Object o : doc.selectNodes(xpath)) { |
|
87 |
queue.add(((Node) o).asXML()); |
|
88 |
} |
|
89 |
} catch (Exception e) { |
|
90 |
log.error("Error unpacking record: \n" + record, e); |
|
91 |
throw new RuntimeException(e); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
public IterableResultSetFactory getIterableResultSetFactory() { |
|
96 |
return iterableResultSetFactory; |
|
97 |
} |
|
98 |
|
|
99 |
@Required |
|
100 |
public void setIterableResultSetFactory(final IterableResultSetFactory iterableResultSetFactory) { |
|
101 |
this.iterableResultSetFactory = iterableResultSetFactory; |
|
102 |
} |
|
103 |
|
|
104 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
105 |
return resultSetClientFactory; |
|
106 |
} |
|
107 |
|
|
108 |
@Required |
|
109 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
110 |
this.resultSetClientFactory = resultSetClientFactory; |
|
111 |
} |
|
112 |
|
|
113 |
public String getInputEprParam() { |
|
114 |
return inputEprParam; |
|
115 |
} |
|
116 |
|
|
117 |
public void setInputEprParam(final String inputEprParam) { |
|
118 |
this.inputEprParam = inputEprParam; |
|
119 |
} |
|
120 |
|
|
121 |
public String getOutputEprParam() { |
|
122 |
return outputEprParam; |
|
123 |
} |
|
124 |
|
|
125 |
public void setOutputEprParam(final String outputEprParam) { |
|
126 |
this.outputEprParam = outputEprParam; |
|
127 |
} |
|
128 |
|
|
129 |
public String getXpath() { |
|
130 |
return xpath; |
|
131 |
} |
|
132 |
|
|
133 |
public void setXpath(final String xpath) { |
|
134 |
this.xpath = xpath; |
|
135 |
} |
|
136 |
|
|
137 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/SetFormatInfoJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes; |
|
2 |
|
|
3 |
import static java.lang.String.format; |
|
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.msro.workflows.nodes.SimpleJobNode; |
|
12 |
|
|
13 |
public class SetFormatInfoJobNode extends SimpleJobNode { |
|
14 |
|
|
15 |
/** |
|
16 |
* logger. |
|
17 |
*/ |
|
18 |
private static final Log log = LogFactory.getLog(SetFormatInfoJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
19 |
|
|
20 |
private String format; |
|
21 |
private String formatParam = "format"; |
|
22 |
|
|
23 |
private String layout; |
|
24 |
private String layoutParam = "layout"; |
|
25 |
|
|
26 |
private String interpretation; |
|
27 |
private String interpretationParam = "interpretation"; |
|
28 |
|
|
29 |
/** |
|
30 |
* {@inheritDoc} |
|
31 |
* |
|
32 |
* @see com.googlecode.sarasvati.mem.MemNode#execute(com.googlecode.sarasvati.Engine, com.googlecode.sarasvati.NodeToken) |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public String execute(final NodeToken token) { |
|
36 |
|
|
37 |
log.info(format("setting mdFromat: %s, layout: %s, interpretation: %s", getFormat(), getLayout(), getInterpretation())); |
|
38 |
|
|
39 |
token.getEnv().setAttribute(getFormatParam(), getFormat()); |
|
40 |
token.getEnv().setAttribute(getLayoutParam(), getLayout()); |
|
41 |
token.getEnv().setAttribute(getInterpretationParam(), getInterpretation()); |
|
42 |
|
|
43 |
return Arc.DEFAULT_ARC; |
|
44 |
} |
|
45 |
|
|
46 |
public String getFormat() { |
|
47 |
return format; |
|
48 |
} |
|
49 |
|
|
50 |
public void setFormat(final String format) { |
|
51 |
this.format = format; |
|
52 |
} |
|
53 |
|
|
54 |
public String getLayout() { |
|
55 |
return layout; |
|
56 |
} |
|
57 |
|
|
58 |
public void setLayout(final String layout) { |
|
59 |
this.layout = layout; |
|
60 |
} |
|
61 |
|
|
62 |
public String getInterpretation() { |
|
63 |
return interpretation; |
|
64 |
} |
|
65 |
|
|
66 |
public void setInterpretation(final String interpretation) { |
|
67 |
this.interpretation = interpretation; |
|
68 |
} |
|
69 |
|
|
70 |
public String getFormatParam() { |
|
71 |
return formatParam; |
|
72 |
} |
|
73 |
|
|
74 |
public void setFormatParam(final String formatParam) { |
|
75 |
this.formatParam = formatParam; |
|
76 |
} |
|
77 |
|
|
78 |
public String getLayoutParam() { |
|
79 |
return layoutParam; |
|
80 |
} |
|
81 |
|
|
82 |
public void setLayoutParam(final String layoutParam) { |
|
83 |
this.layoutParam = layoutParam; |
|
84 |
} |
|
85 |
|
|
86 |
public String getInterpretationParam() { |
|
87 |
return interpretationParam; |
|
88 |
} |
|
89 |
|
|
90 |
public void setInterpretationParam(final String interpretationParam) { |
|
91 |
this.interpretationParam = interpretationParam; |
|
92 |
} |
|
93 |
|
|
94 |
} |
modules/dnet-msro-service/branches/dsm/src/main/java/eu/dnetlib/msro/workflows/nodes/collect/FindDateRangeForIncrementalHarvestingJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.collect; |
|
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
import java.util.Date; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import javax.annotation.Resource; |
|
9 |
|
|
10 |
import org.apache.commons.lang.math.NumberUtils; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
|
|
14 |
import com.googlecode.sarasvati.Arc; |
|
15 |
import com.googlecode.sarasvati.NodeToken; |
|
16 |
|
|
17 |
import eu.dnetlib.common.logging.DnetLogger; |
|
18 |
import eu.dnetlib.msro.rmi.MSROException; |
|
19 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
20 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
21 |
|
|
22 |
public class FindDateRangeForIncrementalHarvestingJobNode extends SimpleJobNode { |
|
23 |
|
|
24 |
private String fromDateParam; |
|
25 |
private String untilDateParam; |
|
26 |
private long ONE_DAY = 1000 * 60 * 60 * 24; |
|
27 |
|
|
28 |
@Resource(name = "msroWorkflowLogger") |
|
29 |
private DnetLogger dnetLogger; |
Also available in: Unified diff
branch for new dsm