Project

General

Profile

« Previous | Next » 

Revision 33638

[maven-release-plugin] copy for tag dnet-msro-service-2.2.2

View differences:

modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/collect/DateRangeCollectRecordsJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.collect;
2

  
3
import java.io.StringReader;
4

  
5
import javax.annotation.Resource;
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7

  
8
import org.dom4j.Document;
9
import org.dom4j.Node;
10
import org.dom4j.io.SAXReader;
11

  
12
import com.googlecode.sarasvati.Arc;
13
import com.googlecode.sarasvati.NodeToken;
14

  
15
import eu.dnetlib.data.collector.rmi.CollectorService;
16
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
17
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
18
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
19
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
20

  
21
public class DateRangeCollectRecordsJobNode extends SimpleJobNode {
22

  
23
	@Resource
24
	private UniqueServiceLocator serviceLocator;
25

  
26
	private String datasourceId;
27
	private String datasourceInterface;
28
	private String eprParam;
29
	private String fromDateParam;
30
	private String untilDateParam;
31

  
32
	@Override
33
	protected String execute(final NodeToken token) throws Exception {
34
		final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(datasourceId);
35
		final Document doc = new SAXReader().read(new StringReader(profile));
36
		final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + datasourceInterface + "']");
37
		final String fromDate = token.getEnv().getAttribute(getFromDateParam());
38
		final String untilDate = token.getEnv().getAttribute(getUntilDateParam());
39

  
40
		final InterfaceDescriptor interfaceDescriptor = InterfaceDescriptor.newInstance(ifcNode);
41

  
42
		final W3CEndpointReference epr = serviceLocator.getService(CollectorService.class).dateRangeCollect(interfaceDescriptor, fromDate, untilDate);
43

  
44
		token.getEnv().setAttribute(getEprParam(), epr.toString());
45

  
46
		return Arc.DEFAULT_ARC;
47
	}
48

  
49
	public String getFromDateParam() {
50
		return fromDateParam;
51
	}
52

  
53
	public void setFromDateParam(final String fromDateParam) {
54
		this.fromDateParam = fromDateParam;
55
	}
56

  
57
	public String getUntilDateParam() {
58
		return untilDateParam;
59
	}
60

  
61
	public void setUntilDateParam(final String untilDateParam) {
62
		this.untilDateParam = untilDateParam;
63
	}
64

  
65
	public String getDatasourceId() {
66
		return datasourceId;
67
	}
68

  
69
	public void setDatasourceId(final String datasourceId) {
70
		this.datasourceId = datasourceId;
71
	}
72

  
73
	public String getDatasourceInterface() {
74
		return datasourceInterface;
75
	}
76

  
77
	public void setDatasourceInterface(final String datasourceInterface) {
78
		this.datasourceInterface = datasourceInterface;
79
	}
80

  
81
	public String getEprParam() {
82
		return eprParam;
83
	}
84

  
85
	public void setEprParam(final String eprParam) {
86
		this.eprParam = eprParam;
87
	}
88

  
89
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>dnet-msro-service</artifactId>
12
	<packaging>jar</packaging>
13
	<version>2.2.2</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-msro-service/tags/dnet-msro-service-2.2.2</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>opensymphony</groupId>
20
			<artifactId>quartz</artifactId>
21
			<version>1.6.6</version>
22
		</dependency>
23
		<dependency>
24
			<groupId>eu.dnetlib</groupId>
25
			<artifactId>dnet-msro-service-api</artifactId>
26
			<version>[2.0.0,3.0.0)</version>
27
		</dependency>
28
		<dependency>
29
			<groupId>eu.dnetlib</groupId>
30
			<artifactId>cnr-resultset-service</artifactId>
31
			<version>[2.0.0,3.0.0)</version>
32
		</dependency>
33
		<dependency>
34
			<groupId>eu.dnetlib</groupId>
35
			<artifactId>cnr-data-utility-cleaner-rmi</artifactId>
36
			<version>[2.0.0,3.0.0)</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>eu.dnetlib</groupId>
40
			<artifactId>cnr-resultset-client</artifactId>
41
			<version>[2.0.0,3.0.0)</version>
42
		</dependency>
43
		<dependency>
44
			<groupId>eu.dnetlib</groupId>
45
			<artifactId>dnet-download-service-rmi</artifactId>
46
			<version>[1.1.0,2.0.0)</version>
47
		</dependency>
48

  
49
		<dependency>
50
			<groupId>eu.dnetlib</groupId>
51
			<artifactId>cnr-blackboard-common</artifactId>
52
			<version>[2.1.0,3.0.0)</version>
53
		</dependency>
54
		<dependency>
55
			<groupId>eu.dnetlib</groupId>
56
			<artifactId>dnet-mongo-logging</artifactId>
57
			<version>[1.0.0,2.0.0)</version>
58
		</dependency>
59
		<dependency>
60
			<groupId>eu.dnetlib</groupId>
61
			<artifactId>dnet-datasource-common</artifactId>
62
			<version>[3.0.0,4.0.0)</version>
63
		</dependency>
64
		<dependency>
65
			<groupId>com.googlecode</groupId>
66
			<artifactId>sarasvati</artifactId>
67
			<version>1.0.3</version>
68
		</dependency>
69
		<dependency>
70
			<groupId>com.googlecode</groupId>
71
			<artifactId>sarasvati-visual</artifactId>
72
			<version>1.0.3</version>
73
		</dependency>
74
		<dependency>
75
			<groupId>eu.dnetlib</groupId>
76
			<artifactId>dnet-modular-collector-service-rmi</artifactId>
77
			<version>[1.3.0,2.0.0)</version>
78
		</dependency>
79
		<dependency>
80
			<groupId>eu.dnetlib</groupId>
81
			<artifactId>cnr-enabling-database-api</artifactId>
82
			<version>[1.0.0,2.0.0)</version>
83
		</dependency>
84
		<dependency>
85
			<groupId>eu.dnetlib</groupId>
86
			<artifactId>dnet-objectstore-rmi</artifactId>
87
			<version>[2.0.0,3.0.0)</version>
88
		</dependency>
89
		<dependency>
90
			<groupId>eu.dnetlib</groupId>
91
			<artifactId>dnet-data-transformation-service-rmi</artifactId>
92
			<version>[1.0.0,2.0.0)</version>
93
		</dependency>
94
		<dependency>
95
			<groupId>eu.dnetlib</groupId>
96
			<artifactId>dnet-data-provision-rmi</artifactId>
97
			<version>[1.0.0,2.0.0)</version>
98
		</dependency>
99
		<dependency>
100
			<groupId>eu.dnetlib</groupId>
101
			<artifactId>dnet-runtime</artifactId>
102
			<version>[1.0.0,2.0.0)</version>
103
		</dependency>
104
		<dependency>
105
			<groupId>javax.mail</groupId>
106
			<artifactId>mail</artifactId>
107
			<version>1.4</version>
108
		</dependency>
109
		<dependency>
110
			<groupId>org.codehaus.groovy</groupId>
111
			<artifactId>groovy-all</artifactId>
112
			<version>2.1.6</version>
113
		</dependency>
114
		<dependency>
115
			<groupId>junit</groupId>
116
			<artifactId>junit</artifactId>
117
			<version>${junit.version}</version>
118
			<scope>test</scope>
119
		</dependency>
120
		<dependency>
121
			<groupId>joda-time</groupId>
122
			<artifactId>joda-time</artifactId>
123
			<version>2.3</version>
124
		</dependency>
125
	</dependencies>
126

  
127
	<properties>
128
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
129
	</properties>
130

  
131
</project>
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/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 validTotals = 0;
44
		int invalidTotals = 0;
45

  
46
		final List<String> list = lookup.listResourceTypes();
47

  
48
		this.total = list.size();
49
		this.current = 0;
50
		for (String resourceType : list) {
51
			int valid = 0;
52
			int invalid = 0;
53

  
54
			final String schemaSource = lookup.getResourceTypeSchema(resourceType);
55
			final Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(schemaSource)));
56
			final Validator validator = schema.newValidator();
57

  
58
			for (String profile : lookup.quickSearchProfile("/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='" + resourceType + "']")) {
59
				try {
60
					validator.validate(new StreamSource(new StringReader(profile)));
61
					valid++;
62
				} catch (Exception e) {
63
					invalid++;
64
				}
65
			}
66
			validTotals += valid;
67
			invalidTotals += invalid;
68

  
69
			final String message = String.format("Valid: %s, Invalid: %s, Total: %s", valid, invalid, valid + invalid);
70
			token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + resourceType, message);
71
			log.info("Validation of " + resourceType + " profiles: " + message);
72
		}
73

  
74
		if (invalidTotals > 0) { throw new MSROException("Validation wf has found " + invalidTotals + " invalid profiles"); }
75

  
76
		return Arc.DEFAULT_ARC;
77
	}
78

  
79
	@Override
80
	public ProgressProvider getProgressProvider() {
81
		return new ProgressProvider() {
82

  
83
			@Override
84
			public boolean isInaccurate() {
85
				return false;
86
			}
87

  
88
			@Override
89
			public int getTotalValue() {
90
				return total;
91
			}
92

  
93
			@Override
94
			public int getCurrentValue() {
95
				return current;
96
			}
97
		};
98
	}
99

  
100
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/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/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/info/MDStoreToApiExtraFieldJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.info;
2

  
3
import java.io.StringReader;
4
import java.util.Map;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.dom4j.Document;
9
import org.dom4j.Node;
10
import org.dom4j.io.SAXReader;
11
import org.springframework.beans.factory.annotation.Required;
12

  
13
import com.google.common.collect.Maps;
14
import com.googlecode.sarasvati.Arc;
15
import com.googlecode.sarasvati.NodeToken;
16

  
17
import eu.dnetlib.datasource.common.utils.DatasourceUpdater;
18
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
19
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
20
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
21

  
22
public class MDStoreToApiExtraFieldJobNode extends SimpleJobNode {
23

  
24
	private String mdId;
25
	private String datasourceId;
26
	private String datasourceInterface;
27
	private String extraFieldForTotal;
28
	private String extraFieldForDate;
29
	private String extraFieldForMdId;
30

  
31
	@Resource
32
	private UniqueServiceLocator serviceLocator;
33

  
34
	private DatasourceUpdater datasourceUpdater;
35

  
36
	@Override
37
	protected String execute(final NodeToken token) throws Exception {
38
		final String xq = "for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') " +
39
				"where $x//RESOURCE_IDENTIFIER/@value='" + mdId + "' " +
40
				"return concat($x//NUMBER_OF_RECORDS, ' @=@ ', $x//LAST_STORAGE_DATE)";
41

  
42
		final String s = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xq);
43

  
44
		final String[] arr = s.split(" @=@ ");
45

  
46
		final Map<String, String> map = getCurrentExtraFields(datasourceId, datasourceInterface);
47
		map.put(extraFieldForTotal, arr[0].trim());
48
		map.put(extraFieldForDate, arr[1].trim());
49
		map.put(extraFieldForMdId, mdId);
50

  
51
		datasourceUpdater.updateApiExtraFields(datasourceId, datasourceInterface, map);
52

  
53
		return Arc.DEFAULT_ARC;
54
	}
55

  
56
	private Map<String, String> getCurrentExtraFields(final String repoId, final String ifaceId) throws Exception {
57
		final Map<String, String> res = Maps.newHashMap();
58

  
59
		final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
60

  
61
		final SAXReader reader = new SAXReader();
62
		final Document doc = reader.read(new StringReader(profile));
63

  
64
		final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
65
		if (ifcNode != null) {
66
			for (Object o : ifcNode.selectNodes("./INTERFACE_EXTRA_FIELD")) {
67
				res.put(((Node) o).valueOf("@name"), ((Node) o).getText());
68
			}
69
		}
70

  
71
		return res;
72
	}
73

  
74
	public String getMdId() {
75
		return mdId;
76
	}
77

  
78
	public void setMdId(final String mdId) {
79
		this.mdId = mdId;
80
	}
81

  
82
	public String getDatasourceId() {
83
		return datasourceId;
84
	}
85

  
86
	public void setDatasourceId(final String datasourceId) {
87
		this.datasourceId = datasourceId;
88
	}
89

  
90
	public String getDatasourceInterface() {
91
		return datasourceInterface;
92
	}
93

  
94
	public void setDatasourceInterface(final String datasourceInterface) {
95
		this.datasourceInterface = datasourceInterface;
96
	}
97

  
98
	public String getExtraFieldForTotal() {
99
		return extraFieldForTotal;
100
	}
101

  
102
	public void setExtraFieldForTotal(final String extraFieldForTotal) {
103
		this.extraFieldForTotal = extraFieldForTotal;
104
	}
105

  
106
	public String getExtraFieldForDate() {
107
		return extraFieldForDate;
108
	}
109

  
110
	public void setExtraFieldForDate(final String extraFieldForDate) {
111
		this.extraFieldForDate = extraFieldForDate;
112
	}
113

  
114
	public String getExtraFieldForMdId() {
115
		return extraFieldForMdId;
116
	}
117

  
118
	public void setExtraFieldForMdId(final String extraFieldForMdId) {
119
		this.extraFieldForMdId = extraFieldForMdId;
120
	}
121

  
122
	public DatasourceUpdater getDatasourceUpdater() {
123
		return datasourceUpdater;
124
	}
125

  
126
	@Required
127
	public void setDatasourceUpdater(final DatasourceUpdater datasourceUpdater) {
128
		this.datasourceUpdater = datasourceUpdater;
129
	}
130

  
131
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/repobye/DeleteMDStoreJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.repobye;
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.mdstore.MDStoreService;
9
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
10
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
11

  
12
public class DeleteMDStoreJobNode extends BlackboardJobNode {
13

  
14
	private static final Log log = LogFactory.getLog(DeleteMDStoreJobNode.class);
15

  
16
	private String mdstoreId;
17

  
18
	@Override
19
	protected String obtainServiceId(final NodeToken token) {
20
		return getServiceLocator().getServiceId(MDStoreService.class, mdstoreId);
21
	}
22

  
23
	@Override
24
	protected void prepareJob(final BlackboardJob job, final NodeToken token) {
25
		log.info("preparing blackboard job: delete of mdstore " + getMdstoreId());
26
		job.setAction("DELETE");
27
		job.getParameters().put("id", getMdstoreId());
28
	}
29

  
30
	public String getMdstoreId() {
31
		return mdstoreId;
32
	}
33

  
34
	public void setMdstoreId(final String mdstoreId) {
35
		this.mdstoreId = mdstoreId;
36
	}
37

  
38
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/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/tags/dnet-msro-service-2.2.2/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-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/blackboard/BlackboardSubscriber.java
1
package eu.dnetlib.msro.workflows.nodes.blackboard;
2

  
3
import javax.annotation.Resource;
4
import javax.xml.ws.Endpoint;
5
import javax.xml.ws.wsaddressing.W3CEndpointReference;
6

  
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.springframework.beans.factory.annotation.Required;
10

  
11
import eu.dnetlib.enabling.is.sn.rmi.ISSNException;
12
import eu.dnetlib.enabling.is.sn.rmi.ISSNService;
13
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
14
import eu.dnetlib.soap.EndpointReferenceBuilder;
15

  
16
public class BlackboardSubscriber {
17

  
18
	/**
19
	 * Logger.
20
	 */
21
	private static final Log log = LogFactory.getLog(BlackboardSubscriber.class); // NOPMD by marko on 11/24/08 5:02 PM
22

  
23
	/**
24
	 * service locator.
25
	 */
26
	@Resource
27
	private UniqueServiceLocator serviceLocator;
28

  
29
	/**
30
	 * injected EPR builder.
31
	 */
32
	@Resource(name = "jaxwsEndpointReferenceBuilder")
33
	private EndpointReferenceBuilder<Endpoint> eprBuilder;
34

  
35
	/**
36
	 * notification endpoint (normally the msro service).
37
	 */
38
	private Endpoint endpoint;
39

  
40
	/**
41
	 * performs the subscription.
42
	 * 
43
	 * @throws ISSNException
44
	 *             could happen
45
	 */
46
	public void subscribeAll() throws ISSNException {
47
		log.info("Subscribing msro service");
48

  
49
		final W3CEndpointReference endpointReference = eprBuilder.getEndpointReference(getEndpoint());
50
		serviceLocator.getService(ISSNService.class).subscribe(endpointReference, "UPDATE/*/*/RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_RESPONSE", 0);
51
	}
52

  
53
	public Endpoint getEndpoint() {
54
		return endpoint;
55
	}
56

  
57
	@Required
58
	public void setEndpoint(final Endpoint endpoint) {
59
		this.endpoint = endpoint;
60
	}
61
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/objectStore/RetrieveMdStoreId.java
1
package eu.dnetlib.msro.workflows.nodes.objectStore;
2

  
3
import java.util.List;
4
import java.util.Set;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.springframework.beans.factory.annotation.Required;
9

  
10
import com.google.common.collect.Lists;
11
import com.google.common.collect.Sets;
12
import com.google.gson.Gson;
13
import com.google.gson.GsonBuilder;
14
import com.googlecode.sarasvati.Arc;
15
import com.googlecode.sarasvati.NodeToken;
16

  
17
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
18
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
19
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
20
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
21

  
22
/**
23
 * The Class RetrieveMdStoreId is a job node used to retrieve the correct MDStore from which extract the url of the file to download.
24
 * metadata format and interpretation are injected as properties
25
 */
26
public class RetrieveMdStoreId extends SimpleJobNode {
27

  
28
	/** The metadata format. */
29
	private String metadataFormat;
30

  
31
	/** The interpretation. */
32
	private String interpretation;
33

  
34
	/** The provider id. */
35
	private String providerId;
36

  
37
	/** The service locator. */
38
	@Resource
39
	private UniqueServiceLocator serviceLocator;
40

  
41
	/*
42
	 * (non-Javadoc)
43
	 *
44
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
45
	 */
46
	@Override
47
	protected String execute(final NodeToken token) throws Exception {
48

  
49
		String workflowQuery =
50
				"for $x in collection('/db/DRIVER/MetaWorkflowDSResources/MetaWorkflowDSResourceType') where($x//DATAPROVIDER/@id='%s') return  distinct-values($x//WORKFLOW/@id/string())";
51

  
52
		List<String> result = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(String.format(workflowQuery, providerId));
53
		if (result.size() == 0) { throw new RuntimeException("there is no mdStore Associated to the provider " + token.getEnv().getAttribute(getProviderId())); }
54
		Set<String> workflowIds = Sets.newHashSet(result);
55

  
56
		Set<String> metadataIds = getMdStores(workflowIds);
57
		Gson g = new GsonBuilder().disableHtmlEscaping().create();
58
		token.getEnv().setAttribute("mdId", g.toJson(metadataIds));
59

  
60
		token.getEnv().setAttribute("mdFormat", getMetadataFormat());
61
		return Arc.DEFAULT_ARC;
62
	}
63

  
64
	private Set<String> getMdStores(final Set<String> workflowsId) {
65
		try {
66

  
67
			String query = "//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='%s']//PARAM[./@category/string()='MDSTORE_ID']/text()";
68

  
69
			Set<String> mdStores = Sets.newHashSet();
70

  
71
			if (workflowsId == null) { return null; }
72

  
73
			for (String workflowId : workflowsId) {
74
				List<String> result = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(String.format(query, workflowId));
75
				Set<String> metadataIds = Sets.newHashSet(result);
76
				mdStores.addAll(getRightMetadataId(Lists.newArrayList(metadataIds)));
77
			}
78
			return mdStores;
79

  
80
		} catch (ISLookUpException e) {
81

  
82
			return null;
83
		}
84
	}
85

  
86
	/**
87
	 * Gets the right metadata id whith the format metadataFormat and interpretation interpretation
88
	 *
89
	 * @return the right metadata id
90
	 * @throws ISLookUpException
91
	 */
92
	private Set<String> getRightMetadataId(final Iterable<String> ids) throws ISLookUpException {
93
		String query =
94
				"let $x:=//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='%s'] return concat($x//METADATA_FORMAT/text(), '::<<>>::', $x//METADATA_FORMAT_INTERPRETATION/text())";
95
		Set<String> result = Sets.newHashSet();
96

  
97
		for (String id : ids) {
98

  
99
			List<String> results = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(String.format(query, id));
100
			if (results.size() > 0) {
101
				String[] values = results.get(0).split("::<<>>::");
102
				if (metadataFormat.equals(values[0]) && interpretation.equals(values[1])) {
103
					result.add(id);
104
				}
105
			}
106
		}
107
		return result;
108

  
109
	}
110

  
111
	/**
112
	 * Gets the interpretation.
113
	 *
114
	 * @return the interpretation
115
	 */
116
	public String getInterpretation() {
117
		return interpretation;
118
	}
119

  
120
	/**
121
	 * Sets the interpretation.
122
	 *
123
	 * @param interpretation
124
	 *            the interpretation to set
125
	 */
126
	@Required
127
	public void setInterpretation(final String interpretation) {
128
		this.interpretation = interpretation;
129
	}
130

  
131
	/**
132
	 * Gets the metadata format.
133
	 *
134
	 * @return the metadataFormat
135
	 */
136
	public String getMetadataFormat() {
137
		return metadataFormat;
138
	}
139

  
140
	/**
141
	 * Sets the metadata format.
142
	 *
143
	 * @param metadataFormat
144
	 *            the metadataFormat to set
145
	 */
146
	@Required
147
	public void setMetadataFormat(final String metadataFormat) {
148
		this.metadataFormat = metadataFormat;
149
	}
150

  
151
	/**
152
	 * Gets the provider id.
153
	 *
154
	 * @return the providerId
155
	 */
156
	public String getProviderId() {
157
		return providerId;
158
	}
159

  
160
	/**
161
	 * Sets the provider id.
162
	 *
163
	 * @param providerId
164
	 *            the providerId to set
165
	 */
166
	public void setProviderId(final String providerId) {
167
		this.providerId = providerId;
168
	}
169

  
170
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/SarasvatiJobNode.java
1
package eu.dnetlib.msro.workflows.nodes;
2

  
3
import java.lang.reflect.Field;
4
import java.util.HashSet;
5
import java.util.Map;
6
import java.util.Map.Entry;
7
import java.util.Set;
8

  
9
import javax.annotation.Resource;
10

  
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.springframework.beans.factory.BeanNameAware;
14

  
15
import com.google.common.collect.Maps;
16
import com.google.gson.Gson;
17
import com.googlecode.sarasvati.Engine;
18
import com.googlecode.sarasvati.NodeToken;
19
import com.googlecode.sarasvati.mem.MemNode;
20

  
21
import eu.dnetlib.conf.PropertyFetcher;
22

  
23
public abstract class SarasvatiJobNode extends MemNode implements BeanNameAware {
24

  
25
	/**
26
	 * logger.
27
	 */
28
	private static final Log log = LogFactory.getLog(SarasvatiJobNode.class);
29

  
30
	private String beanName;
31

  
32
	/**
33
	 * parameter values injected as json map into subclasses instance beans.
34
	 */
35
	private String params;
36

  
37
	/**
38
	 * parameter values retrieved from the sarasvati Env.
39
	 */
40
	private String envParams;
41

  
42
	/**
43
	 * parameter values retrieved from the system properties.
44
	 */
45
	private String sysParams;
46

  
47
	@Resource(name = "propertyFetcher")
48
	private PropertyFetcher propertyFetcher;
49

  
50
	@Override
51
	public void execute(final Engine engine, final NodeToken token) {
52
		final String prefix = "system:node:" + getName() + ":";
53

  
54
		for (Field field : getClass().getDeclaredFields()) {
55
			try {
56
				field.setAccessible(true);
57
				token.getEnv().setAttribute(prefix + field.getName(), "" + field.get(this));
58
			} catch (Exception e) {
59
				log.warn("Error accessing value of field: " + field.getName());
60
			}
61
		}
62
	}
63

  
64
	/**
65
	 * builds a parameter map overriding values having the same name in the following order: sysparams < envparams < params
66
	 * 
67
	 * @param token
68
	 * @return
69
	 */
70
	protected Map<String, String> parseJsonParameters(final NodeToken token) {
71
		final Map<String, String> res = Maps.newHashMap();
72
		for (Entry<?, ?> e : asMapEntries(getSysParams())) {
73
			String propertyName = e.getValue().toString();
74

  
75
			if (!getPropertyFetcher().getProps().containsKey(propertyName)) {
76
				log.warn("unable to find system property: '" + propertyName + "'");
77
			}
78

  
79
			String propertyValue = getPropertyFetcher().getProperty(propertyName);
80
			res.put(e.getKey().toString(), propertyValue);
81
		}
82
		for (Entry<?, ?> e : asMapEntries(getEnvParams())) {
83
			final String param = e.getValue().toString();
84

  
85
			if (token.getEnv().hasAttribute(param)) {
86
				res.put(e.getKey().toString(), token.getEnv().getAttribute(param));
87
			} else {
88
				res.put(e.getKey().toString(), token.getFullEnv().getAttribute(param));
89
			}
90
		}
91
		for (Entry<?, ?> e : asMapEntries(getParams())) {
92
			res.put(e.getKey().toString(), e.getValue().toString());
93
		}
94
		return res;
95
	}
96

  
97
	@SuppressWarnings("unchecked")
98
	private Set<Map.Entry<?, ?>> asMapEntries(final String s) {
99
		return isSet(s) ? new Gson().fromJson(s, Map.class).entrySet() : new HashSet<Map.Entry<?, ?>>();
100
	}
101

  
102
	private boolean isSet(final String s) {
103
		return (s != null) && !s.isEmpty();
104
	}
105

  
106
	// ///////////////
107

  
108
	public String getBeanName() {
109
		return beanName;
110
	}
111

  
112
	@Override
113
	public void setBeanName(final String beanName) {
114
		this.beanName = beanName;
115
	}
116

  
117
	public PropertyFetcher getPropertyFetcher() {
118
		return propertyFetcher;
119
	}
120

  
121
	public String getParams() {
122
		return params;
123
	}
124

  
125
	public void setParams(final String params) {
126
		this.params = params;
127
	}
128

  
129
	public String getEnvParams() {
130
		return envParams;
131
	}
132

  
133
	public void setEnvParams(final String envParams) {
134
		this.envParams = envParams;
135
	}
136

  
137
	public String getSysParams() {
138
		return sysParams;
139
	}
140

  
141
	public void setSysParams(final String sysParams) {
142
		this.sysParams = sysParams;
143
	}
144

  
145
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/objectStore/UpdateObjectStoreSizeJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.objectStore;
2

  
3
import javax.annotation.Resource;
4

  
5
import com.googlecode.sarasvati.Arc;
6
import com.googlecode.sarasvati.NodeToken;
7

  
8
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
9
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
10
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
11
import eu.dnetlib.miscutils.datetime.DateUtils;
12
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
13

  
14
// TODO: Auto-generated Javadoc
15
/**
16
 * The Class UpdateObjectStoreSizeJobNode.
17
 */
18
public class UpdateObjectStoreSizeJobNode extends SimpleJobNode {
19

  
20
	/** The object store id. */
21
	private String objectStoreIdParam;
22

  
23
	/** The service locator. */
24
	@Resource
25
	private UniqueServiceLocator serviceLocator;
26

  
27
	/*
28
	 * (non-Javadoc)
29
	 * 
30
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
31
	 */
32
	@Override
33
	protected String execute(final NodeToken token) throws Exception {
34

  
35
		final ISRegistryService registry = serviceLocator.getService(ISRegistryService.class);
36

  
37
		int size = serviceLocator.getService(ObjectStoreService.class, objectStoreIdParam).getSize(objectStoreIdParam);
38

  
39
		String now = DateUtils.now_ISO8601();
40

  
41
		String mdstoreXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + objectStoreIdParam + "']"
42
				+ "return update value $x//LAST_STORAGE_DATE with '" + now + "'";
43

  
44
		registry.executeXUpdate(mdstoreXUpdate);
45

  
46
		String mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + objectStoreIdParam + "']"
47
				+ "return update value $x//COUNT_STORE with '" + size + "'";
48

  
49
		registry.executeXUpdate(mdstoreNumberXUpdate);
50

  
51
		mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + objectStoreIdParam + "']"
52
				+ "return update value $x//STORE_SIZE with '" + size + "'";
53

  
54
		registry.executeXUpdate(mdstoreNumberXUpdate);
55

  
56
		return Arc.DEFAULT_ARC;
57
	}
58

  
59
	/**
60
	 * Gets the object store id param.
61
	 *
62
	 * @return the objectStoreIdParam
63
	 */
64
	public String getObjectStoreIdParam() {
65
		return objectStoreIdParam;
66
	}
67

  
68
	/**
69
	 * Sets the object store id param.
70
	 *
71
	 * @param objectStoreIdParam
72
	 *            the new object store id param
73
	 */
74
	public void setObjectStoreIdParam(final String objectStoreIdParam) {
75
		this.objectStoreIdParam = objectStoreIdParam;
76
	}
77

  
78
}
modules/dnet-msro-service/tags/dnet-msro-service-2.2.2/src/main/java/eu/dnetlib/msro/workflows/nodes/objectStore/DownloadIntoObjectStoreJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.objectStore;
2

  
3
import java.io.StringReader;
4
import java.util.Iterator;
5
import java.util.Map;
6

  
7
import javax.xml.ws.wsaddressing.W3CEndpointReference;
8
import javax.xml.xpath.XPath;
9
import javax.xml.xpath.XPathFactory;
10

  
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.xml.sax.InputSource;
14

  
15
import com.googlecode.sarasvati.Engine;
16
import com.googlecode.sarasvati.NodeToken;
17
import com.googlecode.sarasvati.env.Env;
18

  
19
import eu.dnetlib.data.objectstore.rmi.MetadataObjectRecord;
20
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
21
import eu.dnetlib.enabling.resultset.IterableResultSetFactory;
22
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
23
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
24
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
25
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode;
26
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
27
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory;
28
import eu.dnetlib.msro.workflows.util.ProgressProvider;
29
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider;
30
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
31

  
32
public class DownloadIntoObjectStoreJobNode extends BlackboardJobNode implements ProgressJobNode {
33

  
34
	private static final Log log = LogFactory.getLog(DownloadIntoObjectStoreJobNode.class);
35

  
36
	class MetadataObjectIterator implements Iterator<String> {
37

  
38
		private Iterator<String> inputIterator;
39

  
40
		private String mime;
41

  
42
		public MetadataObjectIterator(final Iterator<String> inputIterator, final String xpath, final String mime) {
43
			this.inputIterator = inputIterator;
44
		}
45

  
46
		@Override
47
		public boolean hasNext() {
48
			return inputIterator.hasNext();
49
		}
50

  
51
		@Override
52
		public String next() {
53
			try {
54
				String record = inputIterator.next();
55
				XPath xpath = XPathFactory.newInstance().newXPath();
56
				InputSource doc = new InputSource(new StringReader(record));
57
				String identifier = xpath.evaluate(getIdXpath(), doc);
58
				MetadataObjectRecord objectrecord = new MetadataObjectRecord(identifier, record, mime);
59
				return objectrecord.toJSON();
60
			} catch (Exception e) {
61
				return null;
62
			}
63
		}
64

  
65
		@Override
66
		public void remove() {
67

  
68
		}
69

  
70
	}
71

  
72
	private String eprParam;
73

  
74
	private String objectStoreId;
75

  
76
	private String idXpath; // "//*[local-name()='objIdentifier']
77

  
78
	private String contentDescription;
79

  
80
	private String objectIsInsideEpr;
81

  
82
	private IterableResultSetFactory iterableResultSetFactory;
83
	private ResultSetClientFactory resultSetClientFactory;
84

  
85
	private ResultsetProgressProvider progressProvider;
86
	private ProcessCountingResultSetFactory processCountingResultSetFactory;
87

  
88
	@Override
89
	protected String obtainServiceId(final NodeToken token) {
90
		return getServiceLocator().getServiceId(ObjectStoreService.class);
91
	}
92

  
93
	public String getEprParam() {
94
		return eprParam;
95
	}
96

  
97
	public void setEprParam(final String eprParam) {
98
		this.eprParam = eprParam;
99
	}
100

  
101
	public String getObjectStoreId() {
102
		return objectStoreId;
103
	}
104

  
105
	public void setObjectStoreId(final String objectStoreId) {
106
		this.objectStoreId = objectStoreId;
107
	}
108

  
109
	public ProgressProvider getProgressProvider(final NodeToken token) {
110

  
111
		return progressProvider;
112
	}
113

  
114
	@Override
115
	protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception {
116

  
117
		job.setAction("FEEDOBJECT");
118
		final String eprS = token.getEnv().getAttribute(getEprParam());
119
		job.getParameters().put("obsID", getObjectStoreId());
120
		job.getParameters().put("mime", getContentDescription());
121
		final Iterator<String> client = resultSetClientFactory.getClient(eprS).iterator();
122

  
123
		final W3CEndpointReference epr = iterableResultSetFactory.createIterableResultSet(new Iterable<String>() {
124

  
125
			@Override
126
			public Iterator<String> iterator() {
127
				return new MetadataObjectIterator(client, "//*[local-name()='objIdentifier']", "xml");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff