Revision 35642
Added by Alessia Bardi about 9 years ago
modules/dnet-validator-workflows/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/validation/SetInfoForValidationJobNode.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import javax.annotation.Resource; |
4 | 4 |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
|
|
5 | 8 |
import com.googlecode.sarasvati.Arc; |
6 | 9 |
import com.googlecode.sarasvati.NodeToken; |
7 | 10 |
|
... | ... | |
12 | 15 |
|
13 | 16 |
public class SetInfoForValidationJobNode extends SimpleJobNode { |
14 | 17 |
|
18 |
public static final Log log = LogFactory.getLog(SetInfoForValidationJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
19 |
|
|
15 | 20 |
@Resource |
16 | 21 |
private UniqueServiceLocator serviceLocator; |
17 |
|
|
18 | 22 |
private String providerId; |
19 | 23 |
private String providerName; |
20 | 24 |
private String api; |
... | ... | |
34 | 38 |
token.getProcess().getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE, getApi()); |
35 | 39 |
|
36 | 40 |
final String query = "let $x := /*[.//RESOURCE_IDENTIFIER/@value='" + providerId + "']\n" |
37 |
+ "return concat($x//EXTRA_FIELDS/FIELD[./key='NamespacePrefix']/value, ' @@@ ', $x//INTERFACE[./@id='" + api |
|
38 |
+ "']/BASE_URL/text(), ' @@@ ', $x//INTERFACE[./@id='" + api + "']/INTERFACE_EXTRA_FIELD[./@name='last_collection_total']/text() )"; |
|
41 |
+ "return concat($x//EXTRA_FIELDS/FIELD[./key='NamespacePrefix']/value, ' @@@ ', $x//INTERFACE[./@id='" + api + "']/BASE_URL/text())"; |
|
39 | 42 |
|
43 |
log.debug("Running xquery: " + query); |
|
44 |
|
|
40 | 45 |
final String[] arr = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query).split("@@@"); |
41 | 46 |
|
42 | 47 |
token.getEnv().setAttribute("datasourceNamespacePrefix", arr[0].trim()); |
43 | 48 |
// INTERFACE[@id='apiId']/BASE_URL |
44 | 49 |
token.getEnv().setAttribute("baseUrl", arr[1].trim()); |
45 |
// INTERFACE[@id='apiId']/INTERFACE_EXTRA_FIELD[./@name="last_collection_total"] |
|
46 |
token.getEnv().setAttribute("totalRecords", arr[2].trim()); |
|
47 | 50 |
|
48 | 51 |
return Arc.DEFAULT_ARC; |
49 | 52 |
} |
modules/dnet-validator-workflows/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/validation/ValidatorServiceBlackboardJobNode.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.workflows.nodes.validation; |
2 | 2 |
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
3 | 5 |
import org.apache.commons.lang.StringUtils; |
4 | 6 |
import org.apache.commons.logging.Log; |
5 | 7 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
7 | 9 |
import com.googlecode.sarasvati.Engine; |
8 | 10 |
import com.googlecode.sarasvati.NodeToken; |
9 | 11 |
|
12 |
import eu.dnetlib.data.mdstore.MDStoreService; |
|
13 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
10 | 14 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
15 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
11 | 16 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
12 | 17 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
13 | 18 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
... | ... | |
49 | 54 |
private String extraParams; |
50 | 55 |
|
51 | 56 |
// PROGRESS |
57 |
@Resource |
|
58 |
private UniqueServiceLocator serviceLocator; |
|
59 |
|
|
52 | 60 |
/** Number of records after which the Validator must update its progress status in currentlyValidatedParam **/ |
53 | 61 |
private int jobStatusUpdateInterval = 1000; |
54 | 62 |
/** Parameter where the validator tells how many records have been processed sofar **/ |
... | ... | |
83 | 91 |
*/ |
84 | 92 |
@Override |
85 | 93 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
94 |
// calculate total number of records in the store |
|
95 |
total = getTotal(); |
|
86 | 96 |
// required params |
87 | 97 |
job.setAction(VALIDATE_ACTION); |
88 | 98 |
job.getParameters().put("datasourceID", token.getFullEnv().getAttribute(datasourceIDEnvParam)); |
... | ... | |
113 | 123 |
if (StringUtils.isNotBlank(extraParams)) { |
114 | 124 |
job.getParameters().put("extraParams", extraParams); |
115 | 125 |
} |
116 |
try { |
|
117 |
total = Integer.parseInt(token.getEnv().getAttribute("totalRecords")); |
|
118 |
accurate = true; |
|
119 |
} catch (Exception e) { |
|
120 |
log.warn(e.getMessage() + ": progress will be INACCURATE"); |
|
121 |
accurate = false; |
|
122 |
} |
|
123 | 126 |
|
124 | 127 |
if (jobStatusUpdateInterval > 0) { |
125 | 128 |
job.getParameters().put("jobStatusUpdateInterval", "" + jobStatusUpdateInterval); |
126 | 129 |
} |
127 | 130 |
} |
128 | 131 |
|
132 |
private int getTotal() { |
|
133 |
int size = -1; |
|
134 |
accurate = false; |
|
135 |
try { |
|
136 |
size = serviceLocator.getService(MDStoreService.class).size(mdstoreId); |
|
137 |
accurate = true; |
|
138 |
} catch (MDStoreServiceException e) { |
|
139 |
log.warn("Can't get size of mdstore " + mdstoreId + " progress will be INACCURATE"); |
|
140 |
e.printStackTrace(); |
|
141 |
} |
|
142 |
return size; |
|
143 |
} |
|
144 |
|
|
129 | 145 |
/** |
130 | 146 |
* <p> |
131 | 147 |
* Parameters in the VALIDATE BB job response: |
modules/dnet-validator-workflows/trunk/pom.xml | ||
---|---|---|
20 | 20 |
<artifactId>dnet-aggregative-basic-workflows</artifactId> |
21 | 21 |
<version>[0.0.1,2.0.0)</version> |
22 | 22 |
</dependency> |
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>cnr-modular-mdstore-service</artifactId> |
|
26 |
<version>[4.1.0,5.0.0)</version> |
|
27 |
</dependency> |
|
23 | 28 |
</dependencies> |
24 | 29 |
</project> |
Also available in: Unified diff
Depending on modular-mdstore version >=4.1.0 as we require the method size(mdstoreId) to show the progress bar.