1 | /** |
---|
2 | * Copyright (C) 2013 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify it under |
---|
5 | * the terms of the GNU General Public License as published by the Free Software |
---|
6 | * Foundation; either version 2 of the License, or (at your option) any later |
---|
7 | * version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
11 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
12 | * details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License along with |
---|
15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
16 | * Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend; |
---|
19 | |
---|
20 | import eu.dasish.annotation.schema.Annotation; |
---|
21 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
22 | import eu.dasish.annotation.schema.AnnotationBody.TextBody; |
---|
23 | import eu.dasish.annotation.schema.Permission; |
---|
24 | import eu.dasish.annotation.schema.TargetInfo; |
---|
25 | import eu.dasish.annotation.schema.TargetInfoList; |
---|
26 | import eu.dasish.annotation.schema.UserWithPermission; |
---|
27 | import eu.dasish.annotation.schema.UserWithPermissionList; |
---|
28 | import javax.xml.datatype.DatatypeConfigurationException; |
---|
29 | import javax.xml.datatype.DatatypeFactory; |
---|
30 | |
---|
31 | /** |
---|
32 | * |
---|
33 | * @author olhsha |
---|
34 | */ |
---|
35 | public class TestInstances { |
---|
36 | |
---|
37 | final private Annotation _annotationOne; |
---|
38 | final private Annotation _annotationToAdd; |
---|
39 | |
---|
40 | public TestInstances(String baseURI) { |
---|
41 | _annotationOne = makeAnnotationOne(baseURI); |
---|
42 | _annotationToAdd = makeAnnotationToAdd(baseURI); |
---|
43 | } |
---|
44 | |
---|
45 | private Annotation makeAnnotationOne(String baseURI) { |
---|
46 | Annotation result = makeAnnotation(baseURI, "<html><body>some html 1</body></html>", "text/html", "Sagrada Famiglia", "00000000-0000-0000-0000-000000000111"); |
---|
47 | |
---|
48 | try { |
---|
49 | result.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z")); |
---|
50 | } catch (DatatypeConfigurationException dce) { |
---|
51 | System.out.println("wrongly-formatted test timestamp " + "2013-08-12T09:25:00.383000Z"); |
---|
52 | result.setLastModified(null); |
---|
53 | } |
---|
54 | UserWithPermissionList upL = new UserWithPermissionList(); |
---|
55 | TargetInfoList targets = new TargetInfoList(); |
---|
56 | result.setPermissions(upL); |
---|
57 | result.setTargets(targets); |
---|
58 | |
---|
59 | UserWithPermission up1 = new UserWithPermission(); |
---|
60 | up1.setRef(baseURI + "users/00000000-0000-0000-0000-000000000112"); |
---|
61 | up1.setPermission(Permission.WRITER); |
---|
62 | |
---|
63 | UserWithPermission up2 = new UserWithPermission(); |
---|
64 | up2.setRef(baseURI + "users/00000000-0000-0000-0000-000000000113"); |
---|
65 | up2.setPermission(Permission.READER); |
---|
66 | |
---|
67 | upL.getUserWithPermission().add(up1); |
---|
68 | upL.getUserWithPermission().add(up2); |
---|
69 | |
---|
70 | TargetInfo target1 = new TargetInfo(); |
---|
71 | target1.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); |
---|
72 | target1.setRef(baseURI + "targets/00000000-0000-0000-0000-000000000031"); |
---|
73 | target1.setVersion("version 1.0"); |
---|
74 | |
---|
75 | TargetInfo target2 = new TargetInfo(); |
---|
76 | target2.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); |
---|
77 | target2.setRef(baseURI + "targets/00000000-0000-0000-0000-000000000032"); |
---|
78 | target2.setVersion("version 1.1"); |
---|
79 | |
---|
80 | targets.getTargetInfo().add(target1); |
---|
81 | targets.getTargetInfo().add(target2); |
---|
82 | |
---|
83 | return result; |
---|
84 | } |
---|
85 | |
---|
86 | private Annotation makeAnnotationToAdd(String baseURI) { |
---|
87 | Annotation result = makeAnnotation(baseURI, "<html><body>some html 3</body></html>", "text/plain", "Annotation to add to test DAO", "00000000-0000-0000-0000-000000000113"); |
---|
88 | |
---|
89 | TargetInfo TargetInfo = new TargetInfo(); |
---|
90 | TargetInfo.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); |
---|
91 | TargetInfo.setRef(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031"); |
---|
92 | TargetInfo.setVersion("version 1.0"); |
---|
93 | |
---|
94 | TargetInfoList targetInfos = new TargetInfoList(); |
---|
95 | targetInfos.getTargetInfo().add(TargetInfo); |
---|
96 | result.setTargets(targetInfos); |
---|
97 | |
---|
98 | return result; |
---|
99 | } |
---|
100 | |
---|
101 | private Annotation makeAnnotation(String baseURI, String bodyTxt, String bodyMimeType, String headline, String ownerID) { |
---|
102 | Annotation result = new Annotation(); |
---|
103 | AnnotationBody body = new AnnotationBody(); |
---|
104 | result.setBody(body); |
---|
105 | TextBody textBody = new TextBody(); |
---|
106 | body.setTextBody(textBody); |
---|
107 | textBody.setMimeType(bodyMimeType); |
---|
108 | textBody.setBody(bodyTxt); |
---|
109 | |
---|
110 | result.setHeadline(headline); |
---|
111 | |
---|
112 | if (baseURI != null) { |
---|
113 | result.setOwnerRef(baseURI + "users/" + ownerID); |
---|
114 | } else { |
---|
115 | result.setOwnerRef("users/" + ownerID); |
---|
116 | } |
---|
117 | |
---|
118 | result.setLastModified(null); |
---|
119 | result.setURI(null); |
---|
120 | result.setTargets(null); |
---|
121 | result.setURI(null); |
---|
122 | |
---|
123 | return result; |
---|
124 | } |
---|
125 | |
---|
126 | public Annotation getAnnotationOne() { |
---|
127 | return _annotationOne; |
---|
128 | } |
---|
129 | |
---|
130 | public Annotation getAnnotationToAdd() { |
---|
131 | return _annotationToAdd; |
---|
132 | } |
---|
133 | } |
---|