Project

General

Profile

« Previous | Next » 

Revision 48168

[maven-release-plugin] copy for tag unibi-data-collective-transformation-common-2.2.4

View differences:

modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/unibi-data-collective-transformation-common/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": "unibi-data-collective-transformation-common"}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/VocabularyTypeEditorTest.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collective.transformation;
5

  
6
import static org.junit.Assert.*;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10

  
11
/**
12
 * @author js
13
 *
14
 */
15
public class VocabularyTypeEditorTest {
16

  
17
	// class under test
18
	private transient VocabularyTypeEditor editor;
19
	private final String json = "{\"map\":{\"Languages\":{\"name\":\"Names of Languages\", \"caseSensitive\":\"false\", \"delimiter\":\"/\"}, \"TextTypologies\":{\"name\":\"Names of Text Object Typologies\", \"caseSensitive\":\"false\"}}}";
20
	
21
	/**
22
	 * @throws java.lang.Exception
23
	 */
24
	@Before
25
	public void setUp() throws Exception {
26
		editor = new VocabularyTypeEditor();
27
	}
28
	
29
	@Test
30
	public void testGenerate(){
31
		editor.setAsText(json);
32
		assertNotNull(editor.getValue());
33
		assertTrue(editor.getValue() instanceof VocabularyMap);
34
		assertTrue(((VocabularyMap)editor.getValue()).containsKey("Languages"));
35
		assertFalse(((VocabularyMap)editor.getValue()).getMap().get("Languages").isCaseSensitive());
36
	}
37

  
38
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/utils/TransformationRulesImportToolTest.java
1
package eu.dnetlib.data.collective.transformation.utils;
2

  
3
import static org.junit.Assert.*;
4
import static org.mockito.Mockito.*;
5

  
6
import java.util.LinkedList;
7
import java.util.List;
8

  
9
import org.junit.Before;
10
import org.junit.Test;
11
import org.junit.runner.RunWith;
12
import org.mockito.Mock;
13
import org.mockito.junit.MockitoJUnitRunner;
14

  
15
import eu.dnetlib.common.profile.ProfileNotFoundException;
16
import eu.dnetlib.data.collective.transformation.rulelanguage.RuleLanguageParser;
17
import eu.dnetlib.data.collective.transformation.rulelanguage.Rules;
18
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
19
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
20
import eu.dnetlib.enabling.tools.ServiceLocator;
21

  
22
@RunWith(MockitoJUnitRunner.class)
23
public class TransformationRulesImportToolTest {
24
	// class under test
25
	private transient TransformationRulesImportTool importTool;
26
	@Mock
27
	private transient ISLookUpService lookupService;
28
	@Mock
29
	private transient ServiceLocator<ISLookUpService> lookupLocator;
30
	
31
	private transient RuleLanguageParser parser;
32
	
33
	@Before
34
	public void setUp(){
35
		when(lookupLocator.getService()).thenReturn(lookupService);
36
		importTool = new TransformationRulesImportTool();
37
		importTool.setLookupServiceLocator(lookupLocator);
38
	}
39
	
40
	@Test
41
	public void testGetScript() throws ISLookUpException, ProfileNotFoundException{
42
		List<String> queryResult = new LinkedList<String>();
43
		queryResult.add("script");
44
		when(lookupService.quickSearchProfile(anyString())).thenReturn(queryResult);
45
		assertEquals(1, importTool.getScript("someId").size());
46
	}
47
	
48
	@Test(expected = ProfileNotFoundException.class)
49
	public void testScriptNotFound() throws ISLookUpException, ProfileNotFoundException{
50
		List<String> queryResult = new LinkedList<String>();
51
		//queryResult.add("script");
52
		when(lookupService.quickSearchProfile(anyString())).thenReturn(queryResult);
53
		assertEquals(0, importTool.getScript("someId").size());
54
	}
55
	
56
	@Test(expected = IllegalStateException.class)
57
	public void testImportWithInvalidNumberOfSubScripts() throws ISLookUpException, ProfileNotFoundException{
58
		parser = new RuleLanguageParser();
59
		List<String> queryResult = new LinkedList<String>();
60
		queryResult.add(getMainScriptNoSubscripts());
61
		queryResult.add("importedScriptProfileId-1");
62
		List<String> secondQueryResult = new LinkedList<String>();
63
		secondQueryResult.add(getSubScript_1());
64
		when(lookupService.quickSearchProfile(getXQuery("MainScriptProfileId"))).thenReturn(queryResult);
65
		//when(lookupService.quickSearchProfile(getXQuery("importedScriptProfileId-1"))).thenReturn(secondQueryResult);
66
		importTool.importRules(parser, "MainScriptProfileId");
67
		
68
	}
69
	
70
	@Test
71
	public void testImportWithSubScripts() throws ISLookUpException, ProfileNotFoundException{
72
		parser = new RuleLanguageParser();
73
		List<String> queryResult = new LinkedList<String>();
74
		queryResult.add(getMainScriptWithSubscript());
75
		queryResult.add("importedScriptProfileId-1");
76
		List<String> secondQueryResult = new LinkedList<String>();
77
		secondQueryResult.add(getSubScript_1());
78
		when(lookupService.quickSearchProfile(getXQuery("MainScriptProfileId"))).thenReturn(queryResult);
79
		when(lookupService.quickSearchProfile(getXQuery("importedScriptProfileId-1"))).thenReturn(secondQueryResult);
80
		importTool.importRules(parser, "MainScriptProfileId");
81
		assertEquals(1, parser.getElementMappingRules().size());
82
		assertEquals(1, parser.getNamespaceDeclarations().size());
83
		assertEquals(0, parser.getFunctionCalls().size());
84
		assertTrue(parser.getElementMappingRules().containsKey("prefix:element"));
85
		Rules rule = (Rules)parser.getElementMappingRules().get("prefix:element").iterator().next(); 
86
		assertEquals("SomeConstantText", rule.getConstant());
87
	}
88
	
89
	private String getXQuery(String profileId){
90
		return "collection('/db/DRIVER/TransformationRuleDSResources')//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value ='" +
91
			profileId + "']//CODE/child::node(), " +
92
			"for $id in (collection('/db/DRIVER/TransformationRuleDSResources')//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value ='" +
93
			profileId + "']//IMPORTED/SCRIPT_REFERENCE/@id) return string($id)";
94
	}
95
	
96
	private String getMainScriptNoSubscripts(){
97
		StringBuilder builder = new StringBuilder();
98
		//builder.append("import (sub1);");
99
		builder.append("declare_script \"abc\";\r\n");
100
		builder.append("end");
101
		return builder.toString();
102
	}
103
	private String getMainScriptWithSubscript(){
104
		StringBuilder builder = new StringBuilder();
105
		builder.append("declare_script \"abc\";\r\n");
106
		builder.append("import (sub1);");
107
		builder.append("end");
108
		return builder.toString();
109
	}
110
	
111
	private String getSubScript_1(){
112
		StringBuilder builder = new StringBuilder();
113
		builder.append("declare_script \"sub1\";\r\n");
114
		builder.append("declare_ns prefix = \"someUri\";\r\n");
115
		builder.append("prefix:element = \"SomeConstantText\";\r\n");
116
		builder.append("end");
117
		return builder.toString();		
118
	}
119
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/engine/PreProcessorTest.java
1
package eu.dnetlib.data.collective.transformation.engine;
2

  
3
import static org.junit.Assert.*;
4
import static org.mockito.Mockito.*;
5

  
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.List;
9
import java.util.Map;
10

  
11
import org.junit.Before;
12
import org.junit.Test;
13
import org.junit.runner.RunWith;
14
import org.mockito.Mock;
15
import org.mockito.runners.MockitoJUnitRunner;
16

  
17
import eu.dnetlib.data.collective.transformation.VocabularyMap;
18
import eu.dnetlib.data.collective.transformation.VocabularyRegistry;
19
import eu.dnetlib.data.collective.transformation.core.xsl.ext.TransformationFunctionProxy;
20
import eu.dnetlib.data.collective.transformation.engine.functions.Convert;
21
import eu.dnetlib.data.collective.transformation.engine.functions.ProcessingException;
22
import eu.dnetlib.data.collective.transformation.engine.functions.RegularExpression;
23
import eu.dnetlib.data.collective.transformation.engine.functions.Vocabulary;
24
import eu.dnetlib.data.collective.transformation.rulelanguage.IRule;
25
import eu.dnetlib.data.collective.transformation.rulelanguage.util.FunctionCall;
26

  
27
//@RunWith(MockitoJUnitRunner.class)
28
public class PreProcessorTest {
29

  
30
	private transient PreProcessor preProc;
31
	private transient TransformationFunctionProxy functionProxy = TransformationFunctionProxy.getInstance();
32
	private transient Convert convertFunction;
33
	private transient RegularExpression regExprFunction;
34
	
35
	@Mock
36
	private transient FunctionCall functionCall;
37
	@Mock
38
	private transient FunctionCall fc2;
39
	private transient Map<String, String> paramMap = new HashMap<String, String>();
40
	private transient Map<String, String> paramMap2 = new HashMap<String, String>();
41
	
42
	private transient Map<String, String> nsMap = new HashMap<String, String>();
43
	private transient Map<String, String> staticResults = new HashMap<String, String>();
44
	private transient VocabularyMap vocabularyMapWrapper = new VocabularyMap();
45
	private transient Map<String, Vocabulary> vocabulariesMap = new HashMap<String, Vocabulary>();
46
	private transient Map<String, IRule> varRulesMap = new HashMap<String, IRule>();
47
	private transient Map<String, String> jobProperties = new HashMap<String, String>();
48
	@Mock
49
	private transient Vocabulary vocabulary;
50
	private final String vocabularyName = "LANG";
51
	private final String[] fieldValue = {"xyz"};
52
	private final String encodedValue = "abc";
53
	private final String uniqueKey = "uniqueKey-123";
54
	private final String uniqueKey2 = "uniqueKey-456";
55
	@Mock
56
	private transient VocabularyRegistry vocabularyRegistry;
57
	
58
	
59
	//@Before
60
	public void setUp()throws ProcessingException{
61
		nsMap.put("dc", "http://purl.org/dc/elements/1.1/");
62
		paramMap.put(Convert.paramFieldValue, "//dc:language[2]");
63
		paramMap.put(Convert.paramVocabularyName, "LANG");
64
		when(functionCall.getExternalFunctionName()).thenReturn("convert");
65
		when(functionCall.getParameters()).thenReturn(paramMap);
66
		when(functionCall.getUuid()).thenReturn(uniqueKey);
67
		
68
		paramMap2.put(RegularExpression.paramExpr1, "x");
69
		paramMap2.put(RegularExpression.paramExpr2, "y");
70
		paramMap2.put(RegularExpression.paramRegularExpr, "z");
71
		when(fc2.getExternalFunctionName()).thenReturn("regExpr");
72
		when(fc2.getParameters()).thenReturn(paramMap2);
73
		when(fc2.getUuid()).thenReturn(uniqueKey2);
74
		when(fc2.isStatic()).thenReturn(true);
75
		
76
		vocabulariesMap.put(vocabularyName, vocabulary);
77
		vocabularyMapWrapper.setMap(vocabulariesMap);
78
		when(vocabularyRegistry.getVocabularies()).thenReturn(vocabularyMapWrapper);
79
		when(vocabulary.getName()).thenReturn("someQuery");
80
		when(vocabularyRegistry.getVocabulary(vocabularyName)).thenReturn(vocabulary);
81
		convertFunction = new Convert();
82
		convertFunction.setVocabularyRegistry(vocabularyRegistry);
83
		//addVocabulary(vocabularyName, vocabulary);
84
		regExprFunction = new RegularExpression();
85

  
86
		preProc = new PreProcessor();		
87
		preProc.setFunctionProxy(functionProxy);
88
		preProc.setRegExprFunction(regExprFunction);
89
		preProc.setConvertFunction(convertFunction);
90
		when(vocabulary.encoding(Arrays.asList(fieldValue))).thenReturn(encodedValue);
91
	}
92
	
93
	// deprecated
94
//	@Test
95
//	public void testConvert(){
96
//		List<String> objRecords = getObjRecords();
97
//		assertFalse(objRecords.isEmpty());
98
//		preProc.preprocess(functionCall, objRecords, nsMap, staticResults, jobProperties, varRulesMap);
99
//		assertEquals(encodedValue, preProc.getFunctionProxy().convert(uniqueKey, 0));
100
//	}
101
	
102
//	@Test
103
//	public void testRegEpr(){
104
//		List<String> objRecords = getObjRecords();
105
//		assertFalse(objRecords.isEmpty());
106
//		preProc.preprocess(fc2, objRecords, nsMap, staticResults);
107
//		assertNotNull(preProc.getFunctionProxy().regExpr(uniqueKey2, 0));
108
//	}
109
	
110
	private List<String> getObjRecords(){
111
		List<String> objRecordList = new java.util.LinkedList<String>();
112
		StringBuilder builder = new StringBuilder();
113
		builder.append("<objectRecord>");
114
		builder.append(getMdRecord());
115
		builder.append("</objectRecord>");
116
		objRecordList.add(builder.toString());
117
		return objRecordList;
118
	}
119
	
120
	private String getMdRecord(){
121
		StringBuilder builder = new StringBuilder();
122
		builder.append("<record xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\">");
123
		builder.append("<header>");
124
		builder.append("<dri:objIdentifier>234</dri:objIdentifier>");
125
		builder.append("<dri:recordIdentifier>abc</dri:recordIdentifier>");
126
		builder.append("<dri:dateOfCollection>2009-09-30T13:08:57Z</dri:dateOfCollection>");
127
		builder.append("<dri:mdFormat/>");
128
		builder.append("<dri:mdFormatInterpretation/>");
129
		builder.append("<dri:repositoryId>71f5069a-9ea2-41fa-968a-4f69a5722ad0_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>");
130
		builder.append("</header><metadata>");
131
		builder.append("<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/  http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">");
132
		builder.append("<dc:title>SomeTitle</dc:title>");
133
		builder.append("<dc:language>firstLang</dc:language>");
134
		builder.append("<dc:language>" + fieldValue[0] + "</dc:language>");
135
		builder.append("<dc:language>lastLang</dc:language>");
136
		builder.append("</oai_dc:dc>");
137
		builder.append("</metadata>");
138
		builder.append("</record>");
139
		return builder.toString();
140
	}
141
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/engine/SimpleTransformationEngineTest.java
1
package eu.dnetlib.data.collective.transformation.engine;
2

  
3
import static org.junit.Assert.*;
4
import static org.mockito.Mockito.*;
5

  
6
import java.io.StringReader;
7
import java.util.Arrays;
8
import java.util.HashMap;
9
import java.util.LinkedList;
10
import java.util.List;
11
import java.util.Map;
12

  
13
import javax.xml.transform.TransformerConfigurationException;
14

  
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogFactory;
17
import org.dom4j.Document;
18
import org.dom4j.DocumentException;
19
import org.dom4j.io.SAXReader;
20
import org.junit.Before;
21
import org.junit.Test;
22
import org.junit.runner.RunWith;
23
import org.mockito.Mock;
24
import org.mockito.junit.MockitoJUnitRunner;
25
import org.springframework.core.io.ClassPathResource;
26
import org.springframework.core.io.Resource;
27

  
28
import eu.dnetlib.common.profile.ResourceDao;
29
import eu.dnetlib.data.collective.transformation.VocabularyMap;
30
import eu.dnetlib.data.collective.transformation.VocabularyRegistry;
31
import eu.dnetlib.data.collective.transformation.engine.core.TransformationImpl;
32
import eu.dnetlib.data.collective.transformation.engine.functions.DateVocabulary;
33
import eu.dnetlib.data.collective.transformation.engine.functions.PersonVocabulary;
34
import eu.dnetlib.data.collective.transformation.engine.functions.ProcessingException;
35
import eu.dnetlib.data.collective.transformation.engine.functions.Vocabulary;
36
import eu.dnetlib.data.collective.transformation.rulelanguage.RuleLanguageParser;
37

  
38
@RunWith(MockitoJUnitRunner.class)
39
public class SimpleTransformationEngineTest {
40

  
41
	private static final Log log = LogFactory.getLog(SimpleTransformationEngineTest.class);
42
	
43
	private static final String xslTemplatePath = "eu/dnetlib/data/collective/transformation/engine/oaftemplate.xsl";
44
	private transient Resource xslTemplateResource = new ClassPathResource(xslTemplatePath);
45
	private static final String schemaPath = "eu/dnetlib/data/collective/transformation/schema/DMFSchema_vTransformator.xsd";
46
	private transient Resource schemaResource = new ClassPathResource(schemaPath);
47
	
48
	private static final String xslTemplatePath_oaf = "eu/dnetlib/data/collective/transformation/engine/oaftemplate.xsl";         // OpenAIRE specific
49
	private transient Resource xslTemplateResource_oaf = new ClassPathResource(xslTemplatePath_oaf);                              // OpenAIRE specific
50
	private static final String schemaPath_oaf = "eu/dnetlib/data/collective/transformation/schema/OAFSchema_vTransformator.xsd"; // OpenAIRE specific
51
	private transient Resource schemaResource_oaf = new ClassPathResource(schemaPath_oaf);                                        // OpenAIRE specific
52

  
53
	// class under test
54
	private transient SimpleTransformationEngine transformationEngine;
55
	
56
	private transient TransformationImpl transformation;
57
	
58
	private transient TransformationImpl transformationOAF;                                      // OpenAIRE specific
59
	
60
	private transient TransformationImpl transformationProvenance;                               // OpenAIRE specific + provenance
61
	
62
	private transient TransformationImpl transformationAnyFunderProject;							// OpenAIREplus specific
63
	
64
	private transient TransformationImpl transformationWoS;
65
	
66
	@Mock
67
	private transient eu.dnetlib.common.profile.Resource resource;
68
	@Mock
69
	private transient ResourceDao resourceDao;
70
	@Mock
71
	private transient VocabularyRegistry vocabularyRegistry;
72
	private transient VocabularyMap vocabularyMapWrapper = new VocabularyMap();
73
	private transient Map<String, Vocabulary> vocabularies = new HashMap<String, Vocabulary>();
74
	@Mock
75
	private transient Vocabulary vocabularyLang;
76
	
77
	private transient DateVocabulary vocabularyDate = new DateVocabulary();
78
	
79
	private transient PersonVocabulary vocabularyPerson = new PersonVocabulary();
80

  
81
	private transient Vocabulary vocabularyTypes;
82
	
83
	private transient Vocabulary vocabularyRights;
84
	private transient String[] rights = {"info:eu-repo/semantics/openAccess", 
85
			                             "info:eu-repo/semantics/closedAccess",
86
			                             "info:eu-repo/semantics/embargoedAccess", 
87
			                             "info:eu-repo/semantics/restrictedAccess"};
88
	
89
	private transient String repositoryId = "profile-123";
90
	
91
	private transient String dataSinkId = "dnet://MDStoreDS/4-9c7cf682-849b-48bd-92cf-e65367f38e14_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==?type=REFRESH";
92

  
93
	
94
	@SuppressWarnings("unchecked")
95
	@Before
96
	public void setUp() throws TransformerConfigurationException, ProcessingException{
97
		System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
98
		List<String> rightsOA = new LinkedList<String>();
99
		rightsOA.add(rights[0]);
100

  
101
		vocabularyTypes = new Vocabulary();
102
		@SuppressWarnings("rawtypes")
103
		Map encodingMap = new HashMap();
104
		encodingMap.put("name", "Article");
105
		encodingMap.put("encoding", "0001");
106
		encodingMap.put("code", "0001");
107
		encodingMap.put("synonyms", Arrays.asList(new String[]{"info:eu-repo/semantics/article"}));
108
		List<Map<String, ?>> termList = new LinkedList<Map<String,?>>();
109
		termList.add(encodingMap);
110
		encodingMap = new HashMap();
111
		encodingMap.put("name", "Unknown");
112
		encodingMap.put("encoding", "0000");
113
		encodingMap.put("code", "0000");
114
		encodingMap.put("synonyms", Arrays.asList(new String[]{}));
115
		termList.add(encodingMap);
116

  
117
		vocabularyTypes.setResource(termList);
118
		
119
		vocabularyRights = new Vocabulary();
120
		encodingMap = new HashMap();
121
		encodingMap.put("name", "");
122
		encodingMap.put("encoding", "OPEN");
123
		encodingMap.put("code", "OPEN");
124
		encodingMap.put("synonyms", Arrays.asList(new String[]{"info:eu-repo/semantics/openAccess"}));
125
		termList = new LinkedList<Map<String,?>>();
126
		termList.add(encodingMap);
127
		vocabularyRights.setResource(termList);
128
		when(vocabularyRegistry.getVocabularies()).thenReturn(vocabularyMapWrapper);
129
		when(vocabularyRegistry.getVocabulary("LangVocab")).thenReturn(vocabularyLang);
130
		when(vocabularyRegistry.getVocabulary("RightsVocab")).thenReturn(vocabularyRights);
131
		//when(vocabularyRegistry.getVocabulary("DateISO8601")).thenReturn(vocabularyDate);
132
		//when(vocabularyRegistry.getVocabulary("Person")).thenReturn(vocabularyPerson);
133
		//when(vocabularyRegistry.getVocabulary("TypesVocab")).thenReturn(vocabularyTypes);
134
		when(vocabularyLang.encoding(anyList())).thenReturn("Unknown Language");
135
		//when(vocabularyLang.getName()).thenReturn("someQuery");
136
		vocabularies.put("LangVocab", vocabularyLang);
137
		vocabularies.put("RightsVocab", vocabularyRights);                                       // OpenAIRE specific
138
		vocabularies.put("DateISO8601", vocabularyDate);
139
		vocabularies.put("Person", vocabularyPerson);
140
		vocabularies.put("TypesVocab", vocabularyTypes);
141

  
142
		vocabularyMapWrapper.setMap(vocabularies);
143
		transformationEngine = new SimpleTransformationEngine();
144
		transformationEngine.setVocabularyRegistry(vocabularyRegistry);
145
		transformationEngine.setResourceDao(resourceDao);
146
		transformation = new TransformationImpl();
147
		transformation.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
148
		transformation.setTemplate(xslTemplateResource);
149
		transformation.setSchema(schemaResource);
150
		transformation.init();
151
		transformation.setRuleLanguageParser(getRuleLanguageParser(getTransformationScript()));
152
		//transformation.setRootElement("record");
153
		transformation.configureTransformation();
154
		// OpenAIRE specific
155
		transformationOAF = new TransformationImpl();
156
		transformationOAF.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
157
		transformationOAF.setTemplate(xslTemplateResource_oaf);
158
		transformationOAF.setSchema(schemaResource_oaf);
159
		transformationOAF.init();
160
		transformationOAF.setRuleLanguageParser(getRuleLanguageParser(getOAFTransformationScript()));
161
		System.out.println("OAF CONFIGURE TRANSFORMATIOn");
162
		transformationOAF.configureTransformation();
163
		
164
		transformationProvenance = new TransformationImpl();
165
		transformationProvenance.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
166
		transformationProvenance.setTemplate(xslTemplateResource_oaf);
167
		transformationProvenance.setSchema(schemaResource_oaf);
168
		transformationProvenance.init();
169
		transformationProvenance.setRuleLanguageParser(getRuleLanguageParser(getProvenanceTransformationScript() ));
170
		transformationProvenance.configureTransformation();
171
		
172
		transformationAnyFunderProject = new TransformationImpl();
173
		transformationAnyFunderProject.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
174
		transformationAnyFunderProject.setTemplate(xslTemplateResource_oaf);
175
		transformationAnyFunderProject.setSchema(schemaResource_oaf);
176
		transformationAnyFunderProject.init();
177
//		transformationAnyFunderProject.setRuleLanguageParser(getRuleLanguageParser(getFunderTransformationScript() ));
178
		transformationAnyFunderProject.setRuleLanguageParser(getRuleLanguageParser(getOpenaireplusCompatibleFunderTransformationScript() ));
179
		transformationAnyFunderProject.configureTransformation();
180
		
181
		transformationWoS = new TransformationImpl();
182
		transformationWoS.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
183
		transformationWoS.setTemplate(xslTemplateResource_oaf);
184
		transformationWoS.setSchema(schemaResource_oaf);
185
		transformationWoS.init();
186
//		transformationAnyFunderProject.setRuleLanguageParser(getRuleLanguageParser(getFunderTransformationScript() ));
187
		transformationWoS.setRuleLanguageParser(getRuleLanguageParser(getWosTransformationScript() ));
188
		transformationWoS.configureTransformation();
189

  
190
		
191
		String xpathExprOnProfile = "//CONFIGURATION/OFFICIAL_NAME";
192
		String valueOnProfile = "repositoryOfficialName";
193
		try{
194
			when(resourceDao.getResourceByQuery("collection('/db/DRIVER/RepositoryServiceResources')//RESOURCE_PROFILE[.//EXTRA_FIELDS/FIELD[key=\"NamespacePrefix\"][value=\"\"]]")).thenReturn(resource);
195
			when(resourceDao.getResource(repositoryId)).thenReturn(resource);
196
			//when(resourceDao.getResourceByQuery("concat('collection()', '')")).thenReturn(resource);
197
			when(resourceDao.getResourceByQuery("collection()")).thenReturn(resource);			
198
		}catch(Exception e){
199
			e.printStackTrace();
200
		}
201
		when(resource.getValue(xpathExprOnProfile)).thenReturn(valueOnProfile);
202
		String xpathExprDataSourceId = "//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value"; // OpenAIRE specific
203
		String valueDataSourceId = "opendoar::166";                                              // OpenAIRE specific
204
		when(resource.getValue(xpathExprDataSourceId)).thenReturn(valueDataSourceId);            // OpenAIRE specific
205
		String xpathExprDataSourceType = "//EXTRA_FIELDS/FIELD[key='DataSourceType']/value"; // prototype
206
		String valueDataSourceType = "Aggregator";                                              // prototype
207
		when(resource.getValue(xpathExprDataSourceType)).thenReturn(valueDataSourceType);            // prototype
208

  
209
	}
210
	
211
	@Test
212
	public void testTransformationWithObjectRecords() throws DocumentException{
213
		transformationEngine.setTransformation(transformation);
214
		List<String> mdRecords = new LinkedList<String>();
215
		mdRecords.add(getMdRecord("obj-132", "md-1", getDC()));
216
//		mdRecords.add(getMdRecord("obj-132", "md-2", getDidl()));
217
//		List<String> objRecords = new LinkedList<String>();
218
//		objRecords.add(getObjectRecord(mdRecords));
219
		@SuppressWarnings("unused")
220
		String dump;
221
		assertNotNull(dump = transformation.dumpStylesheet());
222
		List<String> transformedMdRecordsResult = new LinkedList<String>();
223
		for (String srcRecord: mdRecords){
224
			transformedMdRecordsResult.add(transformationEngine.transform(srcRecord));
225
		}
226
//		assertEquals(objRecords.size(), transformedMdRecordsResult.size());
227
		//System.out.println(dump);
228
		Document record = (new SAXReader()).read(new StringReader(transformedMdRecordsResult.get(0)));
229
		assertEquals("", record.valueOf("//*[local-name()='header']/@status"));
230
		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
231
		assertNotNull("record contains no metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
232
		assertEquals("http://somehost", record.valueOf("//dc:identifier"));
233
	}
234
	
235
	@Test
236
	public void testTransformationWithMdRecords() throws DocumentException{
237
		transformationEngine.setTransformation(transformation);
238
//		List<String> mdRecords = new LinkedList<String>();
239
//		mdRecords.add(getMdRecord("obj-132", "md-1==::oai:bla-1", getDC()));
240
		@SuppressWarnings("unused")
241
		String dump;
242
		assertNotNull(dump = transformation.dumpStylesheet());
243
		System.out.println("DUMP: " + dump);
244
		
245
		String transformedRecordResult = transformationEngine.transform(getMdRecord("obj-132", "md-1==::oai:bla-1", getDC()));
246
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
247
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
248
		System.out.println(record.asXML());
249
//		assertEquals("", record.valueOf("//*[local-name()='header']/@status"));
250
//		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
251
//		assertNotNull("record contains no metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
252
//		assertEquals("http://somehost", record.valueOf("//dc:identifier"));
253
	}
254
	
255
	@Test
256
	public void testTransformationWithMdRecords_oaf_failed() throws DocumentException{
257
		transformationEngine.setTransformation(transformationOAF);
258
//		List<String> mdRecords = new LinkedList<String>();
259
//		mdRecords.add(getMdRecord("obj-132", "md-1", getOAFDC()));
260
		String dump;
261
		assertNotNull(dump = transformationOAF.dumpStylesheet());
262
		//System.out.println(dump);
263
		String transformedRecordResult = transformationEngine.transform(getMdRecord("obj-132", "md-1", getOAFDC()));
264
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
265
		System.out.println("*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*\r\n" + dump);
266
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
267
		System.out.println(record.asXML());
268
		assertEquals("", record.valueOf("//*[local-name()='header']/@status"));
269
		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
270
		assertNotNull("record contains no metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
271
		assertEquals("failed", record.valueOf("//*[local-name()='header']/@syntaxcheck"));
272
		//assertEquals("http://somehost", record.valueOf("//*[local-name()='metadata']//*[local-name()='identifier']"));
273
		//assertEquals("OPEN", record.valueOf("//oaf:accessrights")); // test convert function with rights vocabulary for many dc:rights elements
274
		//assertEquals("0001", record.valueOf("//dr:CobjCategory"));
275
	}
276
	
277
	@Test
278
	public void testTransformationOfProjectInformation_oaf() throws DocumentException{
279
		transformationEngine.setTransformation(transformationAnyFunderProject);
280
//		List<String> mdRecords = new LinkedList<String>();
281
//		mdRecords.add(getMdRecordWithProvenance("obj-132", "md-1", getOAFDC(), getProvenance()));
282
		String dump;
283
		System.err.println("BEFORE DUMP\r\n");
284
		assertNotNull(dump = transformationAnyFunderProject.dumpStylesheet());
285
		String transformedRecordResult = transformationEngine.transform(getMdRecordWithProvenance("obj-132", "md-1", getOAFDC(), getProvenance()));
286
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
287
		System.err.println("DUMP\r\n" + dump);
288
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
289
		System.out.println(record.asXML());
290
		assertEquals("", record.valueOf("oaf:projectid"));
291
	}
292
	
293
	@Test
294
	public void testTransformationOfWos_oaf() throws DocumentException{
295
		transformationEngine.setTransformation(transformationWoS);
296
//		List<String> mdRecords = new LinkedList<String>();
297
//		mdRecords.add(getMdRecordWithProvenance("obj-132", "md-1", getOAFDC(), getProvenance()));
298
		String dump;
299
		assertNotNull(dump = transformationWoS.dumpStylesheet());
300
		String transformedRecordResult = transformationEngine.transform(getMdRecordWithProvenance("obj-132", "md-1", getWOS(), getProvenance()));
301
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
302
		System.out.println("___WOS___");
303
		System.out.println(dump);
304
		System.out.println("___WOS___");
305
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
306
		System.out.println(record.asXML());
307
		assertEquals("", record.valueOf("oaf:projectid"));
308
	}
309

  
310
	
311
	@Test
312
	public void testTransformationWithMdRecords_provenance() throws DocumentException{
313
		transformationEngine.setTransformation(transformationProvenance);
314
//		List<String> mdRecords = new LinkedList<String>();
315
//		mdRecords.add(getMdRecordWithProvenance("obj-132", "md-1", getOAFDC(), getProvenance() ));
316
		String dump;
317
		assertNotNull(dump = transformationProvenance.dumpStylesheet());
318
		String transformedRecordResult = transformationEngine.transform(getMdRecordWithProvenance("obj-132", "md-1", getOAFDC(), getProvenance() ));
319
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
320
		System.out.println(dump);
321
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
322
		System.out.println("_______________________________________");
323
		System.out.println(record.asXML());
324
		System.out.println("_______________________________________");
325
		assertEquals("", record.valueOf("//*[local-name()='header']/@status"));
326
		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
327
		assertNotNull("record contains no metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
328
		assertEquals("http://somehost", record.valueOf("//dc:identifier"));
329
		assertEquals("OPEN", record.valueOf("//oaf:accessrights")); // test convert function with rights vocabulary for many dc:rights elements
330
		
331
	}
332

  
333
//	@Test
334
//	public void testTransformationWithSkippedRecord() throws DocumentException{
335
//		transformationEngine.setTransformation(transformation);
336
//		List<String> mdRecords = new LinkedList<String>();
337
//		mdRecords.add(getMdRecord("obj-132", "md-1==::oai:bla-1", getDC()));
338
//		mdRecords.add(getMdRecord("obj-133", "md-1==::oai:bla-2", getDC2()));
339
//		List<String> transformedMdRecordsResult = transformationEngine.transform(mdRecords);
340
//		assertEquals(mdRecords.size() - 1, transformedMdRecordsResult.size());
341
//		//System.out.println(dump);
342
//		Document record = (new SAXReader()).read(new StringReader(transformedMdRecordsResult.get(0)));
343
//		System.out.println(record.asXML());
344
//		assertEquals("", record.valueOf("//*[local-name()='header']/@status"));
345
//		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
346
//		assertNotNull("record contains no metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
347
//		assertEquals("http://somehost", record.valueOf("//dc:identifier"));		
348
//	}
349
	
350
	@Test
351
	public void testTransformationWithDeletedRecord() throws DocumentException{
352
		transformationEngine.setTransformation(transformation);
353
//		List<String> mdRecords = new LinkedList<String>();
354
//		mdRecords.add(getDeletedMdRecord("obj-132", "md-1"));
355
		@SuppressWarnings("unused")
356
		String dump;
357
		assertNotNull(dump = transformation.dumpStylesheet());
358
		String transformedRecordResult = transformationEngine.transform(getDeletedMdRecord("obj-132", "md-1"));
359
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
360
		//System.out.println(dump);
361
		Document record = (new SAXReader()).read(new StringReader(transformedRecordResult));
362
		//System.out.println(record.asXML());
363
		assertEquals("deleted", record.valueOf("//*[local-name()='header']/@status"));
364
		assertNotNull("record contains no header node", record.selectSingleNode("//*[local-name()='header']"));
365
		assertNull("record contains a metadata node", record.selectSingleNode("//*[local-name()='metadata']"));
366
	}
367
	
368
	@Test
369
	public void testTransformationBehaviourWithEmptyMetadata() throws DocumentException{
370
		log.debug("applying OAF transformation");
371
		transformationEngine.setTransformation(transformationOAF);
372
//		List<String> mdRecords = new LinkedList<String>();
373
//		mdRecords.add(getEmptyMetadataMdRecord("obj-132", "md-1"));
374
		@SuppressWarnings("unused")
375
		String dump;
376
		assertNotNull(dump = transformationOAF.dumpStylesheet());
377
		String transformedRecordResult = transformationEngine.transform(getEmptyMetadataMdRecord("obj-132", "md-1"));
378
//		assertEquals(mdRecords.size(), transformedMdRecordsResult.size());
379
		log.debug("record output: " + transformedRecordResult);
380
	}
381
	
382
	private RuleLanguageParser getRuleLanguageParser(String aTransformationScript){
383
		RuleLanguageParser parser = new RuleLanguageParser();
384
		System.out.println(aTransformationScript);
385
		StringReader reader = new StringReader(aTransformationScript);
386
		parser.parse(reader);
387
		return parser;
388
	}
389
	
390
	private String getTransformationScript(){
391
		StringBuilder scriptBuilder = new StringBuilder();
392
		scriptBuilder.append("declare_script \"MainSample\";\r\n");
393
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
394
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
395
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
396
		scriptBuilder.append("declare_ns didl = \"urn:mpeg:mpeg21:2002:02-DIDL-NS\";\r\n");
397
		//scriptBuilder.append("$a1 = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
398
		//scriptBuilder.append("dri:mdFormat = $a1;\r\n");
399
		scriptBuilder.append("dr:CobjMDFormats = xpath:\"//dc:title\";\r\n");
400
		scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
401
		scriptBuilder.append("dc:relation = xpath:\"//didl:Resource/@ref\";\r\n");
402
		scriptBuilder.append("dc:title = copy(\"dc:title\", \"//dc:title\", \"@*|node()\");\r\n");
403
		//scriptBuilder.append("if xpath:\"//dc:title\" dr:aggregatorName = \"abc\"; else dr:repositoryName = \"def\";\r\n");
404
		scriptBuilder.append("if xpath:\"//dc:language[4]\" dr:CobjTypology = xpath:\"//dc:language[2]\"; else dr:CobjTypology = \"test\";\r\n");
405
		scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(normalize-space(.), 'http')\" dc:identifier = xpath:\"normalize-space(.)\"; else dr:CobjIdentifier = xpath:\"normalize-space(.)\";\r\n");
406
		//scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
407
		scriptBuilder.append("dc:language = Convert(xpath:\"normalize-space(//dc:language[2])\",LangVocab);\r\n");
408
		scriptBuilder.append("dri:recordIdentifier = RegExpr(xpath:\"//dri:recordIdentifier\", $var1, \"s/^(.*)(::)/$2/\");\r\n");
409
		scriptBuilder.append("$var0 = \"''\";\r\n");
410
		scriptBuilder.append("static $var1 = RegExpr($job.datasinkid, $var0, \"s/^(dnet:\\/\\/MDStoreDS\\/)|(\\?.*)//g\");\r\n");
411
		scriptBuilder.append("if xpath:\"//dc:format[text()='digital']\" dc:publisher = xpath:\"//dc:publisher\"; else dc:publisher = skipRecord();\r\n");
412
		scriptBuilder.append("end\r\n");
413
		
414
		return scriptBuilder.toString();
415
	}
416
	
417
	private String getOAFTransformationScript(){
418
		StringBuilder scriptBuilder = new StringBuilder();
419
		scriptBuilder.append("declare_script \"MainSample_OAF\";\r\n");
420
		scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
421
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
422
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
423
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
424
		scriptBuilder.append("oaf:dateAccepted = Convert(xpath:\"descendant-or-self::dc:date\", DateISO8601, \"yyyy-MM-dd\", \"min()\");\r\n");
425
//		scriptBuilder.append("oaf:dateAccepted = Convert(xpath:\"//dc:date\", DateISO8601);\r\n");
426
		//scriptBuilder.append("dc:creator = Convert(xpath:\"descendant-or-self::dc:date\", DateISO8601, \"yyyy-MM-dd\", \"min()\");\r\n");
427
		scriptBuilder.append("apply xpath:\"//dc:date\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/date')\" oaf:embargoenddate = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/date\\/embargoEnd\\/)//g\"); else $var0 = \"''\";\r\n");  // retrieve from dc:date , test the info prefix
428
		scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"string-length(translate(normalize-space(.),'info:eu-repo/grantAgreement/EC/FP7','')) = 5\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/)//gm\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
429
//		scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/)//gm\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
430
//		scriptBuilder.append("apply xpath:\"//dc:rights\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/semantics')\" dc:rights = empty; else dc:rights = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:rights, better retrieve from vocabulary
431
		scriptBuilder.append("oaf:accessrights = Convert(xpath:\"//dc:rights\", RightsVocab);\r\n");
432
		scriptBuilder.append("oaf:datasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n"); // retrieve from profile
433
		scriptBuilder.append("dr:CobjMDFormats = xpath:\"//dc:title\";\r\n");
434
		scriptBuilder.append("dc:rights = skipRecord();\r\n");
435
		scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language\", LangVocab);\r\n");
436
		scriptBuilder.append("$varFulltext = xpath:\"//dc:relation[starts-with(., 'http')]\";\r\n");
437
		scriptBuilder.append("if xpath:\"//dc:relation[starts-with(., 'http')]\" oaf:fulltext = $varFulltext; else $var0 = \"''\";\r\n");
438
		scriptBuilder.append("oaf:person = set(xpath:\"//dc:creator\", @normalized = Convert(xpath:\".\", Person););\r\n");
439
//		scriptBuilder.append("apply xpath:\"//dc:creator\" if xpath:\"string-length(.) > 0\" oaf:person = set(xpath:\".\", @normalized = \"test\";); else dc:creator = xpath:\"normalize-space(.)\";\r\n");
440
//		scriptBuilder.append("dc:creator = xpath:\"//dc:creator\";\r\n");
441
//		scriptBuilder.append("apply xpath:\"//dc:creator\" if xpath:\"string-length(.) > 0\"  dc:creator = Convert(xpath:\".\", Person); else $var0 = \"''\";\r\n");
442
		scriptBuilder.append("$varjournaltitle = \"'some title'\";\r\n");
443
		scriptBuilder.append("oaf:journal = set($varjournaltitle, @issn=\"1234-5678\"; , @eissn=\"1234-5679\";);\r\n");
444
		scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
445
		//scriptBuilder.append("if xpath:\"//dc:title\" dr:aggregatorName = \"abc\"; else dr:repositoryName = \"def\";\r\n");
446
		//scriptBuilder.append("if xpath:\"//dc:language[4]\" dr:CobjTypology = xpath:\"//dc:language[2]\"; else dr:CobjTypology = \"test\";\r\n");
447
		scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(normalize-space(.), 'http')\" dc:identifier = xpath:\"normalize-space(.)\"; else dr:CobjIdentifier = xpath:\"normalize-space(.)\";\r\n");
448
		//scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
449
		scriptBuilder.append("$var0 = \"''\";\r\n"); // workaround - placeholder for an empty string
450
		scriptBuilder.append("oaf:hostedBy = set(\"''\", @name = \"hostedName\"; , @id = \"hostedId\";);\r\n");
451
		scriptBuilder.append("$varId = identifierExtract('[\"//dc:identifier\"]' , xpath:\"./record\" , '(10[.][0-9]{4,}[^\\s\"/<>]*/[^\\s\"<>]+)');\r\n");
452
		scriptBuilder.append("oaf:identifier = set(xpath:\"$varId//value\", @identifierType = \"doi\";);\r\n");
453
		
454
		System.err.println("???????????????????????????");
455
		scriptBuilder.append("dr:CobjCategory = Convert(xpath:\"//dc:type\",TypesVocab);\r\n");
456
		
457
		scriptBuilder.append("end\r\n");
458
		
459
		return scriptBuilder.toString();		
460
	}
461
	
462
	private String getProvenanceTransformationScript(){
463
		StringBuilder scriptBuilder = new StringBuilder();
464

  
465
		scriptBuilder.append("declare_script \"MainSample_Provenance\";\r\n");
466
		scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
467
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
468
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
469
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
470
		scriptBuilder.append("declare_ns prov = \"http://www.openarchives.org/OAI/2.0/provenance\";\r\n");
471
//		scriptBuilder.append("dc:dateAccepted = Convert(xpath:\"//dc:date\", DateISO8601);\r\n");
472
		//scriptBuilder.append("dc:creator = Convert(xpath:\"descendant-or-self::dc:date\", DateISO8601, \"yyyy-MM-dd\", \"min()\");\r\n");
473
		//scriptBuilder.append("dc:creator = xpath:\"//dc:creator\";\r\n");
474
		scriptBuilder.append("apply xpath:\"//dc:date\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/date')\" oaf:embargoenddate = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/date\\/embargoEnd\\/)//g\"); else $var0 = \"''\";\r\n");  // retrieve from dc:date , test the info prefix
475
		scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/)//gm\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
476
//		scriptBuilder.append("apply xpath:\"//dc:rights\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/semantics')\" dc:rights = empty; else dc:rights = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:rights, better retrieve from vocabulary
477
		scriptBuilder.append("oaf:accessrights = Convert(xpath:\"//dc:rights\", RightsVocab);\r\n");
478
		scriptBuilder.append("oaf:datasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n"); // retrieve from profile
479
		scriptBuilder.append("static $varDsType = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='DataSourceType']/value\"]);\r\n");
480
		scriptBuilder.append("if xpath:\"$varDsType='Aggregator'\" oaf:hostingDatasourceid = xpath:\"//prov:baseURL\"; else oaf:hostingDatasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
481
		scriptBuilder.append("oaf:collectedDatasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
482
		scriptBuilder.append("dr:CobjMDFormats = xpath:\"//dc:title\";\r\n");
483
		scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language\", LangVocab);\r\n");
484
		scriptBuilder.append("%myTemplate = split(xpath:\"//dc:creator/text()\", \"dc:creator\", \";\");\r\n");
485
		scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
486
		//scriptBuilder.append("if xpath:\"//dc:title\" dr:aggregatorName = \"abc\"; else dr:repositoryName = \"def\";\r\n");
487
		//scriptBuilder.append("if xpath:\"//dc:language[4]\" dr:CobjTypology = xpath:\"//dc:language[2]\"; else dr:CobjTypology = \"test\";\r\n");
488
		scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(normalize-space(.), 'http')\" dc:identifier = xpath:\"normalize-space(.)\"; else dr:CobjIdentifier = xpath:\"normalize-space(.)\";\r\n");
489
		//scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
490
		scriptBuilder.append("$var0 = \"''\";\r\n"); // workaround - placeholder for an empty string
491
		scriptBuilder.append("end\r\n");
492
		
493
		return scriptBuilder.toString();		
494
	}
495
	
496
	private String getWosTransformationScript(){
497
		StringBuilder scriptBuilder = new StringBuilder();
498

  
499
		scriptBuilder.append("declare_script \"MainSample\";\r\n");
500
		scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
501
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
502
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
503
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
504
		scriptBuilder.append("declare_ns prov = \"http://www.openarchives.org/OAI/2.0/provenance\";\r\n");
505
		// header
506
		scriptBuilder.append("dri:objIdentifier = xpath:\"//dri:objIdentifier\";\r\n");
507
		scriptBuilder.append("dri:recordIdentifier = xpath:\"//csvRecord/row[@name='UT']\";\r\n");
508
		scriptBuilder.append("dri:dateOfCollection = xpath:\"//dri:dateOfCollection\";\r\n");
509
//		scriptBuilder.append("dri:repositoryId;\r\n");
510
//		scriptBuilder.append("dri:datasourceprefix;\r\n");
511
		// metadata
512
		scriptBuilder.append("dc:language = Convert(xpath:\"//csvRecord/row[@name='LA']\", LangVocab);\r\n");
513
		scriptBuilder.append("dc:title = xpath:\"//csvRecord/row[@name='TI']\";\r\n");
514
		scriptBuilder.append("%myTemplate = split(xpath:\"//csvRecord/row[@name='AF']/text()\", \"dc:creator\", \";\");\r\n");
515
		scriptBuilder.append("$varIssn = xpath:\"//csvRecord/row[@name='SN']\";");
516
		scriptBuilder.append("oaf:journal = set(xpath:\"//csvRecord/row[@name='SO']\", @issn = $varIssn;);\r\n");
517
//		scriptBuilder.append("dr:CobjCategory = Convert(xpath:\"//csvRecord/row[@name='DT']\", TextTypologies);\r\n");
518
		scriptBuilder.append("dr:CobjCategory = Convert(xpath:\"//csvRecord/row[@name='DT']\", LangVocab);\r\n");
519
		scriptBuilder.append("dc:subject = xpath:\"//csvRecord/row[@name='ID']\";\r\n");
520
		scriptBuilder.append("dc:description = xpath:\"//csvRecord/row[@name='AB']\";\r\n");
521
		scriptBuilder.append("dc:publisher = xpath:\"//csvRecord/row[@name='PU']\";\r\n");
522
		scriptBuilder.append("dc:dateAccepted = xpath:\"//csvRecord/row[@name='PY']\";\r\n");
523
		scriptBuilder.append("$varDoi = xpath:\"concat('http://dx.doi.org/', normalize-space(//csvRecord/row[@name='DI']))\";\r\n");
524
		scriptBuilder.append("dc:identifier = $varDoi;\r\n");
525
		scriptBuilder.append("$varPart1 = xpath:\"concat('Test', 'No.2')\";\r\n");
526
		scriptBuilder.append("dc:subject = $varPart1;\r\n");
527
		scriptBuilder.append("$varIfTest = xpath:\"//dc:creator\";\r\n");
528
		scriptBuilder.append("if xpath:\"count($varIfTest) &gt; 0\" dc:subject = \"'yes'\"; else dc:subject = \"'no'\";\r\n");
529
		scriptBuilder.append("oaf:identifier = set(xpath:\"//csvRecord/row[@name='DI']\", @identifierType = \"doi\";);\r\n");
530
		scriptBuilder.append("oaf:fundingunit = xpath:\"//csvRecord/row[@name='FU']\";\r\n");
531
		scriptBuilder.append("oaf:fundingtext = xpath:\"//csvRecord/row[@name='FX']\";\r\n");
532
		// adapt the attribute values for name and id
533
		scriptBuilder.append("oaf:hostedBy = set(\"''\", @name=\"Unknown Repository\";, @id=\"openaire____::55045bd2a65019fd8e6741a755395c8c\";);\r\n");
534
		scriptBuilder.append("oaf:collectedFrom = set(\"''\", @name=\"Unknown Repository\";, @id=\"openaire____::55045bd2a65019fd8e6741a755395c8c\";);\r\n");
535

  
536
		scriptBuilder.append("end\r\n");
537
		return scriptBuilder.toString();		
538
	}
539

  
540
	private String getFunderTransformationScript(){
541
		StringBuilder scriptBuilder = new StringBuilder();
542

  
543
		scriptBuilder.append("declare_script \"MainSample\";\r\n");
544
		scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
545
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
546
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
547
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
548
		scriptBuilder.append("declare_ns prov = \"http://www.openarchives.org/OAI/2.0/provenance\";\r\n");
549
//		scriptBuilder.append("dc:dateAccepted = Convert(xpath:\"//dc:date\", DateISO8601);\r\n");
550
		//scriptBuilder.append("dc:creator = Convert(xpath:\"descendant-or-self::dc:date\", DateISO8601, \"yyyy-MM-dd\", \"min()\");\r\n");
551
		//scriptBuilder.append("dc:creator = xpath:\"//dc:creator\";\r\n");
552
		scriptBuilder.append("apply xpath:\"//dc:date\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/date')\" oaf:embargoenddate = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/date\\/embargoEnd\\/)//g\"); else $var0 = \"''\";\r\n");  // retrieve from dc:date , test the info prefix
553
		scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"/info:eu-repo/grantAgreement/([A-Za-z]+)/(.*)/([0-9]+)/\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
554
//		scriptBuilder.append("apply xpath:\"//dc:rights\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/semantics')\" dc:rights = empty; else dc:rights = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:rights, better retrieve from vocabulary
555
		scriptBuilder.append("oaf:accessrights = Convert(xpath:\"//dc:rights\", RightsVocab);\r\n");
556
		scriptBuilder.append("oaf:datasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection(')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n"); // retrieve from profile
557
		scriptBuilder.append("static $varDsType = getValue(PROFILEFIELD, [xpath:\"concat('collection(')\", xpath:\"//EXTRA_FIELDS/FIELD[key='DataSourceType']/value\"]);\r\n");
558
		scriptBuilder.append("if xpath:\"$varDsType='Aggregator'\" oaf:hostingDatasourceid = xpath:\"//prov:baseURL\"; else oaf:hostingDatasourceid = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
559
		scriptBuilder.append("oaf:collectedDatasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection(')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
560
		scriptBuilder.append("dr:CobjMDFormats = xpath:\"//dc:title\";\r\n");
561
		scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language\", LangVocab);\r\n");
562
		scriptBuilder.append("%myTemplate = split(xpath:\"//dc:creator/text()\", \"dc:creator\", \";\");\r\n");
563
		scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"concat('collection(')\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
564
		//scriptBuilder.append("if xpath:\"//dc:title\" dr:aggregatorName = \"abc\"; else dr:repositoryName = \"def\";\r\n");
565
		//scriptBuilder.append("if xpath:\"//dc:language[4]\" dr:CobjTypology = xpath:\"//dc:language[2]\"; else dr:CobjTypology = \"test\";\r\n");
566
		scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(normalize-space(.), 'http')\" dc:identifier = xpath:\"normalize-space(.)\"; else dr:CobjIdentifier = xpath:\"normalize-space(.)\";\r\n");
567
		//scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
568
		scriptBuilder.append("$var0 = \"''\";\r\n"); // workaround - placeholder for an empty string
569
		scriptBuilder.append("$varPmc = \"'PMC:123456'\";\r\n"); 		
570
		scriptBuilder.append("oaf:identifier = set($varPmc, @identifierType = \"pmc\";);");
571
		scriptBuilder.append("end\r\n");
572
		
573
		return scriptBuilder.toString();		
574
	}
575
	
576
	private String getOpenaireplusCompatibleFunderTransformationScript(){
577
		StringBuilder scriptBuilder = new StringBuilder();
578

  
579
		scriptBuilder.append("declare_script \"MainSample\";\r\n");
580
		scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
581
		scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
582
		scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
583
		scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
584
		scriptBuilder.append("declare_ns prov = \"http://www.openarchives.org/OAI/2.0/provenance\";\r\n");
585
//		scriptBuilder.append("dc:dateAccepted = Convert(xpath:\"//dc:date\", DateISO8601);\r\n");
586
		//scriptBuilder.append("dc:creator = Convert(xpath:\"descendant-or-self::dc:date\", DateISO8601, \"yyyy-MM-dd\", \"min()\");\r\n");
587
		//scriptBuilder.append("dc:creator = xpath:\"//dc:creator\";\r\n");
588
		scriptBuilder.append("apply xpath:\"//dc:date\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/date')\" oaf:embargoenddate = RegExpr(xpath:\"normalize-space(.)\", $var0, \"s/^(.*info:eu-repo\\/date\\/embargoEnd\\/)//g\"); else $var0 = \"''\";\r\n");  // retrieve from dc:date , test the info prefix
589
//		String regExpr = "s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/([0-9]+).*/$1/gm";
590
		String arg = "$1"; // TODO
591
//		scriptBuilder.append("$varPrj0 = RegExpr(xpath:\"//dc:relation[0][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", $var0, \"s/^.*info:eu-repo\\/grantAgreement\\/EU\\/FP7\\/([0-9]+)//gm\");");
592
		scriptBuilder.append("$varCorda = \"'corda_______::$1'\";\r\n");
593

  
594
		String regExpr = "s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*/$1/gm";
595
		scriptBuilder.append("$varArg = \"'$1'\";\r\n");
596
		scriptBuilder.append("$varPrj1 = " +
597
"RegExpr(xpath:\"//dc:relation[1][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
598
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
599
		scriptBuilder.append("$varPrj2 = " +
600
"RegExpr(xpath:\"//dc:relation[2][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
601
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
602
		scriptBuilder.append("$varPrj3 = " +
603
"RegExpr(xpath:\"//dc:relation[3][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
604
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
605
		scriptBuilder.append("$varPrj4 = " +
606
"RegExpr(xpath:\"//dc:relation[4][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
607
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
608
		scriptBuilder.append("$varPrj5 = " +
609
"RegExpr(xpath:\"//dc:relation[5][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
610
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
611
		scriptBuilder.append("$varPrj6 = " +
612
"RegExpr(xpath:\"//dc:relation[6][starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')]\", " +
613
"$varCorda, \"s/^.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/(\\d\\d\\d\\d\\d\\d).*//gm\");\r\n");
614
		scriptBuilder.append("if xpath:\"string-length($varPrj1) = 20\" oaf:projectid = $varPrj1; else $var0 = \"''\";\r\n");
615
		scriptBuilder.append("if xpath:\"string-length($varPrj2) = 20\" oaf:projectid = $varPrj2; else $var0 = \"''\";\r\n");
616
		scriptBuilder.append("if xpath:\"string-length($varPrj3) = 20\" oaf:projectid = $varPrj3; else $var0 = \"''\";\r\n");
617
		scriptBuilder.append("if xpath:\"string-length($varPrj4) = 20\" oaf:projectid = $varPrj4; else $var0 = \"''\";\r\n");
618
		scriptBuilder.append("if xpath:\"string-length($varPrj5) = 20\" oaf:projectid = $varPrj5; else $var0 = \"''\";\r\n");
619
		scriptBuilder.append("if xpath:\"string-length($varPrj6) = 20\" oaf:projectid = $varPrj6; else $var0 = \"''\";\r\n");
620
//		scriptBuilder.append("apply xpath:\"//dc:relation[starts-with(., 'info:eu-repo/grantAgreement')]\" if xpath:\"string-length() = 6\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"/info:eu-repo/grantAgreement/([A-Za-z]+)/(.*)/([0-9]+)/\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
621
//		scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/grantAgreement/EC/FP7')\" oaf:projectid = RegExpr(xpath:\"normalize-space(.)\", $var0, \"/info:eu-repo/grantAgreement/([A-Za-z]+)/(.*)/([0-9]+)/\"); else dc:relation = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:relation , test the info prefix
622
//		scriptBuilder.append("apply xpath:\"//dc:rights\" if xpath:\"starts-with(normalize-space(.), 'info:eu-repo/semantics')\" dc:rights = empty; else dc:rights = xpath:\"normalize-space(.)\";\r\n");  // retrieve from dc:rights, better retrieve from vocabulary
623
		scriptBuilder.append("oaf:accessrights = Convert(xpath:\"//dc:rights\", RightsVocab);\r\n");
624
		scriptBuilder.append("oaf:datasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n"); // retrieve from profile
625
		scriptBuilder.append("static $varDsType = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='DataSourceType']/value\"]);\r\n");
626
		scriptBuilder.append("if xpath:\"$varDsType='Aggregator'\" oaf:hostingDatasourceid = xpath:\"//prov:baseURL\"; else oaf:hostingDatasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
627
		scriptBuilder.append("oaf:collectedDatasourceid = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//EXTRA_FIELDS/FIELD[key='OpenAireDataSourceId']/value\"]);\r\n");
628
		scriptBuilder.append("dr:CobjMDFormats = xpath:\"//dc:title\";\r\n");
629
		scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language\", LangVocab);\r\n");
630
		scriptBuilder.append("%myTemplate = split(xpath:\"//dc:creator/text()\", \"dc:creator\", \";\");\r\n");
631
		scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"concat('collection()', '')\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
632
		//scriptBuilder.append("if xpath:\"//dc:title\" dr:aggregatorName = \"abc\"; else dr:repositoryName = \"def\";\r\n");
633
		//scriptBuilder.append("if xpath:\"//dc:language[4]\" dr:CobjTypology = xpath:\"//dc:language[2]\"; else dr:CobjTypology = \"test\";\r\n");
634
		scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(normalize-space(.), 'http')\" dc:identifier = xpath:\"normalize-space(.)\"; else dr:CobjIdentifier = xpath:\"normalize-space(.)\";\r\n");
635
		//scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language[2]\",LangVocab);\r\n");
636
		scriptBuilder.append("$var0 = \"''\";\r\n"); // workaround - placeholder for an empty string
637
		scriptBuilder.append("$varPmc = \"'PMC:123456'\";\r\n"); 		
638
		scriptBuilder.append("oaf:identifier = set($varPmc, @identifierType = \"pmc\";);");
639
		scriptBuilder.append("end\r\n");
640
		
641
		return scriptBuilder.toString();		
642
	}
643

  
644

  
645
	private String getObjectRecord(List<String> mdRecords){
646
		StringBuilder builder = new StringBuilder();
647
		builder.append("<objectRecord>");
648
		for (String record: mdRecords) builder.append(record);
649
		builder.append("</objectRecord>");
650
		return builder.toString();
651
	}
652
	
653
	private String getMdRecord(String objIdentifier, String recordIdentifier, String metadata){
654
		StringBuilder builder = new StringBuilder();
655
		builder.append("<record xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\">");
656
		builder.append("<header>");
657
		builder.append("<dri:objIdentifier>");
658
		builder.append(objIdentifier);
659
		builder.append("</dri:objIdentifier>");
660
		builder.append("<dri:repositoryId>profile-123</dri:repositoryId>");
661
		builder.append("<dri:recordIdentifier>");
662
		builder.append(recordIdentifier);
663
		builder.append("</dri:recordIdentifier>");
664
		builder.append("<dri:dateOfCollection>2009-09-30T13:08:57Z</dri:dateOfCollection>");
665
		builder.append("<dri:mdFormat/>");
666
		builder.append("<dri:mdFormatInterpretation/>");
667
		builder.append("<dri:repositoryId>71f5069a-9ea2-41fa-968a-4f69a5722ad0_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>");
668
		builder.append("</header><metadata>");
669
		builder.append(metadata);
670
		builder.append("</metadata>");
671
		builder.append("</record>");
672
		return builder.toString();
673
	}
674
	
675
	private String getMdRecordWithProvenance(String objIdentifier, String recordIdentifier, String metadata, String provenance){
676
		StringBuilder builder = new StringBuilder();
677
		builder.append("<record xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\">");
678
		builder.append("<header>");
679
		builder.append("<dri:objIdentifier>");
680
		builder.append(objIdentifier);
681
		builder.append("</dri:objIdentifier>");
682
		builder.append("<dri:repositoryId>profile-123</dri:repositoryId>");
683
		builder.append("<dri:recordIdentifier>");
684
		builder.append(recordIdentifier);
685
		builder.append("</dri:recordIdentifier>");
686
		builder.append("<dri:dateOfCollection>2009-09-30T13:08:57Z</dri:dateOfCollection>");
687
		builder.append("<dri:mdFormat/>");
688
		builder.append("<dri:mdFormatInterpretation/>");
689
		builder.append("<dri:repositoryId>71f5069a-9ea2-41fa-968a-4f69a5722ad0_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>");
690
		builder.append("</header><metadata>");
691
		builder.append(metadata);
692
		builder.append("</metadata>");
693
		builder.append("<about>");
694
		builder.append(provenance);
695
		builder.append("</about>");
696
		builder.append("</record>");
697
		return builder.toString();		
698
	}
699
	
700
	private String getDeletedMdRecord(String objIdentifier, String recordIdentifier){
701
		StringBuilder builder = new StringBuilder();
702
		builder.append("<record xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
703
		builder.append("<header status=\"deleted\">");
704
		builder.append("<dri:objIdentifier>");
705
		builder.append(objIdentifier);
706
		builder.append("</dri:objIdentifier>");
707
		builder.append("<dri:repositoryId>profile-123</dri:repositoryId>");
708
		builder.append("<dri:recordIdentifier>");
709
		builder.append(recordIdentifier);
710
		builder.append("</dri:recordIdentifier>");
711
		builder.append("<dri:dateOfCollection>2009-09-30T13:08:57Z</dri:dateOfCollection>");
712
		builder.append("<dri:mdFormat/>");
713
		builder.append("<dri:mdFormatInterpretation/>");
714
		builder.append("<dri:repositoryId>71f5069a-9ea2-41fa-968a-4f69a5722ad0_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>");
715
		builder.append("</header>");
716
		builder.append("</record>");		
717
		return builder.toString();
718
	}
719
	
720
	private String getEmptyMetadataMdRecord(String objIdentifier, String recordIdentifier){
721
		// this is an exception case
722
		StringBuilder builder = new StringBuilder();
723
		builder.append("<record>");
724
		builder.append("<header xmlns:oai=\"http://www.openarchives.org/OAI/2.0/\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\">");
725
		builder.append("<dri:objIdentifier>");
726
		builder.append(objIdentifier);
727
		builder.append("</dri:objIdentifier>");
728
		builder.append("<dri:recordIdentifier>");
729
		builder.append(recordIdentifier);
730
		builder.append("</dri:recordIdentifier>");
731
		builder.append("<dri:dateOfCollection>2011-03-29T08:41:48Z</dri:dateOfCollection>");
732
		builder.append("<dri:repositoryId>profile-123</dri:repositoryId>");
733
		builder.append("<identifier>oai:openaire.cern.ch:8</identifier>");
734
		builder.append("<datestamp>2010-12-11T19:14:26Z</datestamp>");
735
		builder.append("<setSpec>EC_fundedresources</setSpec>");
736
		builder.append("</header>");
737
		builder.append("<metadata>");
738
		builder.append("</metadata>");
739
		builder.append("</record>");
740
		return builder.toString();
741
	}
742
	
743
	private String getDC(){
744
		StringBuilder builder = new StringBuilder();
745
		builder.append("<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/  http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">");
746
		builder.append("<dc:title xml:lang=\"en\">SomeTitle</dc:title>");
747
		builder.append("<dc:title xml:lang=\"de\">Irgendein Titel</dc:title>");
748
		//builder.append("<title>SomeTitle</title>");
749
		builder.append("<dc:language>firstLang</dc:language>");
750
		builder.append("<dc:language>   \r\n" + "middleLang   </dc:language>");
751
		builder.append("<dc:language>lastLang</dc:language>");
752
		builder.append("<dc:creator>Any Author</dc:creator>");
753
		builder.append("<dc:contributor>First Contributor</dc:contributor>");
754
		builder.append("<dc:contributor>Second Contributor</dc:contributor>");
755
		builder.append("<dc:format>9</dc:format>");
756
		builder.append("<dc:format>application/pdf</dc:format>");
757
		builder.append("<dc:format>digital</dc:format>");
758
		builder.append("<dc:format>dc</dc:format>");
759
		builder.append("<dc:identifier> http://somehost </dc:identifier>");
760
		builder.append("<dc:identifier>urn:nbn:123-456</dc:identifier>");
761
		builder.append("<dc:source>4-9c7cf682-849b-48bd-92cf-e65367f38e14_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==</dc:source>");
762
		builder.append("<dc:type>someType</dc:type>");
763
		builder.append("<dc:type>info:eu-repo/semantics/article</dc:type>");
764
		builder.append("</oai_dc:dc>");
765
		return builder.toString();		
766
	}
767
	
768
	private String getDC2(){
769
		StringBuilder builder = new StringBuilder();
770
		builder.append("<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/  http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">");
771
		builder.append("<dc:title>SomeTitle</dc:title>");
772
		//builder.append("<title>SomeTitle</title>");
773
		builder.append("<dc:language>firstLang</dc:language>");
774
		builder.append("<dc:language>middleLang</dc:language>");
775
		builder.append("<dc:language>lastLang</dc:language>");
776
		builder.append("<dc:creator>Any Author</dc:creator>");
777
		builder.append("<dc:contributor>First Contributor</dc:contributor>");
778
		builder.append("<dc:contributor>Second Contributor</dc:contributor>");
779
		builder.append("<dc:identifier> http://somehost </dc:identifier>");
780
		builder.append("<dc:identifier>urn:nbn:123-456</dc:identifier>");
781
		builder.append("<dc:source>4-9c7cf682-849b-48bd-92cf-e65367f38e14_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==</dc:source>");
782
		builder.append("<dc:type>someType</dc:type>");
783
		builder.append("<dc:type>info:eu-repo/semantics/article</dc:type>");
784
		builder.append("</oai_dc:dc>");
785
		return builder.toString();		
786
	}
787
	
788
	private String getDidl(){
789
		StringBuilder builder = new StringBuilder();
790
		builder.append("<didl:DIDL xmlns:didl=\"urn:mpeg:mpeg21:2002:02-DIDL-NS\" xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:diext=\"http://library.lanl.gov/2004-04/STB-RL/DIEXT\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dii=\"urn:mpeg:mpeg21:2002:01-DII-NS\" xmlns:dip=\"urn:mpeg:mpeg21:2002:01-DIP-NS\" DIDLDocumentId=\"DIDL:URN:NBN:NL:UI:10-1874-1678\" xsi:schemaLocation=\" urn:mpeg:mpeg21:2002:02-DIDL-NS    http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-21_schema_files/did/didl.xsd urn:mpeg:mpeg21:2002:01-DII-NS    http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-21_schema_files/dii/dii.xsd urn:mpeg:mpeg21:2005:01-DIP-NS    http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-21_schema_files/dip/dip.xsd http://library.lanl.gov/2004-04/STB-RL/DIEXT   http://purl.lanl.gov/STB-RL/schemas/2004-04/DIEXT.xsd\">");
791
		builder.append("<didl:Item>");
792
        builder.append("<didl:Descriptor>"); 
793
        builder.append("<didl:Statement mimeType=\"application/xml\">");
794
        builder.append("<dip:ObjectType>info:eu-repo/semantics/humanStartPage</dip:ObjectType>");
795
        builder.append("</didl:Statement></didl:Descriptor><didl:Component>"); 
796
        builder.append("<didl:Resource ref=\"http://igitur-archive.library.uu.nl/bio/2001-0803-123812/UUindex.html\" mimeType=\"text/html\"/>");
797
        builder.append("</didl:Component></didl:Item>");
798
		builder.append("</didl:DIDL>");
799
		
800
		return builder.toString();				
801
	}
802
	
803
	private String getWOS(){
804
		StringBuilder builder = new StringBuilder();
805
		builder.append("<oai:record xmlns:oai=\"http://www.openarchives.org/OAI/2.0/\"" +
806
				" xmlns:dnet=\"eu.dnetlib.data.transform.xml.DataciteToHbaseXsltFunctions\"" +
807
				" xmlns:oaf=\"http://namespace.openaire.eu/oaf\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\">" +
808
				"    <header>" +
809
				"        <dri:objIdentifier>::00a3e38eff10c4f2f35ffde55ee22e63</dri:objIdentifier>" +
810
				"        <dri:recordIdentifier>WOS:000298601300043</dri:recordIdentifier>" +
811
				"        <dri:dateOfCollection>2013-10-29T10:25:51+01:00</dri:dateOfCollection>" +
812
				"        <dri:repositoryId/>" +
813
				"        <oaf:datasourceprefix/>" +
814
				"    </header>" +
815
				"    <metadata>" +
816
				"        <csvRecord>" +
817
				"            <row name=\"OA\">true</row>" +
818
				"            <row name=\"PT\">J</row>" +
819
				"            <row name=\"AU\">Punta, M; Coggill, PC; Eberhardt, RY; Mistry, J; Tate, J; Boursnell, C; Pang, N;Forslund, K; Ceric, G; Clements, J; Heger, A; Holm, L; Sonnhammer, ELL; Eddy, SR; Bateman, A; Finn, RD</row>" +
820
				"            <row name=\"AF\">Punta, Marco; Coggill, Penny C.; Eberhardt, Ruth Y.; Mistry, Jaina; Tate, John;                Boursnell, Chris; Pang, Ningze; Forslund, Kristoffer; Ceric, Goran; Clements, Jody; Heger,                Andreas; Holm, Liisa; Sonnhammer, Erik L. L.; Eddy, Sean R.; Bateman, Alex; Finn, Robert D.</row>" +
821
				"    <row name=\"TI\">The Pfam protein families database</row>" +
822
				"            <row name=\"SO\">NUCLEIC ACIDS RESEARCH</row>" +
823
				"            <row name=\"LA\">English</row>" +
824
				"            <row name=\"DT\">Article</row>" +
825
				"            <row name=\"ID\">CRYSTAL-STRUCTURE; DOMAIN; IDENTIFICATION; ANNOTATION; HOMOLOGY; CAPSULE;                REVEALS; SEARCH</row>" +
826
				"            <row name=\"AB\">Pfam is a widely used database of protein families, currently containing more                than 13 000 manually curated protein families as of release 26.0. Pfam is available via                servers in the UK (http://pfam.sanger.ac.uk/), the USA (http://pfam.janelia.org/) and Sweden" +
827
				"                (http://pfam.sbc.su.se/). Here, we report on changes that have occurred since our 2010 NAR   paper (release 24.0). Over the last 2 years, we have generated 1840 new families and" +
828
				"                increased coverage of the UniProt Knowledgebase (UniProtKB) to nearly 80%. Notably, we have" +
829
				"                taken the step of opening up the annotation of our families to the Wikipedia community, by" +
830
				"                linking Pfam families to relevant Wikipedia pages and encouraging the Pfam and Wikipedia" +
831
				"                communities to improve and expand those pages. We continue to improve the Pfam website and" +
832
				"                add new visualizations, such as the 'sunburst' representation of taxonomic distribution of" +
833
				"                families. In this work we additionally address two topics that will be of particular" +
834
				"                interest to the Pfam community. First, we explain the definition and use of family-specific," +
835
				"                manually curated gathering thresholds. Second, we discuss some of the features of domains of" +
836
				"                unknown function (also known as DUFs), which constitute a rapidly growing class of families" +
837
				"                within Pfam.</row>" +
838
				"     <row name=\"C1\">[Punta, Marco; Coggill, Penny C.; Eberhardt, Ruth Y.; Mistry, Jaina; Tate, John;" +
839
				"                Boursnell, Chris; Pang, Ningze; Bateman, Alex] Wellcome Trust Sanger Inst, Hinxton CB10 1SA," +
840
				"                England; [Forslund, Kristoffer; Sonnhammer, Erik L. L.] Stockholm Univ, Dept Biochem &amp;" +
841
				"                Biophys, Sci Life Lab, Swedish eSci Res Ctr,Stockholm Bioinformat Ctr, SE-17121 Solna," +
842
				"                Sweden; [Ceric, Goran; Clements, Jody; Eddy, Sean R.; Finn, Robert D.] HHMI Janelia Farm Res" +
843
				"                Campus, Ashburn, VA 20147 USA; [Heger, Andreas] Univ Oxford, MRC Funct Genom Unit, Dept" +
844
				"                Physiol Anat &amp; Genet, Oxford OX1 3QX, England; [Holm, Liisa] Univ Helsinki, Inst" +
845
				"                Biotechnol, Helsinki 00014, Finland; [Holm, Liisa] Univ Helsinki, Dept Biol &amp; Environm" +
846
				"                Sci, FIN-00014 Helsinki, Finland</row>" +
847
				"     <row name=\"RP\">Punta, M (reprint author), Wellcome Trust Sanger Inst, Wellcome Trust Genome" +
848
				"                Campus, Hinxton CB10 1SA, England.</row>" +
849
				"     <row name=\"EM\">mp13@sanger.ac.uk</row>" +
850
				"     <row name=\"FU\">Wellcome Trust [WT077044/Z/05/Z]; BBSRC [BB/F010435/1]; Howard Hughes Medical" +
851
				"               Institute; Stockholm University; Royal Institute of Technology; Swedish Natural Sciences" +
852
				"                Research Council</row>" +
853
				"     <row name=\"FX\">Wellcome Trust (grant numbers WT077044/Z/05/Z); BBSRC Bioinformatics and" +
854
				"                Biological Resources Fund (grant numbers BB/F010435/1); Howard Hughes Medical Institute (to" +
855
				"                G. C., J.C., S. R. E and R. D. F.); Stockholm University, Royal Institute of Technology and" +
856
				"                the Swedish Natural Sciences Research Council (to K. F. and E. L. L. S.) and Systems, Web" +
857
				"                and Database administration teams at Wellcome Trust Sanger Institute (WTSI) (infrastructure" +
858
				"                support). Funding for open access charge: Wellcome Trust (grant numbers WT077044/Z/05/Z);" +
859
				"                BBSRC Bioinformatics and Biological Resources Fund (grant numbers BB/F010435/1).</row>" +
860
				"      <row name=\"NR\">29</row>" +
861
				"		<row name=\"TC\">92</row>" +
862
				"             <row name=\"Z9\">94</row>" +
863
				"            <row name=\"PU\">OXFORD UNIV PRESS</row>" +
864
				"            <row name=\"PI\">OXFORD</row>            " +
865
				"            <row name=\"PA\">GREAT CLARENDON ST, OXFORD OX2 6DP, ENGLAND</row>" +
866
				"          <row name=\"SN\">0305-1048</row>" +
867
				"                 <row name=\"J9\">NUCLEIC ACIDS RES</row>" +
868
				"                        <row name=\"JI\">Nucleic Acids Res.</row>" +
869
				"                        <row name=\"PD\">JAN</row>" +
870
				"                        <row name=\"PY\">2012</row>" +
871
				"                        <row name=\"VL\">40</row>" +
872
				"                        <row name=\"IS\">D1</row>" +
873
				"                        <row name=\"BP\">D290</row>" +
874
				"                       <row name=\"EP\">D301</row>" +
875
				"            <row name=\"DI\">10.1093/nar/gkr1065</row>            " +
876
				"<row name=\"PG\">12</row>" +
877
				"                        <row name=\"WC\">Biochemistry &amp; Molecular Biology</row>" +
878
				"                        <row name=\"SC\">Biochemistry &amp; Molecular Biology</row>" +
879
				"                        <row name=\"GA\">869MD</row>" +
880
				"                        <row isID=\"true\" name=\"UT\">WOS:000298601300043</row>" +
881
				"                    </csvRecord>" +
882
				"    </metadata>" +
883
				"</oai:record>");
884
		return builder.toString();
885
	}
886
	
887
	private String getOAFDC(){
888
		StringBuilder builder = new StringBuilder();
889
		builder.append(
890
				"<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">" +
891
				"<dc:title>Grass roots lobbying: marketing politics and policy 'beyond the Beltway'</dc:title>" +
892
				"<dc:creator>McGrath, Conor; Xyz, Opq</dc:creator>" +
893
				"<dc:creator>Abc, Def</dc:creator>" +
894
				"<dc:creator>Muñoz-Castellanos, L</dc:creator>" +
895
				"<dc:subject>JA Political science (General)</dc:subject>" +
896
				"<dc:description/>" +
897
				"<dc:publisher/>" +
898
				"<dc:date>2011</dc:date>" +
899
				"<dc:date>info:eu-repo/date/embargoEnd/2011-05-12</dc:date>" +
900
				"<dc:date>2004-03-15</dc:date>" +
901
				"<dc:date>2009-02-24T13:27:42Z</dc:date>" +
902
				"<dc:date>2009-02</dc:date>" +
903
				"<dc:date>2009</dc:date>" +
904
				"<dc:type>Conference or Workshop Item</dc:type>" +
905
				"<dc:type>NonPeerReviewed</dc:type>" +
906
				"<dc:type>info:eu-repo/semantics/article</dc:type>" +
907
				"<dc:identifier>http://somehost</dc:identifier>" +
908
				"<dc:format>application/pdf</dc:format>" +
909
				"<dc:relation>info:eu-repo/grantAgreement/EC/FP7/241479</dc:relation>" +
910
				"<dc:relation>http://sherpa.bl.uk/1/01/PMMcgrath.pdf</dc:relation>" +
911
				"<dc:relation>info:eu-repo/grantAgreement/EC/FP7/246682/EU/Towards a 10-Year Vision for Global Research Data Infrastructures/GRDI2020</dc:relation>" +
912
				"<dc:relation>info:eu-repo/grantAgreement/EC/FP7/PITN-GA-2009-237252</dc:relation>" +
913
			    "<dc:relation>info:eu-repo/grantAgreement/EC/FP7/PITN-GA-2009-235114</dc:relation>" +
914
			    "<dc:relation>info:eu-repo/grantAgreement/EC/FP7/237252</dc:relation>" +
915
			    "<dc:identifier>http://dx.doi.org/10.1103/PhysRevLett.104.126402</dc:identifier>" +
916
			    "<dc:rights>Tots els drets reservats</dc:rights>" +
917
			    "<dc:rights>Used by permission of the publisher</dc:rights>" +
918
				"<dc:rights>info:eu-repo/semantics/openAccess  </dc:rights>" +
919
				"</oai_dc:dc>");
920
		return builder.toString();
921
	}
922
	
923
	private String getProvenance(){
924
		StringBuilder builder = new StringBuilder();
925
		builder.append(
926
				"<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\">" +
927
				"<originDescription altered=\"true\" harvestDate=\"2012-01-20T00:04:10Z\">" +
928
				"<baseURL>http://dspace.library.uu.nl:8080/dspace-oai/request</baseURL>" +
929
				"<identifier>oai:dspace.library.uu.nl:1874/218065</identifier>" +
930
				"<datestamp>2012-01-19T12:38:56Z</datestamp>" +
931
				"<metadataNamespace>http://www.loc.gov/mods/v3</metadataNamespace>" +
932
				"</originDescription>" +
933
				"</provenance>");		
934
		return builder.toString();
935
		
936
	}
937

  
938
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/engine/core/TransformationImplTest.java
1
package eu.dnetlib.data.collective.transformation.engine.core;
2

  
3
import java.io.StringReader;
4

  
5
import javax.xml.transform.TransformerConfigurationException;
6
import javax.xml.transform.TransformerException;
7

  
8
import org.junit.Before;
9
import org.junit.Test;
10
import org.springframework.core.io.ClassPathResource;
11
import org.springframework.core.io.Resource;
12

  
13
import eu.dnetlib.data.collective.transformation.rulelanguage.RuleLanguageParser;
14

  
15
public class TransformationImplTest {
16

  
17
	private static final String xslTemplatePath = "eu/dnetlib/data/collective/transformation/engine/template.xsl";
18
	private transient Resource xslTemplateResource = new ClassPathResource(xslTemplatePath);
19
//	private static final String schemaPath = "eu/dnetlib/data/collective/transformation/schema/DMFSchema_vTransformator.xsd";
20
	private static final String schemaPath = "eu/dnetlib/data/collective/transformation/schema/OAFSchema_vTransformator.xsd";
21
	private transient Resource schemaResource = new ClassPathResource(schemaPath);
22
	private transient RuleLanguageParser parser;
23
	private static final String dataSinkId = "132";
24
	
25
	private transient TransformationImpl transformation;
26
	
27
	@Before
28
	public void setUp(){
29
		System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
30

  
31
		parser = new RuleLanguageParser();
32

  
33
		transformation = new TransformationImpl();
34
		transformation.addJobConstant(TransformationImpl.JOBCONST_DATASINKID, dataSinkId);
35
		transformation.setTemplate(xslTemplateResource);
36
		transformation.setSchema(schemaResource);
37
		transformation.init();
38
		transformation.setRuleLanguageParser(parser);
39
		
40
	}
41
	
42
	@Test
43
	public void testStyleSheet() throws TransformerConfigurationException{
44
		StringReader reader = new StringReader(dc2DmfScript());
45
		parser.parse(reader);
46
		try{
47
			transformation.configureTransformation();						
48
		}catch(TransformerConfigurationException e){
49
			e.printStackTrace();
50
		}
51
		System.out.println(transformation.dumpStylesheet());
52
	}
53
	
54
	private String dc2DmfScript(){
55
	   StringBuilder scriptBuilder = new StringBuilder();
56
	   scriptBuilder.append("declare_script \"MainSample\";\r\n");
57
	   
58
	   scriptBuilder.append("declare_ns oaf = \"http://namespace.openaire.eu/oaf\";\r\n");
59
	   scriptBuilder.append("declare_ns dr = \"http://www.driver-repository.eu/namespace/dr\";\r\n");
60
	   scriptBuilder.append("declare_ns dri = \"http://www.driver-repository.eu/namespace/dri\";\r\n");
61
	   scriptBuilder.append("declare_ns dc = \"http://purl.org/dc/elements/1.1/\";\r\n");
62
	
63
	   scriptBuilder.append("$var0 = \"''\";\r\n");
64
	   scriptBuilder.append("static $var1 = RegExpr($job.datasinkid, $var0, \"s/^(dnet:\\/\\/MDStoreDS\\/)|(\\?.*)//g\");\r\n");
65
       scriptBuilder.append("dr:objectIdentifier = xpath:\"//dri:objIdentifier\";\r\n");
66
	   scriptBuilder.append("dr:dateOfCollection = getValue(CURRENTDATE, []);\r\n");
67
	   scriptBuilder.append("dr:CobjContentSynthesis = empty;\r\n");
68
	   scriptBuilder.append("dr:CobjTypology = \"Textual\";\r\n");
69
	   scriptBuilder.append("dr:CobjModel = \"OAI\";\r\n");
70
	   scriptBuilder.append("dr:CobjMdFormats = \"oai_dc\";\r\n");
71
	   scriptBuilder.append("dr:CobjDescriptionSynthesis = empty;\r\n");
72
	   scriptBuilder.append("//dr:aggregatorName = getValue(PROFILEFIELD, [\"transformationmanager-service-profile-id\", xpath:\"//PROPERTY/@key='name'\"]);\r\n");
73
	   scriptBuilder.append("dr:aggregatorInstitution = empty;\r\n");
74
	   scriptBuilder.append("dr:repositoryName = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//CONFIGURATION/OFFICIAL_NAME\"]);\r\n");
75
	   scriptBuilder.append("dr:repositoryLink = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//REPOSITORY_WEBPAGE\"]);\r\n");
76
	   scriptBuilder.append("dr:repositoryCountry = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//COUNTRY\"]);\r\n");
77
	   scriptBuilder.append("dr:repositoryInstitution = getValue(PROFILEFIELD, [xpath:\"//dri:repositoryId\", xpath:\"//REPOSITORY_INSTITUTION\"]);\r\n");
78
	   scriptBuilder.append("dc:creator = xpath:\"//dc:creator\";\r\n");
79
	   scriptBuilder.append("dc:title = xpath:\"//dc:title\";\r\n");
80
	   scriptBuilder.append("dc:subject = xpath:\"//dc:subject\";\r\n");
81
	   scriptBuilder.append("dr:CobjCategory = Convert(xpath:\"//dc:type\", TextTypologies);\r\n");
82
	   scriptBuilder.append("%templ = split(xpath:\"/dc:creator\", \"dc:creator\", \";\");\r\n");
83
	   //scriptBuilder.append("dc:language = Convert(xpath:\"//dc:language\", Languages);\r\n");
84
//	   scriptBuilder.append("dc:language = Extract(language);\r\n");
85
//	   scriptBuilder.append("dc:dateAccepted = Convert(xpath:\"//dc:date\", DateISO8601);\r\n");
86
//	   scriptBuilder.append("apply xpath:\"//dc:identifier\" if xpath:\"starts-with(., 'http')\" dc:identifier = xpath:\".\"; else dr:CobjIdentifier = xpath:\".\";\r\n");
87
       scriptBuilder.append("apply xpath:\"//dc:relation\" if xpath:\"starts-with(., 'http')\" dc:identifier = RegExpr(xpath:\"//dc:relation\", xpath:\"//dc:relation\", \"s/^(.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/)//g\"); else dr:CobjIdentifier = xpath:\".\";\r\n");
88
//       apply xpath:"//dc:rights" if xpath:"starts-with(normalize-space(.), 'info:eu-repo/semantics')" oaf:accessrights = Convert(xpath:"normalize-space(.)", AccessRights); else dc:rights = xpath:"normalize-space(.)";
89
       //	   scriptBuilder.append("dc:publisher = xpath:\"//dc:publisher\";\r\n");
90
//	   scriptBuilder.append("dc:source = xpath:\"//dc:source\";\r\n");
91
//	   scriptBuilder.append("dc:contributor = xpath:\"//dc:contributor\";\r\n");
92
//	   scriptBuilder.append("dc:relation = xpath:\"//dc:relation\";\r\n");
93
//	   scriptBuilder.append("dc:description = xpath:\"//dc:description\";\r\n");
94
	   scriptBuilder.append("end\r\n"); 		
95
	   return scriptBuilder.toString();
96
	}
97

  
98
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/engine/functions/ConvertTest.java
1
package eu.dnetlib.data.collective.transformation.engine.functions;
2

  
3
import static org.junit.Assert.*;
4
import static org.mockito.Mockito.*;
5

  
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.Map;
9

  
10
import org.dom4j.Document;
11
import org.dom4j.DocumentException;
12
import org.dom4j.io.SAXReader;
13
import org.junit.Before;
14
import org.junit.Test;
15
import org.junit.runner.RunWith;
16
import org.mockito.Mock;
17

  
18
import eu.dnetlib.common.profile.Resource;
19
import eu.dnetlib.data.collective.transformation.VocabularyMap;
20
import eu.dnetlib.data.collective.transformation.VocabularyRegistry;
21
import org.mockito.junit.MockitoJUnitRunner;
22

  
23
@RunWith(MockitoJUnitRunner.class)
24
public class ConvertTest {
25

  
26
	static final String type_vocabulary = "type_vocabulary.xml";
27
	static final String lang_vocabulary = "lang_vocabulary.xml";
28
	Convert c;
29
	Vocabulary v_type;
30
	Vocabulary v_lang;
31
	@Mock
32
	private transient VocabularyRegistry vocabularyRegistry;
33
	private transient VocabularyMap vocabularyMapWrapper = new VocabularyMap();
34
	private transient Map<String, Vocabulary> vocabulariesMap = new HashMap<String, Vocabulary>();
35
	
36
	@Before
37
	public void setUp(){
38

  
39
		c = new Convert();
40
		v_type = new Vocabulary();
41
		v_type.setCaseSensitive(false);
42
		v_type.setResource(getResource(type_vocabulary));
43
		v_lang = new Vocabulary();
44
		v_lang.setCaseSensitive(false);
45
		v_lang.setDelimiter("/");
46
		v_lang.setResource(getResource(lang_vocabulary));
47
		v_type.setName("someQuery");
48
		vocabulariesMap.put(v_type.getVocabularyName(), v_type);
49
		v_lang.setName("someQuery");
50
		vocabulariesMap.put(v_lang.getVocabularyName(), v_lang);
51
		vocabularyMapWrapper.setMap(vocabulariesMap);
52
		when(vocabularyRegistry.getVocabularies()).thenReturn(vocabularyMapWrapper);		
53
		c.setVocabularyRegistry(vocabularyRegistry);
54
		when(vocabularyRegistry.getVocabulary(v_type.getVocabularyName())).thenReturn(v_type);
55
		when(vocabularyRegistry.getVocabulary(v_lang.getVocabularyName())).thenReturn(v_lang);
56
	}
57
	
58
	private Resource getResource(String vocabularyName){
59
		Resource r = null;
60
		SAXReader reader = new SAXReader();
61
		Document d;
62
		try {
63
			d = reader.read(this.getClass().getClassLoader().getResourceAsStream(vocabularyName));
64
			r = new Resource(d);
65
		} catch (DocumentException e) {
66
			e.printStackTrace();
67
		}
68
		return r;
69
	}
70
	
71
	@Test
72
	public void testTypeEncoding() throws ProcessingException{
73
		String[] values1 = {"abc"};
74
		assertEquals("0000", c.executeSingleValue(v_type.getVocabularyName(), Arrays.asList(values1)));
75
		String[] values2 = {"abc", "Aufsatz"};
76
		assertEquals("0001", c.executeSingleValue(v_type.getVocabularyName(), Arrays.asList(values2)));
77
		//String[] values3 = {"Conference report"};
78
		String[] values3 = {"Conference or workshop item"};
79
		assertEquals("0004", c.executeSingleValue(v_type.getVocabularyName(), Arrays.asList(values3)));
80
		
81
	}
82
	
83
	@Test
84
	public void testLangEncoding() throws ProcessingException{
85
		String[] values1 = {"he"};
86
		assertEquals("heb", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values1)));
87
		String[] values2 = {"jkjhh"};
88
		assertEquals("und", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values2)));		
89
		String[] values3 = {"german"};
90
		assertEquals("deu/ger", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values3)));
91
		String[] values4 = {"eng"};
92
		assertEquals("eng", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values4)));
93
		String[] values5 = {"ger"};
94
		assertEquals("deu/ger", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values5)));
95
		String[] values6 = {"deu/ger"};
96
		assertEquals("deu/ger", c.executeSingleValue(v_lang.getVocabularyName(), Arrays.asList(values6)));
97
	}
98
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-2.2.4/src/test/java/eu/dnetlib/data/collective/transformation/engine/functions/RegularExpressionTest.java
1
package eu.dnetlib.data.collective.transformation.engine.functions;
2

  
3
import static org.junit.Assert.*;
4

  
5
import org.apache.oro.text.perl.Perl5Util;
6
import org.junit.Before;
7
import org.junit.Test;
8
import org.junit.runner.RunWith;
9
import org.mockito.junit.MockitoJUnitRunner;
10

  
11
@RunWith(MockitoJUnitRunner.class)
12
public class RegularExpressionTest {
13

  
14
	private transient RegularExpression regExprFunc;
15
	
16
	@Before
17
	public void setUp(){
18
		regExprFunc = new RegularExpression();
19
	}
20
	
21
	@Test
22
	public void testSubstitute() throws ProcessingException{
23
		
24
		String projId = "241479";
25
		String regExpr = "s/^(.*info:eu-repo\\/grantAgreement\\/EC\\/FP7\\/)//gm";
26
		String input = "info:eu-repo/grantAgreement/EC/FP7/241479";
27
		assertEquals(projId, regExprFunc.executeSingleValue(regExpr, input, "anyValue"));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff