Project

General

Profile

« Previous | Next » 

Revision 36598

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

View differences:

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

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

  
130
</project>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/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

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

  
16
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
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 MDStoreToApiExtraFieldJobNode extends SimpleJobNode {
22

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

  
30
	@Resource
31
	private UniqueServiceLocator serviceLocator;
32

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

  
39
		final String s = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xq);
40

  
41
		final String[] arr = s.split(" @=@ ");
42

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

  
48
		serviceLocator.getService(DatasourceManagerService.class).bulkUpdateApiExtraFields(datasourceId, datasourceInterface, map);
49

  
50
		return Arc.DEFAULT_ARC;
51
	}
52

  
53
	private Map<String, String> getCurrentExtraFields(final String repoId, final String ifaceId) throws Exception {
54
		final Map<String, String> res = Maps.newHashMap();
55

  
56
		final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
57

  
58
		final SAXReader reader = new SAXReader();
59
		final Document doc = reader.read(new StringReader(profile));
60

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

  
68
		return res;
69
	}
70

  
71
	public String getMdId() {
72
		return mdId;
73
	}
74

  
75
	public void setMdId(final String mdId) {
76
		this.mdId = mdId;
77
	}
78

  
79
	public String getDatasourceId() {
80
		return datasourceId;
81
	}
82

  
83
	public void setDatasourceId(final String datasourceId) {
84
		this.datasourceId = datasourceId;
85
	}
86

  
87
	public String getDatasourceInterface() {
88
		return datasourceInterface;
89
	}
90

  
91
	public void setDatasourceInterface(final String datasourceInterface) {
92
		this.datasourceInterface = datasourceInterface;
93
	}
94

  
95
	public String getExtraFieldForTotal() {
96
		return extraFieldForTotal;
97
	}
98

  
99
	public void setExtraFieldForTotal(final String extraFieldForTotal) {
100
		this.extraFieldForTotal = extraFieldForTotal;
101
	}
102

  
103
	public String getExtraFieldForDate() {
104
		return extraFieldForDate;
105
	}
106

  
107
	public void setExtraFieldForDate(final String extraFieldForDate) {
108
		this.extraFieldForDate = extraFieldForDate;
109
	}
110

  
111
	public String getExtraFieldForMdId() {
112
		return extraFieldForMdId;
113
	}
114

  
115
	public void setExtraFieldForMdId(final String extraFieldForMdId) {
116
		this.extraFieldForMdId = extraFieldForMdId;
117
	}
118

  
119
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/java/eu/dnetlib/msro/workflows/nodes/info/SetProviderInfoJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.info;
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.WorkflowsConstants;
8

  
9
public class SetProviderInfoJobNode extends SimpleJobNode {
10
	private String providerId;
11
	private String providerName;
12
	private String api;
13
	
14
	@Override
15
	protected String execute(NodeToken token) throws Exception {
16
		token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_ID, getProviderId());
17
		token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_NAME, getProviderName());
18
		token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE, getApi());
19
		
20
		token.getFullEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_ID, getProviderId());
21
		token.getFullEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_NAME, getProviderName());
22
		token.getFullEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE, getApi());
23
		
24
		token.getProcess().getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_ID, getProviderId());
25
		token.getProcess().getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_NAME, getProviderName());
26
		token.getProcess().getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE, getApi());
27
		
28
		return Arc.DEFAULT_ARC;
29
	}
30

  
31
	public String getProviderId() {
32
		return providerId;
33
	}
34

  
35
	public void setProviderId(String providerId) {
36
		this.providerId = providerId;
37
	}
38

  
39
	public String getProviderName() {
40
		return providerName;
41
	}
42

  
43
	public void setProviderName(String providerName) {
44
		this.providerName = providerName;
45
	}
46

  
47
	public String getApi() {
48
		return api;
49
	}
50

  
51
	public void setApi(String api) {
52
		this.api = api;
53
	}
54

  
55
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/xslt/mdBuilder.xslt.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:datetime="http://exslt.org/dates-and-times" xmlns:exslt="http://exslt.org/common"
4
    xmlns:oai="http://www.openarchives.org/OAI/2.0/"
5
    xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
6
    xmlns:dri="http://www.driver-repository.eu/namespace/dri"
7
    exclude-result-prefixes="xsl datetime exslt dnet">
8
    
9
    <xsl:variable name="status" select="/*[local-name() = 'record']/*[local-name() = 'header']/@status" />
10
    
11
    <xsl:template match="/">
12
        <oai:record xmlns:oai="http://www.openarchives.org/OAI/2.0/"
13
            xmlns:dri="http://www.driver-repository.eu/namespace/dri"
14
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
15
            
16
            <xsl:variable name="datestamp" select="datetime:dateTime()" />
17
            <xsl:variable name="evaluatedMetadataId" select="normalize-space($xpath$)" />
18
            
19
			<!-- Patch OAI header or create ex-novo if not oai -->
20
            <oai:header>
21
                <xsl:if test="\$status">
22
                    <xsl:attribute name="status" >
23
                        <xsl:value-of select="\$status"/>
24
                    </xsl:attribute>
25
                </xsl:if>
26
                <xsl:if test="not(.//dri:objIdentifier)">
27
                	<xsl:if test="\$evaluatedMetadataId != ''">
28
	                    <dri:objIdentifier><xsl:value-of select="concat('$namespacePrefix$::', dnet:md5(\$evaluatedMetadataId))"/></dri:objIdentifier>
29
                	</xsl:if>
30
                </xsl:if>
31
                <xsl:if test="not(.//dri:recordIdentifier)">
32
                    <dri:recordIdentifier><xsl:value-of select="\$evaluatedMetadataId"/></dri:recordIdentifier>
33
                </xsl:if>
34
                <xsl:if test="not(.//dri:dateOfCollection)">
35
                    <dri:dateOfCollection><xsl:value-of select="\$datestamp"/></dri:dateOfCollection>
36
                </xsl:if>
37
				<xsl:if test="not(.//dri:repositoryId)">
38
                    <dri:repositoryId>$datasourceId$</dri:repositoryId>
39
                </xsl:if>
40
                <xsl:if test="not(.//dri:datasourceprefix)">
41
                    <dri:datasourceprefix>$namespacePrefix$</dri:datasourceprefix>
42
                </xsl:if>
43
                
44
				<!-- Bulk copy of old header -->
45
                <xsl:for-each select="/*[local-name() = 'record']/*[local-name() = 'header']/*">
46
                    <xsl:copy-of select="."/>
47
                </xsl:for-each>
48
            </oai:header>
49
            
50
			<!-- Handle metadata block -->
51
            <xsl:choose>
52
            	<!-- If OAI then copy copy the metadata block along -->
53
                <xsl:when test="count(/*[local-name() = 'record']/*[local-name() = 'metadata']) &gt; 0">
54
                    <xsl:copy-of select="/*[local-name() = 'record']/*[local-name() = 'metadata']"/>
55
                </xsl:when>
56
                <!-- If OAI copy in bulk the metadata block -->
57
                <xsl:when test="\$status = 'deleted'" />
58
                <!-- If not-OAI copy ALL the record inside metadata block -->
59
                <xsl:otherwise>
60
                    <oai:metadata>
61
                        <xsl:copy-of select="."/>
62
                    </oai:metadata>
63
                </xsl:otherwise>
64
            </xsl:choose>
65
            
66
            <!-- Handle oai:about block -->
67
            <oai:about>
68
                <provenance xmlns="http://www.openarchives.org/OAI/2.0/provenance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/provenance http://www.openarchives.org/OAI/2.0/provenance.xsd">
69
  					<originDescription harvestDate="{\$datestamp}" altered="true">
70
	    				<baseURL>$baseurl$</baseURL>
71
	    				<identifier><xsl:value-of select="//*[local-name()='header']/*[local-name()='identifier']"/></identifier>
72
	    				<datestamp><xsl:value-of select="//*[local-name()='header']/*[local-name()='datestamp']"/></datestamp>
73
	    				<metadataNamespace>$metadatanamespace$</metadataNamespace>
74
	    				<xsl:copy-of select="//*[local-name()='provenance']/*[local-name() = 'originDescription']"/>
75
  					</originDescription>
76
				</provenance>
77
			</oai:about>
78
        </oai:record>
79
    </xsl:template>
80
    
81
</xsl:stylesheet>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/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-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/xslt/layoutToRecordStylesheet.xsl
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0"
3
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nxsl="http://www.w3.org/1999/XSL/TransformXX"
4
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5

  
6
	<xsl:output omit-xml-declaration="yes" method="xml"
7
		encoding="UTF-8" />
8
	<xsl:namespace-alias stylesheet-prefix="nxsl"
9
		result-prefix="xsl" />
10

  
11
	<xsl:param name="format" />
12

  
13
	<xsl:template match="/">
14
		<xsl:apply-templates select="//LAYOUT" />
15
	</xsl:template>
16

  
17
	<xsl:template match="LAYOUT">
18
		<nxsl:stylesheet version="1.0"
19
			xmlns:dr="http://www.driver-repository.eu/namespace/dr" xmlns:dc="http://purl.org/dc/elements/1.1/"
20
			xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
21
			xmlns:exsl="http://exslt.org/common"
22
      extension-element-prefixes="exsl">
23

  
24
			<nxsl:output version="1.0" omit-xml-declaration="yes"
25
				method="xml" encoding="UTF8" />
26

  
27
			<nxsl:variable name="format">
28
				<xsl:value-of select="$format" />
29
			</nxsl:variable>
30

  
31
			<nxsl:template match="/">
32
				<indexRecord>
33
					<indexRecordIdentifier>
34
						<nxsl:value-of select="//dri:objIdentifier" />
35
					</indexRecordIdentifier>
36
					<targetFields>
37
						<nxsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
38
							<xsl:apply-templates select="FIELDS/FIELD[@indexable='true']" />
39
						</nxsl:if>		
40
					</targetFields>
41
					<result>
42
						<header>
43
							<dri:objIdentifier>
44
								<nxsl:value-of select="//dri:objIdentifier" />
45
							</dri:objIdentifier>
46
							<dri:repositoryId>
47
								<nxsl:value-of select="//dri:repositoryId" />
48
							</dri:repositoryId>
49
							<dri:dateOfCollection>
50
								<nxsl:value-of select="//dri:dateOfCollection" />
51
							</dri:dateOfCollection>
52
							<xsl:apply-templates select="FIELDS/FIELD"
53
								mode="header" />
54
						</header>
55
						<metadata>
56
							<xsl:apply-templates select="FIELDS/FIELD"
57
								mode="result" />
58
						</metadata>
59
					</result>
60
				</indexRecord>
61
			</nxsl:template>
62
		</nxsl:stylesheet>
63
	</xsl:template>
64

  
65
	<xsl:template match="FIELD[@indexable='true']">
66
		<xsl:choose>
67
			<!-- 
68
			<xsl:when test="@name = 'description'">
69
				<nxsl:for-each select="{@xpath}">
70
					<xsl:element name="{@name}">
71
						<nxsl:value-of select="substring(.,1,210)" />
72
					</xsl:element>
73
				</nxsl:for-each>
74
			</xsl:when>
75
			 -->
76
			<xsl:when test="@constant">
77
				<xsl:element name="{@name}">
78
					<xsl:value-of select="@constant" />
79
				</xsl:element>
80
			</xsl:when>
81
			<xsl:when test="@value and not(@xpath)">
82
				<nxsl:element name="{@name}">
83
					<nxsl:value-of select="{@value}" />
84
				</nxsl:element>
85
			</xsl:when>
