1 |
26600
|
sandro.lab
|
package eu.dnetlib.msro.workflows.sarasvati.loader;
|
2 |
|
|
|
3 |
|
|
import java.io.StringReader;
|
4 |
|
|
|
5 |
32639
|
michele.ar
|
import javax.annotation.Resource;
|
6 |
|
|
|
7 |
26600
|
sandro.lab
|
import org.apache.commons.lang.math.NumberUtils;
|
8 |
|
|
import org.apache.commons.logging.Log;
|
9 |
|
|
import org.apache.commons.logging.LogFactory;
|
10 |
|
|
import org.dom4j.Document;
|
11 |
|
|
import org.dom4j.DocumentException;
|
12 |
|
|
import org.dom4j.io.SAXReader;
|
13 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
14 |
|
|
|
15 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
16 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
17 |
32639
|
michele.ar
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
18 |
26600
|
sandro.lab
|
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
|
19 |
|
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
20 |
|
|
|
21 |
|
|
public class ProfileToSarasvatiConverter {
|
22 |
32639
|
michele.ar
|
|
23 |
|
|
@Resource
|
24 |
|
|
private UniqueServiceLocator serviceLocator;
|
25 |
|
|
|
26 |
|
|
private org.springframework.core.io.Resource xslt;
|
27 |
|
|
|
28 |
|
|
private static final Log log = LogFactory.getLog(ProfileToSarasvatiConverter.class);
|
29 |
|
|
|
30 |
|
|
public WfProfileDescriptor getSarasvatiWorkflow(final String id) throws DocumentException {
|
31 |
26600
|
sandro.lab
|
final String s = getProfile(id);
|
32 |
32639
|
michele.ar
|
final Document doc = new SAXReader().read(new StringReader(s));
|
33 |
26600
|
sandro.lab
|
final WfProfileDescriptor desc = new WfProfileDescriptor();
|
34 |
|
|
desc.setName(doc.valueOf("//WORKFLOW_NAME"));
|
35 |
|
|
desc.setType(doc.valueOf("//WORKFLOW_TYPE"));
|
36 |
|
|
desc.setPriority(NumberUtils.toInt("//WORKFLOW_PRIORITY", WorkflowsConstants.DEFAULT_WF_PRIORITY));
|
37 |
32639
|
michele.ar
|
desc.setWorkflowXml(new ApplyXslt(xslt).evaluate(s));
|
38 |
26600
|
sandro.lab
|
desc.setReady(doc.selectNodes("//PARAM[@required='true' and string-length(normalize-space(.)) = 0]").isEmpty());
|
39 |
|
|
return desc;
|
40 |
|
|
}
|
41 |
32639
|
michele.ar
|
|
42 |
|
|
public String getProfile(final String id) {
|
43 |
26600
|
sandro.lab
|
try {
|
44 |
32639
|
michele.ar
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfile(id);
|
45 |
26600
|
sandro.lab
|
} catch (ISLookUpException e) {
|
46 |
|
|
log.error("Error finding profile: " + id, e);
|
47 |
|
|
return null;
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
32639
|
michele.ar
|
public org.springframework.core.io.Resource getXslt() {
|
52 |
26600
|
sandro.lab
|
return xslt;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
@Required
|
56 |
32639
|
michele.ar
|
public void setXslt(final org.springframework.core.io.Resource xslt) {
|
57 |
26600
|
sandro.lab
|
this.xslt = xslt;
|
58 |
|
|
}
|
59 |
|
|
}
|