source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java @ 4903

Last change on this file since 4903 was 4903, checked in by olhsha@mpi.nl, 10 years ago

tested and debugged on localhost. Error status messages are corrected.

File size: 5.2 KB
Line 
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 */
18package eu.dasish.annotation.backend;
19
20import eu.dasish.annotation.schema.Annotation;
21import eu.dasish.annotation.schema.AnnotationBody;
22import eu.dasish.annotation.schema.AnnotationBody.TextBody;
23import eu.dasish.annotation.schema.Access;
24import eu.dasish.annotation.schema.TargetInfo;
25import eu.dasish.annotation.schema.TargetInfoList;
26import eu.dasish.annotation.schema.Permission;
27import eu.dasish.annotation.schema.PermissionList;
28import javax.xml.datatype.DatatypeConfigurationException;
29import javax.xml.datatype.DatatypeFactory;
30
31/**
32 *
33 * @author olhsha
34 */
35public 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        result.setURI(baseURI+"annotations/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.setPrincipalRef(baseURI + "principals/00000000-0000-0000-0000-000000000112");
62        up1.setLevel(Access.WRITE);
63
64        Permission up2 = new Permission();
65        up2.setPrincipalRef(baseURI + "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.setRef(baseURI + "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.setRef(baseURI + "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 baseURI) {
89        Annotation result = makeAnnotation(baseURI, "<html><body>some html 3</body></html>", "text/plain", "Annotation to add to test DAO", "00000000-0000-0000-0000-000000000113");
90
91        TargetInfo TargetInfo = new TargetInfo();
92        TargetInfo.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht");
93        TargetInfo.setRef(baseURI+  "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       
104        return result;
105    }
106
107    private Annotation makeAnnotation(String baseURI, String bodyTxt, String bodyMimeType, String headline, String ownerExternalId) {
108        Annotation result = new Annotation();
109        AnnotationBody body = new AnnotationBody();
110        result.setBody(body);
111        TextBody textBody = new TextBody();
112        body.setTextBody(textBody);
113        textBody.setMimeType(bodyMimeType);
114        textBody.setBody(bodyTxt);
115
116        result.setHeadline(headline);
117
118        if (baseURI != null) {
119            result.setOwnerRef(baseURI + "principals/" + ownerExternalId);
120        } else {
121            result.setOwnerRef("principals/" + ownerExternalId);
122        }
123
124        result.setLastModified(null);
125        result.setURI(null);
126        result.setTargets(null);
127        result.setURI(null);
128
129        return result;
130    }
131
132    public Annotation getAnnotationOne() {
133        return _annotationOne;
134    }
135
136    public Annotation getAnnotationToAdd() {
137        return _annotationToAdd;
138    }
139}
Note: See TracBrowser for help on using the repository browser.