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.Access; |
---|
24 | import eu.dasish.annotation.schema.TargetInfo; |
---|
25 | import eu.dasish.annotation.schema.TargetInfoList; |
---|
26 | import eu.dasish.annotation.schema.Permission; |
---|
27 | import eu.dasish.annotation.schema.PermissionList; |
---|
28 | import java.util.UUID; |
---|
29 | import javax.xml.datatype.DatatypeConfigurationException; |
---|
30 | import javax.xml.datatype.DatatypeFactory; |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | * @author olhsha |
---|
35 | */ |
---|
36 | public class TestInstances { |
---|
37 | |
---|
38 | final private Annotation _annotationOne; |
---|
39 | final private Annotation _annotationToAdd; |
---|
40 | |
---|
41 | public TestInstances(String relativePath) { |
---|
42 | _annotationOne = makeAnnotationOne(relativePath); |
---|
43 | _annotationToAdd = makeAnnotationToAdd(relativePath); |
---|
44 | } |
---|
45 | |
---|
46 | private Annotation makeAnnotationOne(String relativePath) { |
---|
47 | Annotation result = makeAnnotation(relativePath, "<html><body>some html 1</body></html>", "text/html", "Sagrada Famiglia", "00000000-0000-0000-0000-000000000111", "00000000-0000-0000-0000-000000000021"); |
---|
48 | |
---|
49 | try { |
---|
50 | result.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z")); |
---|
51 | } catch (DatatypeConfigurationException dce) { |
---|
52 | System.out.println("wrongly-formatted test timestamp " + "2013-08-12T09:25:00.383000Z"); |
---|
53 | result.setLastModified(null); |
---|
54 | } |
---|
55 | PermissionList upL = new PermissionList(); |
---|
56 | TargetInfoList targets = new TargetInfoList(); |
---|
57 | result.setPermissions(upL); |
---|
58 | result.setTargets(targets); |
---|
59 | |
---|
60 | Permission up1 = new Permission(); |
---|
61 | up1.setPrincipalHref(relativePath + "/principals/00000000-0000-0000-0000-000000000112"); |
---|
62 | up1.setLevel(Access.WRITE); |
---|
63 | |
---|
64 | Permission up2 = new Permission(); |
---|
65 | up2.setPrincipalHref(relativePath + "/principals/00000000-0000-0000-0000-000000000113"); |
---|
66 | up2.setLevel(Access.READ); |
---|
67 | |
---|
68 | upL.getPermission().add(up1); |
---|
69 | upL.getPermission().add(up2); |
---|
70 | upL.setPublic(Access.WRITE); |
---|
71 | |
---|
72 | TargetInfo target1 = new TargetInfo(); |
---|
73 | target1.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); |
---|
74 | target1.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000031"); |
---|
75 | target1.setVersion("version 1.0"); |
---|
76 | |
---|
77 | TargetInfo target2 = new TargetInfo(); |
---|
78 | target2.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); |
---|
79 | target2.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000032"); |
---|
80 | target2.setVersion("version 1.1"); |
---|
81 | |
---|
82 | targets.getTargetInfo().add(target1); |
---|
83 | targets.getTargetInfo().add(target2); |
---|
84 | |
---|
85 | return result; |
---|
86 | } |
---|
87 | |
---|
88 | private Annotation makeAnnotationToAdd(String relativePath) { |
---|
89 | Annotation result = makeAnnotation(relativePath, "<html><body>some html 3</body></html>", "text/plain", "Annotation to add to test DAO", "00000000-0000-0000-0000-000000000113", Helpers.generateUUID().toString()); |
---|
90 | |
---|
91 | TargetInfo TargetInfo = new TargetInfo(); |
---|
92 | TargetInfo.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht"); |
---|
93 | TargetInfo.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000031"); |
---|
94 | TargetInfo.setVersion("version 1.0"); |
---|
95 | |
---|
96 | TargetInfoList targetInfos = new TargetInfoList(); |
---|
97 | targetInfos.getTargetInfo().add(TargetInfo); |
---|
98 | result.setTargets(targetInfos); |
---|
99 | |
---|
100 | PermissionList permissions = new PermissionList(); |
---|
101 | permissions.setPublic(Access.WRITE); |
---|
102 | result.setPermissions(permissions); |
---|
103 | Permission p = new Permission(); |
---|
104 | p.setLevel(Access.ALL); |
---|
105 | p.setPrincipalHref(relativePath +"/principals/00000000-0000-0000-0000-000000000111"); |
---|
106 | permissions.getPermission().add(p); |
---|
107 | |
---|
108 | return result; |
---|
109 | } |
---|
110 | |
---|
111 | private Annotation makeAnnotation(String relativePath, String bodyTxt, String bodyMimeType, String headline, String ownerExternalId, String externalId) { |
---|
112 | Annotation result = new Annotation(); |
---|
113 | |
---|
114 | AnnotationBody body = new AnnotationBody(); |
---|
115 | result.setBody(body); |
---|
116 | TextBody textBody = new TextBody(); |
---|
117 | body.setTextBody(textBody); |
---|
118 | textBody.setMimeType(bodyMimeType); |
---|
119 | textBody.setBody(bodyTxt); |
---|
120 | |
---|
121 | result.setHeadline(headline); |
---|
122 | result.setOwnerHref(relativePath + "/principals/" + ownerExternalId); |
---|
123 | result.setLastModified(null); |
---|
124 | result.setId(externalId); |
---|
125 | result.setHref(relativePath + "/annotations/"+externalId); |
---|
126 | result.setTargets(null); |
---|
127 | return result; |
---|
128 | } |
---|
129 | |
---|
130 | public Annotation getAnnotationOne() { |
---|
131 | return _annotationOne; |
---|
132 | } |
---|
133 | |
---|
134 | public Annotation getAnnotationToAdd() { |
---|
135 | return _annotationToAdd; |
---|
136 | } |
---|
137 | } |
---|