86
			<xsl:otherwise>
87
				<xsl:variable name="value">
88
					<xsl:choose>
89
						<xsl:when test="@value">
90
							<xsl:value-of select="@value" />
91
						</xsl:when>
92
						<xsl:otherwise>
93
							.
94
						</xsl:otherwise>
95
					</xsl:choose>
96
				</xsl:variable>
97
				<nxsl:for-each select="{@xpath}">
98
					<xsl:element name="{@name}">
99
						<xsl:if test="@external='true'">
100
							<xsl:attribute name="external">true</xsl:attribute>
101
						</xsl:if>
102
						<xsl:choose>
103
							<xsl:when test="@tokenizable='false'">
104
								<nxsl:value-of select="normalize-space({normalize-space($value)})" />
105
							</xsl:when>
106
							<xsl:otherwise>
107
								<nxsl:value-of select="{normalize-space($value)}" />
108
							</xsl:otherwise>
109
						</xsl:choose>
110
					</xsl:element>
111
				</nxsl:for-each>
112
			</xsl:otherwise>
113
		</xsl:choose>
114
	</xsl:template>
115

  
116

  
117
	<xsl:template match="FIELD" mode="result">
118
		<xsl:if test="@result='true'">
119
			<nxsl:copy-of select="{@xpath}" />
120
		</xsl:if>
121
	</xsl:template>
122

  
123
	<xsl:template match="FIELD" mode="header">
124
		<xsl:if test="@header='true'">
125
			<nxsl:copy-of select="{@xpath}" />
126
		</xsl:if>
127
	</xsl:template>
128

  
129
</xsl:stylesheet>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/xslt/wf_profile2sarasvati.xslt
1
<?xml version="1.0"?>
2

  
3
<xsl:stylesheet version="1.0"
4
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5

  
6
	<xsl:template match="/">
7
		<xsl:variable name="wfname" select="translate(.//WORKFLOW_NAME, ' ', '_')" />
8

  
9
		<process-definition name="{$wfname}" xmlns="http://sarasvati.googlecode.com/ProcessDefinition">
10
			<xsl:apply-templates select=".//NODE"/>            
11
			
12
			<node name="success" type="Success" />
13
			<node name="failure" type="Failure" />
14
		</process-definition>
15
	</xsl:template>
16

  
17
	<xsl:template match="NODE">
18
		<xsl:element name="node" namespace="http://sarasvati.googlecode.com/ProcessDefinition">
19
			<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
20
			<xsl:if test="@isJoin = 'true'">
21
				<xsl:attribute name="joinType">and</xsl:attribute>
22
			</xsl:if>
23
			<xsl:if test="@isStart = 'true'">
24
				<xsl:attribute name="isStart">true</xsl:attribute>
25
			</xsl:if>
26
			<xsl:if test="string-length(@type) &gt; 0">
27
				<xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute>
28
			</xsl:if>
29
			
30
			<xsl:apply-templates select=".//ARC"/>
31
			
32
			<arc xmlns="http://sarasvati.googlecode.com/ProcessDefinition" name="failed" to="failure" />
33
			
34
			<xsl:if test="count(.//PARAM[string-length(normalize-space(text())) &gt; 0]) &gt; 0">
35
				<custom xmlns="http://sarasvati.googlecode.com/ProcessDefinition">
36
					<xsl:apply-templates select=".//PARAM"/>
37
				</custom>
38
			</xsl:if>
39
		</xsl:element>
40
	</xsl:template>
41

  
42
	<xsl:template match="ARC">
43
		<xsl:element name="arc" namespace="http://sarasvati.googlecode.com/ProcessDefinition">
44
			<xsl:attribute name="to"><xsl:value-of select="@to" /></xsl:attribute>
45
			<xsl:if test="string-length(@name) &gt; 0">
46
				<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
47
			</xsl:if>
48
		</xsl:element> 
49
	</xsl:template>
50
	
51
	<xsl:template match="PARAM">
