Project

General

Profile

« Previous | Next » 

Revision 49116

[maven-release-plugin] copy for tag dnet-data-services-2.0.0-SAXONHE

View differences:

modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/deploy.info
1
{
2
"type_source": "SVN",
3
"goal": "package -U source:jar",
4
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet50/modules/dnet-data-services/branches/saxonHE",
5
"deploy_repository": "dnet5-snapshots",
6
"version": "5",
7
"mail": "alessia.bardi@isti.cnr.it",
8
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet5-snapshots",
9
"name": "dnet-data-services-saxonHE"
10
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/enabling/tools/blackboard/SampleCreateAction.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import eu.dnetlib.data.mdstore.modular.action.MDStoreActions;
4

  
5
public class SampleCreateAction implements BlackboardServerAction<MDStoreActions> {
6

  
7
	@Override
8
	public void execute(BlackboardServerHandler handler, BlackboardJob job) {
9
		handler.done(job);
10
	}
11

  
12
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/enabling/tools/blackboard/MockBeanFactory.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import org.springframework.beans.factory.FactoryBean;
4

  
5
import static org.mockito.Mockito.mock;
6

  
7
/**
8
 * Created by sandro on 3/22/16.
9
 */
10
public class MockBeanFactory implements FactoryBean<BlackboardServerHandler> {
11

  
12
	@Override
13
	public BlackboardServerHandler getObject() throws Exception {
14
		return mock(BlackboardServerHandler.class);
15
	}
16

  
17
	@Override
18
	public Class<BlackboardServerHandler> getObjectType() {
19
		return BlackboardServerHandler.class;
20
	}
21

  
22
	@Override
23
	public boolean isSingleton() {
24
		return true;
25
	}
26
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/enabling/tools/blackboard/BlackboardServerActionExecutorTest.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import eu.dnetlib.data.mdstore.modular.action.MDStoreActions;
4
import org.junit.Before;
5
import org.junit.Test;
6
import org.junit.runner.RunWith;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.test.context.ContextConfiguration;
9
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10

  
11
import static org.junit.Assert.assertNotNull;
12
import static org.mockito.Matchers.anyObject;
13
import static org.mockito.Matchers.eq;
14
import static org.mockito.Mockito.*;
15

  
16
@RunWith(SpringJUnit4ClassRunner.class)
17
@ContextConfiguration
18
public class BlackboardServerActionExecutorTest {
19

  
20
	@Autowired
21
	public BlackboardServerHandler blackboardHandler;
22

  
23
	@Autowired
24
	public transient BlackboardServerActionExecutor<MDStoreActions> executor;
25

  
26
	@Before
27
	public void setUp() throws Exception {
28

  
29
	}
30

  
31
	@Test
32
	public void testExecutor() {
33
		assertNotNull(executor);
34

  
35
		BlackboardJob job = mock(BlackboardJob.class);
36
		when(job.getAction()).thenReturn("CREATE");
37

  
38
		executor.execute(job);
39

  
40
		verify(blackboardHandler).done(eq(job));
41
	}
42

  
43
	@Test
44
	public void testExecutorUnimplemented() {
45
		assertNotNull(executor);
46

  
47
		BlackboardJob job = mock(BlackboardJob.class);
48
		when(job.getAction()).thenReturn("DELETE");
49

  
50
		executor.execute(job);
51

  
52
		verify(blackboardHandler).failed(eq(job), (Throwable) anyObject());
53
	}
54
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/collector/plugins/HttpSimpleCollectorPluginTest.java
1
package eu.dnetlib.data.collector.plugins;
2

  
3
import com.google.common.collect.Lists;
4
import eu.dnetlib.rmi.data.CollectorServiceException;
5
import eu.dnetlib.rmi.data.InterfaceDescriptor;
6
import org.junit.Assert;
7
import org.junit.Before;
8
import org.junit.Ignore;
9
import org.junit.Test;
10

  
11
/**
12
 * Created by Alessia Bardi on 10/08/2017.
13
 *
14
 * @author Alessia Bardi
15
 */
16
@Ignore
17
public class HttpSimpleCollectorPluginTest {
18

  
19
	private InterfaceDescriptor apiDescriptor;
20
	private HttpSimpleCollectorPlugin plugin;
21

  
22
	@Before
23
	public void prepare(){
24
		plugin = new HttpSimpleCollectorPlugin();
25
		apiDescriptor = new InterfaceDescriptor();
26
		apiDescriptor.setBaseUrl("http://data.d4science.org/em1EemhBdUZ0bjNGTWJNNjlxVDltcm9acDFmMHlBSVVHbWJQNStIS0N6Yz0");
27
	}
28

  
29
	@Test
30
	public void test() throws CollectorServiceException {
31
	Iterable<String> res = plugin.collect(apiDescriptor, null, null);
32
	Assert.assertTrue(Lists.newArrayList(res).size() == 1);
33
	for(String r : res){
34
		System.out.println(r);
35
		Assert.assertNotNull(r);
36
	}
37

  
38
	}
39

  
40
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/collector/plugins/sftp/SftpPubKeyCollectorPluginTest.java
1
package eu.dnetlib.data.collector.plugins.sftp;
2

  
3
import eu.dnetlib.rmi.data.CollectorServiceException;
4
import eu.dnetlib.rmi.data.InterfaceDescriptor;
5
import org.junit.Assert;
6
import org.junit.Before;
7
import org.junit.Ignore;
8
import org.junit.Test;
9
import org.junit.runner.RunWith;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.test.context.ContextConfiguration;
12
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13

  
14
/**
15
 * Created by alessia on 16/03/17.
16
 */
17
@RunWith(SpringJUnit4ClassRunner.class)
18
@ContextConfiguration
19
@Ignore
20
public class SftpPubKeyCollectorPluginTest {
21

  
22
	@Autowired
23
	private  SftpPubKeyCollectorPlugin plugin;
24
	private InterfaceDescriptor apiDescriptor;
25
	private int max_records = 10;
26

  
27
	@Before
28
	public void prepare(){
29
		apiDescriptor = new InterfaceDescriptor();
30
		apiDescriptor.setBaseUrl("sftp://ariadne2.isti.cnr.it/../../data/transform/old/acdm_correct");
31
		apiDescriptor.setProtocol("sftp");
32
		apiDescriptor.setId("testSFTP");
33
		apiDescriptor.getParams().put("recursive", "true");
34
		apiDescriptor.getParams().put("extensions", "xml");
35
		apiDescriptor.getParams().put("username", "alessia");
36
	}
37

  
38
	@Test
39
	public void testWithAriadneServer() throws CollectorServiceException {
40

  
41
		Iterable<String> res = plugin.collect(apiDescriptor, null, null);
42
		Assert.assertNotNull(res);
43
		int i =0;
44
		for(String r : res){
45
			i++;
46
			Assert.assertNotNull(r);
47
			if(i > max_records) break;
48
		}
49

  
50
	}
51

  
52
	@Test
53
	public void testIncrementalWithAriadneServer() throws CollectorServiceException {
54

  
55
		Iterable<String> res = plugin.collect(apiDescriptor, "2017-06-06", null);
56
		Assert.assertNotNull(res);
57
		int i =0;
58
		for(String r : res){
59
			i++;
60
			Assert.assertNotNull(r);
61
			if(i > max_records) break;
62
		}
63

  
64
	}
65
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/cleaner/VocabularyRuleTest.java
1
package eu.dnetlib.data.cleaner;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5
import static org.junit.Assert.assertNull;
6
import static org.mockito.Matchers.anyString;
7
import static org.mockito.Mockito.times;
8
import static org.mockito.Mockito.verify;
9
import static org.mockito.Mockito.when;
10

  
11
import java.io.StringReader;
12
import java.util.List;
13

  
14
import org.dom4j.Document;
15
import org.dom4j.io.SAXReader;
16
import org.junit.Before;
17
import org.junit.Test;
18
import org.junit.runner.RunWith;
19
import org.mockito.Mock;
20
import org.mockito.runners.MockitoJUnitRunner;
21

  
22
import com.google.common.collect.Lists;
23
import com.google.common.collect.Sets;
24

  
25
import eu.dnetlib.data.cleaner.VocabularyRule;
26
import eu.dnetlib.rmi.enabling.ISLookUpService;
27

  
28
@RunWith(MockitoJUnitRunner.class)
29
public class VocabularyRuleTest {
30

  
31
	private static final String VOCABULARY_NAME_1 = "TEST VOCABULARY 1";
32
	private static final String VOCABULARY_NAME_2 = "TEST VOCABULARY 2";
33
	private static final List<String> VOCABULARY = Lists.newArrayList("XXXX|-:-|AAAA", "YYYY|-:-|AAAA", "ZZZZ|-:-|AAAA");
34

  
35
	/**
36
	 * Class Under Test
37
	 */
38
	private VocabularyRule rule;
39

  
40
	@Mock
41
	private ISLookUpService lookup;
42

  
43
	@Before
44
	public void setUp() throws Exception {
45
		when(this.lookup.quickSearchProfile(anyString())).thenReturn(VOCABULARY);
46

  
47
		this.rule = new VocabularyRule(Sets.newHashSet(VOCABULARY_NAME_1, VOCABULARY_NAME_2), this.lookup);
48
	}
49

  
50
	@Test
51
	public void testSetup() throws Exception {
52
		final String xpath = "/a/b";
53
		this.rule.setXpath(xpath);
54

  
55
		execute("<a><b>XXXX</b></a>");
56

  
57
		verify(this.lookup, times(2)).quickSearchProfile(anyString());
58
		assertEquals(VOCABULARY.size(), this.rule.getVocabularyTerms().size());
59
	}
60

  
61
	@Test
62
	public void testApplyXpathRule() throws Exception {
63
		final String xpath = "/a/b";
64
		this.rule.setXpath(xpath);
65
		final Document doc = execute("<a><b>XXXX</b></a>");
66
		assertEquals("AAAA", doc.valueOf(xpath));
67
		assertNull(this.rule.verifyValue("AAAA"));
68
		assertNotNull(this.rule.verifyValue("XXXX"));
69
	}
70

  
71
	@Test
72
	public void testApplyXpathRule_2() throws Exception {
73
		final String xpath = "/a/b";
74
		this.rule.setXpath(xpath);
75
		final Document doc = execute("<a><b>XXXX</b></a>");
76
		assertEquals("AAAA", doc.valueOf(xpath));
77
		assertNull(this.rule.verifyValue("AAAA"));
78
		assertNotNull(this.rule.verifyValue("XXXX"));
79
	}
80

  
81
	@Test
82
	public void testApplyXpathRule_3() throws Exception {
83
		final String xpath = "/a/b";
84
		this.rule.setXpath(xpath);
85
		final Document doc = execute("<a><b>XXXX</b></a>");
86
		assertEquals("AAAA", doc.valueOf(xpath));
87
	}
88

  
89
	@Test
90
	public void testApplyXpathRule_attr() throws Exception {
91
		final String xpath = "/a/b/@value";
92
		this.rule.setXpath(xpath);
93
		final Document doc = execute("<a><b value='XXXX' /></a>");
94
		assertEquals("AAAA", doc.valueOf(xpath));
95
		assertNull(this.rule.verifyValue("AAAA"));
96
		assertNotNull(this.rule.verifyValue("XXXX"));
97
	}
98

  
99
	@Test
100
	public void testApplyXpathRule_with_spaces() throws Exception {
101
		final String xpath = "/a/b";
102
		this.rule.setXpath(xpath);
103
		final Document doc = execute("<a><b>  XXXX  </b></a>");
104
		assertEquals("AAAA", doc.valueOf(xpath));
105
		assertNull(this.rule.verifyValue("AAAA"));
106
		assertNotNull(this.rule.verifyValue("  XXXX  "));
107
	}
108

  
109
	@Test
110
	public void testApplyXpathRule_case() throws Exception {
111
		final String xpath = "/a/b";
112
		this.rule.setXpath(xpath);
113
		final Document doc = execute("<a><b>Xxxx</b></a>");
114
		assertEquals("AAAA", doc.valueOf(xpath));
115
		assertNull(this.rule.verifyValue("AAAA"));
116
		assertNotNull(this.rule.verifyValue("Xxxx"));
117
	}
118

  
119
	private Document execute(final String xml) throws Exception {
120
		final SAXReader reader = new SAXReader();
121
		final Document doc = reader.read(new StringReader(xml));
122
		System.out.println("BEFORE:\n" + doc.asXML() + "\n");
123
		this.rule.applyXpathRule(doc);
124
		System.out.println("AFTER:\n" + doc.asXML() + "\n");
125
		System.out.println("-----------------------------\n");
126
		return doc;
127
	}
128

  
129
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/cleaner/XMLCleaningRuleTest.java
1
package eu.dnetlib.data.cleaner;
2

  
3
import static org.junit.Assert.assertFalse;
4
import static org.junit.Assert.assertTrue;
5

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

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

  
14
import com.google.common.collect.Lists;
15

  
16
import eu.dnetlib.data.cleaner.CleaningRule;
17
import eu.dnetlib.data.cleaner.XPATHCleaningRule;
18
import eu.dnetlib.rmi.data.CleanerException;
19

  
20
@RunWith(MockitoJUnitRunner.class)
21
public class XMLCleaningRuleTest {
22

  
23
	private static final String INPUT_VALID = "<record>" + "	<header />" + "	<metadata>" + "		<a>HELLO</a>" + "	</metadata>" + "</record>";
24

  
25
	private static final String INPUT_INVALID = "<record>" + "	<header />" + "	<metadata>" + "		<a>GOOD BYE</a>" + "	</metadata>" + "</record>";
26

  
27
	/**
28
	 * Class under test.
29
	 */
30
	private CleaningRule xmlRule;
31
	private final XPATHCleaningRule mockXpathRule = new XPATHCleaningRule() {
32

  
33
		@Override
34
		protected Map<String, String> verifyValue(final String value) throws CleanerException {
35
			if (value.equals("CIAO")) { return null; }
36

  
37
			final Map<String, String> err = new HashMap<String, String>();
38
			err.put("term", value);
39
			return err;
40
		}
41

  
42
		@Override
43
		protected String calculateNewValue(final String oldValue) throws CleanerException {
44
			if (oldValue.equals("HELLO")) { return "CIAO"; }
45
			return oldValue;
46
		}
47
	};;
48

  
49
	@Before
50
	public void setUp() throws Exception {
51
		this.xmlRule = new CleaningRule();
52

  
53
		this.mockXpathRule.setStrict(true);
54
		this.mockXpathRule.setXpath("//a");
55

  
56
		this.xmlRule.setXpathRules(Lists.newArrayList(this.mockXpathRule));
57
	}
58

  
59
	@Test
60
	public void testEvaluate_valid() {
61
		final String s = this.xmlRule.apply(INPUT_VALID);
62
		assertTrue(s.contains("CIAO"));
63
		assertFalse(s.contains("invalid"));
64
	}
65

  
66
	@Test
67
	public void testEvaluate_invalid() {
68
		final String s = this.xmlRule.apply(INPUT_INVALID);
69
		System.out.println(s);
70
		assertFalse(s.contains("CIAO"));
71
		assertTrue(s.contains("invalid"));
72
	}
73

  
74
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/cleaner/CleanerServiceImplTest.java
1
package eu.dnetlib.data.cleaner;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5
import static org.mockito.Mockito.verify;
6
import static org.mockito.Mockito.when;
7

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

  
14
import eu.dnetlib.data.cleaner.CleanerServiceImpl;
15
import eu.dnetlib.data.cleaner.CleaningRule;
16
import eu.dnetlib.data.cleaner.CleaningRuleFactory;
17
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
18
import eu.dnetlib.rmi.common.ResultSet;
19
import eu.dnetlib.rmi.data.CleanerException;
20

  
21
@RunWith(MockitoJUnitRunner.class)
22
public class CleanerServiceImplTest {
23

  
24
	/**
25
	 * Class under test.
26
	 */
27
	private CleanerServiceImpl service;
28

  
29
	@Mock
30
	private CleaningRuleFactory cleaningRuleFactory;
31
	@Mock
32
	private ResultSetFactory resultSetFactory;
33
	@Mock
34
	private CleaningRule cleaningRule;
35
	@Mock
36
	private ResultSet<String> rs_IN;
37
	@Mock
38
	private ResultSet<String> rs_OUT;
39

  
40
	private static final String RULE_ID = "RULE_01";
41

  
42
	@Before
43
	public void setUp() throws Exception {
44
		when(this.cleaningRuleFactory.obtainCleaningRule(RULE_ID)).thenReturn(this.cleaningRule);
45
		when(this.resultSetFactory.map(this.rs_IN, String.class, this.cleaningRule)).thenReturn(this.rs_OUT);
46

  
47
		this.service = new CleanerServiceImpl();
48
		this.service.setCleaningRuleFactory(this.cleaningRuleFactory);
49
		this.service.setResultSetFactory(this.resultSetFactory);
50
	}
51

  
52
	@Test
53
	public void testClean() throws CleanerException {
54
		final ResultSet<String> rs = this.service.clean(this.rs_IN, RULE_ID);
55
		assertNotNull(rs);
56
		assertEquals(this.rs_OUT, rs);
57
		verify(this.cleaningRuleFactory).obtainCleaningRule(RULE_ID);
58
	}
59

  
60
	@Test(expected = CleanerException.class)
61
	public void testClean_null_1() throws CleanerException {
62
		this.service.clean(this.rs_IN, null);
63
	}
64

  
65
	@Test(expected = CleanerException.class)
66
	public void testClean_null_2() throws CleanerException {
67
		this.service.clean(null, RULE_ID);
68
	}
69
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/cleaner/GroovyRuleTest.java
1
package eu.dnetlib.data.cleaner;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertTrue;
5

  
6
import java.io.StringReader;
7
import java.util.List;
8

  
9
import org.dom4j.Document;
10
import org.dom4j.Node;
11
import org.dom4j.io.SAXReader;
12
import org.junit.Test;
13
import org.junit.runner.RunWith;
14
import org.mockito.runners.MockitoJUnitRunner;
15

  
16
import eu.dnetlib.data.cleaner.GroovyRule;
17

  
18
@RunWith(MockitoJUnitRunner.class)
19
public class GroovyRuleTest {
20

  
21
	@Test
22
	public void testApplyXpathRule_simple_constant() throws Exception {
23
		final GroovyRule rule = new GroovyRule("'YYYY'");
24

  
25
		final String xpath = "/a/b";
26

  
27
		rule.setXpath(xpath);
28

  
29
		final Document doc = execute(rule, "<a><b>XXXX</b></a>");
30

  
31
		assertEquals("YYYY", doc.valueOf(xpath));
32
	}
33

  
34
	@Test
35
	public void testApplyXpathRule_simple_regex() throws Exception {
36
		final GroovyRule rule = new GroovyRule("(input =~ /X/).replaceAll('Y')");
37

  
38
		final String xpath = "/a/b";
39

  
40
		rule.setXpath(xpath);
41

  
42
		final Document doc = execute(rule, "<a><b>aXaXa</b></a>");
43

  
44
		assertEquals("aYaYa", doc.valueOf(xpath));
45
	}
46

  
47
	@Test
48
	public void testApplyXpathRule_simple_upper() throws Exception {
49
		final GroovyRule rule = new GroovyRule("input.toUpperCase()");
50

  
51
		final String xpath = "/a/b";
52

  
53
		rule.setXpath(xpath);
54

  
55
		final Document doc = execute(rule, "<a><b>xyz</b></a>");
56

  
57
		assertEquals("XYZ", doc.valueOf(xpath));
58
	}
59

  
60
	@Test
61
	public void testApplyXpathRule_multi() throws Exception {
62
		final GroovyRule rule = new GroovyRule("'Y'");
63

  
64
		final String xpath = "/a/b";
65

  
66
		rule.setXpath(xpath);
67

  
68
		final Document doc = execute(rule, "<a><b>X</b><b>X</b><b>X</b></a>");
69

  
70
		final List<?> list = doc.selectNodes(xpath);
71

  
72
		assertEquals(3, list.size());
73
		for (final Object o : list) {
74
			assertEquals("Y", ((Node) o).getText());
75
		}
76

  
77
	}
78

  
79
	@Test
80
	public void testApplyXpathRule_singleAttr() throws Exception {
81
		final GroovyRule rule = new GroovyRule("'BBBB'");
82

  
83
		final String xpath = "/a/b/@value";
84

  
85
		rule.setXpath(xpath);
86

  
87
		final Document doc = execute(rule, "<a><b value='AAAA'>XXXX</b></a>");
88

  
89
		assertEquals("BBBB", doc.valueOf(xpath));
90
		assertEquals("XXXX", doc.valueOf("/a/b"));
91
	}
92

  
93
	@Test
94
	public void testApplyXpathRule_multiAttr() throws Exception {
95
		final GroovyRule rule = new GroovyRule("'B'");
96

  
97
		final String xpath = "/a/b/@value";
98

  
99
		rule.setXpath(xpath);
100

  
101
		final Document doc = execute(rule, "<a><b value='a' /><b value='b' /><b value='c' /></a>");
102

  
103
		final List<?> list = doc.selectNodes(xpath);
104

  
105
		assertEquals(3, list.size());
106
		for (final Object o : list) {
107
			assertEquals("B", ((Node) o).getText());
108
		}
109
	}
110

  
111
	@Test
112
	public void testApplyXpathRule_complex() throws Exception {
113
		final GroovyRule rule = new GroovyRule("'B'");
114

  
115
		final String xpath = "/a/b";
116

  
117
		rule.setXpath(xpath);
118

  
119
		final Document doc = execute(rule, "<a><b>X<c>C</c></b></a>");
120

  
121
		assertTrue(doc.valueOf(xpath).contains("B"));
122
		assertEquals("C", doc.valueOf("/a/b/c"));
123
	}
124

  
125
	private Document execute(final GroovyRule rule, final String xml) throws Exception {
126

  
127
		final SAXReader reader = new SAXReader();
128
		final Document doc = reader.read(new StringReader(xml));
129

  
130
		System.out.println("BEFORE:\n" + doc.asXML() + "\n");
131
		rule.applyXpathRule(doc);
132
		System.out.println("AFTER:\n" + doc.asXML() + "\n");
133

  
134
		System.out.println("-----------------------------\n");
135
		return doc;
136
	}
137
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/MDStoreDaoImplTest.java
1
package eu.dnetlib.data.mdstore.modular.mongodb;
2

  
3
import com.mongodb.BasicDBObject;
4
import com.mongodb.DBObject;
5
import com.mongodb.client.MongoCollection;
6
import com.mongodb.client.MongoDatabase;
7
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDBStatus;
8
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
9
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
10
import eu.dnetlib.rmi.data.MDStoreServiceException;
11
import org.junit.After;
12
import org.junit.Before;
13
import org.junit.Ignore;
14
import org.junit.Test;
15
import org.junit.runner.RunWith;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.test.context.ContextConfiguration;
18
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
19

  
20
import static org.junit.Assert.assertEquals;
21

  
22
@Ignore
23
@RunWith(SpringJUnit4ClassRunner.class)
24
@ContextConfiguration(classes = ConfigurationTestConfig.class)
25
public class MDStoreDaoImplTest {
26

  
27
	@Autowired
28
	private MDStoreDao dao;
29
	@Autowired
30
	private MongoDatabase db;
31
	@Autowired
32
	private MDStoreTransactionManager manager;
33

  
34
	@After
35
	public void tearDown() throws MDStoreServiceException {
36
		dao.deleteMDStore("1");
37
		dao.deleteMDStore("2");
38
		dao.deleteMDStore("3");
39
		dao.deleteMDStore("4");
40
		dao.deleteMDStore("5");
41
		dao.deleteMDStore("6");
42
	}
43

  
44
	@Before
45
	public void setUp() throws Exception {
46
		dao.createMDStore("1", "F", "I", "L");
47
		dao.createMDStore("2", "F", "I", "L");
48
		dao.createMDStore("3", "F", "I", "L");
49
		dao.createMDStore("4", "F", "I", "L");
50
		dao.createMDStore("5", "F1", "I", "L");
51
		dao.createMDStore("6", "F1", "I", "L");
52

  
53
		final MongoCollection<DBObject> metadata = db.getCollection(MDStoreDaoImpl.METADATA_NAME, DBObject.class);
54

  
55
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "1"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
56
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "2"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
57
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "3"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
58
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "4"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
59
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "5"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
60
		metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "6"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
61

  
62
	}
63

  
64
	@Test
65
	public void test() throws MDStoreServiceException {
66
		assertEquals(40, dao.getSumOfSizes("F", "L", "I"));
67
		assertEquals(20, dao.getSumOfSizes("F1", "L", "I"));
68
		assertEquals(0, dao.getSumOfSizes("F_0", "L", "I"));
69
	}
70

  
71
	@Test
72
	public void getDBStatusTest() {
73
		final MDStoreDBStatus dbStatus = dao.getDBStatus();
74
		System.out.println(dbStatus);
75

  
76
	}
77

  
78
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/FeedSpeedTest.java
1
package eu.dnetlib.data.mdstore.modular.mongodb;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.IOException;
6
import java.util.Iterator;
7
import java.util.UUID;
8

  
9
import com.mongodb.DBObject;
10
import com.mongodb.client.MongoDatabase;
11
import eu.dnetlib.data.mdstore.modular.RecordParserFactory;
12
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
13
import eu.dnetlib.rmi.data.MDStoreServiceException;
14
import org.apache.commons.io.IOUtils;
15
import org.junit.Before;
16
import org.junit.Ignore;
17
import org.junit.Test;
18
import org.junit.runner.RunWith;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.core.io.ClassPathResource;
21
import org.springframework.test.context.ContextConfiguration;
22
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
23

  
24
@Ignore
25
@RunWith(SpringJUnit4ClassRunner.class)
26
@ContextConfiguration(classes = ConfigurationTestConfig.class)
27
public class FeedSpeedTest {
28

  
29
	private static final int N_RECORDS = 68271;
30

  
31
	@Autowired
32
	private MongoDatabase db;
33

  
34
	@Autowired
35
	private MDStoreDao dao;
36

  
37
	@Autowired
38
	private RecordParserFactory recordParserfactory;
39

  
40
	@Before
41
	public void setup() throws MDStoreServiceException {
42
		dao.createMDStore("speed_test", "testFormat", "testInterpretation", "testLayout");
43
	}
44

  
45
	@Test
46
	public void testSpeedFromFolder() throws IOException {
47
		Iterable<String> iterable = new Iterable<String>() {
48

  
49
			private int counter = 0;
50
			private double last = System.currentTimeMillis();
51

  
52
			@Override
53
			public Iterator<String> iterator() {
54
				return new Iterator<String>() {
55

  
56
					@Override
57
					public boolean hasNext() {
58
						return counter < N_RECORDS;
59
					}
60

  
61
					@Override
62
					public String next() {
63
						if (counter % 10000 == 0) {
64
							System.out.println("10K records processed in " + (System.currentTimeMillis() - last) / 1000 + " seconds");
65
							last = System.currentTimeMillis();
66
						}
67

  
68
						File f = new File(String.format("/var/lib/eagle/content/EDH/HD%06d.xml", counter++));
69
						if (f.exists()) {
70
							try {
71
								FileInputStream fileInputStream = new FileInputStream(f);
72
								String s = IOUtils.toString(fileInputStream);
73
								fileInputStream.close();
74
								return s;
75
							} catch (Exception e) {
76
								return null;
77
							}
78
						} else {
79
							try {
80
								FileInputStream fileInputStream = new FileInputStream(new File("/var/lib/eagle/content/EDH/HD000001.xml"));
81
								String s = IOUtils.toString(fileInputStream);
82
								fileInputStream.close();
83
								return s;
84
							} catch (Exception e) {
85
								return null;
86
							}
87
						}
88
					}
89

  
90
					@Override
91
					public void remove() {
92
					}
93
				};
94
			}
95
		};
96

  
97
		MongoMDStore mdStore =
98
				new MongoMDStore(UUID.randomUUID().toString(), db.getCollection("speed_test", DBObject.class), recordParserfactory.newInstance(), true, db);
99
		mdStore.feed(iterable, false);
100
	}
101

  
102
	//@Ignore
103
	@Test
104
	public void testFeedSpeedFromTemplate() throws MDStoreServiceException, IOException {
105
		MongoMDStore mdStore =
106
				new MongoMDStore(UUID.randomUUID().toString(), db.getCollection("speed_test", DBObject.class), recordParserfactory.newInstance(), false, db);
107
		mdStore.feed(new Iterable<String>() {
108

  
109
			private int counter = 0;
110
			private double last = System.currentTimeMillis();
111
			private String templateRecord = IOUtils.toString(new ClassPathResource("/eu/dnetlib/data/mdstore/modular/mongodb/templateRecord.xml")
112
					.getInputStream());
113

  
114
			@Override
115
			public Iterator<String> iterator() {
116
				return new Iterator<String>() {
117

  
118
					@Override
119
					public boolean hasNext() {
120
						return counter < N_RECORDS;
121
					}
122

  
123
					@Override
124
					public String next() {
125
						if (counter % 10000 == 0) {
126
							System.out.println("10K records processed in " + (System.currentTimeMillis() - last) / 1000 + " seconds");
127
							last = System.currentTimeMillis();
128
						}
129

  
130
						File f = new File(String.format("/var/lib/eagle/content/EDH/HD%06d.xml", counter++));
131
						if (f.exists()) {
132
							try {
133
								FileInputStream fileInputStream = new FileInputStream(f);
134
								String s = IOUtils.toString(fileInputStream);
135
								fileInputStream.close();
136
								return s;
137
							} catch (Exception e) {
138
								return null;
139
							}
140
						} else {
141
							counter++;
142
							try {
143
								FileInputStream fileInputStream = new FileInputStream(new File("/var/lib/eagle/content/EDH/HD000009.xml"));
144
								String s = IOUtils.toString(fileInputStream);
145
								fileInputStream.close();
146
								return s;
147
							} catch (Exception e) {
148
								return null;
149
							}
150
						}
151
					}
152

  
153
					@Override
154
					public void remove() {
155
					}
156
				};
157
			}
158
		}, false);
159
	}
160
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/ConfigurationTestConfig.java
1
package eu.dnetlib.data.mdstore.modular.mongodb;
2

  
3
import java.net.UnknownHostException;
4

  
5
import com.mongodb.MongoClient;
6
import com.mongodb.client.MongoDatabase;
7
import eu.dnetlib.data.mdstore.modular.RecordParserFactory;
8
import eu.dnetlib.data.mdstore.modular.StreamingRecordParser;
9
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
10
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
11
import org.springframework.context.annotation.Bean;
12
import org.springframework.context.annotation.Configuration;
13

  
14
@Configuration
15
public class ConfigurationTestConfig {
16

  
17
	@Bean
18
	public MongoDatabase db() throws UnknownHostException {
19
		final MongoClient mongo = new MongoClient("localhost", 27017);
20
		return mongo.getDatabase("mdstore_test");
21
	}
22

  
23
	@Bean
24
	public MDStoreTransactionManager manager() throws UnknownHostException {
25
		final MDStoreTransactionManagerImpl manager = new MDStoreTransactionManagerImpl();
26
		manager.setDb(db());
27
		return manager;
28
	}
29

  
30
	@Bean
31
	public RecordParserFactory recordParserFactory() {
32
		final RecordParserFactory rpfactory = new RecordParserFactory();
33
		rpfactory.setParserType(StreamingRecordParser.class);
34
		return rpfactory;
35
	}
36

  
37
	@Bean
38
	public MDStoreDao mdstoreDao() throws UnknownHostException {
39
		final MDStoreDaoImpl dao = new MDStoreDaoImpl();
40
		dao.setDb(db());
41
		dao.setRecordParserFactory(recordParserFactory());
42
		return dao;
43
	}
44

  
45
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/MDStoreTransactionManagerTest.java
1
package eu.dnetlib.data.mdstore.modular.mongodb;
2

  
3
import java.net.UnknownHostException;
4
import java.util.ArrayList;
5
import java.util.Iterator;
6
import java.util.UUID;
7

  
8
import com.mongodb.DBObject;
9
import com.mongodb.MongoClient;
10
import com.mongodb.client.FindIterable;
11
import com.mongodb.client.MongoCollection;
12
import com.mongodb.client.MongoDatabase;
13
import eu.dnetlib.data.mdstore.modular.connector.MDStore;
14
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
15
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
16
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
17
import eu.dnetlib.rmi.data.MDStoreServiceException;
18
import org.junit.Assert;
19
import org.junit.Ignore;
20
import org.junit.Test;
21
import org.junit.runner.RunWith;
22
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.test.context.ContextConfiguration;
24
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25

  
26
// TODO: reimplement tests
27

  
28
@Ignore
29
@RunWith(SpringJUnit4ClassRunner.class)
30
@ContextConfiguration(classes = ConfigurationTestConfig.class)
31
public class MDStoreTransactionManagerTest {
32

  
33
	@Autowired
34
	private MongoDatabase db;
35

  
36
	@Autowired
37
	private MDStoreTransactionManager manager;
38

  
39
	@Autowired
40
	private MDStoreDao dao;
41

  
42
	@Test
43
	public void testCreateandRetrieve() throws MDStoreServiceException {
44
		UUID idCreation = UUID.randomUUID();
45
		db.getCollection("metadataManager").drop();
46
		((MDStoreTransactionManagerImpl) manager).setManagerTable(null);
47

  
48
		String mdId = idCreation.toString() + "_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==";
49
		manager.createMDStore(mdId);
50

  
51
		Assert.assertNotNull(manager.startTransaction(mdId, true));
52
		Assert.assertNotNull(manager.startTransaction(mdId, true));
53

  
54
		String s = manager.getMDStoreCollection(mdId);
55
		Assert.assertNotNull(s);
56
		this.manager.dropMDStore(mdId);
57
		s = manager.getMDStoreCollection(mdId);
58
		Assert.assertNull(s);
59
		db.getCollection("metadataManager").drop();
60
		((MDStoreTransactionManagerImpl) manager).setManagerTable(null);
61
	}
62

  
63
	@Test
64
	public void testReadMdStore() throws MDStoreServiceException {
65
		UUID idCreation = UUID.randomUUID();
66
		String mdId = idCreation.toString() + "_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==";
67
		manager.createMDStore(mdId);
68
		Assert.assertNotNull(manager.readMdStore(mdId));
69
		Assert.assertNotNull(manager.startTransaction(mdId, true));
70
		Assert.assertNotNull(manager.readMdStore(mdId));
71
		db.getCollection("metadataManager").drop();
72
		((MDStoreTransactionManagerImpl) manager).setManagerTable(null);
73
		db.getCollection("metadataManager").drop();
74
		((MDStoreTransactionManagerImpl) manager).setManagerTable(null);
75

  
76
	}
77

  
78
	@Test
79
	public void testCommit() throws MDStoreServiceException {
80
		UUID idCreation = UUID.randomUUID();
81
		String mdId = idCreation.toString() + "_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==";
82
		manager.createMDStore(mdId);
83
		String idCurrent = manager.readMdStore(mdId);
84
		String transaction = manager.startTransaction(mdId, true);
85
		// Assert.assertTrue(manager.commit(transaction, mdId));
86
		Assert.assertNotSame(idCurrent, manager.readMdStore(mdId));
87

  
88
	}
89

  
90
	@Ignore
91
	@Test
92
	public void testDateTime() throws MDStoreServiceException, UnknownHostException {
93
		MongoClient mongo = new MongoClient("localhost", 27017);
94
		MongoDatabase dbinput = mongo.getDatabase("mdstore");
95
		MongoCollection<DBObject> inputCollection = dbinput.getCollection("70e07e9f-b3bf-4423-8777-b159819e0c6a", DBObject.class);
96
		Assert.assertNotNull(inputCollection.find().first().get("body"));
97
		UUID idCreation = UUID.randomUUID();
98

  
99
		String mdId = idCreation.toString() + "_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==";
100

  
101
		manager.createMDStore(mdId);
102
		dao.createMDStore(mdId, "a", "a", "a");
103

  
104
		String transId = manager.startTransaction(mdId, true);
105

  
106
		ArrayList<String> data = new ArrayList<String>();
107
		FindIterable<DBObject> cursor = inputCollection.find();
108

  
109
		Iterator<DBObject> it = cursor.iterator();
110
		for (int i = 0; i < 1000; i++) {
111
			data.add((String) it.next().get("body"));
112
		}
113
		dao.getMDStore(transId).feed(data, true);
114
		// manager.commit(transId, mdId);
115

  
116
		cursor = inputCollection.find();
117
		it = cursor.iterator();
118
		transId = manager.startTransaction(mdId, false);
119

  
120
		data.clear();
121
		for (int i = 0; i < 10; i++) {
122
			data.add(it.next().get("body").toString().replace("oai:pumaoai.isti.cnr.it:", "SUUUCAAA"));
123
		}
124

  
125
		String currentId = manager.readMdStore(mdId);
126

  
127
		final MDStore newMdstore = dao.getMDStore(currentId);
128

  
129
		new Thread(() -> {
130
			final ResultSetListener<String> deliver = newMdstore.deliver("", "", null, false);
131

  
132
			for (int i = 0; i < 10; i++) {
133
				try {
134
					Thread.sleep(1000);
135
					System.out.println(deliver.next());
136
				} catch (Exception e) {
137
					// TODO Auto-generated catch block
138
					e.printStackTrace();
139
				}
140
			}
141

  
142
		}).start();
143
		dao.getMDStore(transId).feed(data, true);
144

  
145
	}
146
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/resources/eu/dnetlib/enabling/tools/blackboard/BlackboardServerActionExecutorTest-context.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
       xmlns:p="http://www.springframework.org/schema/p" xmlns="http://www.springframework.org/schema/beans"
4
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
5

  
6
	<bean id="blackboardHandler" class="eu.dnetlib.enabling.tools.blackboard.MockBeanFactory"/>
7

  
8
	<bean id="executor"
9
	      class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerActionExecutor"
10
	      p:blackboardHandler-ref="blackboardHandler" p:actionType="eu.dnetlib.data.mdstore.modular.action.MDStoreActions"
11
	      p:incomplete="true">
12
		<property name="actionMap">
13
			<map>
14
				<entry key="CREATE">
15
					<bean class="eu.dnetlib.enabling.tools.blackboard.SampleCreateAction"/>
16
				</entry>
17
			</map>
18
		</property>
19

  
20
	</bean>
21
</beans>
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/resources/eu/dnetlib/data/collector/plugins/sftp/SftpPubKeyCollectorPluginTest-context.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
       xmlns:p="http://www.springframework.org/schema/p" xmlns="http://www.springframework.org/schema/beans"
4
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
5

  
6
	<bean id="sftpPubKeyCollectorPlugin" class="eu.dnetlib.data.collector.plugins.sftp.SftpPubKeyCollectorPlugin"
7
	      p:sftpIteratorFactory-ref="sftpIteratorFactory">
8
		<property name="protocolDescriptor">
9
			<bean class="eu.dnetlib.rmi.data.ProtocolDescriptor" p:name="sftpPubKeyAuthentication">
10
				<property name="params">
11
					<list>
12
						<bean class="eu.dnetlib.rmi.data.ProtocolParameter"
13
						      p:name="username" />
14
						<bean class="eu.dnetlib.rmi.data.ProtocolParameter"
15
						      p:name="recursive" p:type="BOOLEAN"/>
16
						<bean class="eu.dnetlib.rmi.data.ProtocolParameter"
17
						      p:name="extensions" p:type="LIST"/>
18
					</list>
19
				</property>
20
			</bean>
21
		</property>
22
	</bean>
23

  
24
	<bean id="sftpIteratorFactory" class="eu.dnetlib.data.collector.plugins.sftp.SftpIteratorFactory"/>
25

  
26
	<bean id="propertyConfigurer"
27
	      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
28
		<property name="properties">
29
			<props>
30
				<prop key="collector.sftp.auth.prvKeyPath">~/.ssh/id_rsa</prop>
31
				<prop key="collector.sftp.auth.passphrase"></prop>
32
				<prop key="collector.sftp.auth.knownHostsPath">~/.ssh/known_hosts</prop>
33
			</props>
34
		</property>
35
	</bean>
36

  
37

  
38
</beans>
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/resources/eu/dnetlib/data/mdstore/modular/mongodb/templateRecord.xml
1
<oai:record xmlns:dri="http://www.driver-repository.eu/namespace/dri"
2
            xmlns:oai="http://www.openarchives.org/OAI/2.0/"
3
            xmlns="http://namespace.openaire.eu/"
4
>
5
	<oai:header>
6
		<dri:objIdentifier>{id}</dri:objIdentifier>
7
		<dri:recordIdentifier>entityId:2533216</dri:recordIdentifier>
8
		<dri:dateOfCollection>2015-01-09T12:15:02.177+01:00</dri:dateOfCollection>
9
		<dri:repositoryId>8e17a4fe-b77d-406b-8c75-4cfa233092d2_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>
10
		<dri:datasourceprefix>DAI</dri:datasourceprefix>
11
	</oai:header>
12
	<oai:metadata>
13
		<eagle:eagleObject xmlns:eagle="http://www.eagle-network.eu/eagle">
14
			<eagle:recordSourceInfo
15
					landingPage="http://arachne.uni-koeln.de/entity/2533216" providerName="Arachne">entityId:2533216
16
			</eagle:recordSourceInfo>
17
			<eagle:editingInfo>
18
				<eagle:dateEdited>0000-00-00</eagle:dateEdited>
19
				<eagle:metadataEditor>unknown</eagle:metadataEditor>
20
			</eagle:editingInfo>
21
			<eagle:metadataIpr uri="http://creativecommons.org/licenses/by/3.0/">This file is licensed under the Creative Commons Attribution 3.0 Unported license.</eagle:metadataIpr>
22
			<eagle:title lang="de">CMS-XII-d009c-3_168111,02.jpg</eagle:title>
23
			<!-- objekt http://arachne.uni-koeln.de/entity/1160926 -->
24
			<eagle:description lang="de">Foto von: Siegel CMS XII D009c</eagle:description>
25
			<eagle:entityType>visual</eagle:entityType>
26
			<eagle:visualRepresentation>
27
				<eagle:representationType>image</eagle:representationType>
28
				<eagle:url>http://arachne.uni-koeln.de/entity/2533216</eagle:url>
29
				<eagle:thumbnail>http://arachne.dainst.org/data/image/thumbnail/2533216</eagle:thumbnail>
30
				<eagle:visualRepresentationIpr uri="http://creativecommons.org/licenses/by/3.0/">This file is licensed under the Creative Commons Attribution 3.0 Unported license.</eagle:visualRepresentationIpr>
31
				<eagle:format>jpg</eagle:format>
32
				<!-- objekt http://arachne.uni-koeln.de/entity/1160926 -->
33
				<eagle:hasArtifact>
34
					<eagle:artifactTitle>Siegel CMS XII D009c</eagle:artifactTitle>
35
					<eagle:objectType>Dreiseitiges Prisma Mallia Steatitgruppe</eagle:objectType>
36
					<eagle:material>weicher Stein</eagle:material>
37
				</eagle:hasArtifact>
38
			</eagle:visualRepresentation>
39
		</eagle:eagleObject>
40
	</oai:metadata>
41
</oai:record>
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/test/resources/log4j.properties
1
org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
2
log4j.rootLogger=WARN, CONSOLE
3
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
4
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
5
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
6

  
7
log4j.logger.eu.dnetlib=INFO
8
log4j.logger.eu.dnetlib.data.collector.plugins=DEBUG
9
log4j.logger.eu.dnetlib.data.collector.plugins.sftp=DEBUG
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/main/java/prototype/utils/DotAbbreviations.java
1
package prototype.utils;
2

  
3
import com.google.common.base.Function;
4

  
5
public class DotAbbreviations implements Function<String, String> {
6

  
7
	@Override
8
	public String apply(String s) {
9
		return s.length() == 1 ? s + "." : s;
10
	}
11
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/main/java/prototype/utils/Capitalize.java
1
package prototype.utils;
2

  
3
import com.google.common.base.Function;
4
import org.apache.commons.lang3.text.WordUtils;
5

  
6
public class Capitalize implements Function<String, String> {
7

  
8
	@Override
9
	public String apply(String s) {
10
		return WordUtils.capitalize(s.toLowerCase());
11
	}
12
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/main/java/prototype/Person.java
1
package prototype;
2

  
3
import java.nio.charset.StandardCharsets;
4
import java.text.Normalizer;
5
import java.util.List;
6
import java.util.Set;
7

  
8
import com.google.common.base.Joiner;
9
import com.google.common.base.Splitter;
10
import com.google.common.collect.Iterables;
11
import com.google.common.collect.Lists;
12
import com.google.common.hash.Hashing;
13
import prototype.utils.Capitalize;
14
import prototype.utils.DotAbbreviations;
15

  
16
//import eu.dnetlib.pace.clustering.NGramUtils;
17
//import eu.dnetlib.pace.util.Capitalise;
18
//import eu.dnetlib.pace.util.DotAbbreviations;
19

  
20
public class Person {
21

  
22
	private static Set<String> particles = null;
23
	private List<String> name = Lists.newArrayList();
24
	private List<String> surname = Lists.newArrayList();
25
	private List<String> fullname = Lists.newArrayList();
26

  
27
	public Person(String s) {
28
		s = Normalizer.normalize(s, Normalizer.Form.NFD); // was NFD
29
		s = s.replaceAll("\\(.+\\)", "");
30
		s = s.replaceAll("\\[.+\\]", "");
31
		s = s.replaceAll("\\{.+\\}", "");
32
		s = s.replaceAll("\\s+-\\s+", "-");
33

  
34
		//		s = s.replaceAll("[\\W&&[^,-]]", " ");
35

  
36
		//		System.out.println("class Person: s: " + s);
37

  
38
		//		s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}&&[^,-]]", " ");
39
		s = s.replaceAll("[\\p{Punct}&&[^-,]]", " ");
40
		s = s.replaceAll("\\d", " ");
41
		s = s.replaceAll("\\n", " ");
42
		s = s.replaceAll("\\.", " ");
43
		s = s.replaceAll("\\s+", " ");
44

  
45
		if (s.contains(",")) {
46
			//		System.out.println("class Person: s: " + s);
47

  
48
			String[] arr = s.split(",");
49
			if (arr.length == 1) {
50
				fullname = splitTerms(arr[0]);
51
			} else if (arr.length > 1) {
52
				surname = splitTerms(arr[0]);
53
				name = splitTermsFirstName(arr[1]);
54
				//				System.out.println("class Person: surname: " + surname);
55
				//				System.out.println("class Person: name: " + name);
56

  
57
				fullname.addAll(surname);
58
				fullname.addAll(name);
59
			}
60
		} else {
61
			fullname = splitTerms(s);
62

  
63
			int lastInitialPosition = fullname.size();
64
			boolean hasSurnameInUpperCase = false;
65

  
66
			for (int i = 0; i < fullname.size(); i++) {
67
				String term = fullname.get(i);
68
				if (term.length() == 1) {
69
					lastInitialPosition = i;
70
				} else if (term.equals(term.toUpperCase())) {
71
					hasSurnameInUpperCase = true;
72
				}
73
			}
74
			if (lastInitialPosition < fullname.size() - 1) { // Case: Michele G. Artini
75
				name = fullname.subList(0, lastInitialPosition + 1);
76
				System.out.println("name: " + name);
77
				surname = fullname.subList(lastInitialPosition + 1, fullname.size());
78
			} else if (hasSurnameInUpperCase) { // Case: Michele ARTINI
79
				for (String term : fullname) {
80
					if (term.length() > 1 && term.equals(term.toUpperCase())) {
81
						surname.add(term);
82
					} else {
83
						name.add(term);
84
					}
85
				}
86
			} else if (lastInitialPosition == fullname.size()) {
87
				surname = fullname.subList(lastInitialPosition - 1, fullname.size());
88
				name = fullname.subList(0, lastInitialPosition - 1);
89
			}
90

  
91
		}
92
	}
93

  
94
	private List<String> splitTermsFirstName(String s) {
95
		List<String> list = Lists.newArrayList();
96
		for (String part : Splitter.on(" ").omitEmptyStrings().split(s)) {
97
			if (s.trim().matches("\\p{Lu}{2,3}")) {
98
				String[] parts = s.trim().split("(?=\\p{Lu})"); // (Unicode UpperCase)
99
				for (String p : parts) {
100
					if (p.length() > 0)
101
						list.add(p);
102
				}
103
			} else {
104
				list.add(part);
105
			}
106

  
107
		}
108
		return list;
109
	}
110

  
111
	private List<String> splitTerms(String s) {
112
		if (particles == null) {
113
			//			particles = NGramUtils.loadFromClasspath("/eu/dnetlib/pace/config/name_particles.txt");
114
		}
115

  
116
		List<String> list = Lists.newArrayList();
117
		for (String part : Splitter.on(" ").omitEmptyStrings().split(s)) {
118
			//		if (!particles.contains(part.toLowerCase())) {
119
			list.add(part);
120

  
121
			//		}
122
		}
123
		return list;
124
	}
125

  
126
	public List<String> getName() {
127
		return name;
128
	}
129

  
130
	public List<String> getSurname() {
131
		return surname;
132
	}
133

  
134
	public List<String> getFullname() {
135
		return fullname;
136
	}
137

  
138
	public String hash() {
139
		return Hashing.murmur3_128().hashString(getNormalisedFullname(), StandardCharsets.UTF_8).toString();
140
	}
141

  
142
	public String getNormalisedFullname() {
143
		return isAccurate() ?
144
				Joiner.on(" ").join(getSurname()) + ", " + Joiner.on(" ").join(getNameWithAbbreviations()) :
145
				Joiner.on(" ").join(fullname);
146
		//				return isAccurate() ?
147
		//						Joiner.on(" ").join(getCapitalSurname()) + ", " + Joiner.on(" ").join(getNameWithAbbreviations()) :
148
		//						Joiner.on(" ").join(fullname);
149
	}
150

  
151
	public List<String> getCapitalSurname() {
152
		return Lists.newArrayList(Iterables.transform(surname, new Capitalize()));
153
	}
154

  
155
	public List<String> getNameWithAbbreviations() {
156
		return Lists.newArrayList(Iterables.transform(name, new DotAbbreviations()));
157
	}
158

  
159
	public boolean isAccurate() {
160
		return (name != null && surname != null && !name.isEmpty() && !surname.isEmpty());
161
	}
162
}
modules/dnet-data-services/tags/dnet-data-services-2.0.0-SAXONHE/src/main/java/prototype/PersonOrig.java
1
package prototype;
2

  
3
import java.nio.charset.StandardCharsets;
4
import java.text.Normalizer;
5
import java.util.List;
6
import java.util.Set;
7

  
8
import com.google.common.base.Joiner;
9
import com.google.common.base.Splitter;
10
import com.google.common.collect.Iterables;
11
import com.google.common.collect.Lists;
12
import com.google.common.hash.Hashing;
13
import prototype.utils.Capitalize;
14
import prototype.utils.DotAbbreviations;
15

  
16
//import eu.dnetlib.pace.clustering.NGramUtils;
17
//import eu.dnetlib.pace.util.Capitalise;
18
//import eu.dnetlib.pace.util.DotAbbreviations;
19

  
20
public class PersonOrig {
21

  
22
	private static Set<String> particles = null;
23
	private List<String> name = Lists.newArrayList();
24
	private List<String> surname = Lists.newArrayList();
25
	private List<String> fullname = Lists.newArrayList();
26

  
27
	public PersonOrig(String s) {
28
		s = Normalizer.normalize(s, Normalizer.Form.NFD);
29
		s = s.replaceAll("\\(.+\\)", "");
30
		s = s.replaceAll("\\[.+\\]", "");
31
		s = s.replaceAll("\\{.+\\}", "");
32
		s = s.replaceAll("\\s+-\\s+", "-");
33
		s = s.replaceAll("[\\W&&[^,-]]", " ");
34
		s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}&&[^,-]]", " ");
35
		s = s.replaceAll("[\\p{Punct}&&[^-,]]", " ");
36
		s = s.replaceAll("\\d", " ");
37
		s = s.replaceAll("\\n", " ");
38
		s = s.replaceAll("\\.", " ");
39
		s = s.replaceAll("\\s+", " ");
40

  
41
		if (s.contains(",")) {
42
			String[] arr = s.split(",");
43
			if (arr.length == 1) {
44
				fullname = splitTerms(arr[0]);
45
			} else if (arr.length > 1) {
46
				surname = splitTerms(arr[0]);
47
				name = splitTerms(arr[1]);
48
				fullname.addAll(surname);
49
				fullname.addAll(name);
50
			}
51
		} else {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff