Revision 48267
Added by Katerina Iatropoulou almost 7 years ago
modules/uoa-commons/tags/uoa-commons-2.0.0/deploy.info | ||
---|---|---|
1 |
{ |
|
2 |
"type_source": "SVN", |
|
3 |
"goal": "package -U -T 4C source:jar", |
|
4 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-commons/trunk", |
|
5 |
"deploy_repository": "dnet45-snapshots", |
|
6 |
"version": "4", |
|
7 |
"mail": "antleb@di.uoa.gr, kiatrop@di.uoa.gr", |
|
8 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", |
|
9 |
"name": "uoa-commons" |
|
10 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/resources/gr/uoa/di/driver/xml/profile.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
|
2 |
<RESOURCE_PROFILE> |
|
3 |
<HEADER> |
|
4 |
<RESOURCE_IDENTIFIER value="" /> |
|
5 |
<RESOURCE_TYPE value="UserDSResourceType" /> |
|
6 |
<RESOURCE_KIND value="UserDSResources" /> |
|
7 |
<RESOURCE_URI value="" /> |
|
8 |
<DATE_OF_CREATION value="2009-09-10T17:16:37+03:00" /> |
|
9 |
</HEADER> |
|
10 |
<BODY> |
|
11 |
<CONFIGURATION> |
|
12 |
<PERSONAL_INFO> |
|
13 |
<FIRST_NAME /> |
|
14 |
<LAST_NAME /> |
|
15 |
<INSTITUTION /> |
|
16 |
<EMAIL value="Helenaki" /> |
|
17 |
<ACTIVATION_ID value="123" /> |
|
18 |
<ACTIVE value="true" /> |
|
19 |
</PERSONAL_INFO> |
|
20 |
<COMMUNITIES /> |
|
21 |
<SAVED_QUERIES> |
|
22 |
<query> |
|
23 |
<CQL value="cqlTesxt" /> |
|
24 |
<COMMUNITYID communityId="My community1" /> |
|
25 |
</query> |
|
26 |
<alertOnChange>false</alertOnChange> |
|
27 |
</SAVED_QUERIES> |
|
28 |
<FILTER> |
|
29 |
<query> |
|
30 |
<query> |
|
31 |
<CQL value="cql" /> |
|
32 |
<REFINE value="refine" /> |
|
33 |
<COLLECTIONID collectionId="Collection 1" /> |
|
34 |
</query> |
|
35 |
<alertOnChange>false</alertOnChange> |
|
36 |
</query> |
|
37 |
</FILTER> |
|
38 |
<RECOMMENDATION SEND_EMAIL="false"> |
|
39 |
<RECOMMENDATIONS /> |
|
40 |
</RECOMMENDATION> |
|
41 |
<DOCUMENTS> |
|
42 |
<DOCUMENT_ID>Document 1</DOCUMENT_ID> |
|
43 |
<DOCUMENT_ID>Document 2</DOCUMENT_ID> |
|
44 |
</DOCUMENTS> |
|
45 |
<USER_STORE> |
|
46 |
<serviceURL>service URL</serviceURL> |
|
47 |
<storeID>store ID</storeID> |
|
48 |
</USER_STORE> |
|
49 |
<userImageID>photoID</userImageID> |
|
50 |
</CONFIGURATION> |
|
51 |
<STATUS></STATUS> |
|
52 |
<SECURITY_PARAMETERS> |
|
53 |
<SECURITY_PARAMETER>value</SECURITY_PARAMETER> |
|
54 |
</SECURITY_PARAMETERS> |
|
55 |
</BODY> |
|
56 |
</RESOURCE_PROFILE> |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/CleanupSecurityProfiles.java | ||
---|---|---|
1 |
import eu.dnetlib.domain.enabling.SecurityProfile; |
|
2 |
import eu.dnetlib.domain.functionality.UserProfile; |
|
3 |
import eu.dnetlib.utils.md5.MD5; |
|
4 |
import gr.uoa.di.driver.xml.SecurityProfileXmlConverter; |
|
5 |
import gr.uoa.di.driver.xml.UserProfileXmlConverter; |
|
6 |
|
|
7 |
import java.io.File; |
|
8 |
import java.io.FileReader; |
|
9 |
import java.io.FileWriter; |
|
10 |
import java.io.FilenameFilter; |
|
11 |
import java.io.IOException; |
|
12 |
import java.security.NoSuchAlgorithmException; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import javax.xml.bind.JAXBException; |
|
17 |
|
|
18 |
public class CleanupSecurityProfiles { |
|
19 |
final static File rootDir = new File("/home/antleb/projects/dnet1.1/uoa-is/cnr-test-profiles/src/main/eu/dnetlib/test/profiles/"); |
|
20 |
final static File userDir = new File(rootDir, "UserDSResources/UserDSResourceType"); |
|
21 |
final static File secProfDir = new File(rootDir, "SecurityProfileDSResources/SecurityProfileDSResourceType"); |
|
22 |
|
|
23 |
public static void cleanupUserProfiles() |
|
24 |
throws JAXBException, IOException { |
|
25 |
UserProfileXmlConverter conv = new UserProfileXmlConverter(); |
|
26 |
File[] xmlsFiles = userDir.listFiles(new FilenameFilter() { |
|
27 |
|
|
28 |
@Override |
|
29 |
public boolean accept(File dir, String name) { |
|
30 |
return name.endsWith(".xml"); |
|
31 |
} |
|
32 |
}); |
|
33 |
List<String> users = new ArrayList<String>(); |
|
34 |
|
|
35 |
for (File xmlFile : xmlsFiles) { |
|
36 |
String xml = readXml(xmlFile); |
|
37 |
UserProfile user = conv.XmlToObject(xml); |
|
38 |
|
|
39 |
if (users.contains(user.getEmail())) { |
|
40 |
System.out.println("user with email '" + user.getEmail() + "' already exists. Removing profile"); |
|
41 |
xmlFile.delete(); |
|
42 |
} else { |
|
43 |
users.add(user.getEmail()); |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public static void cleanupSecProfiles() throws JAXBException, |
|
49 |
NoSuchAlgorithmException, IOException { |
|
50 |
SecurityProfileXmlConverter conv = new SecurityProfileXmlConverter(); |
|
51 |
File[] xmlsFiles = secProfDir.listFiles(new FilenameFilter() { |
|
52 |
|
|
53 |
@Override |
|
54 |
public boolean accept(File dir, String name) { |
|
55 |
return name.endsWith(".xml"); |
|
56 |
} |
|
57 |
}); |
|
58 |
|
|
59 |
for (File xmlFile : xmlsFiles) { |
|
60 |
String xml = readXml(xmlFile); |
|
61 |
SecurityProfile secProfile = conv.XmlToObject(xml); |
|
62 |
|
|
63 |
if (secProfile.getDriverResourceId() == null |
|
64 |
|| secProfile.getDriverResourceId().trim().equals("")) { |
|
65 |
System.out.println("Security profile is orphan: " + secProfile.getResourceId()); |
|
66 |
xmlFile.delete(); |
|
67 |
} else if (!new File(userDir, secProfile.getDriverResourceId().split("_")[0] + ".xml").exists()) { |
|
68 |
System.out.println("Security profile points to non existing user: " + secProfile.getResourceId()); |
|
69 |
xmlFile.delete(); |
|
70 |
|
|
71 |
} else { |
|
72 |
System.out.println("---"); |
|
73 |
if (secProfile.getPassword() != null) { |
|
74 |
String oldPass = secProfile.getPassword(); |
|
75 |
String newPass = MD5.encrypt2Hex(oldPass); |
|
76 |
|
|
77 |
System.out.println(oldPass + " -> " + newPass); |
|
78 |
|
|
79 |
secProfile.setPassword(newPass); |
|
80 |
|
|
81 |
xml = conv.ObjectToXml(secProfile); |
|
82 |
|
|
83 |
saveXml(xml, xmlFile); |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
private static void saveXml(String xml, File xmlFile) throws IOException { |
|
90 |
FileWriter fw = new FileWriter(xmlFile); |
|
91 |
|
|
92 |
fw.append(xml); |
|
93 |
|
|
94 |
fw.close(); |
|
95 |
} |
|
96 |
|
|
97 |
private static String readXml(File xmlFile) throws IOException { |
|
98 |
FileReader fr = new FileReader(xmlFile); |
|
99 |
StringBuilder sb = new StringBuilder(); |
|
100 |
char buffer[] = new char[1024]; |
|
101 |
while (fr.read(buffer) != -1) { |
|
102 |
sb.append(buffer); |
|
103 |
|
|
104 |
buffer = new char[1024]; |
|
105 |
} |
|
106 |
|
|
107 |
fr.close(); |
|
108 |
|
|
109 |
return sb.toString().trim(); |
|
110 |
} |
|
111 |
|
|
112 |
public static void main(String[] args) throws Exception { |
|
113 |
cleanupUserProfiles(); |
|
114 |
cleanupSecProfiles(); |
|
115 |
} |
|
116 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/data/BrowseDataUtilTest.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.data; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.BrowseData; |
|
4 |
import gr.uoa.di.driver.data.browsedata.BrowseDataUtil; |
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
import static org.junit.Assert.assertArrayEquals; |
|
9 |
|
|
10 |
public class BrowseDataUtilTest { |
|
11 |
|
|
12 |
private static String record = null; |
|
13 |
|
|
14 |
@Before |
|
15 |
public void setup() { |
|
16 |
} |
|
17 |
|
|
18 |
@Test |
|
19 |
public void testFullRow(){ |
|
20 |
record = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + |
|
21 |
"<row>" + |
|
22 |
"<groupresult field=\"repositoryname\">" + |
|
23 |
"<count>12946</count>" + |
|
24 |
"<value>DigitalCommons@USU</value>" + |
|
25 |
"</groupresult>" + |
|
26 |
"</row>"; |
|
27 |
|
|
28 |
record = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><row><groupresult field=\"repositoryname\"><count>12946</count><value>DigitalCommons@USU</value></groupresult><groupresult field=\"cobjcategory\"><count>12946</count><value>0000</value></groupresult><groupresult field=\"language\"><count>12946</count><value>und</value></groupresult></row>"; |
|
29 |
|
|
30 |
/* record = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + |
|
31 |
"<row>" + |
|
32 |
"<groupresult field=\"language\">" + |
|
33 |
"<count>266</count>" + |
|
34 |
"<value>spa</value>" + |
|
35 |
"</groupresult>" + |
|
36 |
"</row>"; |
|
37 |
*/ |
|
38 |
BrowseData expected = new BrowseData(); |
|
39 |
expected.addFieldEntry("repositoryName", "DigitalCommons@USU", 12946); |
|
40 |
expected.addFieldEntry("cobjcategory", "0000", 12946); |
|
41 |
expected.addFieldEntry("language", "und", 12946); |
|
42 |
|
|
43 |
// expected.addFieldEntry("language", "spa", 266); |
|
44 |
BrowseData actual = BrowseDataUtil.parseRows(record); |
|
45 |
|
|
46 |
//record = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><row><groupresult field=\"repositoryname\"><count>12946</count><value>DigitalCommons@USU</value></groupresult><groupresult field=\"cobjcategory\"><value>0000</value><count>12946</count></groupresult><groupresult field=\"language\"><value>und</value><count>12946</count></groupresult></row>"; |
|
47 |
assertArrayEquals(expected.getFields().toArray(), actual.getFields().toArray()); |
|
48 |
for (String field:expected.getFields()){ |
|
49 |
assertArrayEquals(expected.getFieldValues(field).toArray(), actual.getFieldValues(field).toArray()); |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
@Test |
|
55 |
public void testIncompleteRow(){ |
|
56 |
record = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><row><groupresult field=\"repositoryname\"><value>DigitalCommons@USU</value></groupresult><groupresult field=\"cobjcategory\"><count>12946</count><value>0000</value></groupresult><groupresult field=\"language\"><count>12946</count></groupresult></row>"; |
|
57 |
BrowseData expected = new BrowseData(); |
|
58 |
expected.addFieldEntry("repositoryName", "DigitalCommons@USU", 0); |
|
59 |
expected.addFieldEntry("cobjcategory", "0000", 12946); |
|
60 |
expected.addFieldEntry("language", null, 12946); |
|
61 |
|
|
62 |
BrowseData actual = BrowseDataUtil.parseRows(record); |
|
63 |
|
|
64 |
assertArrayEquals(expected.getFields().toArray(), actual.getFields().toArray()); |
|
65 |
for (String field:expected.getFields()){ |
|
66 |
assertArrayEquals(expected.getFieldValues(field).toArray(), actual.getFieldValues(field).toArray()); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/enabling/a2/TestAASExecutor.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling.a2; |
|
2 |
|
|
3 |
import java.util.concurrent.ScheduledExecutorService; |
|
4 |
import java.util.concurrent.TimeUnit; |
|
5 |
|
|
6 |
import org.junit.Assert; |
|
7 |
|
|
8 |
import org.junit.BeforeClass; |
|
9 |
import org.junit.Test; |
|
10 |
|
|
11 |
public class TestAASExecutor { |
|
12 |
|
|
13 |
public static ThreadLocal<String> t = new ThreadLocal<String>(); |
|
14 |
public static AASExecutor executor = null; |
|
15 |
|
|
16 |
@BeforeClass |
|
17 |
public static void setup() { |
|
18 |
ScheduledExecutorService service = java.util.concurrent.Executors |
|
19 |
.newScheduledThreadPool(1); |
|
20 |
|
|
21 |
executor = new AASExecutor(); |
|
22 |
executor.setExecutorService(service); |
|
23 |
executor.setCallerSecurityContext(t); |
|
24 |
} |
|
25 |
|
|
26 |
@Test |
|
27 |
public void test() throws InterruptedException { |
|
28 |
t.set("value"); |
|
29 |
Task task = new Task(t); |
|
30 |
|
|
31 |
executor.execute(task); |
|
32 |
|
|
33 |
TimeUnit.SECONDS.sleep(1); |
|
34 |
|
|
35 |
Assert.assertEquals(t.get(), task.getValueOfT()); |
|
36 |
} |
|
37 |
|
|
38 |
class Task implements Runnable { |
|
39 |
private ThreadLocal<String> t = null; |
|
40 |
String valueOfT = null; |
|
41 |
|
|
42 |
public String getValueOfT() { |
|
43 |
return valueOfT; |
|
44 |
} |
|
45 |
|
|
46 |
public Task(ThreadLocal<String> t) { |
|
47 |
this.t = t; |
|
48 |
} |
|
49 |
|
|
50 |
public void run() { |
|
51 |
valueOfT = t.get(); |
|
52 |
} |
|
53 |
} |
|
54 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/enabling/registry/TestValidation.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling.registry; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
|
|
5 |
import javax.xml.bind.JAXBException; |
|
6 |
|
|
7 |
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; |
|
8 |
import org.junit.BeforeClass; |
|
9 |
import org.junit.Test; |
|
10 |
|
|
11 |
import eu.dnetlib.domain.enabling.SecurityProfile; |
|
12 |
import eu.dnetlib.domain.functionality.Collection; |
|
13 |
import eu.dnetlib.domain.functionality.Community; |
|
14 |
import eu.dnetlib.domain.functionality.QueryHash; |
|
15 |
import eu.dnetlib.domain.functionality.Recommendation; |
|
16 |
import eu.dnetlib.domain.functionality.UserProfile; |
|
17 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
18 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
19 |
import gr.uoa.di.driver.xml.CollectionXmlConverter; |
|
20 |
import gr.uoa.di.driver.xml.CommunityXmlConverter; |
|
21 |
import gr.uoa.di.driver.xml.QueryHashXmlConverter; |
|
22 |
import gr.uoa.di.driver.xml.RecommendationXmlConverter; |
|
23 |
import gr.uoa.di.driver.xml.SecurityProfileXmlConverter; |
|
24 |
import gr.uoa.di.driver.xml.UserProfileXmlConverter; |
|
25 |
|
|
26 |
public class TestValidation { |
|
27 |
|
|
28 |
// private static String registryAddress = "http://146.48.85.160:8280/is/services/isRegistry"; |
|
29 |
private static String registryAddress = "http://node3.t.openaire.research-infrastructures.eu:8280/cnr-container-latest/services/isRegistry"; |
|
30 |
|
|
31 |
private static ISRegistryService registry = null; |
|
32 |
|
|
33 |
@BeforeClass |
|
34 |
public static void setup() { |
|
35 |
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); |
|
36 |
factory.setServiceClass(ISRegistryService.class); |
|
37 |
factory.setAddress(registryAddress); |
|
38 |
|
|
39 |
registry = (ISRegistryService) factory.create(); |
|
40 |
} |
|
41 |
|
|
42 |
public void testSecProf() throws JAXBException { |
|
43 |
SecurityProfile sp = new SecurityProfile(); |
|
44 |
String xml = new SecurityProfileXmlConverter().ObjectToXml(sp); |
|
45 |
|
|
46 |
System.out.println(xml); |
|
47 |
|
|
48 |
try { |
|
49 |
System.out.println(registry.registerProfile(xml)); |
|
50 |
} catch (ISRegistryException e) { |
|
51 |
e.printStackTrace(); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
public void testRecommendation() throws JAXBException { |
|
56 |
Recommendation r = new Recommendation(); |
|
57 |
r.setExpirationDate(new Date()); |
|
58 |
String xml = new RecommendationXmlConverter().ObjectToXml(r); |
|
59 |
|
|
60 |
System.out.println(xml); |
|
61 |
|
|
62 |
try { |
|
63 |
System.out.println(registry.registerProfile(xml)); |
|
64 |
} catch (ISRegistryException e) { |
|
65 |
e.printStackTrace(); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
public void testHashQuery() throws JAXBException { |
|
70 |
QueryHash qh = new QueryHash(); |
|
71 |
String xml = new QueryHashXmlConverter().ObjectToXml(qh); |
|
72 |
|
|
73 |
System.out.println(xml); |
|
74 |
|
|
75 |
try { |
|
76 |
System.out.println(registry.registerProfile(xml)); |
|
77 |
} catch (ISRegistryException e) { |
|
78 |
e.printStackTrace(); |
|
79 |
} |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
public void testCollection() throws JAXBException { |
|
84 |
Collection col = new Collection(); |
|
85 |
String xml = new CollectionXmlConverter().ObjectToXml(col); |
|
86 |
|
|
87 |
System.out.println(xml); |
|
88 |
|
|
89 |
try { |
|
90 |
System.out.println(registry.registerProfile(xml)); |
|
91 |
} catch (ISRegistryException e) { |
|
92 |
e.printStackTrace(); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public void testCommunity() throws JAXBException { |
|
97 |
Community comm = new Community(); |
|
98 |
String xml = new CommunityXmlConverter().ObjectToXml(comm); |
|
99 |
|
|
100 |
System.out.println(xml); |
|
101 |
|
|
102 |
try { |
|
103 |
System.out.println(registry.registerProfile(xml)); |
|
104 |
} catch (ISRegistryException e) { |
|
105 |
e.printStackTrace(); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
public void testProfile() throws JAXBException { |
|
110 |
UserProfile prof = new UserProfile(); |
|
111 |
|
|
112 |
String xml = new UserProfileXmlConverter().ObjectToXml(prof); |
|
113 |
|
|
114 |
System.out.println(xml); |
|
115 |
|
|
116 |
try { |
|
117 |
String id = registry.registerProfile(xml); |
|
118 |
|
|
119 |
System.out.println(id); |
|
120 |
} catch (ISRegistryException e) { |
|
121 |
e.printStackTrace(); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
@Test |
|
126 |
public void testRepository() throws JAXBException { |
|
127 |
// Repository repo = new Repository(); |
|
128 |
// RepositoryInterface repoInter = new RepositoryInterface(); |
|
129 |
// |
|
130 |
//// repoInter.setAccessProtocol("OAI"); |
|
131 |
// repoInter.setAddress("http://www.www.ww.gr"); |
|
132 |
// repoInter.setExposedFormats(Arrays.asList("f1", "f2")); |
|
133 |
// repoInter.setExposedSets(Arrays.asList("s1", "s2")); |
|
134 |
// |
|
135 |
// repo.setResourceId(""); |
|
136 |
//// repo.setResourceUri("uri"); |
|
137 |
// |
|
138 |
// repo.setOfficialName("officialName"); |
|
139 |
// repo.setAdminEmail("adminEmail"); |
|
140 |
// repo.setAdministratorContactInfo("administratorContactInfo"); |
|
141 |
// repo.setEnglishName("englishName"); |
|
142 |
// repo.setTypology("Eprints"); |
|
143 |
// repo.setCountry("gr"); |
|
144 |
// repo.setRepositoryInstitution("repositoryInstitution"); |
|
145 |
// repo.setEntryUrl("http://www.a.b.c"); |
|
146 |
// repo.setInterfaces(Arrays.asList(repoInter)); |
|
147 |
// |
|
148 |
// String xml = new RepositoryXmlConverter().ObjectToXml(repo); |
|
149 |
// |
|
150 |
// System.out.println(xml); |
|
151 |
// |
|
152 |
// try { |
|
153 |
// String id = registry.insertProfileForValidation( |
|
154 |
// "RepositoryServiceResourceType", xml); |
|
155 |
// |
|
156 |
// id = registry.validateProfile(id); |
|
157 |
// |
|
158 |
// System.out.println("id: " + id); |
|
159 |
// |
|
160 |
// repo.setResourceId(id); |
|
161 |
// xml = new RepositoryXmlConverter().ObjectToXml(repo); |
|
162 |
// |
|
163 |
// System.out.println(xml); |
|
164 |
// |
|
165 |
// registry.updateProfile(id, xml, "RepositoryServiceResourceType"); |
|
166 |
// |
|
167 |
// } catch (Exception e) { |
|
168 |
// e.printStackTrace(); |
|
169 |
// } |
|
170 |
} |
|
171 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/xml/TestCommunityXmlConverter.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.xml; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
|
|
6 |
import javax.xml.bind.JAXBException; |
|
7 |
|
|
8 |
import org.junit.Test; |
|
9 |
|
|
10 |
import eu.dnetlib.domain.functionality.Community; |
|
11 |
|
|
12 |
public class TestCommunityXmlConverter { |
|
13 |
|
|
14 |
|
|
15 |
@Test |
|
16 |
public void test() throws JAXBException { |
|
17 |
CommunityXmlConverter conv = new CommunityXmlConverter(); |
|
18 |
Community com = new Community(); |
|
19 |
|
|
20 |
com.setName("communityName"); |
|
21 |
com.setResourceId("42"); |
|
22 |
com.setOwner("ownerId"); |
|
23 |
com.setDescription("Looooong descriptioooooon"); |
|
24 |
com.getAuthoritativeDocuments().add("authId1"); |
|
25 |
com.getAuthoritativeDocuments().add("authId2"); |
|
26 |
com.getAuthoritativeDocuments().add("authId3"); |
|
27 |
com.getAuthoritativeDocuments().add("authId4"); |
|
28 |
|
|
29 |
String xml = conv.ObjectToXml(com); |
|
30 |
assertNotNull(xml); |
|
31 |
|
|
32 |
com = conv.XmlToObject(xml); |
|
33 |
|
|
34 |
assertEquals("communityName", com.getName()); |
|
35 |
assertEquals("42", com.getResourceId()); |
|
36 |
assertEquals("ownerId", com.getOwner()); |
|
37 |
assertEquals("Looooong descriptioooooon", com.getDescription()); |
|
38 |
assertNotNull(com.getAuthoritativeDocuments()); |
|
39 |
assertEquals(4, com.getAuthoritativeDocuments().size()); |
|
40 |
} |
|
41 |
|
|
42 |
@Test |
|
43 |
public void testXml() throws JAXBException { |
|
44 |
|
|
45 |
String xml = "<RESOURCE_PROFILE>" + |
|
46 |
"<HEADER>" + |
|
47 |
"<RESOURCE_IDENTIFIER value=\"1-b42e67bf-b0f4-4cd2-b364-3acae398ee0b_Q29tbXVuaXR5RFNSZXNvdXJjZXMvQ29tbXVuaXR5RFNSZXNvdXJjZVR5cGU=\"/>" + |
|
48 |
"<RESOURCE_TYPE value=\"CommunityDSResourceType\"/>" + |
|
49 |
"<RESOURCE_KIND value=\"CommunityDSResources\"/>" + |
|
50 |
"<RESOURCE_URI value=\"http://146.48.87.216:8180/community/services/CommunityService?wsdl\"/>" + |
|
51 |
"<DATE_OF_CREATION value=\"2008-02-15T09:48:11+01:00\"/>" + |
|
52 |
"</HEADER>"+ |
|
53 |
"<BODY>" + |
|
54 |
"<CONFIGURATION>" + |
|
55 |
"<NAME value=\"Computer Science in the UK\"/>"+ |
|
56 |
"<OWNER value=\"26-1fd69d42-a0e7-4c2a-8029-14c24fc05dec_VXNlckRTUmVzb3VyY2VzL1VzZXJEU1Jlc291cmNlVHlwZQ==\"/>"+ |
|
57 |
"<DESCRIPTION value=\"Publications in Computer Science from Repositories in the UK\"/>" + |
|
58 |
"<COLLECTIONS>" + |
|
59 |
"<COLLECTION collection=\"22-8be06951-861f-44ac-9bd1-8a5a47df3c14_Q29sbGVjdGlvbkRTUmVzb3VyY2VzL0NvbGxlY3Rpb25EU1Jlc291cmNlVHlwZQ==\"/>"+ |
|
60 |
"<COLLECTION collection=\"32-46c93e25-f144-4665-bef2-f93856239328_Q29sbGVjdGlvbkRTUmVzb3VyY2VzL0NvbGxlY3Rpb25EU1Jlc291cmNlVHlwZQ==\"/>"+ |
|
61 |
"</COLLECTIONS>" + |
|
62 |
"<MANAGERS/>" + |
|
63 |
"<RECOMMENDATIONS/>" + |
|
64 |
"</CONFIGURATION>" + |
|
65 |
"<STATUS>value</STATUS>" + |
|
66 |
"<SECURITY_PARAMETERS SECURITY_PARAMETER=\"Security Parameters\"/>" + |
|
67 |
"</BODY>" + |
|
68 |
"</RESOURCE_PROFILE>"; |
|
69 |
|
|
70 |
CommunityXmlConverter conv = new CommunityXmlConverter(); |
|
71 |
conv.XmlToObject(xml); |
|
72 |
} |
|
73 |
|
|
74 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/xml/TestVocabularyXmlConverter.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.xml; |
|
2 |
|
|
3 |
import javax.xml.bind.JAXBException; |
|
4 |
|
|
5 |
import org.junit.Assert; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
import eu.dnetlib.domain.enabling.Vocabulary; |
|
9 |
|
|
10 |
public class TestVocabularyXmlConverter { |
|
11 |
|
|
12 |
private String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RESOURCE_PROFILE><HEADER><RESOURCE_IDENTIFIER value=\"aecdb60c-e1ed-40bd-a6c1-edc9993f07cb_Vm9jYWJ1bGFyeURTUmVzb3VyY2VzL1ZvY2FidWxhcnlEU1Jlc291cmNlVHlwZQ==\"/><RESOURCE_TYPE value=\"VocabularyDSResourceType\"/><RESOURCE_KIND value=\"VocabularyDSResources\"/><RESOURCE_URI value=\"\"/><DATE_OF_CREATION value=\"2013-11-18T10:46:37+01:00\"/></HEADER><BODY><CONFIGURATION><VOCABULARY_NAME code=\"dnet:countries\">dnet:countries</VOCABULARY_NAME><VOCABULARY_DESCRIPTION>dnet:countries</VOCABULARY_DESCRIPTION><TERMS><TERM english_name=\"ANDORRA\" native_name=\"ANDORRA\" encoding=\"OPENAIRE\" code=\"AD\"><SYNONYMS/></TERM> <TERM code=\"ZW\" encoding=\"OPENAIRE\" english_name=\"Zimbabwe\" native_name=\"Zimbabwe\"><SYNONYMS/></TERM></TERMS></CONFIGURATION><STATUS><LAST_UPDATE value=\"2013-11-18T10:46:36Z\"/></STATUS><SECURITY_PARAMETERS>String</SECURITY_PARAMETERS></BODY></RESOURCE_PROFILE>"; |
|
13 |
|
|
14 |
@Test |
|
15 |
public void xml2ObjectTest() throws JAXBException{ |
|
16 |
VocabularyXmlConverter vocabularyXmlConverter = new VocabularyXmlConverter(); |
|
17 |
Vocabulary vocabulary = vocabularyXmlConverter.XmlToObject(xml); |
|
18 |
|
|
19 |
Assert.assertNotNull(vocabulary.getEnglishName("ZW")); |
|
20 |
Assert.assertEquals("Zimbabwe", vocabulary.getEnglishName("ZW")); |
|
21 |
|
|
22 |
Assert.assertNotNull(vocabulary.getEncoding("Zimbabwe")); |
|
23 |
Assert.assertEquals("ZW", vocabulary.getEncoding("Zimbabwe")); |
|
24 |
|
|
25 |
} |
|
26 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/xml/TestCollectionXmlConverter.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.xml; |
|
2 |
|
|
3 |
import java.io.ByteArrayInputStream; |
|
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.Date; |
|
7 |
|
|
8 |
import javax.xml.XMLConstants; |
|
9 |
import javax.xml.bind.JAXBException; |
|
10 |
import javax.xml.transform.sax.SAXSource; |
|
11 |
import javax.xml.validation.Schema; |
|
12 |
import javax.xml.validation.SchemaFactory; |
|
13 |
import javax.xml.validation.Validator; |
|
14 |
|
|
15 |
import org.junit.Assert; |
|
16 |
|
|
17 |
import org.junit.Test; |
|
18 |
import org.xml.sax.InputSource; |
|
19 |
import org.xml.sax.SAXException; |
|
20 |
|
|
21 |
import eu.dnetlib.domain.functionality.Collection; |
|
22 |
|
|
23 |
public class TestCollectionXmlConverter { |
|
24 |
|
|
25 |
|
|
26 |
@Test |
|
27 |
public void test() throws SAXException, JAXBException, IOException { |
|
28 |
Schema schema = loadSchema("src/xsd/CollectionDSResourceType.xsd"); |
|
29 |
|
|
30 |
CollectionXmlConverter conv = new CollectionXmlConverter(); |
|
31 |
|
|
32 |
//String xml1 = loadCollectionFromFile("test/junit/gr/uoa/di/driver/xml/collection.xml"); |
|
33 |
|
|
34 |
Collection collection = new Collection(); |
|
35 |
collection.setDescription(java.util.Arrays.asList("description")); |
|
36 |
collection.setName("Collection 1"); |
|
37 |
collection.setSubject("No subject"); |
|
38 |
collection.setDateOfCreation(new Date()); |
|
39 |
collection.setQuery("Query 1"); |
|
40 |
collection.setContainer(true); |
|
41 |
collection.setRetrievalCondition("Condition 1"); |
|
42 |
collection.setFrozen(false); |
|
43 |
|
|
44 |
|
|
45 |
collection.getDocumentsInBasket().add("document1"); |
|
46 |
collection.getDocumentsInBasket().add("document2"); |
|
47 |
|
|
48 |
|
|
49 |
String xml = conv.ObjectToXml(collection); |
|
50 |
System.out.println(xml); |
|
51 |
|
|
52 |
Assert.assertEquals(xml, conv.ObjectToXml(conv.XmlToObject(xml))); |
|
53 |
|
|
54 |
validateXml(schema, xml); |
|
55 |
validateXml(schema,conv.ObjectToXml(conv.XmlToObject(xml))); |
|
56 |
|
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
public static void validateXml(Schema schema, String xml) |
|
64 |
throws SAXException, IOException { |
|
65 |
Validator validator = schema.newValidator(); |
|
66 |
SAXSource source = new SAXSource(new InputSource( |
|
67 |
new ByteArrayInputStream(xml.getBytes()))); |
|
68 |
|
|
69 |
validator.validate(source); |
|
70 |
} |
|
71 |
|
|
72 |
private Schema loadSchema(String name) throws SAXException { |
|
73 |
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI; |
|
74 |
SchemaFactory factory = SchemaFactory.newInstance(language); |
|
75 |
Schema schema = factory.newSchema(new File(name)); |
|
76 |
|
|
77 |
return schema; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/gr/uoa/di/driver/xml/TestUserProfileXmlConverter.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.xml; |
|
2 |
|
|
3 |
import java.io.ByteArrayInputStream; |
|
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.Date; |
|
7 |
|
|
8 |
import javax.xml.XMLConstants; |
|
9 |
import javax.xml.bind.JAXBException; |
|
10 |
import javax.xml.transform.sax.SAXSource; |
|
11 |
import javax.xml.validation.Schema; |
|
12 |
import javax.xml.validation.SchemaFactory; |
|
13 |
import javax.xml.validation.Validator; |
|
14 |
|
|
15 |
import org.junit.Assert; |
|
16 |
|
|
17 |
import org.junit.Test; |
|
18 |
import org.xml.sax.InputSource; |
|
19 |
import org.xml.sax.SAXException; |
|
20 |
|
|
21 |
import eu.dnetlib.domain.functionality.SavedQuery; |
|
22 |
import eu.dnetlib.domain.functionality.UserProfile; |
|
23 |
import eu.dnetlib.domain.functionality.UserStore; |
|
24 |
|
|
25 |
public class TestUserProfileXmlConverter { |
|
26 |
UserProfileXmlConverter conv; |
|
27 |
Schema schema; |
|
28 |
|
|
29 |
@Test |
|
30 |
public void testSimpleUserProfile() throws Exception { |
|
31 |
|
|
32 |
conv = new UserProfileXmlConverter(); |
|
33 |
UserProfile profile = new UserProfile(); |
|
34 |
profile.setEmail("Helenaki"); |
|
35 |
profile.setActivationId("123"); |
|
36 |
profile.setActive(true); |
|
37 |
profile.setDateOfCreation(new Date()); |
|
38 |
|
|
39 |
testConverter(profile); |
|
40 |
conv = null; |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
@Test |
|
47 |
public void testUserProfile() throws Exception { |
|
48 |
|
|
49 |
conv = new UserProfileXmlConverter(); |
|
50 |
UserProfile profile = new UserProfile(); |
|
51 |
profile.setEmail("Helenaki"); |
|
52 |
profile.setActivationId("123"); |
|
53 |
profile.setActive(true); |
|
54 |
profile.setDateOfCreation(new Date()); |
|
55 |
|
|
56 |
profile.setFilter(new SavedQuery()); |
|
57 |
profile.getFilter().setCqlText("cql"); |
|
58 |
|
|
59 |
profile.getFilter().setRefineText("refine"); |
|
60 |
profile.getFilter().getCollectionIds().add("Collection 1"); |
|
61 |
|
|
62 |
profile.getDocumentIds().add("Document 1"); |
|
63 |
profile.getDocumentIds().add("Document 2"); |
|
64 |
|
|
65 |
profile.setUserPhotoID("photoID"); |
|
66 |
profile.setStore(new UserStore()); |
|
67 |
profile.getStore().setStoreID("store ID"); |
|
68 |
profile.getStore().setStoreServiceURL("service URL"); |
|
69 |
|
|
70 |
SavedQuery squery = new SavedQuery(); |
|
71 |
squery.setCqlText("cqlTesxt"); |
|
72 |
squery.getCommunityIds().add("My community1"); |
|
73 |
|
|
74 |
profile.getSavedQueries().add(squery); |
|
75 |
|
|
76 |
testConverter(profile); |
|
77 |
conv = null; |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
private void testConverter(UserProfile userProfile) throws JAXBException, |
|
82 |
SAXException, IOException { |
|
83 |
String xml1 = conv.ObjectToXml(userProfile); |
|
84 |
|
|
85 |
UserProfile user = conv.XmlToObject(xml1); |
|
86 |
|
|
87 |
String xml2 = conv.ObjectToXml(user); |
|
88 |
|
|
89 |
Assert.assertEquals(xml1, xml2); |
|
90 |
System.out.println(xml1 + "\n\n\n"); |
|
91 |
schema = loadSchema("src/xsd/UserDSResourceType.xsd"); |
|
92 |
validateXml(schema, xml1); |
|
93 |
} |
|
94 |
|
|
95 |
public static void validateXml(Schema schema, String xml) |
|
96 |
throws SAXException, IOException { |
|
97 |
Validator validator = schema.newValidator(); |
|
98 |
SAXSource source = new SAXSource(new InputSource( |
|
99 |
new ByteArrayInputStream(xml.getBytes()))); |
|
100 |
|
|
101 |
validator.validate(source); |
|
102 |
} |
|
103 |
|
|
104 |
private Schema loadSchema(String name) throws SAXException { |
|
105 |
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI; |
|
106 |
SchemaFactory factory = SchemaFactory.newInstance(language); |
|
107 |
Schema schema = factory.newSchema(new File(name)); |
|
108 |
|
|
109 |
return schema; |
|
110 |
} |
|
111 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/eu/dnetlib/utils/parser/text.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<result xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:dc="http://purl.org/dc/elements/1.1/" type="result"> |
|
3 |
<field name="resultId" multiplicity="false" indexId="objIdentifier" label="Object id" value="WOS:000277866500014"/> |
|
4 |
<field name="title" indexId="resulttitle" multiplicity="true" label="Title" value="Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population"/> |
|
5 |
<field name="subject" indexId="resultsubject" multiplicity="true" label="Subject(s)" value="Biophysics"/> |
|
6 |
<field name="subject" indexId="resultsubject" multiplicity="true" label="Subject(s)" value="Engineering, Biomedical"/> |
|
7 |
<field name="dateofacceptance" indexId="resultdateofacceptance" multiplicity="true" label="Date of acceptance" value="2010-01-01"/> |
|
8 |
<field name="description" indexId="resultdescription" multiplicity="true" label="Description" value="Responsible for making and maintaining the extracellular matrix, the cells of intervertebral discs are supplied with essential nutrients by diffusion from the blood supply through mainly the cartilaginous endplates (CEPs) and disc tissue. Decrease in transport rate and increase in cellular activity may adversely disturb the intricate supply-demand balance leading ultimately to cell death and disc degeneration. The present numerical study aimed to introduce for the first time cell viability criteria into nonlinear coupled nutrition transport equations thereby evaluating the dynamic nutritional processes governing viable cell population and concentrations of oxygen, glucose and lactic acid in the disc as CEP exchange area dropped from a fully permeable condition to an almost impermeable one. A uniaxial model of an in vitro cell culture analogue of the disc is first employed to examine and validate cell viability criteria. An axisymmetric model of the disc with four distinct regions was subsequently used to investigate the survival of cells at different CEP exchange areas. In agreement with measurements, predictions of the diffusion chamber model demonstrated substantial cell death as essential nutrient concentrations fell to levels too low to support cells. Cells died away from the nutrient supply and at higher cell densities. In the disc model, the nucleus region being farthest away from supply sources was most affected; cell death initiated first as CEP exchange area dropped below similar to 40% and continued exponentially thereafter to depletion as CEP calcified further. In cases with loss of endplate permeability and/or disruptions therein, as well as changes in geometry and fall in diffusivity associated with fluid outflow, the nutrient concentrations could fall to levels inadequate to maintain cellular activity or viability, resulting in cell death and disc degeneration. (C) 2010 Elsevier Ltd. All rights reserved."/> |
|
9 |
<field name="publisher" indexId="resultpublisher" multiplicity="true" label="Publisher(s)" value="ELSEVIER SCI LTD"/> |
|
10 |
<field name="typeclass" indexId="resulttypeclass" multiplicity="true" label="Type class" value="0001"/> |
|
11 |
<field name="language" indexId="resultlanguage" multiplicity="true" label="Language(s)" value="eng"/> |
|
12 |
<field name="rights" indexId="resultrights" multiplicity="true" label="Acces mode" value="Closed Access"/> |
|
13 |
<field name="type" indexId="resulttype" multiplicity="true" label="Type" value="Article"/> |
|
14 |
<field name="booleanValue" indexId="resulttype" multiplicity="true" label="Type" value="wrongvalue"/> |
|
15 |
<field name="compliancy" indexId="resulttype" multiplicity="true" label="Type" value="true"/> |
|
16 |
<field name="odnumberofitemsdate" indexId="datasourceodnumberofitemsdate" multiplicity="true" label="date" value="2012-10-30"/> |
|
17 |
<field name="author" indexId="" multiplicity="true"> |
|
18 |
<field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_A._Shirazi-Adl"/> |
|
19 |
<field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="A. Shirazi-Adl"/> |
|
20 |
</field> |
|
21 |
<field name="author" indexId="" multiplicity="true"> |
|
22 |
<field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_M._Taheri"/> |
|
23 |
<field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="M. Taheri"/> |
|
24 |
</field> |
|
25 |
<field name="author" indexId="" multiplicity="true"> |
|
26 |
<field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_J._P._G._Urban"/> |
|
27 |
<field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="J. P. G. Urban"/> |
|
28 |
</field> |
|
29 |
<field name="project" indexId="" multiplicity="true"> |
|
30 |
<field name="project id" indexId="relprojectid" multiplicity="false" label="Project id" value="ec::201626"/> |
|
31 |
<field name="projectname" indexId="relprojectname" multiplicity="false" label="Project(s)" value="GENODISC"/> |
|
32 |
<field name="projectdescription" indexId="relprojectdescription" multiplicity="false" label="Project description" value="Disc-degeneration linked pathologies: novel biomarkers and diagnostics for targeting treatment and repair"/> |
|
33 |
<field name="projectcontracttypeclass" indexId="???" multiplicity="false" label="Project contract type class" value="CP"/> |
|
34 |
<field name="projectcontracttypescheme" indexId="???" multiplicity="false" label="Project contract type scheme" value="ec:FP7contractTypes"/> |
|
35 |
</field> |
|
36 |
<field name="project" indexId="" multiplicity="true"> |
|
37 |
<field name="project id" indexId="objIdentifier" multiplicity="false" label="Project id" value="ec::216444"/> |
|
38 |
<field name="projectcode" indexId="projectcode" multiplicity="false" label="Project(s)" value="216444"/> |
|
39 |
<field name="projectacronym" indexId="projectacronym" multiplicity="false" label="Project(s)" value="PETAMEDIA"/> |
|
40 |
<field name="projecttitle" indexId="projecttitle" multiplicity="false" label="Project title" value="PEer-to-peer TAgged MEDIA"/> |
|
41 |
<field name="projectcontracttypeid" indexId="projectcontracttypeid" multiplicity="false" label="Project contract type id" value="NoE"/> |
|
42 |
<field name="projectcontracttypename" indexId="projectcontracttypename" multiplicity="false" label="Project contract type name" value="Network of Excellence"/> |
|
43 |
</field> |
|
44 |
<field name="repository" indexId="" multiplicity="true"> |
|
45 |
<field name="instanceId" indexId="" multiplicity="false" value="WOS:000277866500014"/> |
|
46 |
<field name="datasource" indexId="" multiplicity="true"> |
|
47 |
<field name="hostedby" indexId="resulthostingdatasourceid" multiplicity="false" value="openaire"/> |
|
48 |
<field name="collectedfrom" indexId="resultcollectedfromdatasourceid" multiplicity="false" value=""/> |
|
49 |
</field> |
|
50 |
<field name="identifier" indexId="resultidentifier" multiplicity="true" value="http://dx.doi.org/10.1016/j.jbiomech.2010.01.023"/> |
|
51 |
</field> |
|
52 |
</result> |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/test/java/eu/dnetlib/utils/parser/ParserTest.java | ||
---|---|---|
1 |
package eu.dnetlib.utils.parser; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
import static org.junit.Assert.assertNull; |
|
6 |
|
|
7 |
import javax.xml.xpath.XPathExpressionException; |
|
8 |
|
|
9 |
import org.junit.Before; |
|
10 |
import org.junit.Test; |
|
11 |
|
|
12 |
|
|
13 |
public class ParserTest { |
|
14 |
|
|
15 |
private String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" type=\"result\"> <field name=\"resultId\" multiplicity=\"false\" indexId=\"objIdentifier\" label=\"Object id\" value=\"WOS:000277866500014\"/> <field name=\"title\" indexId=\"resulttitle\" multiplicity=\"true\" label=\"Title\" value=\"Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population\"/> <field name=\"subject\" indexId=\"resultsubject\" multiplicity=\"true\" label=\"Subject(s)\" value=\"Biophysics\"/> <field name=\"subject\" indexId=\"resultsubject\" multiplicity=\"true\" label=\"Subject(s)\" value=\"Engineering, Biomedical\"/> <field name=\"dateofacceptance\" indexId=\"resultdateofacceptance\" multiplicity=\"true\" label=\"Date of acceptance\" value=\"2010-01-01\"/> <field name=\"description\" indexId=\"resultdescription\" multiplicity=\"true\" label=\"Description\" value=\"Responsible for making and maintaining the extracellular matrix, the cells of intervertebral discs are supplied with essential nutrients by diffusion from the blood supply through mainly the cartilaginous endplates (CEPs) and disc tissue. Decrease in transport rate and increase in cellular activity may adversely disturb the intricate supply-demand balance leading ultimately to cell death and disc degeneration. The present numerical study aimed to introduce for the first time cell viability criteria into nonlinear coupled nutrition transport equations thereby evaluating the dynamic nutritional processes governing viable cell population and concentrations of oxygen, glucose and lactic acid in the disc as CEP exchange area dropped from a fully permeable condition to an almost impermeable one. A uniaxial model of an in vitro cell culture analogue of the disc is first employed to examine and validate cell viability criteria. An axisymmetric model of the disc with four distinct regions was subsequently used to investigate the survival of cells at different CEP exchange areas. In agreement with measurements, predictions of the diffusion chamber model demonstrated substantial cell death as essential nutrient concentrations fell to levels too low to support cells. Cells died away from the nutrient supply and at higher cell densities. In the disc model, the nucleus region being farthest away from supply sources was most affected; cell death initiated first as CEP exchange area dropped below similar to 40% and continued exponentially thereafter to depletion as CEP calcified further. In cases with loss of endplate permeability and/or disruptions therein, as well as changes in geometry and fall in diffusivity associated with fluid outflow, the nutrient concentrations could fall to levels inadequate to maintain cellular activity or viability, resulting in cell death and disc degeneration. (C) 2010 Elsevier Ltd. All rights reserved.\"/> <field name=\"publisher\" indexId=\"resultpublisher\" multiplicity=\"true\" label=\"Publisher(s)\" value=\"ELSEVIER SCI LTD\"/> <field name=\"typeclass\" indexId=\"resulttypeclass\" multiplicity=\"true\" label=\"Type class\" value=\"0001\"/> <field name=\"language\" indexId=\"resultlanguage\" multiplicity=\"true\" label=\"Language(s)\" value=\"eng\"/> <field name=\"rights\" indexId=\"resultrights\" multiplicity=\"true\" label=\"Acces mode\" value=\"Closed Access\"/> <field name=\"type\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"Article\"/> " + |
|
16 |
"<field name=\"author\" indexId=\"\" multiplicity=\"true\" value=\"WOS:000277866500014_A._Shirazi-Adl\">" + |
|
17 |
" <field name=\"personId\" indexId=\"relpersonid\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000277866500014_A._Shirazi-Adl\"/>" + |
|
18 |
" <field name=\"fullname\" indexId=\"relperson\" multiplicity=\"false\" label=\"Person fullname\" value=\"A. Shirazi-Adl\"/> " + |
|
19 |
" </field> " + |
|
20 |
"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Yuriy_I._Prostov\">" + |
|
21 |
"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Yuriy_I._Prostov\"/>" + |
|
22 |
"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" + |
|
23 |
"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Prostov, Yuriy I.\"/>" + |
|
24 |
"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"3\"/>" + |
|
25 |
"</field>" + |
|
26 |
"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Duc-Truong_Pham\">" + |
|
27 |
"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Duc-Truong_Pham\"/>" + |
|
28 |
"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" + |
|
29 |
"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Pham, Duc-Truong\"/>" + |
|
30 |
"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"1\"/>" + |
|
31 |
"</field>" + |
|
32 |
"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Maria_M._Suarez-Alvarez\">" + |
|
33 |
"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Maria_M._Suarez-Alvarez\"/>" + |
|
34 |
"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" + |
|
35 |
"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Suarez-Alvarez, Maria M.\"/>" + |
|
36 |
"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"2\"/>"+ |
|
37 |
"</field>" + |
|
38 |
"<field name=\"project\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"ec::216444\">" + |
|
39 |
"<field name=\"projectid\" indexId=\"relprojectid\" multiplicity=\"false\" label=\"Project id\" value=\"ec::201626\"/> " + |
|
40 |
"<field name=\"projectname\" indexId=\"relprojectname\" multiplicity=\"false\" label=\"Project(s)\" value=\"GENODISC\"/> " + |
|
41 |
"<field name=\"projectdescription\" indexId=\"relprojectdescription\" multiplicity=\"false\" label=\"Project description\" value=\"Disc-degeneration linked pathologies: novel biomarkers and diagnostics for targeting treatment and repair\"/> " + |
|
42 |
"<field name=\"projectcontracttypeclass\" indexId=\"???\" multiplicity=\"false\" label=\"Project contract type class\" value=\"CP\"/> " + |
|
43 |
"<field name=\"projectcontracttypescheme\" indexId=\"???\" multiplicity=\"false\" label=\"Project contract type scheme\" value=\"ec:FP7contractTypes\"/> " + |
|
44 |
"</field> " + |
|
45 |
"<field name=\"project\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"ec::224853\">" + |
|
46 |
"<field name=\"projectid\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Project id\" value=\"ec::216444\"/>" + |
|
47 |
"<field name=\"projectcode\" indexId=\"projectcode\" multiplicity=\"false\" label=\"Project(s)\" value=\"216444\"/>" + |
|
48 |
"<field name=\"projectacronym\" indexId=\"projectacronym\" multiplicity=\"false\" label=\"Project(s)\" value=\"PETAMEDIA\"/>" + |
|
49 |
"<field name=\"projecttitle\" indexId=\"projecttitle\" multiplicity=\"false\" label=\"Project title\" value=\"PEer-to-peer TAgged MEDIA\"/>" + |
|
50 |
"<field name=\"projectcontracttypeid\" indexId=\"projectcontracttypeid\" multiplicity=\"false\" label=\"Project contract type id\" value=\"NoE\"/>" + |
|
51 |
"<field name=\"projectcontracttypename\" indexId=\"projectcontracttypename\" multiplicity=\"false\" label=\"Project contract type name\" value=\"Network of Excellence\"/>" + |
|
52 |
"</field>" + |
|
53 |
|
|
54 |
"<field name=\"repository\" indexId=\"\" multiplicity=\"true\"> " + |
|
55 |
"<field name=\"instanceId\" indexId=\"\" multiplicity=\"false\" value=\"WOS:000277866500014\"/> " + |
|
56 |
"<field name=\"datasource\" indexId=\"\" multiplicity=\"true\"> " + |
|
57 |
"<field name=\"hostedby\" indexId=\"resulthostingdatasourceid\" multiplicity=\"false\" value=\"\"/> " + |
|
58 |
"<field name=\"collectedfrom\" indexId=\"resultcollectedfromdatasourceid\" multiplicity=\"false\" value=\"openaire\"/> " + |
|
59 |
"</field> " + |
|
60 |
"<field name=\"identifier\" indexId=\"resultidentifier\" multiplicity=\"true\" value=\"http://dx.doi.org/10.1016/j.jbiomech.2010.01.023\"/> " + |
|
61 |
"</field>" + |
|
62 |
|
|
63 |
"<field name=\"booleanValue\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"wrongvalue\"/>" + |
|
64 |
"<field name=\"compliancy\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"true\"/>" + |
|
65 |
"<field name=\"odnumberofitemsdate\" indexId=\"datasourceodnumberofitemsdate\" multiplicity=\"true\" label=\"date\" value=\"2012-10-30\"/>" + |
|
66 |
"<field name=\"odnumberofitems\" indexId=\"datasourceodnumberofitems\" multiplicity=\"true\" label=\"number of items\" value=\"9767\"/>" + |
|
67 |
"<field name=\"numberofitems\" indexId=\"datasourceodnumberofitems\" multiplicity=\"true\" label=\"number of items\" value=\"\"/>" + |
|
68 |
"</result>"; |
|
69 |
|
|
70 |
private Parser parser = null; |
|
71 |
|
|
72 |
@Before |
|
73 |
public void setup() { |
|
74 |
parser = new Parser(xml); |
|
75 |
} |
|
76 |
|
|
77 |
@Test |
|
78 |
public void getValuesTest() throws XPathExpressionException{ |
|
79 |
//String existing |
|
80 |
assertNotNull(parser.getValues("author.fullname")); |
|
81 |
assertEquals(4, parser.getValues("author.fullname").length); |
|
82 |
assertEquals("Prostov, Yuriy I.", parser.getValues("author.fullname")[1]); |
|
83 |
|
|
84 |
//String existing |
|
85 |
assertNotNull(parser.getValues("resultId")); |
|
86 |
assertEquals(1, parser.getValues("resultId").length); |
|
87 |
assertEquals("WOS:000277866500014", parser.getValue("resultId")); |
|
88 |
|
|
89 |
//String not existing |
|
90 |
assertNull(parser.getValue("foo")); |
|
91 |
assertNull(parser.getValues("foo")); |
|
92 |
|
|
93 |
assertEquals("openaire",parser.getValue("repository.datasource.collectedfrom")); |
|
94 |
assertNull(parser.getValue("repository.foo.collectedfrom")); |
|
95 |
|
|
96 |
//String existing - wrong request |
|
97 |
assertNull(parser.getValue("project", new String[]{"ec::216444"})); |
|
98 |
|
|
99 |
//String existing - right request |
|
100 |
assertEquals("PETAMEDIA", parser.getValue("project.projectacronym", new String[]{"ec::224853"})); |
|
101 |
|
|
102 |
//String existing - right request |
|
103 |
assertEquals("PETAMEDIA", parser.getValue("project.projectacronym",new String[]{"ec::224853"})); |
|
104 |
|
|
105 |
//String not existing - right request |
|
106 |
assertNull(parser.getValue("project.projectname", new String[]{"ec::224853"})); |
|
107 |
|
|
108 |
//Boolean check |
|
109 |
assertNotNull(parser.getBoolean("booleanValue")); |
|
110 |
assertEquals(Boolean.FALSE, parser.getBoolean("booleanValue")); |
|
111 |
|
|
112 |
assertNotNull(parser.getBoolean("compliancy")); |
|
113 |
assertEquals(Boolean.TRUE, parser.getBoolean("compliancy")); |
|
114 |
|
|
115 |
assertNull(parser.getBoolean("notexisting")); |
|
116 |
|
|
117 |
//Date check |
|
118 |
assertNull(parser.getDate("notexisting","wrong-format")); |
|
119 |
assertNull(parser.getDate("odnumberofitemsdate","wrong-format")); |
|
120 |
|
|
121 |
assertNotNull(parser.getDate("odnumberofitemsdate","yyyy-mm-dd")); |
|
122 |
|
|
123 |
//Integer check |
|
124 |
assertNull(parser.getInteger("repository.datasource.collectedfrom")); |
|
125 |
assertNotNull(parser.getInteger("odnumberofitems")); |
|
126 |
|
|
127 |
assertEquals(parser.getInteger("odnumberofitems"), new Integer(9767)); |
|
128 |
assertNull(parser.getInteger("numberofitems")); |
|
129 |
|
|
130 |
for (String name :parser.getValues("author")) { |
|
131 |
System.out.println(parser.getValue("author.fullname", new String[]{name})); |
|
132 |
} |
|
133 |
} |
|
134 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/dao/GenericDAO.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.dao; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import eu.dnetlib.domain.SearchCriteria; |
|
6 |
|
|
7 |
|
|
8 |
/** |
|
9 |
* A class used to access a data source and perform basic actions. |
|
10 |
* @author antleb@di.uoa.gr |
|
11 |
* |
|
12 |
* @param <T> The type of elements managed by this dao. |
|
13 |
*/ |
|
14 |
public interface GenericDAO<T> { |
|
15 |
|
|
16 |
/** |
|
17 |
* Returns the element with the given id. |
|
18 |
* @param id The element's id. |
|
19 |
* @return the element with the given id. |
|
20 |
* @throws DAOException |
|
21 |
*/ |
|
22 |
T getById(String id) throws DAOException; |
|
23 |
|
|
24 |
/** |
|
25 |
* Saves the given element. |
|
26 |
* @param entity The element to save. |
|
27 |
* @return The same element with its id changed |
|
28 |
* @throws DAOException |
|
29 |
*/ |
|
30 |
T save(T entity) throws DAOException; |
|
31 |
|
|
32 |
/** |
|
33 |
* Deletes the given element. |
|
34 |
* @param entity The element to delete. |
|
35 |
* @throws DAOException |
|
36 |
*/ |
|
37 |
void delete(T entity) throws DAOException; |
|
38 |
|
|
39 |
/** |
|
40 |
* Returns all elements. |
|
41 |
* @return A ResultSetIterator with all of the elements. |
|
42 |
* @throws DAOException |
|
43 |
*/ |
|
44 |
List<T> getAll() throws DAOException; |
|
45 |
|
|
46 |
/** |
|
47 |
* Returns all elements that comply with the restrictions described by the criteria |
|
48 |
* object. |
|
49 |
* @param criteria The searh criteria. |
|
50 |
* @return A ResultSetIterator with the results of the query. |
|
51 |
* @throws DAOException |
|
52 |
*/ |
|
53 |
public List<T> search(SearchCriteria criteria) throws DAOException; |
|
54 |
|
|
55 |
/** |
|
56 |
* Performs a search and returns the unique result. Throws a DAOException if |
|
57 |
* there were more than one results. |
|
58 |
* @param criteria the search criteria; |
|
59 |
* @return the unique result of this query. |
|
60 |
* @throws DAOException If there was a problem in the search or there were |
|
61 |
* more than one results in the query. |
|
62 |
*/ |
|
63 |
public T getUniqueResult(SearchCriteria criteria) throws DAOException; |
|
64 |
|
|
65 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/dao/DAOException.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.dao; |
|
2 |
|
|
3 |
public class DAOException extends Exception { |
|
4 |
private static final long serialVersionUID = -2561665485195003136L; |
|
5 |
|
|
6 |
public DAOException() { |
|
7 |
super(); |
|
8 |
} |
|
9 |
|
|
10 |
public DAOException(Throwable cause) { |
|
11 |
super(cause); |
|
12 |
} |
|
13 |
|
|
14 |
public DAOException(String message, Throwable cause) { |
|
15 |
super(message, cause); |
|
16 |
} |
|
17 |
|
|
18 |
public DAOException(String message) { |
|
19 |
super(message); |
|
20 |
} |
|
21 |
|
|
22 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/dao/GenericISDao.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.dao; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
|
|
7 |
import eu.dnetlib.domain.DriverResource; |
|
8 |
import eu.dnetlib.domain.SearchCriteria; |
|
9 |
import gr.uoa.di.driver.enabling.ISLookUp; |
|
10 |
import gr.uoa.di.driver.enabling.ISLookUpException; |
|
11 |
import gr.uoa.di.driver.enabling.ISRegistry; |
|
12 |
import gr.uoa.di.driver.enabling.ISRegistryException; |
|
13 |
|
|
14 |
public class GenericISDao<D extends DriverResource> implements GenericDAO<D> { |
|
15 |
private static Logger loggger = Logger.getLogger(GenericISDao.class); |
|
16 |
|
|
17 |
protected ISLookUp<D> lookUp = null; |
|
18 |
protected ISRegistry<D> registry = null; |
|
19 |
|
|
20 |
public void setLookUp(ISLookUp<D> lookUp) { |
|
21 |
this.lookUp = lookUp; |
|
22 |
} |
|
23 |
|
|
24 |
public void setRegistry(ISRegistry<D> registry) { |
|
25 |
this.registry = registry; |
|
26 |
} |
|
27 |
|
|
28 |
public D getById(String id) throws DAOException { |
|
29 |
try { |
|
30 |
return lookUp.getById(id); |
|
31 |
} catch (ISLookUpException ile) { |
|
32 |
throw new DAOException("Error getting object", ile); |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
public D save(D entity) throws DAOException { |
|
37 |
D object = null; |
|
38 |
|
|
39 |
try { |
|
40 |
object = registry.save(entity); |
|
41 |
} catch (ISRegistryException e) { |
|
42 |
throw new DAOException("Error saving profile", e); |
|
43 |
} |
|
44 |
|
|
45 |
return object; |
|
46 |
} |
|
47 |
|
|
48 |
public void delete(D entity) throws DAOException { |
|
49 |
try { |
|
50 |
this.registry.delete(entity); |
|
51 |
} catch (ISRegistryException ire) { |
|
52 |
throw new DAOException("Error deleting object", ire); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
public List<D> getAll() throws DAOException { |
|
57 |
try { |
|
58 |
return lookUp.fetch( (SearchCriteria) null); |
|
59 |
} catch (ISLookUpException e) { |
|
60 |
throw new DAOException(e); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
public List<D> search(SearchCriteria criteria) throws DAOException { |
|
65 |
try { |
|
66 |
loggger.debug("Performing search"); |
|
67 |
|
|
68 |
return lookUp.fetch(criteria); |
|
69 |
} catch (ISLookUpException e) { |
|
70 |
loggger.error(e); |
|
71 |
throw new DAOException(e); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
public D getUniqueResult(SearchCriteria criteria) throws DAOException { |
|
76 |
List<D> results = null; |
|
77 |
|
|
78 |
try { |
|
79 |
results = lookUp.performQuickSearch(criteria); |
|
80 |
} catch (ISLookUpException e) { |
|
81 |
throw new DAOException("Error searching", e); |
|
82 |
} |
|
83 |
|
|
84 |
if (results.size() == 0) |
|
85 |
return null; |
|
86 |
else if (results.size() == 1) |
|
87 |
return results.get(0); |
|
88 |
else |
|
89 |
throw new DAOException("More than one results in query."); |
|
90 |
} |
|
91 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/dao/SecurityProfileDao.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.enabling.SecurityProfile; |
|
4 |
|
|
5 |
public interface SecurityProfileDao extends GenericDAO<SecurityProfile> { |
|
6 |
|
|
7 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/data/browsedata/BrowseDataUtil.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.data.browsedata; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.data.BrowseData; |
|
4 |
import org.apache.log4j.Logger; |
|
5 |
import org.w3c.dom.Node; |
|
6 |
import org.w3c.dom.NodeList; |
|
7 |
import org.xml.sax.InputSource; |
|
8 |
|
|
9 |
import javax.xml.xpath.*; |
|
10 |
import java.io.StringReader; |
|
11 |
|
|
12 |
public class BrowseDataUtil { |
|
13 |
|
|
14 |
static XPathExpression FIELD_EXPR = null; |
|
15 |
static XPathExpression VALUE_EXPR = null; |
|
16 |
static XPathExpression COUNT_EXPR = null; |
|
17 |
static XPathExpression GROUP_RESULT_EXPR = null; |
|
18 |
|
|
19 |
static { |
|
20 |
XPathFactory factory = XPathFactory.newInstance(); |
|
21 |
XPath xpath = factory.newXPath(); |
|
22 |
//xpath.setNamespaceContext(new RSClientNSContext()); |
|
23 |
|
|
24 |
try { |
|
25 |
FIELD_EXPR = xpath.compile("//groupresult/@field"); |
|
26 |
VALUE_EXPR = xpath.compile("//value"); |
|
27 |
COUNT_EXPR = xpath.compile("//count"); |
|
28 |
GROUP_RESULT_EXPR = xpath.compile("//groupresult"); |
|
29 |
|
|
30 |
} catch (XPathExpressionException e) { |
|
31 |
throw new RuntimeException("Failed to build xpath expression.", e); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
static Logger logger = Logger.getLogger(BrowseDataUtil.class); |
|
36 |
|
|
37 |
|
|
38 |
private static InputSource source(String message) { |
|
39 |
return new InputSource(new StringReader(message)); |
|
40 |
} |
|
41 |
|
|
42 |
private static String parseString(String record, XPathExpression expr) { |
|
43 |
String result = null; |
|
44 |
try { |
|
45 |
result = (String) expr.evaluate( |
|
46 |
source(record), XPathConstants.STRING); |
|
47 |
|
|
48 |
} catch (XPathExpressionException xpee) { |
|
49 |
logger.error("Cannot parse record " |
|
50 |
+ record.replaceAll("\n", " "), xpee); |
|
51 |
} |
|
52 |
return result; |
|
53 |
} |
|
54 |
|
|
55 |
public static BrowseData parseRows(String record) { |
|
56 |
logger.debug("Record " + record); |
|
57 |
|
|
58 |
// record = record.replaceAll("\t",""); |
|
59 |
record = record.replaceAll("\n",""); |
|
60 |
|
|
61 |
// logger.debug("Record new " + record); |
|
62 |
//record = record.replaceAll(" ",""); |
|
63 |
|
|
64 |
BrowseData bd = new BrowseData(); |
|
65 |
|
|
66 |
try { |
|
67 |
NodeList nodes = (NodeList) GROUP_RESULT_EXPR.evaluate(source(record), XPathConstants.NODESET); |
|
68 |
|
|
69 |
for (int i = 0; i < nodes.getLength(); i++) { |
|
70 |
Node node = nodes.item(i); |
|
71 |
String field = node.getAttributes().getNamedItem("field").getTextContent(); |
|
72 |
|
|
73 |
int count = 0; |
|
74 |
String value = null; |
|
75 |
|
|
76 |
for (int j = 0; j < node.getChildNodes().getLength(); j++) { |
|
77 |
Node child = node.getChildNodes().item(j); |
|
78 |
if (child.getNodeType() != 3) { |
|
79 |
if (child.getLocalName().toLowerCase().equals("count")) |
|
80 |
count = Integer.parseInt(child.getTextContent()); |
|
81 |
else if (child.getLocalName().toLowerCase().equals("value")) |
|
82 |
value = child.getTextContent(); |
|
83 |
} |
|
84 |
} |
|
85 |
bd.addFieldEntry(field, value, count); |
|
86 |
} |
|
87 |
} catch (XPathExpressionException e) { |
|
88 |
logger.warn("Error parsing index row.", e); |
|
89 |
} |
|
90 |
|
|
91 |
return bd; |
|
92 |
} |
|
93 |
|
|
94 |
public static String parseField(String record) { |
|
95 |
return parseString(record, FIELD_EXPR); |
|
96 |
} |
|
97 |
|
|
98 |
public static String parseValue(String record) { |
|
99 |
return parseString(record, VALUE_EXPR); |
|
100 |
} |
|
101 |
|
|
102 |
public static int parseCount(String record) { |
|
103 |
String text = parseString(record, COUNT_EXPR); |
|
104 |
int count = 0; |
|
105 |
try { |
|
106 |
count = Integer.parseInt(text); |
|
107 |
} catch (NumberFormatException nfe) { |
|
108 |
logger.error("Expected number in count, but found: " + text, nfe); |
|
109 |
} |
|
110 |
return count; |
|
111 |
} |
|
112 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/util/RefreshingServiceLocator.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.util; |
|
2 |
|
|
3 |
import java.util.concurrent.ScheduledExecutorService; |
|
4 |
import java.util.concurrent.TimeUnit; |
|
5 |
|
|
6 |
import org.apache.log4j.Logger; |
|
7 |
|
|
8 |
import eu.dnetlib.api.DriverService; |
|
9 |
|
|
10 |
/** |
|
11 |
* An implementation of the service locator that keeps a cache of the service |
|
12 |
* and refreshes it periodically. |
|
13 |
* |
|
14 |
* The actual task of service discovery is performed by a locator that is |
|
15 |
* injected. |
|
16 |
* |
|
17 |
* @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a> |
|
18 |
* |
|
19 |
* @param <S> the service type |
|
20 |
*/ |
|
21 |
public class RefreshingServiceLocator<S extends DriverService> implements |
|
22 |
ServiceLocator<S> { |
|
23 |
/** The locator used to discover the service */ |
|
24 |
private ServiceLocator<S> locator = null; |
|
25 |
/** the cached instance of the service */ |
|
26 |
private S service = null; |
|
27 |
/** the executor that runs the refresh tasks */ |
|
28 |
private ScheduledExecutorService executor = null; |
|
29 |
/** the discovery period in milliseconds*/ |
|
30 |
private long period = 0; |
|
31 |
|
|
32 |
@Override |
|
33 |
public synchronized S getService() { |
|
34 |
if (service == null) |
|
35 |
init(); |
|
36 |
|
|
37 |
return service; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Called to initialize the locator. Performs the first service lookup and |
|
42 |
* also schedules the periodic refresh of the cache. |
|
43 |
* |
|
44 |
* */ |
|
45 |
private void init() { |
|
46 |
this.service = locator.getService(); |
|
47 |
|
|
48 |
executor.scheduleWithFixedDelay(new RefreshTask(), period, period, |
|
49 |
TimeUnit.MILLISECONDS); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* A very simple runnable that refreshed the cache. No synchronization is |
|
54 |
* needed during cache refresh: The old instance will be returned while the |
|
55 |
* locator is working to refresh the cache. |
|
56 |
* |
|
57 |
* @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a> |
|
58 |
* |
|
59 |
*/ |
|
60 |
private class RefreshTask implements Runnable { |
|
61 |
private Logger logger = Logger.getLogger(RefreshTask.class); |
|
62 |
|
|
63 |
@Override |
|
64 |
public void run() { |
|
65 |
try { |
|
66 |
logger.debug("Refreshing service cache"); |
|
67 |
service = locator.getService(); |
|
68 |
} catch (Exception e) { |
|
69 |
logger.info("Error refreshing service", e); |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
public ServiceLocator<S> getLocator() { |
|
75 |
return locator; |
|
76 |
} |
|
77 |
|
|
78 |
public void setLocator(ServiceLocator<S> locator) { |
|
79 |
this.locator = locator; |
|
80 |
} |
|
81 |
|
|
82 |
public ScheduledExecutorService getExecutor() { |
|
83 |
return executor; |
|
84 |
} |
|
85 |
|
|
86 |
public void setExecutor(ScheduledExecutorService executor) { |
|
87 |
this.executor = executor; |
|
88 |
} |
|
89 |
|
|
90 |
public long getPeriod() { |
|
91 |
return period; |
|
92 |
} |
|
93 |
|
|
94 |
public void setPeriod(long period) { |
|
95 |
this.period = period; |
|
96 |
} |
|
97 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/util/FallBackServiceLocator.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.util; |
|
2 |
|
|
3 |
import eu.dnetlib.api.DriverService; |
|
4 |
|
|
5 |
public class FallBackServiceLocator<S extends DriverService> |
|
6 |
implements ServiceLocator<S> { |
|
7 |
|
|
8 |
private ServiceLocator<S> mainLocator = null; |
|
9 |
private ServiceLocator<S> fallBackLocator = null; |
|
10 |
|
|
11 |
@Override |
|
12 |
public S getService() { |
|
13 |
S service = null; |
|
14 |
|
|
15 |
if (mainLocator != null) |
|
16 |
service = mainLocator.getService(); |
|
17 |
|
|
18 |
if (service == null && fallBackLocator != null) |
|
19 |
service = fallBackLocator.getService(); |
|
20 |
|
|
21 |
return service; |
|
22 |
} |
|
23 |
|
|
24 |
public FallBackServiceLocator(ServiceLocator<S> mainLocator, |
|
25 |
ServiceLocator<S> fallBackLocator) { |
|
26 |
this.mainLocator = mainLocator; |
|
27 |
this.fallBackLocator = fallBackLocator; |
|
28 |
} |
|
29 |
|
|
30 |
public void setMainLocator(ServiceLocator<S> mainLocator) { |
|
31 |
this.mainLocator = mainLocator; |
|
32 |
} |
|
33 |
|
|
34 |
public void setFallBackLocator(ServiceLocator<S> fallBackLocator) { |
|
35 |
this.fallBackLocator = fallBackLocator; |
|
36 |
} |
|
37 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/util/ServiceLocator.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.util; |
|
2 |
|
|
3 |
import eu.dnetlib.api.DriverService; |
|
4 |
|
|
5 |
public interface ServiceLocator<S extends DriverService> { |
|
6 |
|
|
7 |
public S getService(); |
|
8 |
} |
Also available in: Unified diff
Removing wrongly released module