52
		<xsl:if test="string-length(normalize-space(text())) &gt; 0">
53
			<xsl:element name="{@name}" namespace="http://sarasvati.googlecode.com/ProcessDefinition"><xsl:value-of select="text()" /></xsl:element>
54
		</xsl:if>
55
	</xsl:template>
56
	
57
</xsl:stylesheet>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/VerifyDatasourceJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.repohi;
2

  
3
import javax.annotation.Resource;
4

  
5
import com.google.common.base.Splitter;
6
import com.googlecode.sarasvati.Arc;
7
import com.googlecode.sarasvati.NodeToken;
8

  
9
import eu.dnetlib.enabling.datasources.rmi.DatasourceConstants;
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
11
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
12
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
13
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
14
import eu.dnetlib.msro.rmi.MSROException;
15
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
16
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
17

  
18
public class VerifyDatasourceJobNode extends SimpleJobNode {
19

  
20
	@Resource
21
	private UniqueServiceLocator serviceLocator;
22

  
23
	private String expectedInterfaceTypologyPrefixes;
24

  
25
	private String expectedCompliancePrefixes;
26

  
27
	@Override
28
	protected String execute(final NodeToken token) throws Exception {
29
		final String dsId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID);
30
		final String ifaceId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE);
31
		final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class);
32

  
33
		String compliance;
34
		try {
35
			compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
36
					+ "']/INTERFACE_EXTRA_FIELD[@name='"
37
					+ DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD + "']/text()");
38
		} catch (ISLookUpDocumentNotFoundException e) {
39
			compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
40
					+ "']/@compliance/string()");
41
		}
42

  
43
		final String typology = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
44
				+ "']/@typology/string()");
45

  
46
		verifyValue(compliance, expectedCompliancePrefixes);
47
		verifyValue(typology, expectedInterfaceTypologyPrefixes);
48

  
49
		if (isPending(dsId)) {
50
			return "validateDs";
51
		} else {
52
			return Arc.DEFAULT_ARC;
53
		}
54
	}
55

  
56
	private void verifyValue(final String value, final String expected) throws Exception {
57
		if (expected != null && !expected.isEmpty()) {
58
			for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(expected)) {
59
				if (value.toLowerCase().startsWith(s.toLowerCase())) { return; }
60
			}
61
			throw new MSROException("Invalid value: " + value + ", Valid term prefixes are: [" + expected + "]");
62
		}
63
	}
64

  
65
	private boolean isPending(final String id) throws ISLookUpDocumentNotFoundException, ISLookUpException {
66
		final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//RESOURCE_KIND/@value/string()";
67
		final String res = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
68
		return res.trim().equals("PendingRepositoryResources");
69
	}
70

  
71
	public String getExpectedInterfaceTypologyPrefixes() {
72
		return expectedInterfaceTypologyPrefixes;
73
	}
74

  
75
	public void setExpectedInterfaceTypologyPrefixes(final String expectedInterfaceTypologyPrefixes) {
76
		this.expectedInterfaceTypologyPrefixes = expectedInterfaceTypologyPrefixes;
77
	}
78

  
79
	public String getExpectedCompliancePrefixes() {
80
		return expectedCompliancePrefixes;
81
	}
82

  
83
	public void setExpectedCompliancePrefixes(final String expectedCompliancePrefixes) {
84
		this.expectedCompliancePrefixes = expectedCompliancePrefixes;
85
	}
86

  
87
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/templates/workflow.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE>
3
    <HEADER>
4
        <RESOURCE_IDENTIFIER value=""/>
5
        <RESOURCE_TYPE value="WorkflowDSResourceType"/>
6
        <RESOURCE_KIND value="WorkflowDSResources"/>
7
        <RESOURCE_URI value=""/>
8
        <DATE_OF_CREATION value="2006-05-04T18:13:51.0Z"/>
9
    </HEADER>
10
    <BODY>
11
        <WORKFLOW_NAME>$name$</WORKFLOW_NAME>
12
		<WORKFLOW_TYPE>$type$</WORKFLOW_TYPE>
13
		<WORKFLOW_PRIORITY>$priority$</WORKFLOW_PRIORITY>
14
        <CONFIGURATION start="$startMode$">
15
        	$conf$
16
        </CONFIGURATION>
17
        <STATUS />
18
    </BODY>
19
</RESOURCE_PROFILE>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/CreateObjectStoreJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.repohi;
2

  
3
import java.util.Map;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7

  
8
import com.googlecode.sarasvati.Engine;
9
import com.googlecode.sarasvati.NodeToken;
10
import com.googlecode.sarasvati.env.Env;
11

  
12
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
13
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
14
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
15
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
16

  
17
public class CreateObjectStoreJobNode extends BlackboardJobNode {
18

  
19
	private static final Log log = LogFactory.getLog(CreateObjectStoreJobNode.class);
20

  
21
	private String interpretation;
22
	private String outputPrefix = "objectStore_";
23

  
24
	@Override
25
	protected String obtainServiceId(final NodeToken token) {
26
		return getServiceLocator().getServiceId(ObjectStoreService.class);
27
	}
28

  
29
	@Override
30
	protected void prepareJob(final BlackboardJob job, final NodeToken token) {
31
		log.info("preparing blackboard job for the creation of the objectStore ");
32
		job.setAction("CREATE");
33
		job.getParameters().put("interpretation", interpretation);
34
	}
35

  
36
	public String getInterpretation() {
37
		return interpretation;
38
	}
39

  
40
	public void setInterpretation(final String interpretation) {
41
		this.interpretation = interpretation;
42
	}
43

  
44
	public String getOutputPrefix() {
45
		return outputPrefix;
46
	}
47

  
48
	public void setOutputPrefix(final String outputPrefix) {
49
		this.outputPrefix = outputPrefix;
50
	}
51

  
52
	@Override
53
	protected BlackboardWorkflowJobListener generateBlackboardListener(final Engine engine, final NodeToken token) {
54
		return new BlackboardWorkflowJobListener(engine, token) {
55

  
56
			@Override
57
			protected void populateEnv(final Env env, final Map<String, String> responseParams) {
58
				;
59
				env.setAttribute(getOutputPrefix() + "interpretation", interpretation);
60
				env.setAttribute(getOutputPrefix() + "id", responseParams.get("objectStoreId"));
61
			}
62
		};
63
	}
64

  
65
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/UpdateMetaWfJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.repohi;
2

  
3
import java.io.IOException;
4
import java.io.StringWriter;
5
import java.util.Map;
6

  
7
import javax.annotation.Resource;
8

  
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

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

  
16
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
17
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
18
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
19
import eu.dnetlib.msro.workflows.metawf.DatasourceMetaWorkflow;
20
import eu.dnetlib.msro.workflows.metawf.DatasourceMetaWorkflowFactory;
21
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
22
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
23

  
24
public class UpdateMetaWfJobNode extends SimpleJobNode {
25

  
26
	@Resource
27
	private UniqueServiceLocator serviceLocator;
28

  
29
	@Resource
30
	private DatasourceMetaWorkflowFactory datasourceMetaWorkflowFactory;
31

  
32
	private String beanName;
33

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

  
36
	@Override
37
	protected String execute(final NodeToken token) throws Exception {
38
		final String metaWfId = token.getFullEnv().getAttribute("META_WORKFLOW_ID");
39

  
40
		serviceLocator.getService(ISRegistryService.class).updateProfileNode(metaWfId, "//CONFIGURATION/@status", "'" + WorkflowStatus.WAIT_SYS_SETTINGS + "'");
41

  
42
		final Map<String, String> map = Maps.newHashMap();
43
		for (String s : token.getFullEnv().getAttributeNames()) {
44
			map.put(s, token.getFullEnv().getAttribute(s));
45
		}
46
		for (String s : token.getEnv().getAttributeNames()) {
47
			map.put(s, token.getEnv().getAttribute(s));
48
		}
49

  
50
		final DatasourceMetaWorkflow prototypeMetaWf = datasourceMetaWorkflowFactory.newMetaWorkflow(beanName);
51

  
52
		log.info("Updating metaWorkflow of type: " + beanName);
53

  
54
		final int count = prototypeMetaWf.registerAllWorkflows(map);
55
		log.info("  -- Registered wfs: " + count);
56

  
57
		final String repoByeId = prototypeMetaWf.registerDestroyWorkflow(map);
58
		log.info("  -- Repo Bye Wf: " + repoByeId);
59

  
60
		updateDatasourceWorkflow(metaWfId, repoByeId, prototypeMetaWf.asXML());
61
		log.info("Done");
62

  
63
		return Arc.DEFAULT_ARC;
64
	}
65

  
66
	protected boolean updateDatasourceWorkflow(final String id, final String repoByeId, final String metawf) throws ISRegistryException, IOException {
67
		final StringWriter sw = new StringWriter();
68
		sw.append("<CONFIGURATION status='");
69
		sw.append(WorkflowStatus.WAIT_USER_SETTINGS.toString());
70
		sw.append("' destroyWorkflow='");
71
		sw.append(repoByeId);
72
		sw.append("'>");
73
		sw.append(metawf);
74
		sw.append("</CONFIGURATION>");
75
		return serviceLocator.getService(ISRegistryService.class).updateProfileNode(id, "//CONFIGURATION", sw.toString());
76
	}
77

  
78
	@Override
79
	public String getBeanName() {
80
		return beanName;
81
	}
82

  
83
	@Override
84
	public void setBeanName(final String name) {
85
		this.beanName = name;
86
	}
87
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/templates/meta-workflow.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE>
3
	<HEADER>
4
		<RESOURCE_IDENTIFIER value="" />
5
		<RESOURCE_TYPE value="MetaWorkflowDSResourceType" />
6
		<RESOURCE_KIND value="MetaWorkflowDSResources" />
7
		<RESOURCE_URI value="" />
8
		<DATE_OF_CREATION value="2006-05-04T18:13:51.0Z" />
9
	</HEADER>
10
	<BODY>
11
		<DATAPROVIDER id="$dsId$" interface="$ifaceId$">$dsName$</DATAPROVIDER>
12
		<METAWORKFLOW_NAME family="$wfFamily$">$wfName$</METAWORKFLOW_NAME>
13
		<METAWORKFLOW_DESCRIPTION></METAWORKFLOW_DESCRIPTION>
14
		<METAWORKFLOW_SECTION>$section$</METAWORKFLOW_SECTION>
15
		<ADMIN_EMAIL/>
16
		<CONFIGURATION status="$status$" />
17
		<SCHEDULING enabled="false">
18
			<CRON>0 0 0 ? * *</CRON>
19
			<MININTERVAL>10080</MININTERVAL>
20
		</SCHEDULING>
21
	</BODY>
22
</RESOURCE_PROFILE>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/java/eu/dnetlib/msro/workflows/nodes/repohi/UpdateMetaWfStatusJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.repohi;
2

  
3
import java.util.List;
4

  
5
import javax.annotation.Resource;
6

  
7
import com.googlecode.sarasvati.Arc;
8
import com.googlecode.sarasvati.NodeToken;
9

  
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
11
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
12
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
13
import eu.dnetlib.msro.rmi.MSROException;
14
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
15
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
16
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
17

  
18
public class UpdateMetaWfStatusJobNode extends SimpleJobNode {
19

  
20
	@Resource
21
	private UniqueServiceLocator serviceLocator;
22

  
23
	@Override
24
	protected String execute(final NodeToken token) throws Exception {
25
		final String metaWfId = token.getFullEnv().getAttribute("META_WORKFLOW_ID");
26

  
27
		final String dsId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID);
28
		final String ifaceId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE);
29

  
30
		updateDatasource(dsId, ifaceId);
31

  
32
		if (isReady(metaWfId)) {
33
			serviceLocator.getService(ISRegistryService.class).updateProfileNode(metaWfId, "//CONFIGURATION/@status", "'" + WorkflowStatus.EXECUTABLE + "'");
34
		}
35

  
36
		return Arc.DEFAULT_ARC;
37
	}
38

  
39
	protected void updateDatasource(final String dsId, final String ifaceId) throws Exception {
40
		serviceLocator.getService(ISRegistryService.class).updateProfileNode(dsId, "//INTERFACE[@id = '" + ifaceId + "']/@active", "'true'");
41
	}
42

  
43
	private boolean isReady(final String metaWfId) throws Exception {
44
		final String query = "for $x in collection('/db/DRIVER/MetaWorkflowDSResources/MetaWorkflowDSResourceType')"
45
				+ "//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value eq '" + metaWfId + "']//WORKFLOW/@id "
46
				+ "for $y in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') " + "where $y//RESOURCE_IDENTIFIER/@value = $x "
47
				+ "return $y//PARAM[@required='true' and string-length(text()) = 0]/@managedBy/string()";
48

  
49
		final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(query);
50

  
51
		if (list.contains("system")) { throw new MSROException("A system param is missing in profile: " + metaWfId); }
52

  
53
		return list.isEmpty();
54
	}
55

  
56
}
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/workflows/templates/workflow_status.xml.st
1
<STATUS>
2
	<LAST_EXECUTION_ID>$procId$</LAST_EXECUTION_ID>
3
	<LAST_EXECUTION_DATE>$date$</LAST_EXECUTION_DATE>
4
	$if(error)$
5
		<LAST_EXECUTION_STATUS>FAILURE</LAST_EXECUTION_STATUS>
6
		<LAST_EXECUTION_ERROR>$error$</LAST_EXECUTION_ERROR>
7
	$else$
8
		<LAST_EXECUTION_STATUS>SUCCESS</LAST_EXECUTION_STATUS>
9
		<LAST_EXECUTION_ERROR />
10
	$endif$
11
	$params.keys:{k|<LAST_EXECUTION_OUTPUT name='$k$'>$params.(k)$</LAST_EXECUTION_OUTPUT>}$
12
</STATUS>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/src/main/resources/eu/dnetlib/msro/mail/wf_failed.mail.st
1
<div>
2
	<p>**** This mail has been generated automatically by D-NET Manager Service, please don't reply ****</p>
3
	<h3>Infrastructure: $infrastructure$ </h3>
4
	<p>Workflow: <b>$wfName$</b></p>
5
	<p>Status: <b>FAILURE</b></p>
6
	<p>
7
		Error message: <i>$error$</i><br /><br />
8
		You can relaunch it clicking <a href="$baseUrl$/workflows.do?wfId=$wfId$">HERE</a>
9
	</p>
10
	
11
	<hr />
12
	
13
	<p>
14
		<b>Workflow details:</b><br /><br />
15
		<table>
16
			<tr><td>Process ID: </td><td><a href="$baseUrl$/workflow_journal.do?procId=$procId$">$procId$</a></td></tr>
17
			$if(responses)$
18
				$responses.keys:{k|<tr><td>$k$: </td><td><i>$responses.(k)$</i></td></tr>}$
19
			$endif$
20
		</table>
21
	</p>
22
	<hr />
23
	
24
	$if(pendingWfs)$
25
		<p>
26
			If it's OK, you can launch manually its dependencies:
27
			<ul>$pendingWfs.keys:{k|<li><a href="$baseUrl$/workflows.do?wfId=$k$">$pendingWfs.(k)$</a></li>}$</ul>
28
		</p>
29
	$endif$
30
</div>
modules/dnet-msro-service/tags/dnet-msro-service-3.0.3/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);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff