Revision 48242
Added by Katerina Iatropoulou over 6 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/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/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/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/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/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/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/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/main/java/gr/uoa/di/driver/enabling/ISSubscription.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling; |
|
2 |
|
|
3 |
import eu.dnetlib.domain.enabling.Subscription; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* A thin client to the IS_SN service |
|
8 |
* @author christos |
|
9 |
* |
|
10 |
*/ |
|
11 |
public interface ISSubscription { |
|
12 |
/** |
|
13 |
* |
|
14 |
* @param subscription |
|
15 |
* @return the subscription's id |
|
16 |
* @throws SubscriptionException |
|
17 |
*/ |
|
18 |
public String subscribe(Subscription subscription) throws SubscriptionException; |
|
19 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
* @param subscriptionId |
|
23 |
* @param time |
|
24 |
*/ |
|
25 |
public void renewSubscription(String subscriptionId, int time); |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @param subscriptionId |
|
30 |
*/ |
|
31 |
public void pauseNotifications(String subscriptionId); |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @param subscriptionId |
|
36 |
*/ |
|
37 |
public void resumeNotification(String subscriptionId); |
|
38 |
|
|
39 |
/** |
|
40 |
* |
|
41 |
* @param subscriptionId |
|
42 |
*/ |
|
43 |
public void removeSubscription(String subscriptionId); |
|
44 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/enabling/a2/A2Wrapper.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling.a2; |
|
2 |
|
|
3 |
import eu.dnetlib.api.enabling.A2ServiceException; |
|
4 |
|
|
5 |
|
|
6 |
public interface A2Wrapper { |
|
7 |
|
|
8 |
/** |
|
9 |
* Authenticates a DRIVER user. |
|
10 |
* |
|
11 |
* @param email |
|
12 |
* @param password |
|
13 |
* @return The security context id of the user or null if the authentication |
|
14 |
* fails |
|
15 |
* @throws A2ServiceException |
|
16 |
*/ |
|
17 |
public String authenticateUser(String email, String password) throws A2ServiceException; |
|
18 |
|
|
19 |
/** |
|
20 |
* Authenticates a DRIVER service |
|
21 |
* |
|
22 |
* @param certificate |
|
23 |
* @return The security context id of the service or null if the authentication |
|
24 |
* fails |
|
25 |
* |
|
26 |
* @throws A2ServiceException |
|
27 |
*/ |
|
28 |
public String authenticateService(String certificate) throws A2ServiceException; |
|
29 |
|
|
30 |
/** |
|
31 |
* Requests authorization for a given action. Resources and actions are defined in the |
|
32 |
* security policies that must have been to AAS prior to these call |
|
33 |
* |
|
34 |
* @param resource |
|
35 |
* @param action |
|
36 |
* @param contextId |
|
37 |
* @return true if the action is authorized, false otherwise. |
|
38 |
* @throws A2ServiceException |
|
39 |
*/ |
|
40 |
public boolean authorizeAction(String resource, String action, String contextId) throws A2ServiceException; |
|
41 |
|
|
42 |
/** |
|
43 |
* Invalidates the given security context. |
|
44 |
* |
|
45 |
* @param contextId the id of the context to invalidate. |
|
46 |
*/ |
|
47 |
public void invalidate(String contextId); |
|
48 |
|
|
49 |
/** |
|
50 |
* Chains 2 security contexts. |
|
51 |
* @param contextIdA |
|
52 |
* @param contextIdB |
|
53 |
* @return the security context chain |
|
54 |
*/ |
|
55 |
public String createSecurityContextChain(String contextIdA, String contextIdB); |
|
56 |
|
|
57 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/enabling/a2/AASExecutor.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling.a2; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.List; |
|
6 |
import java.util.concurrent.Callable; |
|
7 |
import java.util.concurrent.ExecutionException; |
|
8 |
import java.util.concurrent.Future; |
|
9 |
import java.util.concurrent.ScheduledExecutorService; |
|
10 |
import java.util.concurrent.ScheduledFuture; |
|
11 |
import java.util.concurrent.TimeUnit; |
|
12 |
import java.util.concurrent.TimeoutException; |
|
13 |
|
|
14 |
/** |
|
15 |
* An implementation of the ScheduledExecutorService that takes care of |
|
16 |
* preserving the value of a ThreadLocal variable in each tasks thread. |
|
17 |
* |
|
18 |
* @author antleb |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class AASExecutor implements ScheduledExecutorService { |
|
22 |
private ThreadLocal<String> callerSecurityContext = null; |
|
23 |
private ScheduledExecutorService executorService = null; |
|
24 |
|
|
25 |
@Override |
|
26 |
public ScheduledFuture<?> schedule(Runnable command, long delay, |
|
27 |
TimeUnit unit) { |
|
28 |
return executorService.schedule(new AASRunnable(command), delay, unit); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, |
|
33 |
TimeUnit unit) { |
|
34 |
return executorService.schedule(new AASCallable<V>(callable), delay, |
|
35 |
unit); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, |
|
40 |
long initialDelay, long period, TimeUnit unit) { |
|
41 |
return scheduleAtFixedRate(new AASRunnable(command), initialDelay, |
|
42 |
period, unit); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, |
|
47 |
long initialDelay, long delay, TimeUnit unit) { |
|
48 |
return executorService.scheduleWithFixedDelay(new AASRunnable(command), |
|
49 |
initialDelay, delay, unit); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean awaitTermination(long timeout, TimeUnit unit) |
|
54 |
throws InterruptedException { |
|
55 |
return executorService.awaitTermination(timeout, unit); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) |
|
60 |
throws InterruptedException { |
|
61 |
Collection<Callable<T>> aasTasks = new ArrayList<Callable<T>>(); |
|
62 |
|
|
63 |
for (Callable<T> task : tasks) |
|
64 |
aasTasks.add(new AASCallable<T>(task)); |
|
65 |
|
|
66 |
return executorService.invokeAll(tasks); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public <T> List<Future<T>> invokeAll( |
|
71 |
Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) |
|
72 |
throws InterruptedException { |
|
73 |
Collection<Callable<T>> aasTasks = new ArrayList<Callable<T>>(); |
|
74 |
|
|
75 |
for (Callable<T> task : tasks) |
|
76 |
aasTasks.add(new AASCallable<T>(task)); |
|
77 |
|
|
78 |
return executorService.invokeAll(aasTasks, timeout, unit); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) |
|
83 |
throws InterruptedException, ExecutionException { |
|
84 |
Collection<Callable<T>> aasTasks = new ArrayList<Callable<T>>(); |
|
85 |
|
|
86 |
for (Callable<T> task : tasks) |
|
87 |
aasTasks.add(new AASCallable<T>(task)); |
|
88 |
|
|
89 |
return executorService.invokeAny(aasTasks); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, |
|
94 |
long timeout, TimeUnit unit) throws InterruptedException, |
|
95 |
ExecutionException, TimeoutException { |
|
96 |
Collection<Callable<T>> aasTasks = new ArrayList<Callable<T>>(); |
|
97 |
|
|
98 |
for (Callable<T> task : tasks) |
|
99 |
aasTasks.add(new AASCallable<T>(task)); |
|
100 |
|
|
101 |
return executorService.invokeAny(aasTasks, timeout, unit); |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public boolean isShutdown() { |
|
106 |
return executorService.isShutdown(); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public boolean isTerminated() { |
|
111 |
return executorService.isTerminated(); |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public void shutdown() { |
|
116 |
executorService.shutdown(); |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public List<Runnable> shutdownNow() { |
|
121 |
executorService.shutdownNow(); |
|
122 |
return null; |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public <T> Future<T> submit(Callable<T> task) { |
|
127 |
return executorService.submit(new AASCallable<T>(task)); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public Future<?> submit(Runnable task) { |
|
132 |
return executorService.submit(new AASRunnable(task)); |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public <T> Future<T> submit(Runnable task, T result) { |
|
137 |
return executorService.submit(new AASRunnable(task), result); |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public void execute(Runnable command) { |
|
142 |
executorService.execute(new AASRunnable(command)); |
|
143 |
} |
|
144 |
|
|
145 |
class AASRunnable implements Runnable { |
|
146 |
private Runnable runnable = null; |
|
147 |
String securityContext = null; |
|
148 |
|
|
149 |
public AASRunnable(Runnable runnable) { |
|
150 |
this.runnable = runnable; |
|
151 |
|
|
152 |
// runs in main thread |
|
153 |
this.securityContext = callerSecurityContext.get(); |
|
154 |
} |
|
155 |
|
|
156 |
public void run() { |
|
157 |
// runs in another thread |
|
158 |
callerSecurityContext.set(securityContext); |
|
159 |
runnable.run(); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
class AASCallable<V> implements Callable<V> { |
|
164 |
private Callable<V> callable = null; |
|
165 |
String securityContext = null; |
|
166 |
|
|
167 |
public AASCallable(Callable<V> callable) { |
|
168 |
this.callable = callable; |
|
169 |
|
|
170 |
// runs in main thread |
|
171 |
this.securityContext = callerSecurityContext.get(); |
|
172 |
} |
|
173 |
|
|
174 |
public V call() throws Exception { |
|
175 |
// runs in another thread |
|
176 |
callerSecurityContext.set(securityContext); |
|
177 |
|
|
178 |
return callable.call(); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
public ThreadLocal<String> getCallerSecurityContext() { |
|
183 |
return callerSecurityContext; |
|
184 |
} |
|
185 |
|
|
186 |
public void setCallerSecurityContext( |
|
187 |
ThreadLocal<String> callerSecurityContext) { |
|
188 |
this.callerSecurityContext = callerSecurityContext; |
|
189 |
} |
|
190 |
|
|
191 |
public ScheduledExecutorService getExecutorService() { |
|
192 |
return executorService; |
|
193 |
} |
|
194 |
|
|
195 |
public void setExecutorService(ScheduledExecutorService executorService) { |
|
196 |
this.executorService = executorService; |
|
197 |
} |
|
198 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/enabling/a2/A2WrapperImpl.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling.a2; |
|
2 |
|
|
3 |
import eu.dnetlib.api.enabling.A2Service; |
|
4 |
//import eu.dnetlib.enabling.aas.ctx.tools.CodingContext; |
|
5 |
//import eu.dnetlib.enabling.aas.ctx.tools.SimpleContextRecoder; |
|
6 |
//import eu.dnetlib.enabling.aas.rmi.AuthenticateRequest; |
|
7 |
//import eu.dnetlib.enabling.aas.rmi.AuthenticateResp; |
|
8 |
//import eu.dnetlib.enabling.aas.rmi.AuthorizeRequest; |
|
9 |
//import eu.dnetlib.enabling.aas.rmi.AuthorizeResp; |
|
10 |
//import eu.dnetlib.enabling.aas.rmi.InvalidateRequest; |
|
11 |
//import eu.dnetlib.enabling.aas.rmi.TypedString; |
|
12 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
13 |
|
|
14 |
//TODO remove??? |
|
15 |
|
|
16 |
public class A2WrapperImpl implements A2Wrapper { |
|
17 |
private ServiceLocator<A2Service> locator = null; |
|
18 |
|
|
19 |
public void setLocator(ServiceLocator<A2Service> locator) { |
|
20 |
this.locator = locator; |
|
21 |
} |
|
22 |
|
|
23 |
|
|
24 |
@Override |
|
25 |
public String authenticateService(String certificate) { |
|
26 |
throw new UnsupportedOperationException(); |
|
27 |
// // TODO check certificates |
|
28 |
// String contextId = null; |
|
29 |
// AuthenticateRequest request = new AuthenticateRequest(); |
|
30 |
// |
|
31 |
// TypedString principals = this.createTypedString("certificate", |
|
32 |
// certificate); |
|
33 |
// //TypedString credentials = this.createTypedString("", ""); |
|
34 |
// |
|
35 |
// TypedString principalsArray[] = new TypedString[] {principals}; |
|
36 |
// //TypedString credentialsArray[] = new TypedString[] {credentials}; |
|
37 |
// |
|
38 |
// request.setPrincipals(principalsArray); |
|
39 |
// // request.setCredentials(credentialsArray); |
|
40 |
// |
|
41 |
// AuthenticateResp a2Response = locator.getService() |
|
42 |
// .authenticate(request); |
|
43 |
// |
|
44 |
// if (a2Response.getErrors() == null |
|
45 |
// || a2Response.getErrors().length == 0) |
|
46 |
// contextId = a2Response.getContextId(); |
|
47 |
// |
|
48 |
// return contextId; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public String authenticateUser(String email, String password) { |
|
53 |
throw new UnsupportedOperationException(); |
|
54 |
|
|
55 |
/*String contextId = null; |
|
56 |
AuthenticateRequest request = new AuthenticateRequest(); |
|
57 |
|
|
58 |
TypedString principals = this.createTypedString("login", email); |
|
59 |
TypedString credentials = this.createTypedString("password", password); |
|
60 |
|
|
61 |
TypedString principalsArray[] = new TypedString[] {principals}; |
|
62 |
TypedString credentialsArray[] = new TypedString[] {credentials}; |
|
63 |
|
|
64 |
request.setPrincipals(principalsArray); |
|
65 |
request.setCredentials(credentialsArray); |
|
66 |
|
|
67 |
AuthenticateResp a2Response = locator.getService() |
|
68 |
.authenticate(request); |
|
69 |
|
|
70 |
if (a2Response.getErrors() == null |
|
71 |
|| a2Response.getErrors().length == 0) { |
|
72 |
|
|
73 |
contextId = a2Response.getContextId(); |
|
74 |
//TODO remove |
|
75 |
contextId = "contextId"; |
|
76 |
} |
|
77 |
|
|
78 |
return contextId; */ |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public boolean authorizeAction(String resource, String action, |
|
83 |
String contextId) { |
|
84 |
|
|
85 |
throw new UnsupportedOperationException(); |
|
86 |
|
|
87 |
/* AuthorizeRequest request = new AuthorizeRequest(); |
|
88 |
|
|
89 |
request.setContextId(contextId); |
|
90 |
|
|
91 |
TypedString resourceType = this.createTypedString(null, resource); |
|
92 |
TypedString actionType = this.createTypedString(null, action); |
|
93 |
|
|
94 |
request.setResource(resourceType); |
|
95 |
request.setAction(actionType); |
|
96 |
|
|
97 |
AuthorizeResp a2Response = locator.getService().authorize(request); |
|
98 |
|
|
99 |
return a2Response.isAuthorized(); */ |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public String createSecurityContextChain(String contextIdA, |
|
104 |
String contextIdB) { |
|
105 |
|
|
106 |
throw new UnsupportedOperationException(); |
|
107 |
|
|
108 |
/* String secCtxIdChain = null; |
|
109 |
SimpleContextRecoder recoder = new SimpleContextRecoder(); |
|
110 |
|
|
111 |
CodingContext ctx = new CodingContext(); |
|
112 |
ctx.secCtxId = contextIdA; |
|
113 |
secCtxIdChain = recoder.encode(ctx, secCtxIdChain, null); |
|
114 |
ctx.secCtxId = contextIdB; |
|
115 |
secCtxIdChain = recoder.encode(ctx, secCtxIdChain, null); |
|
116 |
secCtxIdChain = recoder.appendVersionPrefix(secCtxIdChain); |
|
117 |
|
|
118 |
return secCtxIdChain; |
|
119 |
*/ |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public void invalidate(String contextId) { |
|
124 |
throw new UnsupportedOperationException(); |
|
125 |
/* |
|
126 |
InvalidateRequest request = new InvalidateRequest(); |
|
127 |
|
|
128 |
request.setContextId(contextId); |
|
129 |
|
|
130 |
locator.getService().invalidate(request);*/ |
|
131 |
} |
|
132 |
|
|
133 |
/* |
|
134 |
private TypedString createTypedString(String type, String value) { |
|
135 |
TypedString string = new TypedString(); |
|
136 |
|
|
137 |
string.setText(value); |
|
138 |
string.setType(type); |
|
139 |
|
|
140 |
return string; |
|
141 |
}*/ |
|
142 |
|
|
143 |
} |
modules/uoa-commons/tags/uoa-commons-2.0.0/src/main/java/gr/uoa/di/driver/enabling/ISRegistryException.java | ||
---|---|---|
1 |
package gr.uoa.di.driver.enabling; |
|
2 |
|
|
3 |
public class ISRegistryException extends Exception { |
|
4 |
private static final long serialVersionUID = -1416313006769865476L; |
|
5 |
|
|
6 |
public ISRegistryException() { |
|
7 |
super(); |
|
8 |
} |
|
9 |
|
|
10 |
public ISRegistryException(String message, Throwable cause) { |
|
11 |
super(message, cause); |
|
12 |
} |
|
13 |
|
|
14 |
public ISRegistryException(String message) { |
Also available in: Unified diff
[maven-release-plugin] copy for tag uoa-commons-2.0.0