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