Project

General

Profile

« Previous | Next » 

Revision 55823

cleanup

View differences:

modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/deploy.info
1
{"type_source": "SVN", "goal": "package -U source:jar", 
2
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-openaireplus-mapping-utils/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-openaireplus-mapping-utils"}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/resources/eu/dnetlib/actionmanager/xslt/datacite2insertActions.xslt
1
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
                xmlns:oaf="http://namespace.openaire.eu/oaf"
3
                xmlns:dnet="eu.dnetlib.data.transform.xml.OdfToHbaseXsltFunctions"
4
                xmlns:dri="http://www.driver-repository.eu/namespace/dri"
5
                xmlns:dr="http://www.driver-repository.eu/namespace/dr" xmlns:exslt="http://exslt.org/common"
6
                version="1.0" extension-element-prefixes="exslt"
7
                exclude-result-prefixes="xsl oaf dr dri dnet exslt">
8

  
9
	<xsl:output omit-xml-declaration="yes" indent="yes"/>
10

  
11
	<xsl:param name="invisible" select="false()"/>
12
	<xsl:param name="trust" select="string('0.9')"/>
13
	<xsl:param name="provenance" select="string('sysimport:crosswalk:datasetarchive')"/>
14
	<xsl:template match="/*">
15
		<xsl:variable name="about" select="/*[local-name() = 'record']/*[local-name() = 'about']"/>
16
		<xsl:variable name="dateOfCollection" select="concat('', //dri:dateOfCollection)"/>
17
		<xsl:variable name="dateoftransformation" select="concat('', //dr:dateOfTransformation)"/>
18
		<xsl:variable name="metadata" select="exslt:node-set(//*[local-name()='metadata']/*)"/>
19
		<xsl:variable name="namespaceprefix">
20
			<xsl:choose>
21
				<!-- TODO check namespaceprefix length is 12 -->
22
				<xsl:when test="string-length(//oaf:datasourceprefix) &gt; 0">
23
					<xsl:value-of select="//oaf:datasourceprefix"/>
24
				</xsl:when>
25
				<xsl:otherwise>
26
					<xsl:value-of select="unknown_____"/>
27
				</xsl:otherwise>
28
			</xsl:choose>
29
		</xsl:variable>
30

  
31
		<xsl:choose>
32
			<xsl:when
33
					test="count($metadata) = 0 or normalize-space(//oaf:skipRecord)= 'true'">
34
				<ROWS/>
35
			</xsl:when>
36
			<xsl:otherwise>
37

  
38
				<xsl:variable name="resultId"
39
				              select="dnet:oafSimpleId('result', //dri:objIdentifier)"/>
40

  
41
				<xsl:if test="string-length($resultId) &gt; 0">
42
					<xsl:variable name="originalids"
43
					              select="//*[local-name() = 'resource']/*[local-name()='identifier'] | //*[local-name() = 'resource']//*[local-name()='alternateIdentifier']"/>
44
					<xsl:variable name="creators" select="//*[local-name() = 'creators']/*[local-name() = 'creator']"/>
45
					<xsl:variable name="titles" select="//*[local-name() = 'title']"/>
46
					<xsl:variable name="subjects" select="//*[local-name() = 'subject']"/>
47
					<xsl:variable name="publisher" select="//*[local-name() = 'publisher']"/>
48
					<xsl:variable name="descriptions" select="//*[local-name() = 'description']"/>
49
					<xsl:variable name="dates" select="//*[local-name() = 'date']"/>
50
					<xsl:variable name="dateaccepted" select="//oaf:dateAccepted"/>
51
					<xsl:variable name="resourceType" select="//*[local-name() = 'resourceType']"/>
52
					<xsl:variable name="formats" select="//*[local-name() = 'format']"/>
53
					<xsl:variable name="sizes" select="//*[local-name() = 'size']"/>
54
					<xsl:variable name="rights" select="//oaf:accessrights"/>
55
					<xsl:variable name="license" select="//oaf:license"/>
56
					<xsl:variable name="version" select="//*[local-name() = 'version']"/>
57
					<xsl:variable name="language" select="//oaf:language"/>
58
					<xsl:variable name="cobjcategory" select="//dr:CobjCategory"/>
59
					<xsl:variable name="contributor" select="//*[local-name() = 'contributor']/*[local-name() = 'contributorName']"/>
60

  
61
					<xsl:variable name="instanceURI">
62
						<xsl:choose>
63
							<xsl:when
64
									test="string-length( //*[local-name() = 'resource']/*[local-name()='identifier' and ./@identifierType='DOI']) &gt; 0">
65
								<xsl:value-of
66
										select="concat('http://dx.doi.org','/', //*[local-name() = 'resource']/*[local-name()='identifier' and ./@identifierType='DOI']/text())"/>
67
							</xsl:when>
68
							<xsl:when test="string-length( //*[local-name() = 'resource']/*[local-name()='identifier' and ./@identifierType='URL']) &gt; 0">
69
								<xsl:value-of select="concat('', //*[local-name() = 'resource']/*[local-name()='identifier' and ./@identifierType='URL'])"/>
70
							</xsl:when>
71
							<xsl:otherwise>
72
								<xsl:value-of select="concat('', //*[local-name() = 'resource']//*[local-name()='alternateIdentifier' and ./@alternateIdentifierType='URL'])"/>
73
							</xsl:otherwise>
74
						</xsl:choose>
75
					</xsl:variable>
76

  
77
					<xsl:variable name="hostedby" select="//oaf:hostedBy"/>
78
					<xsl:variable name="collectedfrom" select="//oaf:collectedFrom"/>
79

  
80
					<xsl:variable name="pids"
81
					              select="//*[local-name() = 'resource']//*[local-name()='identifier'or local-name()='alternateIdentifier']"/>
82

  
83
					<xsl:variable name="result"
84
					              select="dnet:odfResult($resultId, $invisible, $about, $metadata, $titles, $creators, $subjects, $publisher, $descriptions,
85
		                        $dates, $dateaccepted, $resourceType, $formats, $sizes, $language, $cobjcategory, $contributor, $rights, $license,
86
		                        $version, $pids, $provenance, $trust, $hostedby, $collectedfrom, $originalids, $instanceURI, $dateOfCollection, $dateoftransformation)"/>
87

  
88
					<ROWS>
89
						<ROW key="{$resultId}" columnFamily="result">
90
							<QUALIFIER name="body" type="base64">
91
								<xsl:value-of select="$result"/>
92
							</QUALIFIER>
93
						</ROW>
94

  
95
						<xsl:for-each select="//*[local-name()='projectid']">
96

  
97
							<xsl:variable name="projectId"
98
							              select="dnet:oafSplitId('project', normalize-space(.))"/>
99

  
100
							<xsl:variable name="resultproject"
101
							              select="dnet:rel($resultId, $projectId, 'resultProject', 'outcome', 'isProducedBy',
102
		                              $collectedfrom, $provenance, $trust, $about)"/>
103
							<xsl:variable name="projectresult"
104
							              select="dnet:rel($projectId, $resultId, 'resultProject', 'outcome', 'produces',
105
		                              $collectedfrom, $provenance, $trust, $about)"/>
106

  
107
							<xsl:if test="string-length($projectId) &gt; 0">
108
								<ROW key="{$resultId}" columnFamily="resultProject_outcome_isProducedBy">
109
									<QUALIFIER name="{$projectId}" type="base64">
110
										<xsl:value-of select="$resultproject"/>
111
									</QUALIFIER>
112
								</ROW>
113
								<ROW key="{$projectId}" columnFamily="resultProject_outcome_produces">
114
									<QUALIFIER name="{$resultId}" type="base64">
115
										<xsl:value-of select="$projectresult"/>
116
									</QUALIFIER>
117
								</ROW>
118
							</xsl:if>
119
						</xsl:for-each>
120

  
121
						<xsl:for-each
122
								select="//*[local-name()='relatedIdentifier' and ./@relatedIdentifierType='OPENAIRE' and ./@relationType='IsSupplementTo']">
123

  
124
							<!-- relatedDataset ids must be in the openaire format  -->
125
							<xsl:variable name="targetId" select="dnet:oafSimpleId('result', normalize-space(.))"/>
126

  
127
							<xsl:if test="string-length($targetId) &gt; 0">
128

  
129
								<xsl:variable name="resultDataset"
130
								              select="dnet:rel($resultId, $targetId, 'resultResult', 'supplement', 'isSupplementTo',
131
			                              $collectedfrom, $provenance, $trust, $about)"/>
132
								<xsl:variable name="datasetResult"
133
								              select="dnet:rel($targetId, $resultId, 'resultResult', 'supplement', 'isSupplementedBy',
134
			                              $collectedfrom, $provenance, $trust, $about)"/>
135

  
136
								<ROW key="{$resultId}" columnFamily="resultResult_supplement_isSupplementTo">
137
									<QUALIFIER name="{$targetId}" type="base64">
138
										<xsl:value-of select="$resultDataset"/>
139
									</QUALIFIER>
140
								</ROW>
141
								<ROW key="{$targetId}" columnFamily="resultResult_supplement_isSupplementedBy">
142
									<QUALIFIER name="{$resultId}" type="base64">
143
										<xsl:value-of select="$datasetResult"/>
144
									</QUALIFIER>
145
								</ROW>
146
							</xsl:if>
147
						</xsl:for-each>
148

  
149
						<xsl:for-each
150
								select="//*[local-name()='relatedIdentifier' and ./@relatedIdentifierType='OPENAIRE' and ./@relationType='IsPartOf']">
151

  
152
							<!-- relatedDataset ids must be in the openaire format  -->
153
							<xsl:variable name="datasetId" select="dnet:oafSimpleId('result', normalize-space(.))"/>
154

  
155
							<xsl:if test="string-length($datasetId) &gt; 0">
156

  
157
								<xsl:variable name="childParent"
158
								              select="dnet:rel($resultId, $datasetId, 'resultResult', 'part', 'isPartOf',
159
			                              $collectedfrom, $provenance, $trust, $about)"/>
160
								<xsl:variable name="parentChild"
161
								              select="dnet:rel($datasetId, $resultId, 'resultResult', 'part', 'hasPart',
162
			                              $collectedfrom, $provenance, $trust, $about)"/>
163

  
164
								<ROW key="{$resultId}" columnFamily="resultResult_part_isPartOf">
165
									<QUALIFIER name="{$datasetId}" type="base64">
166
										<xsl:value-of select="$childParent"/>
167
									</QUALIFIER>
168
								</ROW>
169
								<ROW key="{$datasetId}" columnFamily="resultResult_part_hasPart">
170
									<QUALIFIER name="{$resultId}" type="base64">
171
										<xsl:value-of select="$parentChild"/>
172
									</QUALIFIER>
173
								</ROW>
174
							</xsl:if>
175
						</xsl:for-each>
176

  
177
					</ROWS>
178
				</xsl:if>
179
			</xsl:otherwise>
180
		</xsl:choose>
181
	</xsl:template>
182
</xsl:stylesheet>
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/resources/eu/dnetlib/actionmanager/xslt/rels2actions.xslt
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
	xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dr="http://www.driver-repository.eu/namespace/dr"
4
	xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:oaa="http://namespace.openaire.eu/oaa"
5
	xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:dnet="eu.dnetlib.data.transform.xml.OafToHbaseXsltFunctions"
6
	xmlns:exslt="http://exslt.org/common"
7
	xmlns:action="http://namespace.openaire.eu/action" version="1.0"
8
	extension-element-prefixes="exslt"
9
	exclude-result-prefixes="xsl dc dr dri oaa oaf dnet exslt">
10

  
11
	<xsl:output omit-xml-declaration="yes" indent="yes" />
12

  
13
	<xsl:param name="trust" select="string('0.9')" />
14
	<xsl:param name="provenance" select="string('UNKNOWN')" />
15

  
16
	<xsl:template match="/*">
17

  
18
		<xsl:choose>
19
			<xsl:when test="count(//RELATION) = 0">
20
				<ACTIONS />
21
			</xsl:when>
22
			<xsl:otherwise>
23
				<ACTIONS>
24
					<xsl:for-each select="//RELATION">
25
						<xsl:choose>
26
							<xsl:when test="./@type = 'resultProject'">
27
								<xsl:variable name="resultId" select="./@source" />
28
								<xsl:variable name="projectId">
29
									<xsl:choose>
30
										<xsl:when test="starts-with(@target, '40|')">
31
											<xsl:value-of select="./@target" />
32
										</xsl:when>
33
										<xsl:otherwise>
34
											<xsl:value-of select="dnet:oafSplitId('project', normalize-space(@target))"/>
35
										</xsl:otherwise>
36
									</xsl:choose>
37
								</xsl:variable>
38

  
39
								<ACTION targetKey="{$resultId}" targetColumnFamily="resultProject_outcome_isProducedBy" targetColumn="{$projectId}">
40
									<xsl:value-of select="dnet:rel($resultId, $projectId, 'resultProject', 'outcome', 'isProducedBy', $provenance, $trust)" />
41
								</ACTION>
42
								<ACTION targetKey="{$projectId}" targetColumnFamily="resultProject_outcome_produces" targetColumn="{$resultId}">
43
									<xsl:value-of select="dnet:rel($projectId, $resultId, 'resultProject', 'outcome', 'produces', $provenance, $trust)" />
44
								</ACTION>
45
							</xsl:when>
46
							
47
							<!-- TODO: check this block, it caused problems:
48
									Cannot convert argument/return type in call to method 'eu.dnetlib.actionmanager.actions.infopackage.DMFInfoPackageToHbaseXsltFunctions.oafPersonResultFromInfoPackage(node-set, node-set, result-tree, reference, reference)'
49
									FATAL ERROR:  'Could not compile stylesheet'
50
							
51
							<xsl:when test="./@type = 'personResult'">
52
								<xsl:variable name="personId" select="./@source" />
53
								<xsl:variable name="resultId" select="./@target" />
54
								
55
								<xsl:variable name="pos">
56
									<xsl:choose>
57
										<xsl:when test="@position"><xsl:value-of select="@position"/></xsl:when>
58
										<xsl:otherwise>1000</xsl:otherwise>
59
									</xsl:choose>
60
								</xsl:variable>
61

  
62
								<ACTION targetKey="{$personId}" targetColumnFamily="personResult" targetColumn="{$resultId}">
63
									<xsl:value-of select="dnet:oafPersonResultFromInfoPackage($personId, $resultId, $pos, $provenance, $trust)" />
64
								</ACTION>
65
								<ACTION targetKey="{$resultId}" targetColumnFamily="personResult" targetColumn="{$personId}">
66
									<xsl:value-of select="dnet:oafPersonResultFromInfoPackage($resultId, $personId, $pos, $provenance, $trust)" />
67
								</ACTION>
68
							</xsl:when>
69
							-->
