Revision 50837
Added by Michele Artini over 6 years ago
modules/dnet-msro-service/tags/dnet-msro-service-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/objectStore/RetrieveURLSJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.objectStore; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
5 |
|
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.beans.factory.annotation.Required; |
|
8 |
|
|
9 |
import com.google.common.collect.Iterables; |
|
10 |
import com.googlecode.sarasvati.Arc; |
|
11 |
import com.googlecode.sarasvati.NodeToken; |
|
12 |
|
|
13 |
import eu.dnetlib.enabling.resultset.IterableResultSetFactory; |
|
14 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
15 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
16 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
17 |
import eu.dnetlib.msro.workflows.nodes.download.UrlExtractor; |
|
18 |
|
|
19 |
// TODO: Auto-generated Javadoc |
|
20 |
/** |
|
21 |
* The Class RetrieveURLSJobNode. |
|
22 |
*/ |
|
23 |
public class RetrieveURLSJobNode extends SimpleJobNode { |
|
24 |
|
|
25 |
/** The epr param. */ |
|
26 |
private String inputEprParam; |
|
27 |
|
|
28 |
/** The output epr param. */ |
|
29 |
private String outputEprParam; |
|
30 |
|
|
31 |
/** The xpath. */ |
|
32 |
private String xpath; |
|
33 |
|
|
34 |
/** The xpath metadata id. */ |
|
35 |
private String xpathMetadataId; |
|
36 |
|
|
37 |
/** The xpath open access. */ |
|
38 |
private String xpathOpenAccess; |
|
39 |
|
|
40 |
/** The xpath embargo date. */ |
|
41 |
private String xpathEmbargoDate; |
|
42 |
|
|
43 |
/** The result set client factory. */ |
|
44 |
@Autowired |
|
45 |
private ResultSetClientFactory resultSetClientFactory; |
|
46 |
|
|
47 |
/** The result set factory. */ |
|
48 |
@Resource(name = "iterableResultSetFactory") |
|
49 |
private IterableResultSetFactory resultSetFactory; |
|
50 |
|
|
51 |
/* |
|
52 |
* (non-Javadoc) |
|
53 |
* |
|
54 |
* @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken) |
|
55 |
*/ |
|
56 |
@Override |
|
57 |
protected String execute(final NodeToken token) throws Exception { |
|
58 |
final W3CEndpointReference inputEpr = (new EPRUtils()).getEpr(token.getEnv().getAttribute(inputEprParam)); |
|
59 |
Iterable<String> input = resultSetClientFactory.getClient(inputEpr); |
|
60 |
Iterable<String> extractedUrls = Iterables.transform(input, new UrlExtractor(xpath, xpathMetadataId, xpathOpenAccess, xpathEmbargoDate)); |
|
61 |
W3CEndpointReference eprUrls = resultSetFactory.createIterableResultSet(extractedUrls); |
|
62 |
token.getEnv().setAttribute(getOutputEprParam(), eprUrls.toString()); |
|
63 |
return Arc.DEFAULT_ARC; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Gets the xpath. |
|
68 |
* |
|
69 |
* @return the xpath |
|
70 |
*/ |
|
71 |
public String getXpath() { |
|
72 |
return xpath; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Sets the xpath. |
|
77 |
* |
|
78 |
* @param xpath |
|
79 |
* the xpath to set |
|
80 |
*/ |
|
81 |
public void setXpath(final String xpath) { |
|
82 |
this.xpath = xpath; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Gets the xpath metadata id. |
|
87 |
* |
|
88 |
* @return the xpathMetadataId |
|
89 |
*/ |
|
90 |
public String getXpathMetadataId() { |
|
91 |
return xpathMetadataId; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Sets the xpath metadata id. |
|
96 |
* |
|
97 |
* @param xpathMetadataId |
|
98 |
* the xpathMetadataId to set |
|
99 |
*/ |
|
100 |
@Required |
|
101 |
public void setXpathMetadataId(final String xpathMetadataId) { |
|
102 |
this.xpathMetadataId = xpathMetadataId; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Gets the result set client factory. |
|
107 |
* |
|
108 |
* @return the resultSetClientFactory |
|
109 |
*/ |
|
110 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
111 |
return resultSetClientFactory; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Sets the result set client factory. |
|
116 |
* |
|
117 |
* @param resultSetClientFactory |
|
118 |
* the resultSetClientFactory to set |
|
119 |
*/ |
|
120 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
121 |
this.resultSetClientFactory = resultSetClientFactory; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Gets the result set factory. |
|
126 |
* |
|
127 |
* @return the resultSetFactory |
|
128 |
*/ |
|
129 |
public IterableResultSetFactory getResultSetFactory() { |
|
130 |
return resultSetFactory; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Sets the result set factory. |
|
135 |
* |
|
136 |
* @param resultSetFactory |
|
137 |
* the resultSetFactory to set |
|
138 |
*/ |
|
139 |
public void setResultSetFactory(final IterableResultSetFactory resultSetFactory) { |
|
140 |
this.resultSetFactory = resultSetFactory; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Gets the output epr param. |
|
145 |
* |
|
146 |
* @return the outputEprParam |
|
147 |
*/ |
|
148 |
public String getOutputEprParam() { |
|
149 |
return outputEprParam; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Sets the output epr param. |
|
154 |
* |
|
155 |
* @param outputEprParam |
|
156 |
* the outputEprParam to set |
|
157 |
*/ |
|
158 |
public void setOutputEprParam(final String outputEprParam) { |
|
159 |
this.outputEprParam = outputEprParam; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Gets the input epr param. |
|
164 |
* |
|
165 |
* @return the inputEprParam |
|
166 |
*/ |
|
167 |
public String getInputEprParam() { |
|
168 |
return inputEprParam; |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Sets the input epr param. |
|
173 |
* |
|
174 |
* @param inputEprParam |
|
175 |
* the inputEprParam to set |
|
176 |
*/ |
|
177 |
public void setInputEprParam(final String inputEprParam) { |
|
178 |
this.inputEprParam = inputEprParam; |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Gets the xpath open access. |
|
183 |
* |
|
184 |
* @return the xpath open access |
|
185 |
*/ |
|
186 |
public String getXpathOpenAccess() { |
|
187 |
return xpathOpenAccess; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Sets the xpath open access. |
|
192 |
* |
|
193 |
* @param xpathOpenAccess |
|
194 |
* the new xpath open access |
|
195 |
*/ |
|
196 |
public void setXpathOpenAccess(final String xpathOpenAccess) { |
|
197 |
this.xpathOpenAccess = xpathOpenAccess; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* Gets the xpath embargo date. |
|
202 |
* |
|
203 |
* @return the xpath embargo date |
|
204 |
*/ |
|
205 |
public String getXpathEmbargoDate() { |
|
206 |
return xpathEmbargoDate; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Sets the xpath embargo date. |
|
211 |
* |
|
212 |
* @param xpathEmbargoDate |
|
213 |
* the new xpath embargo date |
|
214 |
*/ |
|
215 |
public void setXpathEmbargoDate(final String xpathEmbargoDate) { |
|
216 |
this.xpathEmbargoDate = xpathEmbargoDate; |
|
217 |
} |
|
218 |
|
|
219 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/sel/SelectiveNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.sel; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.Arc; |
|
4 |
import com.googlecode.sarasvati.NodeToken; |
|
5 |
|
|
6 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
7 |
import eu.dnetlib.msro.workflows.util.WorkflowParam; |
|
8 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
9 |
|
|
10 |
/** |
|
11 |
* The Class SelectiveNode allows to decide which path a workflow must take. |
|
12 |
*/ |
|
13 |
public class SelectiveNode extends SimpleJobNode { |
|
14 |
|
|
15 |
/** The selection. */ |
|
16 |
private String selection = Arc.DEFAULT_ARC; |
|
17 |
|
|
18 |
/* |
|
19 |
* (non-Javadoc) |
|
20 |
* |
|
21 |
* @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken) |
|
22 |
*/ |
|
23 |
@Override |
|
24 |
protected String execute(final NodeToken token) throws Exception { |
|
25 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "selection", getSelection()); |
|
26 |
return getSelection(); |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Gets the selection. |
|
31 |
* |
|
32 |
* @return the selection |
|
33 |
*/ |
|
34 |
public String getSelection() { |
|
35 |
return selection; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Sets the selection. |
|
40 |
* |
|
41 |
* @param selection |
|
42 |
* the new selection |
|
43 |
*/ |
|
44 |
public void setSelection(final String selection) { |
|
45 |
this.selection = selection; |
|
46 |
} |
|
47 |
|
|
48 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/download/UrlExtractor.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.download; |
|
2 |
|
|
3 |
import java.io.ByteArrayInputStream; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.xml.parsers.DocumentBuilder; |
|
8 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
9 |
import javax.xml.xpath.XPath; |
|
10 |
import javax.xml.xpath.XPathConstants; |
|
11 |
import javax.xml.xpath.XPathExpression; |
|
12 |
import javax.xml.xpath.XPathFactory; |
|
13 |
|
|
14 |
import org.apache.commons.lang.StringUtils; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.joda.time.DateTime; |
|
18 |
import org.joda.time.format.DateTimeFormat; |
|
19 |
import org.joda.time.format.DateTimeFormatter; |
|
20 |
import org.w3c.dom.Document; |
|
21 |
import org.w3c.dom.NodeList; |
|
22 |
|
|
23 |
import com.google.common.base.Function; |
|
24 |
import com.google.gson.Gson; |
|
25 |
|
|
26 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
27 |
|
|
28 |
// TODO: Auto-generated Javadoc |
|
29 |
/** |
|
30 |
* The Class UrlExtractor. |
|
31 |
*/ |
|
32 |
public class UrlExtractor implements Function<String, String> { |
|
33 |
|
|
34 |
/** The Constant log. */ |
|
35 |
private static final Log log = LogFactory.getLog(UrlExtractor.class); |
|
36 |
|
|
37 |
/** The xpath url. */ |
|
38 |
private String xpathURL; |
|
39 |
|
|
40 |
/** The xpath. */ |
|
41 |
private String xpathMetadataID; |
|
42 |
|
|
43 |
/** The xpath open access. */ |
|
44 |
private String xpathOpenAccess; |
|
45 |
|
|
46 |
/** The xpath embargo date. */ |
|
47 |
private String xpathEmbargoDate; |
|
48 |
|
|
49 |
/** |
|
50 |
* Instantiates a new url extractor. |
|
51 |
* |
|
52 |
* @param xpath |
|
53 |
* the xpath |
|
54 |
* @param xpathMetadataID |
|
55 |
* the xpath metadata id |
|
56 |
*/ |
|
57 |
public UrlExtractor(final String xpath, final String xpathMetadataID, final String xpathOpenAccess, final String xpathEmbargoDate) { |
|
58 |
this.xpathURL = xpath; |
|
59 |
this.xpathMetadataID = xpathMetadataID; |
|
60 |
this.xpathOpenAccess = xpathOpenAccess; |
|
61 |
this.xpathEmbargoDate = xpathEmbargoDate; |
|
62 |
} |
|
63 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* |
|
67 |
* @see com.google.common.base.Function#apply(java.lang.Object) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public String apply(final String input) { |
|
71 |
try { |
|
72 |
DownloadItem di = new DownloadItem(); |
|
73 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
74 |
DocumentBuilder builder; |
|
75 |
builder = factory.newDocumentBuilder(); |
|
76 |
if (input == null) { |
|
77 |
log.error("Metadata input is null"); |
|
78 |
return null; |
|
79 |
} |
|
80 |
Document doc = builder.parse(new ByteArrayInputStream(input.getBytes())); |
|
81 |
XPathFactory xPathFactory = XPathFactory.newInstance(); |
|
82 |
XPath myXpath = xPathFactory.newXPath(); |
|
83 |
XPathExpression expression = myXpath.compile(xpathURL); |
|
84 |
Object values = expression.evaluate(doc, XPathConstants.NODESET); |
|
85 |
di.setUrl(getNodes((NodeList) values)); |
|
86 |
di.setOriginalUrl(getNodes((NodeList) values)); |
|
87 |
|
|
88 |
if (xpathOpenAccess != null) { |
|
89 |
expression = myXpath.compile(xpathOpenAccess); |
|
90 |
String openAccess = expression.evaluate(doc); |
|
91 |
di.setOpenAccess(openAccess); |
|
92 |
} |
|
93 |
if (xpathEmbargoDate != null) { |
|
94 |
expression = myXpath.compile(xpathEmbargoDate); |
|
95 |
String embargoDate = expression.evaluate(doc); |
|
96 |
if (!StringUtils.isEmpty(embargoDate)) { |
|
97 |
try { |
|
98 |
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); |
|
99 |
DateTime dt = fmt.parseDateTime(embargoDate); |
|
100 |
di.setEmbargoDate(dt.toDate()); |
|
101 |
} catch (Exception pe) {} |
|
102 |
} |
|
103 |
} |
|
104 |
expression = myXpath.compile(xpathMetadataID); |
|
105 |
String extracted_metadataId = expression.evaluate(doc); |
|
106 |
di.setIdItemMetadata(extracted_metadataId); |
|
107 |
return di.toJSON(); |
|
108 |
} catch (Exception e) { |
|
109 |
log.error("OPSSS... Something bad happen on evaluating ", e); |
|
110 |
return null; |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Gets the nodes. |
|
117 |
* |
|
118 |
* @param nodes |
|
119 |
* the nodes |
|
120 |
* @return the nodes |
|
121 |
*/ |
|
122 |
private String getNodes(final NodeList nodes) { |
|
123 |
List<String> extracted_Url = new ArrayList<String>(); |
|
124 |
if (nodes != null) { |
|
125 |
for (int i = 0; i < nodes.getLength(); i++) { |
|
126 |
extracted_Url.add(nodes.item(i).getNodeValue()); |
|
127 |
} |
|
128 |
} |
|
129 |
return new Gson().toJson(extracted_Url); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Gets the xpath metadata id. |
|
134 |
* |
|
135 |
* @return the xpathMetadataID |
|
136 |
*/ |
|
137 |
public String getXpathMetadataID() { |
|
138 |
return xpathMetadataID; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Sets the xpath metadata id. |
|
143 |
* |
|
144 |
* @param xpathMetadataID |
|
145 |
* the xpathMetadataID to set |
|
146 |
*/ |
|
147 |
public void setXpathMetadataID(final String xpathMetadataID) { |
|
148 |
this.xpathMetadataID = xpathMetadataID; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Gets the xpath url. |
|
153 |
* |
|
154 |
* @return the xpath url |
|
155 |
*/ |
|
156 |
public String getXpathURL() { |
|
157 |
return xpathURL; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Sets the xpath url. |
|
162 |
* |
|
163 |
* @param xpathURL |
|
164 |
* the new xpath url |
|
165 |
*/ |
|
166 |
public void setXpathURL(final String xpathURL) { |
|
167 |
this.xpathURL = xpathURL; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Gets the xpath open access. |
|
172 |
* |
|
173 |
* @return the xpath open access |
|
174 |
*/ |
|
175 |
public String getXpathOpenAccess() { |
|
176 |
return xpathOpenAccess; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* Sets the xpath open access. |
|
181 |
* |
|
182 |
* @param xpathOpenAccess |
|
183 |
* the new xpath open access |
|
184 |
*/ |
|
185 |
public void setXpathOpenAccess(final String xpathOpenAccess) { |
|
186 |
this.xpathOpenAccess = xpathOpenAccess; |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Gets the xpath embargo date. |
|
191 |
* |
|
192 |
* @return the xpath embargo date |
|
193 |
*/ |
|
194 |
public String getXpathEmbargoDate() { |
|
195 |
return xpathEmbargoDate; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Sets the xpath embargo date. |
|
200 |
* |
|
201 |
* @param xpathEmbargoDate |
|
202 |
* the new xpath embargo date |
|
203 |
*/ |
|
204 |
public void setXpathEmbargoDate(final String xpathEmbargoDate) { |
|
205 |
this.xpathEmbargoDate = xpathEmbargoDate; |
|
206 |
} |
|
207 |
|
|
208 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-3.2.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-3.2.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-3.2.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-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/db/UpdateDbJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.db; |
|
2 |
|
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 |
import org.springframework.beans.factory.annotation.Required; |
|
6 |
|
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
|
|
9 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
10 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
11 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
12 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
13 |
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory; |
|
14 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
15 |
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider; |
|
16 |
|
|
17 |
public class UpdateDbJobNode extends BlackboardJobNode implements ProgressJobNode { |
|
18 |
|
|
19 |
private String db; |
|
20 |
private String dbParam; |
|
21 |
private String eprParam; |
|
22 |
private ProcessCountingResultSetFactory processCountingResultSetFactory; |
|
23 |
private ResultsetProgressProvider progressProvider; |
|
24 |
|
|
25 |
private static final Log log = LogFactory.getLog(UpdateDbJobNode.class); |
|
26 |
|
|
27 |
@Override |
|
28 |
protected String obtainServiceId(final NodeToken token) { |
|
29 |
return getServiceLocator().getServiceId(DatabaseService.class); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
34 |
if (db == null || db.isEmpty()) { |
|
35 |
db = token.getEnv().getAttribute(getDbParam()); |
|
36 |
} |
|
37 |
|
|
38 |
log.info("preparing blackboard job to update DB: " + db); |
|
39 |
|
|
40 |
final String epr = token.getEnv().getAttribute(getEprParam()); |
|
41 |
|
|
42 |
this.progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), epr); |
|
43 |
|
|
44 |
job.setAction("IMPORT"); |
|
45 |
job.getParameters().put("db", db); |
|
46 |
job.getParameters().put("epr", this.progressProvider.getEpr().toString()); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public ProgressProvider getProgressProvider() { |
|
51 |
return progressProvider; |
|
52 |
} |
|
53 |
|
|
54 |
public String getDb() { |
|
55 |
return db; |
|
56 |
} |
|
57 |
|
|
58 |
public void setDb(final String db) { |
|
59 |
this.db = db; |
|
60 |
} |
|
61 |
|
|
62 |
public String getEprParam() { |
|
63 |
return eprParam; |
|
64 |
} |
|
65 |
|
|
66 |
public void setEprParam(final String eprParam) { |
|
67 |
this.eprParam = eprParam; |
|
68 |
} |
|
69 |
|
|
70 |
public ProcessCountingResultSetFactory getProcessCountingResultSetFactory() { |
|
71 |
return processCountingResultSetFactory; |
|
72 |
} |
|
73 |
|
|
74 |
@Required |
|
75 |
public void setProcessCountingResultSetFactory(final ProcessCountingResultSetFactory processCountingResultSetFactory) { |
|
76 |
this.processCountingResultSetFactory = processCountingResultSetFactory; |
|
77 |
} |
|
78 |
|
|
79 |
public String getDbParam() { |
|
80 |
return dbParam; |
|
81 |
} |
|
82 |
|
|
83 |
public void setDbParam(final String dbParam) { |
|
84 |
this.dbParam = dbParam; |
|
85 |
} |
|
86 |
|
|
87 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-3.2.1/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/tags/dnet-msro-service-3.2.1/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/tags/dnet-msro-service-3.2.1/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/tags/dnet-msro-service-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/index/UpdateIndexJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.index; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringReader; |
|
5 |
import java.io.StringWriter; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
import javax.xml.transform.Transformer; |
|
9 |
import javax.xml.transform.TransformerConfigurationException; |
|
10 |
import javax.xml.transform.TransformerException; |
|
11 |
import javax.xml.transform.TransformerFactory; |
|
12 |
import javax.xml.transform.dom.DOMResult; |
|
13 |
import javax.xml.transform.dom.DOMSource; |
|
14 |
import javax.xml.transform.stream.StreamResult; |
|
15 |
import javax.xml.transform.stream.StreamSource; |
|
16 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
17 |
|
|
18 |
import org.apache.commons.codec.binary.Base64; |
|
19 |
import org.apache.commons.logging.Log; |
|
20 |
import org.apache.commons.logging.LogFactory; |
|
21 |
import org.springframework.beans.factory.annotation.Required; |
|
22 |
|
|
23 |
import com.googlecode.sarasvati.NodeToken; |
|
24 |
|
|
25 |
import eu.dnetlib.data.provision.index.rmi.IndexService; |
|
26 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
|
27 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
28 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
29 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
30 |
import eu.dnetlib.enabling.resultset.XSLTMappedResultSetFactory; |
|
31 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
32 |
import eu.dnetlib.enabling.resultset.rmi.ResultSetException; |
|
33 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
34 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
35 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
36 |
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory; |
|
37 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
38 |
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider; |
|
39 |
|
|
40 |
public class UpdateIndexJobNode extends BlackboardJobNode implements ProgressJobNode { |
|
41 |
|
|
42 |
private static final Log log = LogFactory.getLog(UpdateIndexJobNode.class); |
|
43 |
|
|
44 |
private String eprParam; |
|
45 |
private String indexId; |
|
46 |
private String format; |
|
47 |
private String layout; |
|
48 |
private String feedingType; |
|
49 |
private String defaultIndexId; |
|
50 |
|
|
51 |
/** |
|
52 |
* xslt mapped resultset factory. |
|
53 |
*/ |
|
54 |
private XSLTMappedResultSetFactory xsltRSFactory; |
|
55 |
|
|
56 |
private ProcessCountingResultSetFactory processCountingResultSetFactory; |
|
57 |
private ResultsetProgressProvider progressProvider; |
|
58 |
|
|
59 |
/** |
|
60 |
* Stylesheet which transforms a layout to another stylesheet which converts a input record to a index record. |
|
61 |
*/ |
|
62 |
private org.springframework.core.io.Resource layoutToRecordStylesheet; |
|
63 |
|
|
64 |
/** |
|
65 |
* service locator. |
|
66 |
*/ |
|
67 |
@Resource |
|
68 |
private UniqueServiceLocator serviceLocator; |
|
69 |
|
|
70 |
@Override |
|
71 |
protected String obtainServiceId(final NodeToken token) { |
|
72 |
return getServiceLocator().getServiceId(IndexService.class); |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws ResultSetException, ISLookUpException, IOException, TransformerException { |
|
77 |
log.info("preparing blackboard job update index: " + getIndexId()); |
|
78 |
|
|
79 |
final W3CEndpointReference epr = new EPRUtils().getEpr(token.getEnv().getAttribute(getEprParam())); |
|
80 |
|
|
81 |
final W3CEndpointReference mappedEpr = prepareForIndexing(epr, getFormat(), getLayout()); |
|
82 |
|
|
83 |
progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), mappedEpr); |
|
84 |
|
|
85 |
job.setAction("FEED"); |
|
86 |
job.getParameters().put("resultset_epr", encode(progressProvider.getEpr().toString())); |
|
87 |
job.getParameters().put("id", getIndexId()); |
|
88 |
job.getParameters().put("feeding_type", getFeedingType()); |
|
89 |
job.getParameters().put("backend_Id", defaultIndexId); |
|
90 |
} |
|
91 |
|
|
92 |
// helpers |
|
93 |
|
|
94 |
/** |
|
95 |
* Transforms each mdstore record into a index record. |
|
96 |
* |
|
97 |
* @param mdStoreRsetEpr |
|
98 |
* mdstore resulsetset |
|
99 |
* @param layout |
|
100 |
* layout |
|
101 |
* @param format |
|
102 |
* format |
|
103 |
* @return resultset with transformed records |
|
104 |
* @throws ISLookUpException |
|
105 |
* could happen |
|
106 |
* @throws IOException |
|
107 |
* could happen |
|
108 |
* @throws TransformerException |
|
109 |
* could happen |
|
110 |
*/ |
|
111 |
protected W3CEndpointReference prepareForIndexing(final W3CEndpointReference mdStoreRsetEpr, final String format, final String layout) |
|
112 |
throws ISLookUpException, IOException, TransformerException { |
|
113 |
|
|
114 |
final TransformerFactory factory = TransformerFactory.newInstance(); |
|
115 |
final Transformer layoutTransformer = factory.newTransformer(new StreamSource(getLayoutToRecordStylesheet().getInputStream())); |
|
116 |
|
|
117 |
final DOMResult layoutToXsltXslt = new DOMResult(); |
|
118 |
layoutTransformer.setParameter("format", format); |
|
119 |
layoutTransformer.transform(new StreamSource(new StringReader(getLayoutSource(format, layout))), layoutToXsltXslt); |
|
120 |
|
|
121 |
dumpXslt(factory, layoutToXsltXslt); |
|
122 |
|
|
123 |
return getXsltRSFactory().createMappedResultSet(mdStoreRsetEpr, new DOMSource(layoutToXsltXslt.getNode()), |
|
124 |
"dynamic layout xslt for " + format + ", " + layout); |
|
125 |
} |
|
126 |
|
|
127 |
private String getLayoutSource(final String format, final String layout) throws ISLookUpDocumentNotFoundException, ISLookUpException { |
|
128 |
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery( |
|
129 |
"collection('')//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'MDFormatDSResourceType' and .//NAME='" + format + "']//LAYOUT[@name='" + layout |
|
130 |
+ "']"); |
|
131 |
} |
|
132 |
|
|
133 |
private void dumpXslt(final TransformerFactory factory, final DOMResult layoutToXsltXslt) throws TransformerConfigurationException, TransformerException { |
|
134 |
if (log.isDebugEnabled()) { |
|
135 |
final StringWriter buffer = new StringWriter(); |
|
136 |
factory.newTransformer().transform(new DOMSource(layoutToXsltXslt.getNode()), new StreamResult(buffer)); |
|
137 |
log.debug(buffer.toString()); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
private String encode(final String epr) { |
|
142 |
return new String(Base64.encodeBase64(epr.getBytes())); |
|
143 |
} |
|
144 |
|
|
145 |
// setters and getters |
|
146 |
|
|
147 |
public String getIndexId() { |
|
148 |
return indexId; |
|
149 |
} |
|
150 |
|
|
151 |
public void setIndexId(final String indexId) { |
|
152 |
this.indexId = indexId; |
|
153 |
} |
|
154 |
|
|
155 |
public String getEprParam() { |
|
156 |
return eprParam; |
|
157 |
} |
|
158 |
|
|
159 |
public void setEprParam(final String eprParam) { |
|
160 |
this.eprParam = eprParam; |
|
161 |
} |
|
162 |
|
|
163 |
public String getFeedingType() { |
|
164 |
return feedingType; |
|
165 |
} |
|
166 |
|
|
167 |
public void setFeedingType(final String feedingType) { |
|
168 |
this.feedingType = feedingType; |
|
169 |
} |
|
170 |
|
|
171 |
public ProcessCountingResultSetFactory getProcessCountingResultSetFactory() { |
|
172 |
return processCountingResultSetFactory; |
|
173 |
} |
|
174 |
|
|
175 |
@Required |
|
176 |
public void setProcessCountingResultSetFactory(final ProcessCountingResultSetFactory processCountingResultSetFactory) { |
|
177 |
this.processCountingResultSetFactory = processCountingResultSetFactory; |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public ProgressProvider getProgressProvider() { |
|
182 |
return progressProvider; |
|
183 |
} |
|
184 |
|
|
185 |
public org.springframework.core.io.Resource getLayoutToRecordStylesheet() { |
|
186 |
return layoutToRecordStylesheet; |
|
187 |
} |
|
188 |
|
|
189 |
@Required |
|
190 |
public void setLayoutToRecordStylesheet(final org.springframework.core.io.Resource layoutToRecordStylesheet) { |
|
191 |
this.layoutToRecordStylesheet = layoutToRecordStylesheet; |
|
192 |
} |
|
193 |
|
|
194 |
public String getFormat() { |
|
195 |
return format; |
|
196 |
} |
|
197 |
|
|
198 |
public void setFormat(final String format) { |
|
199 |
this.format = format; |
|
200 |
} |
|
201 |
|
|
202 |
public String getLayout() { |
|
203 |
return layout; |
|
204 |
} |
|
205 |
|
|
206 |
public void setLayout(final String layout) { |
|
207 |
this.layout = layout; |
|
208 |
} |
|
209 |
|
|
210 |
public XSLTMappedResultSetFactory getXsltRSFactory() { |
|
211 |
return xsltRSFactory; |
|
212 |
} |
|
213 |
|
|
214 |
@Required |
|
215 |
public void setXsltRSFactory(final XSLTMappedResultSetFactory xsltRSFactory) { |
|
216 |
this.xsltRSFactory = xsltRSFactory; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* @return the defaultIndexId |
|
221 |
*/ |
|
222 |
public String getDefaultIndexId() { |
|
223 |
return defaultIndexId; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* @param defaultIndexId |
|
228 |
* the defaultIndexId to set |
|
229 |
*/ |
|
230 |
@Required |
|
231 |
public void setDefaultIndexId(final String defaultIndexId) { |
|
232 |
this.defaultIndexId = defaultIndexId; |
|
233 |
} |
|
234 |
|
|
235 |
} |
modules/dnet-msro-service/tags/dnet-msro-service-3.2.1/src/main/java/eu/dnetlib/msro/workflows/nodes/index/CreateIndexJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.workflows.nodes.index; |
|
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.data.provision.index.rmi.IndexService; |
|
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 |
// TODO: Auto-generated Javadoc |
|
19 |
/** |
|
20 |
* The Class CreateIndexJobNode. |
|
21 |
*/ |
|
22 |
public class CreateIndexJobNode extends BlackboardJobNode { |
|
23 |
|
|
24 |
/** The Constant log. */ |
|
25 |
private static final Log log = LogFactory.getLog(CreateIndexJobNode.class); |
|
26 |
|
|
27 |
/** The output prefix. */ |
|
28 |
private String outputPrefix = "index_"; |
|
29 |
|
|
30 |
/** The default backend id. */ |
|
31 |
private String defaultBackendId; |
|
32 |
|
|
33 |
/** The format. */ |
|
34 |
private String format; |
|
35 |
|
|
36 |
/** The layout. */ |
|
37 |
private String layout; |
|
38 |
|
|
39 |
/** The interpretation. */ |
|
40 |
private String interpretation; |
|
41 |
|
|
42 |
@Override |
|
43 |
protected String obtainServiceId(final NodeToken token) { |
|
44 |
return getServiceLocator().getServiceId(IndexService.class); |
|
45 |
} |
|
46 |
|
|
47 |
/* |
|
48 |
* (non-Javadoc) |
|
49 |
* |
|
50 |
* @see eu.dnetlib.msro.workflows.nodes.BlackboardJobNode#prepareJob(eu.dnetlib.enabling.tools.blackboard.BlackboardJob, |
|
51 |
* com.googlecode.sarasvati.NodeToken) |
|
52 |
*/ |
|
53 |
@Override |
|
54 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) { |
|
55 |
final String env_format = token.getFullEnv().getAttribute("format"); |
|
56 |
final String env_layout = token.getFullEnv().getAttribute("layout"); |
|
57 |
final String env_interp = token.getFullEnv().getAttribute("interpretation"); |
|
58 |
|
|
59 |
if (env_format != null && !env_format.isEmpty()) { |
|
60 |
this.format = env_format; |
|
61 |
} |
|
62 |
if (env_layout != null && !env_layout.isEmpty()) { |
|
63 |
this.layout = env_layout; |
|
64 |
} |
|
65 |
if (env_interp != null && !env_interp.isEmpty()) { |
|
66 |
this.interpretation = env_interp; |
|
67 |
} |
|
68 |
|
|
69 |
log.info("preparing CREATE blackboard job: " + format + "-" + layout + "-" + interpretation); |
|
70 |
|
|
71 |
job.setAction("CREATE"); |
|
72 |
job.getParameters().put("format", format); |
|
73 |
job.getParameters().put("layout", layout); |
|
74 |
job.getParameters().put("interpretation", interpretation); |
|
75 |
job.getParameters().put("backend_Id", defaultBackendId); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Gets the output prefix. |
|
80 |
* |
|
81 |
* @return the output prefix |
|
82 |
*/ |
|
83 |
public String getOutputPrefix() { |
|
84 |
return outputPrefix; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Sets the output prefix. |
|
89 |
* |
|
90 |
* @param outputPrefix |
|
91 |
* the output prefix |
|
92 |
*/ |
|
93 |
public void setOutputPrefix(final String outputPrefix) { |
|
94 |
this.outputPrefix = outputPrefix; |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* (non-Javadoc) |
|
99 |
* |
|
100 |
* @see eu.dnetlib.msro.workflows.nodes.BlackboardJobNode#generateBlackboardListener(com.googlecode.sarasvati.Engine, |
|
101 |
* com.googlecode.sarasvati.NodeToken) |
|
102 |
*/ |
|
103 |
@Override |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-msro-service-3.2.1