70
						</xsl:choose>
71
					</xsl:for-each>
72
				</ACTIONS>
73
			</xsl:otherwise>
74
		</xsl:choose>
75
	</xsl:template>
76

  
77
</xsl:stylesheet>
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/resources/eu/dnetlib/actionmanager/xslt/dmf2updateActions.xslt
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dr="http://www.driver-repository.eu/namespace/dr"
4
                xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:oaa="http://namespace.openaire.eu/oaa"
5
                xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:dnet="eu.dnetlib.data.transform.xml.OafToHbaseXsltFunctions"
6
                xmlns:date="java.lang.System"
7
                xmlns:exslt="http://exslt.org/common"
8
                version="1.0"
9
                extension-element-prefixes="exslt"
10
                exclude-result-prefixes="xsl dc dr dri oaa oaf dnet exslt date">
11

  
12
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
13

  
14
    <xsl:param name="invisible" select="false()"/>
15
    <xsl:param name="trust" select="string('0.9')"/>
16
    <xsl:param name="provenance" select="string('sysimport:crosswalk:repository')"/>
17

  
18
    <xsl:template match="/*">
19
        <xsl:variable name="about" select="/*[local-name() = 'record']/*[local-name() = 'about']"/>
20
        <xsl:variable name="dateofcollection" select="/*[local-name() = 'record']/*[local-name() = 'header']/*[local-name()='dateOfCollection' and text()][1]"/>
21
        <xsl:variable name="dateoftransformation" select="/*[local-name() = 'record']/*[local-name() = 'header']/*[local-name()='dateOfTransformation' and text()][1]"/>
22
        <xsl:variable name="metadata" select="exslt:node-set(/*[local-name() = 'record']/*[local-name()='metadata']/*)"/>
23
        <xsl:variable name="namespaceprefix">
24
            <xsl:choose>
25

  
26
                <!-- TODO check namespaceprefix length is 12 -->
27
                <xsl:when test="string-length(//oaf:datasourceprefix) &gt; 0">
28
                    <xsl:value-of select="//oaf:datasourceprefix"/>
29
                </xsl:when>
30
                <xsl:otherwise>
31
                    <xsl:value-of select="unknown_"/>
32
                </xsl:otherwise>
33
            </xsl:choose>
34
        </xsl:variable>
35

  
36
        <xsl:choose>
37
            <!-- 			<xsl:when test="count($metadata) = 0 or string-length($namespaceprefix) = 0"> -->
38
            <xsl:when test="count($metadata) = 0">
39
                <ROWS/>
40
            </xsl:when>
41
            <xsl:otherwise>
42

  
43
                <xsl:variable name="objIdentifier" select="//dri:objIdentifier"/>
44
                <xsl:variable name="resultId" select="dnet:oafSimpleId('result', //dri:objIdentifier)"/>
45

  
46
                <xsl:if test="string-length($resultId) &gt; 0">
47

  
48
                    <xsl:variable name="cobjcategory" select="//dr:CobjCategory"/>
49
                    <xsl:choose>
50
                        <!-- check if we need to exclude datasets from an OAF MDStore-->
51
                        <xsl:when test="$cobjcategory = '0021'">
52
                            <ROWS/>
53
                        </xsl:when>
54
                        <xsl:otherwise>
55
                            <xsl:variable name="originalidTest" select="/*[local-name()='record']/*[local-name() = 'header']/*[local-name() = 'recordIdentifier']"/>
56
                            <xsl:variable name="originalid">
57
                                <xsl:choose>
58
                                    <xsl:when test="contains($originalidTest, '::')">
59
                                        <xsl:value-of select="substring-after($originalidTest, '::')"/>
60
                                    </xsl:when>
61
                                    <xsl:otherwise>
62
                                        <xsl:value-of select="$originalidTest"/>
63
                                    </xsl:otherwise>
64
                                </xsl:choose>
65
                            </xsl:variable>
66

  
67
                            <xsl:variable name="result"
68
                                          select="dnet:oafResult($resultId, $invisible, $provenance, $trust, $about, $originalid, $dateofcollection, $dateoftransformation, $metadata)"/>
69

  
70
                            <ROWS>
71
                                <ROW targetKey="{$resultId}" targetColumnFamily="result">
72
                                    <QUALIFIER name="{concat('update_', date:nanoTime())}" type="base64"><xsl:value-of select="$result"/></QUALIFIER>
73
                                </ROW>
74
                            </ROWS>
75
                        </xsl:otherwise>
76
                    </xsl:choose>
77
                </xsl:if>
78
            </xsl:otherwise>
79
        </xsl:choose>
80
    </xsl:template>
81

  
82
</xsl:stylesheet>
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/resources/eu/dnetlib/actionmanager/xslt/dmf2insertActions.xslt
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:dc="http://purl.org/dc/elements/1.1/"
4
                xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:dr="http://www.driver-repository.eu/namespace/dr"
5
                xmlns:dnet="eu.dnetlib.data.transform.xml.OafToHbaseXsltFunctions"
6
                xmlns:exslt="http://exslt.org/common"
7
                version="1.0" extension-element-prefixes="exslt"
8
                exclude-result-prefixes="xsl oaf dr dri dnet exslt">
9

  
10
	<xsl:output omit-xml-declaration="yes" indent="yes"/>
11

  
12
	<xsl:param name="invisible" select="false()"/>
13
	<xsl:param name="trust" select="string('0.9')"/>
14
	<xsl:param name="provenance" select="string('sysimport:crosswalk:repository')"/>
15

  
16
	<xsl:template match="/*">
17
		<xsl:variable name="about" select="/*[local-name() = 'record']/*[local-name() = 'about']"/>
18
		<xsl:variable name="dateofcollection" select="/*[local-name() = 'record']/*[local-name() = 'header']/*[local-name()='dateOfCollection' and text()][1]"/>
19
		<xsl:variable name="dateoftransformation" select="/*[local-name() = 'record']/*[local-name() = 'header']/*[local-name()='dateOfTransformation' and text()][1]"/>
20
		<xsl:variable name="metadata" select="exslt:node-set(/*[local-name() = 'record']/*[local-name()='metadata']/*)"/>
21
		<xsl:variable name="namespaceprefix">
22
			<xsl:choose>
23

  
24
				<!-- TODO check namespaceprefix length is 12 -->
25
				<xsl:when test="string-length(//oaf:datasourceprefix) &gt; 0">
26
					<xsl:value-of select="//oaf:datasourceprefix"/>
27
				</xsl:when>
28
				<xsl:otherwise>
29
					<xsl:value-of select="unknown_"/>
30
				</xsl:otherwise>
31
			</xsl:choose>
32
		</xsl:variable>
33

  
34
		<xsl:choose>
35
			<!-- 			<xsl:when test="count($metadata) = 0 or string-length($namespaceprefix) = 0"> -->
36
			<xsl:when test="count($metadata) = 0">
37
				<ROWS/>
38
			</xsl:when>
39
			<xsl:otherwise>
40

  
41
				<xsl:variable name="objIdentifier" select="//dri:objIdentifier"/>
42
				<xsl:variable name="resultId" select="dnet:oafSimpleId('result', //dri:objIdentifier)"/>
43

  
44
				<xsl:if test="string-length($resultId) &gt; 0">
45

  
46
					<xsl:variable name="cobjcategory" select="//dr:CobjCategory"/>
47
					<xsl:choose>
48
						<!-- check if we need to exclude datasets from an OAF MDStore-->
49
						<xsl:when test="$cobjcategory = '0021'">
50
							<ROWS/>
51
						</xsl:when>
52
						<xsl:otherwise>
53
							<xsl:variable name="originalidTest" select="/*[local-name()='record']/*[local-name() = 'header']/*[local-name() = 'recordIdentifier']"/>
54
							<xsl:variable name="originalid">
55
								<xsl:choose>
56
									<xsl:when test="contains($originalidTest, '::')">
57
										<xsl:value-of select="substring-after($originalidTest, '::')"/>
58
									</xsl:when>
59
									<xsl:otherwise>
60
										<xsl:value-of select="$originalidTest"/>
61
									</xsl:otherwise>
62
								</xsl:choose>
63
							</xsl:variable>
64

  
65
							<xsl:variable name="result"
66
							              select="dnet:oafResult($resultId, $invisible, $provenance, $trust, $about, $originalid, $dateofcollection, $dateoftransformation, $metadata)"/>
67

  
68
							<ROWS>
69
								<ROW key="{$resultId}" columnFamily="result">
70
									<QUALIFIER name="body" type="base64">
71
										<xsl:value-of select="$result"/>
72
									</QUALIFIER>
73
								</ROW>
74

  
75
								<xsl:for-each select="//*[local-name()='projectid']">
76

  
77
									<xsl:variable name="projectId" select="dnet:oafSplitId('project', normalize-space(.))"/>
78

  
79
									<xsl:if test="string-length($projectId) &gt; 0">
80

  
81
										<xsl:variable name="resultproject"
82
										              select="dnet:rel($resultId, $projectId, 'resultProject', 'outcome', 'isProducedBy',
83
								                      $metadata, $provenance, $trust, $about)"/>
84
										<xsl:variable name="projectresult"
85
										              select="dnet:rel($projectId, $resultId, 'resultProject', 'outcome', 'produces',
86
								                      $metadata, $provenance, $trust, $about)"/>
87

  
88
										<ROW key="{$resultId}" columnFamily="resultProject_outcome_isProducedBy">
89
											<QUALIFIER name="{$projectId}" type="base64">
90
												<xsl:value-of select="$resultproject"/>
91
											</QUALIFIER>
92
										</ROW>
93
										<ROW key="{$projectId}" columnFamily="resultProject_outcome_produces">
94
											<QUALIFIER name="{$resultId}" type="base64">
95
												<xsl:value-of select="$projectresult"/>
96
											</QUALIFIER>
97
										</ROW>
98
									</xsl:if>
99
								</xsl:for-each>
100

  
101
								<xsl:for-each select="//*[local-name()='relatedDataset']">
102

  
103
									<!-- relatedDataset ids must be in the openaire format  -->
104
									<xsl:variable name="datasetId" select="dnet:oafSimpleId('result', normalize-space(./@id))"/>
105

  
106
									<xsl:if test="string-length($datasetId) &gt; 0">
107

  
108
										<xsl:variable name="resultDataset"
109
										              select="dnet:rel($resultId, $datasetId, 'resultResult', 'publicationDataset', 'isRelatedTo',
110
								                      $metadata, $provenance, $trust, $about)"/>
111
										<xsl:variable name="datasetResult"
112
										              select="dnet:rel($datasetId, $resultId, 'resultResult', 'publicationDataset', 'isRelatedTo',
113
								                      $metadata, $provenance, $trust, $about)"/>
114

  
115
										<ROW key="{$resultId}" columnFamily="resultResult_publicationDataset_isRelatedTo">
116
											<QUALIFIER name="{$datasetId}" type="base64">
117
												<xsl:value-of select="$resultDataset"/>
118
											</QUALIFIER>
119
										</ROW>
120
										<ROW key="{$datasetId}" columnFamily="resultResult_publicationDataset_isRelatedTo">
121
											<QUALIFIER name="{$resultId}" type="base64">
122
												<xsl:value-of select="$datasetResult"/>
123
											</QUALIFIER>
124
										</ROW>
125
									</xsl:if>
126
								</xsl:for-each>
127
							</ROWS>
128
						</xsl:otherwise>
129
					</xsl:choose>
130
				</xsl:if>
131
			</xsl:otherwise>
132
		</xsl:choose>
133
	</xsl:template>
134
</xsl:stylesheet>
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/resources/eu/dnetlib/msro/openaireplus/workflows/index/openaireLayoutToRecordStylesheet.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

  
5
	<xsl:output omit-xml-declaration="yes" method="xml"/>
6
	<xsl:namespace-alias stylesheet-prefix="nxsl" result-prefix="xsl"/>
7

  
8
	<xsl:param name="format"/>
9

  
10
	<xsl:template match="/">
11
		<xsl:apply-templates select="//LAYOUT"/>
12
	</xsl:template>
13

  
14
	<xsl:template match="LAYOUT">
15
		<nxsl:stylesheet version="1.0"
16
		                 xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
17
		                 xmlns:dri="http://www.driver-repository.eu/namespace/dri"
18
		                 exclude-result-prefixes="dnet">
19

  
20
			<nxsl:output version="1.0" omit-xml-declaration="yes"
21
			             method="xml"/>
22

  
23
			<nxsl:variable name="format">
24
				<xsl:value-of select="$format"/>
25
			</nxsl:variable>
26

  
27
			<nxsl:template match="/">
28
				<indexRecord>
29
					<indexRecordIdentifier>
30
						<nxsl:value-of select="//dri:objIdentifier"/>
31
					</indexRecordIdentifier>
32
					<targetFields>
33
						<nxsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
34
							<xsl:apply-templates select="FIELDS/FIELD[@indexable='true']"/>
35
						</nxsl:if>
36
					</targetFields>
37
					<dnetResult>
38
						<nxsl:copy-of select="/*[local-name()='record']/*[local-name()='result']/*[local-name()='header']"/>
39
						<metadata>
40
							<xsl:apply-templates select="FIELDS/FIELD"
41
							                     mode="result"/>
42
						</metadata>
43
					</dnetResult>
44
				</indexRecord>
45
			</nxsl:template>
46
		</nxsl:stylesheet>
47
	</xsl:template>
48

  
49
	<xsl:template match="FIELD[@indexable='true']">
50
		<xsl:choose>
51
			<xsl:when test="@constant">
52
				<xsl:element name="{@name}">
53
					<xsl:value-of select="@constant"/>
54
				</xsl:element>
55
			</xsl:when>
56
			<xsl:when test="@value and not(@xpath)">
57
				<xsl:choose>
58
					<xsl:when test="contains(@type, 'date')">
59
						<nxsl:variable name="{@name}" select="dnet:normalizeDate(normalize-space({normalize-space(@value)}), false())"/>
60
						<nxsl:if test="string-length(${@name}) &gt; 0">
61
							<nxsl:element name="{@name}">
62
								<nxsl:value-of select="${@name}"/>
63
							</nxsl:element>
64
						</nxsl:if>
65
					</xsl:when>
66
					<xsl:otherwise>
67
						<nxsl:element name="{@name}">
68
							<nxsl:value-of select="{@value}"/>
69
						</nxsl:element>
70
					</xsl:otherwise>
71
				</xsl:choose>
72
			</xsl:when>
73
			<xsl:otherwise>
74
				<xsl:variable name="value">
75
					<xsl:choose>
76
						<xsl:when test="@value">
77
							<xsl:value-of select="@value"/>
78
						</xsl:when>
79
						<xsl:otherwise>
80
							.
81
						</xsl:otherwise>
82
					</xsl:choose>
83
				</xsl:variable>
84
				<nxsl:for-each select="{@xpath}">
85
					<xsl:element name="{@name}">
86
						<xsl:choose>
87
							<xsl:when test="@tokenizable='false'">
88
								<nxsl:value-of select="normalize-space({normalize-space($value)})"/>
89
							</xsl:when>
90
							<xsl:otherwise>
91
								<nxsl:value-of select="{normalize-space($value)}"/>
92
							</xsl:otherwise>
93
						</xsl:choose>
94
					</xsl:element>
95
				</nxsl:for-each>
96
			</xsl:otherwise>
97
		</xsl:choose>
98
	</xsl:template>
99

  
100

  
101
	<xsl:template match="FIELD" mode="result">
102
		<xsl:if test="@result='true'">
103
			<nxsl:copy-of select="{@xpath}"/>
104
		</xsl:if>
105
	</xsl:template>
106

  
107
	<xsl:template match="FIELD" mode="header">
108
		<xsl:if test="@header='true'">
109
			<nxsl:copy-of select="{@xpath}"/>
110
		</xsl:if>
111
	</xsl:template>
112

  
113
</xsl:stylesheet>
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/openaire/hadoop/utils/HBaseTableUtils.java
1
package eu.dnetlib.openaire.hadoop.utils;
2

  
3
import java.util.Arrays;
4
import java.util.Set;
5
import java.util.stream.Collectors;
6
import java.util.stream.Stream;
7

  
8
import com.google.common.collect.Sets;
9
import eu.dnetlib.data.proto.DatasourceOrganizationProtos.DatasourceOrganization.Provision;
10
import eu.dnetlib.data.proto.DedupProtos.Dedup;
11
import eu.dnetlib.data.proto.DedupSimilarityProtos.DedupSimilarity;
12
import eu.dnetlib.data.proto.ProjectOrganizationProtos.ProjectOrganization.Participation;
13
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
14
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType;
15
import eu.dnetlib.data.proto.ResultOrganizationProtos.ResultOrganization.Affiliation;
16
import eu.dnetlib.data.proto.ResultProjectProtos.ResultProject.Outcome;
17
import eu.dnetlib.data.proto.ResultResultProtos.ResultResult.*;
18
import eu.dnetlib.data.proto.TypeProtos.Type;
19

  
20
/**
21
 * Common static utility methods to manage the hbase tables
22
 *
23
 * @author claudio
24
 */
25
public class HBaseTableUtils {
26

  
27
	private static final String SEPARATOR = "_";
28

  
29
	public static Set<String> listAllColumns() {
30
		final Set<String> union = Sets.union(listEntities(), listRelationships());
31
		return Sets.union(union, listDedupRelationships());
32
	}
33

  
34
	private static Set<String> listDedupRelationships() {
35
		final Set<String> cfs = Sets.newHashSet();
36
		cfs.add(RelType.organizationOrganization + SEPARATOR + SubRelType.dedup + SEPARATOR + Dedup.RelName.merges);
37
		cfs.add(RelType.organizationOrganization + SEPARATOR + SubRelType.dedup + SEPARATOR + Dedup.RelName.isMergedIn);
38
		cfs.add(RelType.organizationOrganization + SEPARATOR + SubRelType.dedupSimilarity + SEPARATOR + DedupSimilarity.RelName.isSimilarTo);
39

  
40
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.dedup + SEPARATOR + Dedup.RelName.merges);
41
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.dedup + SEPARATOR + Dedup.RelName.isMergedIn);
42
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.dedupSimilarity + SEPARATOR + DedupSimilarity.RelName.isSimilarTo);
43

  
44
		return cfs;
45
	}
46

  
47
	private static Stream<String> types() {
48
		return Arrays.stream(Type.values())
49
				.map(Enum::toString);
50
	}
51

  
52
	public static Set<String> listEntities() {
53
		return types()
54
				.collect(Collectors.toSet());
55
	}
56

  
57
	public static Set<String> listRelationships() {
58
		final Set<String> cfs = Sets.newHashSet();
59
		cfs.add(RelType.datasourceOrganization + SEPARATOR + SubRelType.provision + SEPARATOR + Provision.RelName.isProvidedBy);
60
		cfs.add(RelType.datasourceOrganization + SEPARATOR + SubRelType.provision + SEPARATOR + Provision.RelName.provides);
61

  
62
		cfs.add(RelType.projectOrganization + SEPARATOR + SubRelType.participation + SEPARATOR + Participation.RelName.hasParticipant);
63
		cfs.add(RelType.projectOrganization + SEPARATOR + SubRelType.participation + SEPARATOR + Participation.RelName.isParticipant);
64

  
65
		cfs.add(RelType.resultProject + SEPARATOR + SubRelType.outcome + SEPARATOR + Outcome.RelName.isProducedBy);
66
		cfs.add(RelType.resultProject + SEPARATOR + SubRelType.outcome + SEPARATOR + Outcome.RelName.produces);
67

  
68
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.similarity + SEPARATOR + Similarity.RelName.hasAmongTopNSimilarDocuments);
69
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.similarity + SEPARATOR + Similarity.RelName.isAmongTopNSimilarDocuments);
70

  
71
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.supplement + SEPARATOR + Supplement.RelName.isSupplementedBy);
72
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.supplement + SEPARATOR + Supplement.RelName.isSupplementTo);
73
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.part + SEPARATOR + Part.RelName.isPartOf);
74
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.part + SEPARATOR + Part.RelName.hasPart);
75

  
76
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.publicationDataset + SEPARATOR + PublicationDataset.RelName.isRelatedTo);
77

  
78
		cfs.add(RelType.resultOrganization + SEPARATOR + SubRelType.affiliation + SEPARATOR + Affiliation.RelName.isAuthorInstitutionOf);
79
		cfs.add(RelType.resultOrganization + SEPARATOR + SubRelType.affiliation + SEPARATOR + Affiliation.RelName.hasAuthorInstitution);
80

  
81
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.version + SEPARATOR + SoftwareSoftware.RelName.isVersionOf);
82
		cfs.add(RelType.resultResult + SEPARATOR + SubRelType.relationship + SEPARATOR + Relationship.RelName.isRelatedTo);
83

  
84
		return cfs;
85
	}
86

  
87
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/openaire/exporter/model/Project.java
1
package eu.dnetlib.openaire.exporter.model;
2

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

  
6
import com.google.common.base.Splitter;
7
import com.google.common.collect.Lists;
8
import org.apache.commons.lang.StringUtils;
9

  
10
/**
11
 * Created by claudio on 20/09/16.
12
 */
13
public class Project {
14

  
15
	public static final String INFO_EU_REPO_GRANT_AGREEMENT = "info:eu-repo/grantAgreement/";
16
	private String code;
17
	private String acronym;
18
	private String title;
19
	private String call_identifier;
20
	private String startdate;
21
	private String enddate;
22
	private boolean ec_sc39;
23
	private boolean oa_mandate_for_publications;
24
	private boolean ec_article29_3;
25
	private String fundingpathid;
26
	private String description;
27
	private String jurisdiction;
28
	private String legalname;
29
	private String funder;
30
	private String countryclass;
31
	private String role;
32
	private String firstname;
33
	private String secondnames;
34
	private String email;
35

  
36
	public Project() {
37
	}
38

  
39
	public String getIdnamespace() {
40
		String res = INFO_EU_REPO_GRANT_AGREEMENT + getFunder()+"/";
41
		final String fundingProgram = asFundingProgram(getFundingpathid());
42
		if (StringUtils.isNotBlank(fundingProgram)) {
43
			res += fundingProgram;
44
		}
45
		res += "/" + escapeCode(getCode());
46
		if (StringUtils.isNotBlank(getJurisdiction())) {
47
			res += "/" + getJurisdiction();
48
		}
49
		return res;
50
	}
51

  
52
	public String getListLabel() {
53
		return String.format("for:value:component:_%s_project_id", asFunder(getFunder()));
54
	}
55

  
56
	private String asFunder(final String legalshortname) {
57
		switch (legalshortname.toLowerCase()) {
58
		case "ec":
59
			return asFundingProgram(getFundingpathid()).toLowerCase();
60
		default:
61
			return legalshortname.toLowerCase();
62
		}
63
	}
64

  
65
	public List<String> asList() {
66
		return Lists.newArrayList(
67
				clean(getCode()),
68
				clean(getAcronym()),
69
				clean(getTitle()),
70
				clean(getCall_identifier()),
71
				clean(getStartdate()),
72
				clean(getEnddate()),
73
				String.valueOf(isEc_article29_3()),
74
				String.valueOf(isOa_mandate_for_publications()),
75
				String.valueOf(isEc_article29_3()),
76
				clean(getDescription()),
77
				clean(getLegalname()),
78
				clean(getCountryclass()),
79
				clean(getRole()),
80
				clean(getFirstname()),
81
				clean(getSecondnames()),
82
				clean(getEmail()));
83
	}
84

  
85
	private String clean(final String s) {
86
		return StringUtils.isNotBlank(s) ? "\"" + s.replaceAll("\\n|\\t|\\s+", " ").replace("\"","\"\"").trim() + "\"" : "";
87
	}
88

  
89
	private String escapeCode(final String code) {
90
		return replaceSlash(code);
91
	}
92

  
93
	private String asFundingProgram(final String fundingpathid) {
94
		final ArrayList<String> strings = Lists.newArrayList(Splitter.on("::").split(fundingpathid));
95
		if(strings.size() <= 1) throw new IllegalStateException("Unexpected funding id: "+fundingpathid);
96
		if(strings.size() == 2) return "";
97
		else return replaceSlash(strings.get(2));
98
	}
99

  
100
	private String replaceSlash(final String s) {
101
		return s.replaceAll("/", "%2F");
102
	}
103

  
104
	public String getCode() {
105
		return code;
106
	}
107

  
108
	public Project setCode(final String code) {
109
		this.code = code;
110
		return this;
111
	}
112

  
113
	public String getAcronym() {
114
		return acronym;
115
	}
116

  
117
	public Project setAcronym(final String acronym) {
118
		this.acronym = acronym;
119
		return this;
120
	}
121

  
122
	public String getTitle() {
123
		return title;
124
	}
125

  
126
	public Project setTitle(final String title) {
127
		this.title = title;
128
		return this;
129
	}
130

  
131
	public String getCall_identifier() {
132
		return call_identifier;
133
	}
134

  
135
	public Project setCall_identifier(final String call_identifier) {
136
		this.call_identifier = call_identifier;
137
		return this;
138
	}
139

  
140
	public String getStartdate() {
141
		return startdate;
142
	}
143

  
144
	public Project setStartdate(final String startdate) {
145
		this.startdate = startdate;
146
		return this;
147
	}
148

  
149
	public String getEnddate() {
150
		return enddate;
151
	}
152

  
153
	public Project setEnddate(final String enddate) {
154
		this.enddate = enddate;
155
		return this;
156
	}
157

  
158
	public boolean isEc_sc39() {
159
		return ec_sc39;
160
	}
161

  
162
	public Project setEc_sc39(final boolean ec_sc39) {
163
		this.ec_sc39 = ec_sc39;
164
		return this;
165
	}
166

  
167
	public boolean isOa_mandate_for_publications() {
168
		return oa_mandate_for_publications;
169
	}
170

  
171
	public Project setOa_mandate_for_publications(final boolean oa_mandate_for_publications) {
172
		this.oa_mandate_for_publications = oa_mandate_for_publications;
173
		return this;
174
	}
175

  
176
	public boolean isEc_article29_3() {
177
		return ec_article29_3;
178
	}
179

  
180
	public Project setEc_article29_3(final boolean ec_article29_3) {
181
		this.ec_article29_3 = ec_article29_3;
182
		return this;
183
	}
184

  
185
	public String getFundingpathid() {
186
		return fundingpathid;
187
	}
188

  
189
	public Project setFundingpathid(final String fundingpathid) {
190
		this.fundingpathid = fundingpathid;
191
		return this;
192
	}
193

  
194
	public String getDescription() {
195
		return description;
196
	}
197

  
198
	public Project setDescription(final String description) {
199
		this.description = description;
200
		return this;
201
	}
202

  
203
	public String getJurisdiction() {
204
		return jurisdiction;
205
	}
206

  
207
	public Project setJurisdiction(final String jurisdiction) {
208
		this.jurisdiction = jurisdiction;
209
		return this;
210
	}
211

  
212
	public String getLegalname() {
213
		return legalname;
214
	}
215

  
216
	public Project setLegalname(final String legalname) {
217
		this.legalname = legalname;
218
		return this;
219
	}
220

  
221
	public String getCountryclass() {
222
		return countryclass;
223
	}
224

  
225
	public Project setCountryclass(final String countryclass) {
226
		this.countryclass = countryclass;
227
		return this;
228
	}
229

  
230
	public String getRole() {
231
		return role;
232
	}
233

  
234
	public Project setRole(final String role) {
235
		this.role = role;
236
		return this;
237
	}
238

  
239
	public String getFirstname() {
240
		return firstname;
241
	}
242

  
243
	public Project setFirstname(final String firstname) {
244
		this.firstname = firstname;
245
		return this;
246
	}
247

  
248
	public String getSecondnames() {
249
		return secondnames;
250
	}
251

  
252
	public Project setSecondnames(final String secondnames) {
253
		this.secondnames = secondnames;
254
		return this;
255
	}
256

  
257
	public String getEmail() {
258
		return email;
259
	}
260

  
261
	public Project setEmail(final String email) {
262
		this.email = email;
263
		return this;
264
	}
265

  
266
	public String getFunder() {
267
		return funder;
268
	}
269

  
270
	public Project setFunder(final String funder) {
271
		this.funder = funder;
272
		return this;
273
	}
274
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/openaire/exporter/model/ProjectDetail.java
1
package eu.dnetlib.openaire.exporter.model;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.io.StringWriter;
6
import java.util.List;
7

  
8
import com.google.gson.Gson;
9
import org.supercsv.cellprocessor.Optional;
10
import org.supercsv.cellprocessor.ift.CellProcessor;
11
import org.supercsv.cellprocessor.ift.StringCellProcessor;
12
import org.supercsv.io.CsvBeanReader;
13
import org.supercsv.io.CsvBeanWriter;
14
import org.supercsv.io.ICsvBeanReader;
15
import org.supercsv.io.ICsvBeanWriter;
16
import org.supercsv.prefs.CsvPreference;
17
import org.supercsv.util.CsvContext;
18

  
19
/**
20
 * Created by claudio on 22/09/16.
21
 */
22
public class ProjectDetail {
23

  
24
	private static final String[] NAMEMAPPING = { "projectId", "acronym", "code", "optional1", "optional2", "jsonextrainfo", "fundingPath" };
25

  
26
	private String projectId;
27
	private String acronym;
28
	private String code;
29
	private String optional1;
30
	private String optional2;
31
	private String jsonextrainfo;
32
	private List<String> fundingPath;
33

  
34
	public ProjectDetail() {}
35

  
36
	public static ProjectDetail fromJson(final String json) {
37
		return new Gson().fromJson(json, ProjectDetail.class);
38
	}
39

  
40
	public static ProjectDetail fromCSV(final String csv) throws IOException {
41
		ICsvBeanReader beanReader = null;
42
		try {
43
			beanReader = new CsvBeanReader(new StringReader(csv), CsvPreference.STANDARD_PREFERENCE);
44
			return beanReader.read(ProjectDetail.class, NAMEMAPPING, getProcessors(new StringCellProcessor() {
45
				@Override
46
				public Object execute(final Object value, final CsvContext context) {
47
					return new Gson().fromJson(value.toString(), List.class);
48
				}
49
			}));
50
		} finally {
51
			if (beanReader != null) {
52
				beanReader.close();
53
			}
54
		}
55
	}
56

  
57
	/**
58
	 * Sets up the processors used for the examples. There are 10 CSV columns, so 10 processors are defined. Empty
59
	 * columns are read as null (hence the NotNull() for mandatory columns).
60
	 *
61
	 * @return the cell processors
62
	 */
63
	private static CellProcessor[] getProcessors(final CellProcessor fundingPathProcessor) {
64
		return new CellProcessor[] {
65
				new Optional(), // projectId
66
				new Optional(), // acronym
67
				new Optional(), // code
68
				new Optional(), // optional1
69
				new Optional(), // optional2
70
				new Optional(), // jsonextrainfo
71
				fundingPathProcessor
72
		};
73
	}
74

  
75
	public String asJson() {
76
		return new Gson().toJson(this) + '\n';
77
	}
78

  
79
	public String asCSV() throws IOException {
80
		final StringWriter sb = new StringWriter();
81
		try (ICsvBeanWriter beanWriter = new CsvBeanWriter(sb, CsvPreference.STANDARD_PREFERENCE)) {
82
			beanWriter.write(this, NAMEMAPPING, getProcessors(new StringCellProcessor() {
83
				@Override
84
				public Object execute(final Object value, final CsvContext context) {
85
					return new Gson().toJson(value);
86
				}
87
			}));
88
			beanWriter.flush();
89
		}
90

  
91
		return sb.toString();
92
	}
93

  
94
	public String getProjectId() {
95
		return projectId;
96
	}
97

  
98
	public ProjectDetail setProjectId(final String projectId) {
99
		this.projectId = projectId;
100
		return this;
101
	}
102

  
103
	public String getAcronym() {
104
		return acronym;
105
	}
106

  
107
	public ProjectDetail setAcronym(final String acronym) {
108
		this.acronym = acronym;
109
		return this;
110
	}
111

  
112
	public String getCode() {
113
		return code;
114
	}
115

  
116
	public ProjectDetail setCode(final String code) {
117
		this.code = code;
118
		return this;
119
	}
120

  
121
	public String getOptional1() {
122
		return optional1;
123
	}
124

  
125
	public ProjectDetail setOptional1(final String optional1) {
126
		this.optional1 = optional1;
127
		return this;
128
	}
129

  
130
	public String getOptional2() {
131
		return optional2;
132
	}
133

  
134
	public ProjectDetail setOptional2(final String optional2) {
135
		this.optional2 = optional2;
136
		return this;
137
	}
138

  
139
	public String getJsonextrainfo() {
140
		return jsonextrainfo;
141
	}
142

  
143
	public ProjectDetail setJsonextrainfo(final String jsonextrainfo) {
144
		this.jsonextrainfo = jsonextrainfo;
145
		return this;
146
	}
147

  
148
	public List<String> getFundingPath() {
149
		return fundingPath;
150
	}
151

  
152
	public ProjectDetail setFundingPath(final List<String> fundingPath) {
153
		this.fundingPath = fundingPath;
154
		return this;
155
	}
156

  
157
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/pace/model/ProtoDocumentBuilder.java
1
package eu.dnetlib.pace.model;
2

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

  
6
import com.google.common.collect.Maps;
7
import com.google.protobuf.GeneratedMessage;
8

  
9
import eu.dnetlib.data.transform.AbstractProtoMapper;
10

  
11
public class ProtoDocumentBuilder extends AbstractProtoMapper {
12

  
13
	public static MapDocument newInstance(final String id, final GeneratedMessage proto, final List<FieldDef> fields) {
14
		final Map<String, Field> fieldMap = new ProtoDocumentBuilder().generateFieldMap(proto, fields);
15
		return new MapDocument(id, fieldMap);
16
	}
17

  
18
	private Map<String, Field> generateFieldMap(final GeneratedMessage proto, final List<FieldDef> fields) {
19
		final Map<String, Field> fieldMap = Maps.newHashMap();
20

  
21
		for (final FieldDef fd : fields) {
22

  
23
			final FieldList fl = new FieldListImpl(fd.getName(), fd.getType());
24

  
25
			for (final Object o : processPath(proto, fd.getPathList(), fd.getType())) {
26

  
27
				fl.add(new FieldValueImpl(fd.getType(), fd.getName(), o));
28
			}
29

  
30
			fieldMap.put(fd.getName(), fl);
31
		}
32

  
33
		return fieldMap;
34
	}
35

  
36
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/data/mapreduce/util/OafDecoder.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import java.util.List;
4
import java.util.Map.Entry;
5

  
6
import com.google.protobuf.Descriptors.EnumValueDescriptor;
7
import com.google.protobuf.Descriptors.FieldDescriptor;
8
import com.google.protobuf.GeneratedMessage;
9
import com.google.protobuf.InvalidProtocolBufferException;
10
import com.google.protobuf.Message;
11

  
12
import eu.dnetlib.data.proto.KindProtos.Kind;
13
import eu.dnetlib.data.proto.OafProtos.Oaf;
14
import eu.dnetlib.data.proto.OafProtos.OafEntity;
15
import eu.dnetlib.data.proto.OafProtos.OafRel;
16
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
17

  
18
/**
19
 * Helper class, to be used as accessor helper over the Oaf structure.
20
 *
21
 * @author claudio
22
 *
23
 */
24
public class OafDecoder {
25

  
26
	/**
27
	 * Oaf object
28
	 */
29
	private Oaf oaf;
30

  
31
	/**
32
	 * Cached sub decoder
33
	 */
34
	private OafEntityDecoder entityDecoder = null;
35

  
36
	/**
37
	 * Cached sub decoder
38
	 */
39
	private OafRelDecoder relDecoder = null;
40

  
41
	public static OafDecoder decode(final Oaf oaf) {
42
		return new OafDecoder(oaf);
43
	}
44

  
45
	public static OafDecoder decode(final byte[] oaf) {
46
		return new OafDecoder(oaf);
47
	}
48

  
49
	protected OafDecoder(final byte[] value) {
50
		try {
51
			this.oaf = Oaf.parseFrom(value);
52
		} catch (InvalidProtocolBufferException e) {
53
			throw new RuntimeException("unable to deserialize proto: " + new String(value));
54
		}
55
	}
56

  
57
	private OafDecoder(final Oaf oaf) {
58
		this.oaf = oaf;
59
	}
60

  
61
	public Kind getKind() {
62
		return oaf.getKind();
63
	}
64

  
65
	public Oaf getOaf() {
66
		return oaf;
67
	}
68

  
69
	// / Entity
70

  
71
	public GeneratedMessage getMetadata() {
72
		return decodeEntity().getMetadata();
73
	}
74

  
75
	public GeneratedMessage getOafEntity() {
76
		return decodeEntity().getEntity();
77
	}
78

  
79
	public String getEntityId() {
80
		return decodeEntity().getId();
81
	}
82

  
83
	public OafEntity getEntity() {
84
		return oaf.getEntity();
85
	}
86

  
87
	public OafEntityDecoder decodeEntity() {
88
		if (entityDecoder == null) {
89
			entityDecoder = OafEntityDecoder.decode(getEntity());
90
		}
91
		return entityDecoder;
92
	}
93

  
94
	// / Rel
95

  
96
	public OafRel getOafRel() {
97
		return oaf.getRel();
98
	}
99

  
100
	public GeneratedMessage getRel() {
101
		return decodeRel().getRel();
102
	}
103

  
104
	public RelType relType() {
105
		return decodeRel().getRelType();
106
	}
107

  
108
	public String relTypeName() {
109
		return relType().toString();
110
	}
111

  
112
	public String relSourceId() {
113
		return decodeRel().getRelSourceId();
114
	}
115

  
116
	public String relTargetId() {
117
		return decodeRel().getRelTargetId();
118
	}
119

  
120
	public String getCFQ() {
121
		switch (getKind()) {
122
		case entity:
123
			return getEntity().getType().toString();
124
		case relation:
125
			return decodeRel().getCFQ();
126
		default:
127
			throw new IllegalArgumentException("Invalid Kind: " + getKind());
128
		}
129
	}
130

  
131
	public RelDescriptor getRelDescriptor() {
132
		if (!getKind().equals(Kind.relation)) return null;
133
		return decodeRel().getRelDescriptor();
134
	}
135

  
136
	private OafRelDecoder decodeRel() {
137
		if (relDecoder == null) {
138
			relDecoder = OafRelDecoder.decode(getOafRel());
139
		}
140
		return relDecoder;
141
	}
142

  
143
	public byte[] toByteArray() {
144
		return oaf.toByteArray();
145
	}
146

  
147
	public String asXml() {
148
		StringBuilder sb = new StringBuilder("<oaf>");
149

  
150
		for (Entry<FieldDescriptor, Object> e : oaf.getAllFields().entrySet()) {
151
			asXml(sb, e.getKey(), e.getValue());
152
		}
153
		sb.append("</oaf>");
154
		return sb.toString();
155
	}
156

  
157
	@SuppressWarnings("unchecked")
158
	private void asXml(final StringBuilder sb, final FieldDescriptor fd, final Object value) {
159

  
160
		if (fd.isRepeated() && (value instanceof List<?>)) {
161
			for (Object o : ((List<Object>) value)) {
162
				asXml(sb, fd, o);
163
			}
164
		} else if (fd.getType().equals(FieldDescriptor.Type.MESSAGE)) {
165
			sb.append("<" + fd.getName() + ">");
166
			for (Entry<FieldDescriptor, Object> e : ((Message) value).getAllFields().entrySet()) {
167
				asXml(sb, e.getKey(), e.getValue());
168
			}
169
			sb.append("</" + fd.getName() + ">");
170
		} else if (fd.getType().equals(FieldDescriptor.Type.ENUM)) {
171
			sb.append("<" + fd.getName() + ">");
172
			sb.append(((EnumValueDescriptor) value).getName());
173
			sb.append("</" + fd.getName() + ">");
174
		} else {
175
			sb.append("<" + fd.getName() + ">");
176
			sb.append(escapeXml(value.toString()));
177
			sb.append("</" + fd.getName() + ">");
178
		}
179
	}
180

  
181
	private static String escapeXml(final String value) {
182
		return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
183
	}
184

  
185
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/data/mapreduce/util/OafRowKeyDecoder.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import org.apache.commons.lang.StringUtils;
4
import org.apache.commons.logging.Log;
5
import org.apache.commons.logging.LogFactory;
6
import org.apache.hadoop.io.Text;
7

  
8
import eu.dnetlib.data.proto.TypeProtos.Type;
9

  
10
public class OafRowKeyDecoder {
11

  
12
	/**
13
	 * logger.
14
	 */
15
	private static final Log log = LogFactory.getLog(OafRowKeyDecoder.class); // NOPMD by marko on 11/24/08 5:02 PM
16

  
17
	private static final String SEPARATOR = "|";
18

  
19
	public final static String ID_REGEX = "^[0-9][0-9]\\|.{12}::[a-zA-Z0-9]{32}$";
20

  
21
	private String key;
22

  
23
	private Type type = null;
24

  
25
	private String id = null;
26

  
27
	public static OafRowKeyDecoder decode(final byte[] key) throws IllegalArgumentException {
28
		return new OafRowKeyDecoder(new String(key));
29
	}
30

  
31
	public static OafRowKeyDecoder decode(final String key) throws IllegalArgumentException {
32
		return new OafRowKeyDecoder(key);
33
	}
34

  
35
	private OafRowKeyDecoder(final String key) throws IllegalArgumentException {
36
		this.key = key;
37

  
38
		if (!key.matches(ID_REGEX)) {
39
			String msg = "invalid key: '" + key + "'";
40
			log.error(msg);
41
			throw new IllegalArgumentException(msg);
42
		}
43

  
44
		int tag = Integer.parseInt(StringUtils.substringBefore(key, SEPARATOR));
45
		this.type = Type.valueOf(tag);
46
		this.id = StringUtils.substringAfter(key, SEPARATOR);
47

  
48
		// System.out.println(OafRowTypeDecoder.class.getName() +" decoded key: " + split);
49
	}
50

  
51
	public String getKey() {
52
		return key;
53
	}
54

  
55
	public Text getKeyAsText() {
56
		return new Text(key);
57
	}
58

  
59
	public Type getType() {
60
		return type;
61
	}
62

  
63
	public String getId() {
64
		return id;
65
	}
66
}
modules/dnet-openaireplus-mapping-utils/branches/dnet-openaireplus-mapping-utils-6.2.3_PROD/src/main/java/eu/dnetlib/data/mapreduce/util/OafRelDecoder.java
1
package eu.dnetlib.data.mapreduce.util;
2

  
3
import com.google.protobuf.Descriptors.FieldDescriptor;
4
import com.google.protobuf.GeneratedMessage;
5
import com.google.protobuf.Message.Builder;
6
import com.google.protobuf.MessageOrBuilder;
7
import com.google.protobuf.ProtocolMessageEnum;
8

  
9
import eu.dnetlib.data.proto.OafProtos.OafEntity;
10
import eu.dnetlib.data.proto.OafProtos.OafRel;
11
import eu.dnetlib.data.proto.RelMetadataProtos.RelMetadata;
12
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
13
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType;
14
import eu.dnetlib.data.proto.TypeProtos.Type;
15

  
16
public class OafRelDecoder {
17

  
18
	private static final String SEPARATOR = "_";
19

  
20
	private final OafRel oafRel;
21

  
22
	public static OafRelDecoder decode(final OafRel oafRel) {
23
		return new OafRelDecoder(oafRel);
24
	}
25

  
26
	private OafRelDecoder(final OafRel oafRel) {
27
		this.oafRel = oafRel;
28
	}
29

  
30
	public RelType getRelType() {
31
		return oafRel.getRelType();
32
	}
33

  
34
	public String relTypeName() {
35
		return getRelType().toString();
36
	}
37

  
38
	public SubRelType getSubRelType() {
39
		return oafRel.getSubRelType();
40
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff