Merge lp:~ralf-claussnitzer-deactivatedaccount/goobi-production/rest-api-refactored into lp:goobi-production/1.8

Proposed by Ralf Claussnitzer
Status: Merged
Merged at revision: 83
Proposed branch: lp:~ralf-claussnitzer-deactivatedaccount/goobi-production/rest-api-refactored
Merge into: lp:goobi-production/1.8
Diff against target: 620 lines (+552/-0)
8 files modified
WEB-INF/web.xml (+16/-0)
src/org/goobi/webapi/beans/GoobiProcess.java (+58/-0)
src/org/goobi/webapi/beans/GoobiProcessStep.java (+66/-0)
src/org/goobi/webapi/beans/IdentifierPPN.java (+61/-0)
src/org/goobi/webapi/dao/GoobiProcessDAO.java (+154/-0)
src/org/goobi/webapi/provider/ParamExceptionMapper.java (+40/-0)
src/org/goobi/webapi/resources/Processes.java (+78/-0)
test/src/org/goobi/webapi/beans/IdentifierPPNTest.java (+79/-0)
To merge this branch: bzr merge lp:~ralf-claussnitzer-deactivatedaccount/goobi-production/rest-api-refactored
Reviewer Review Type Date Requested Status
Henning Gerhardt Approve
Review via email: mp+117277@code.launchpad.net

This proposal supersedes a proposal from 2012-07-30.

To post a comment you must log in.
Revision history for this message
Henning Gerhardt (henning-gerhardt) wrote : Posted in a previous version of this proposal

- PPN tests are broken
- replace full qualified class names with imports

review: Needs Fixing
Revision history for this message
Henning Gerhardt (henning-gerhardt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'WEB-INF/web.xml'
2--- WEB-INF/web.xml 2012-07-26 16:41:08 +0000
3+++ WEB-INF/web.xml 2012-07-30 14:30:32 +0000
4@@ -317,4 +317,20 @@
5 <location>/newpages/error.jsf</location>
6 </error-page>
7
8+ <servlet>
9+ <servlet-name>Goobi REST Service based on Jersey</servlet-name>
10+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
11+ <init-param>
12+ <param-name>com.sun.jersey.config.property.packages</param-name>
13+ <param-value>org.goobi.webapi.resources; org.goobi.webapi.provider</param-value>
14+ </init-param>
15+ <!-- explanation of load-on-startup: http://stackoverflow.com/a/1298984 -->
16+ <load-on-startup>1</load-on-startup>
17+ </servlet>
18+
19+ <servlet-mapping>
20+ <servlet-name>Goobi REST Service based on Jersey</servlet-name>
21+ <url-pattern>/rest/*</url-pattern>
22+ </servlet-mapping>
23+
24 </web-app>
25
26=== added file 'lib/asm-3.1.jar'
27Binary files lib/asm-3.1.jar 1970-01-01 00:00:00 +0000 and lib/asm-3.1.jar 2012-07-30 14:30:32 +0000 differ
28=== added file 'lib/jersey-bundle-1.12.jar'
29Binary files lib/jersey-bundle-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-bundle-1.12.jar 2012-07-30 14:30:32 +0000 differ
30=== added file 'lib/jersey-client-1.12.jar'
31Binary files lib/jersey-client-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-client-1.12.jar 2012-07-30 14:30:32 +0000 differ
32=== added file 'lib/jersey-core-1.12.jar'
33Binary files lib/jersey-core-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-core-1.12.jar 2012-07-30 14:30:32 +0000 differ
34=== added file 'lib/jersey-json-1.12.jar'
35Binary files lib/jersey-json-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-json-1.12.jar 2012-07-30 14:30:32 +0000 differ
36=== added file 'lib/jersey-multipart-1.12.jar'
37Binary files lib/jersey-multipart-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-multipart-1.12.jar 2012-07-30 14:30:32 +0000 differ
38=== added file 'lib/jersey-server-1.12.jar'
39Binary files lib/jersey-server-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-server-1.12.jar 2012-07-30 14:30:32 +0000 differ
40=== added file 'lib/jersey-servlet-1.12.jar'
41Binary files lib/jersey-servlet-1.12.jar 1970-01-01 00:00:00 +0000 and lib/jersey-servlet-1.12.jar 2012-07-30 14:30:32 +0000 differ
42=== added file 'lib/jsr311-api-1.1.1.jar'
43Binary files lib/jsr311-api-1.1.1.jar 1970-01-01 00:00:00 +0000 and lib/jsr311-api-1.1.1.jar 2012-07-30 14:30:32 +0000 differ
44=== added directory 'src/org/goobi/webapi'
45=== added directory 'src/org/goobi/webapi/beans'
46=== added file 'src/org/goobi/webapi/beans/GoobiProcess.java'
47--- src/org/goobi/webapi/beans/GoobiProcess.java 1970-01-01 00:00:00 +0000
48+++ src/org/goobi/webapi/beans/GoobiProcess.java 2012-07-30 14:30:32 +0000
49@@ -0,0 +1,58 @@
50+/*
51+ * This file is part of the Goobi Application - a Workflow tool for the support of
52+ * mass digitization.
53+ *
54+ * Visit the websites for more information.
55+ * - http://gdz.sub.uni-goettingen.de
56+ * - http://www.goobi.org
57+ * - http://launchpad.net/goobi-production
58+ *
59+ * This program is free software; you can redistribute it and/or modify it under
60+ * the terms of the GNU General Public License as published by the Free Software
61+ * Foundation; either version 2 of the License, or (at your option) any later
62+ * version.
63+ *
64+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
65+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
66+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
67+ * should have received a copy of the GNU General Public License along with this
68+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
69+ * Suite 330, Boston, MA 02111-1307 USA
70+ */
71+
72+package org.goobi.webapi.beans;
73+
74+import javax.xml.bind.annotation.XmlRootElement;
75+
76+@XmlRootElement
77+public class GoobiProcess {
78+
79+ private String identifier;
80+
81+ private String title;
82+
83+ public GoobiProcess() {
84+ }
85+
86+ public GoobiProcess(String identifier, String title) {
87+ this.identifier = identifier;
88+ this.title = title;
89+ }
90+
91+ public String getIdentifier() {
92+ return identifier;
93+ }
94+
95+ public String getTitle() {
96+ return title;
97+ }
98+
99+ public void setIdentifier(String identifier) {
100+ this.identifier = identifier;
101+ }
102+
103+ public void setTitle(String title) {
104+ this.title = title;
105+ }
106+
107+}
108
109=== added file 'src/org/goobi/webapi/beans/GoobiProcessStep.java'
110--- src/org/goobi/webapi/beans/GoobiProcessStep.java 1970-01-01 00:00:00 +0000
111+++ src/org/goobi/webapi/beans/GoobiProcessStep.java 2012-07-30 14:30:32 +0000
112@@ -0,0 +1,66 @@
113+/*
114+ * This file is part of the Goobi Application - a Workflow tool for the support of
115+ * mass digitization.
116+ *
117+ * Visit the websites for more information.
118+ * - http://gdz.sub.uni-goettingen.de
119+ * - http://www.goobi.org
120+ * - http://launchpad.net/goobi-production
121+ *
122+ * This program is free software; you can redistribute it and/or modify it under
123+ * the terms of the GNU General Public License as published by the Free Software
124+ * Foundation; either version 2 of the License, or (at your option) any later
125+ * version.
126+ *
127+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
128+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
129+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
130+ * should have received a copy of the GNU General Public License along with this
131+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
132+ * Suite 330, Boston, MA 02111-1307 USA
133+ */
134+
135+package org.goobi.webapi.beans;
136+
137+import javax.xml.bind.annotation.XmlRootElement;
138+
139+@XmlRootElement
140+public class GoobiProcessStep {
141+
142+ private Integer sequence;
143+ private Integer state;
144+ private String title;
145+
146+ public GoobiProcessStep() {
147+ }
148+
149+ public GoobiProcessStep(Integer sequence, Integer state, String title) {
150+ this.sequence = sequence;
151+ this.state = state;
152+ this.title = title;
153+ }
154+
155+ public Integer getSequence() {
156+ return sequence;
157+ }
158+
159+ public void setSequence(Integer sequence) {
160+ this.sequence = sequence;
161+ }
162+
163+ public Integer getState() {
164+ return state;
165+ }
166+
167+ public void setState(Integer state) {
168+ this.state = state;
169+ }
170+
171+ public String getTitle() {
172+ return title;
173+ }
174+
175+ public void setTitle(String title) {
176+ this.title = title;
177+ }
178+}
179
180=== added file 'src/org/goobi/webapi/beans/IdentifierPPN.java'
181--- src/org/goobi/webapi/beans/IdentifierPPN.java 1970-01-01 00:00:00 +0000
182+++ src/org/goobi/webapi/beans/IdentifierPPN.java 2012-07-30 14:30:32 +0000
183@@ -0,0 +1,61 @@
184+/*
185+ * This file is part of the Goobi Application - a Workflow tool for the support of
186+ * mass digitization.
187+ *
188+ * Visit the websites for more information.
189+ * - http://gdz.sub.uni-goettingen.de
190+ * - http://www.goobi.org
191+ * - http://launchpad.net/goobi-production
192+ *
193+ * This program is free software; you can redistribute it and/or modify it under
194+ * the terms of the GNU General Public License as published by the Free Software
195+ * Foundation; either version 2 of the License, or (at your option) any later
196+ * version.
197+ *
198+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
199+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
200+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
201+ * should have received a copy of the GNU General Public License along with this
202+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
203+ * Suite 330, Boston, MA 02111-1307 USA
204+ */
205+
206+package org.goobi.webapi.beans;
207+
208+import java.util.regex.Matcher;
209+import java.util.regex.Pattern;
210+
211+public class IdentifierPPN {
212+
213+ private String ppn;
214+
215+ public IdentifierPPN(String ppn) {
216+ if (!isValid(ppn)) {
217+ throw new IllegalArgumentException("Given string is not a valid PPN identifier.");
218+ }
219+ this.ppn = ppn;
220+ }
221+
222+ public static boolean isValid(String identifier) {
223+ Boolean result;
224+ int flags = Pattern.CASE_INSENSITIVE;
225+ Pattern pattern;
226+ Matcher matcher;
227+
228+ if ((identifier == null) || (identifier.length() == 0)) {
229+ result = false;
230+ } else {
231+ pattern = Pattern.compile("^[0-9]{8}[0-9LXYZ]{1}$", flags);
232+ matcher = pattern.matcher(identifier);
233+ result = matcher.matches();
234+ }
235+
236+ return result;
237+ }
238+
239+ public String toString() {
240+ return ppn;
241+ }
242+
243+
244+}
245
246=== added directory 'src/org/goobi/webapi/dao'
247=== added file 'src/org/goobi/webapi/dao/GoobiProcessDAO.java'
248--- src/org/goobi/webapi/dao/GoobiProcessDAO.java 1970-01-01 00:00:00 +0000
249+++ src/org/goobi/webapi/dao/GoobiProcessDAO.java 2012-07-30 14:30:32 +0000
250@@ -0,0 +1,154 @@
251+/*
252+ * This file is part of the Goobi Application - a Workflow tool for the support of
253+ * mass digitization.
254+ *
255+ * Visit the websites for more information.
256+ * - http://gdz.sub.uni-goettingen.de
257+ * - http://www.goobi.org
258+ * - http://launchpad.net/goobi-production
259+ *
260+ * This program is free software; you can redistribute it and/or modify it under
261+ * the terms of the GNU General Public License as published by the Free Software
262+ * Foundation; either version 2 of the License, or (at your option) any later
263+ * version.
264+ *
265+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
266+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
267+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
268+ * should have received a copy of the GNU General Public License along with this
269+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
270+ * Suite 330, Boston, MA 02111-1307 USA
271+ */
272+
273+package org.goobi.webapi.dao;
274+
275+import de.sub.goobi.beans.Prozess;
276+import de.sub.goobi.beans.Schritt;
277+import de.sub.goobi.helper.Helper;
278+import org.apache.log4j.Logger;
279+import org.goobi.webapi.beans.GoobiProcess;
280+import org.goobi.webapi.beans.GoobiProcessStep;
281+import org.goobi.webapi.beans.IdentifierPPN;
282+import org.hibernate.Criteria;
283+import org.hibernate.HibernateException;
284+import org.hibernate.Session;
285+import org.hibernate.criterion.Order;
286+import org.hibernate.criterion.Projections;
287+import org.hibernate.criterion.Restrictions;
288+import org.hibernate.transform.Transformers;
289+
290+import java.util.ArrayList;
291+import java.util.List;
292+
293+public class GoobiProcessDAO {
294+
295+ private static final Logger myLogger = Logger.getLogger(GoobiProcessDAO.class);
296+
297+ public static GoobiProcess getProcessByPPN(IdentifierPPN PPN) {
298+ Session session;
299+ GoobiProcess result = null;
300+
301+ session = Helper.getHibernateSession();
302+
303+ try {
304+
305+ Criteria criteria = session
306+ .createCriteria(Prozess.class)
307+ .createAlias("vorlagen", "v")
308+ .createAlias("vorlagen.eigenschaften", "ve")
309+ .createAlias("werkstuecke", "w")
310+ .createAlias("werkstuecke.eigenschaften", "we")
311+ .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
312+ .add(Restrictions.eq("ve.titel", "Titel"))
313+ .add(Restrictions.eq("we.wert", PPN.toString()))
314+ .addOrder(Order.asc("we.wert"))
315+ .setProjection(Projections.projectionList()
316+ .add(Projections.property("we.wert"), "identifier")
317+ .add(Projections.property("ve.wert"), "title")
318+ )
319+ .setResultTransformer(Transformers.aliasToBean(GoobiProcess.class));
320+
321+ result = (GoobiProcess) criteria.uniqueResult();
322+
323+ } catch (HibernateException he) {
324+ myLogger.error("Catched Hibernate exception: " + he.getMessage());
325+ }
326+
327+ return result;
328+ }
329+
330+ public static List<GoobiProcess> getAllProcesses() {
331+ Session session;
332+ List<GoobiProcess> result;
333+
334+ result = new ArrayList<GoobiProcess>();
335+ session = Helper.getHibernateSession();
336+
337+ try {
338+
339+ Criteria criteria = session
340+ .createCriteria(Prozess.class)
341+ .createAlias("vorlagen", "v")
342+ .createAlias("vorlagen.eigenschaften", "ve")
343+ .createAlias("werkstuecke", "w")
344+ .createAlias("werkstuecke.eigenschaften", "we")
345+ .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
346+ .add(Restrictions.eq("ve.titel", "Titel"))
347+ .addOrder(Order.asc("we.wert"))
348+ .setProjection(Projections.projectionList()
349+ .add(Projections.property("we.wert"), "identifier")
350+ .add(Projections.property("ve.wert"), "title")
351+ )
352+ .setResultTransformer(Transformers.aliasToBean(GoobiProcess.class));
353+
354+ @SuppressWarnings(value = "unchecked")
355+ List<GoobiProcess> list = (List<GoobiProcess>) criteria.list();
356+
357+ if ((list != null) && (list.size() > 0)) {
358+ result.addAll(list);
359+ }
360+ } catch (HibernateException he) {
361+ myLogger.error("Catched Hibernate exception: " + he.getMessage());
362+ }
363+
364+ return result;
365+ }
366+
367+ public static List<GoobiProcessStep> getAllProcessSteps(IdentifierPPN PPN) {
368+ List<GoobiProcessStep> result;
369+ Session session;
370+
371+ result = new ArrayList<GoobiProcessStep>();
372+ session = Helper.getHibernateSession();
373+
374+ try {
375+
376+ Criteria criteria = session
377+ .createCriteria(Schritt.class)
378+ .createAlias("prozess", "p")
379+ .createAlias("prozess.werkstuecke", "w")
380+ .createAlias("prozess.werkstuecke.eigenschaften", "we")
381+ .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
382+ .add(Restrictions.eq("we.wert", PPN.toString()))
383+ .addOrder(Order.asc("reihenfolge"))
384+ .setProjection(Projections.projectionList()
385+ .add(Projections.property("reihenfolge"), "sequence")
386+ .add(Projections.property("bearbeitungsstatus"), "state")
387+ .add(Projections.property("titel"), "title")
388+ )
389+ .setResultTransformer(Transformers.aliasToBean(GoobiProcessStep.class));
390+
391+ @SuppressWarnings(value = "unchecked")
392+ List<GoobiProcessStep> list = (List<GoobiProcessStep>) criteria.list();
393+
394+ if ((list != null) && (!list.isEmpty())) {
395+ result.addAll(list);
396+ }
397+ } catch (HibernateException he) {
398+ myLogger.error("Catched Hibernate exception: " + he.getMessage());
399+ }
400+
401+ return result;
402+ }
403+
404+}
405
406=== added directory 'src/org/goobi/webapi/provider'
407=== added file 'src/org/goobi/webapi/provider/ParamExceptionMapper.java'
408--- src/org/goobi/webapi/provider/ParamExceptionMapper.java 1970-01-01 00:00:00 +0000
409+++ src/org/goobi/webapi/provider/ParamExceptionMapper.java 2012-07-30 14:30:32 +0000
410@@ -0,0 +1,40 @@
411+/*
412+ * This file is part of the Goobi Application - a Workflow tool for the support of
413+ * mass digitization.
414+ *
415+ * Visit the websites for more information.
416+ * - http://gdz.sub.uni-goettingen.de
417+ * - http://www.goobi.org
418+ * - http://launchpad.net/goobi-production
419+ *
420+ * This program is free software; you can redistribute it and/or modify it under
421+ * the terms of the GNU General Public License as published by the Free Software
422+ * Foundation; either version 2 of the License, or (at your option) any later
423+ * version.
424+ *
425+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
426+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
427+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
428+ * should have received a copy of the GNU General Public License along with this
429+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
430+ * Suite 330, Boston, MA 02111-1307 USA
431+ */
432+
433+package org.goobi.webapi.provider;
434+
435+import com.sun.jersey.api.ParamException;
436+
437+import javax.ws.rs.core.MediaType;
438+import javax.ws.rs.core.Response;
439+import javax.ws.rs.ext.ExceptionMapper;
440+import javax.ws.rs.ext.Provider;
441+
442+@Provider
443+public class ParamExceptionMapper implements ExceptionMapper<ParamException> {
444+ public Response toResponse(ParamException e) {
445+ return Response.status(Response.Status.BAD_REQUEST)
446+ .entity(e.getCause().getMessage())
447+ .type(MediaType.TEXT_PLAIN)
448+ .build();
449+ }
450+}
451
452=== added directory 'src/org/goobi/webapi/resources'
453=== added file 'src/org/goobi/webapi/resources/Processes.java'
454--- src/org/goobi/webapi/resources/Processes.java 1970-01-01 00:00:00 +0000
455+++ src/org/goobi/webapi/resources/Processes.java 2012-07-30 14:30:32 +0000
456@@ -0,0 +1,78 @@
457+/*
458+ * This file is part of the Goobi Application - a Workflow tool for the support of
459+ * mass digitization.
460+ *
461+ * Visit the websites for more information.
462+ * - http://gdz.sub.uni-goettingen.de
463+ * - http://www.goobi.org
464+ * - http://launchpad.net/goobi-production
465+ *
466+ * This program is free software; you can redistribute it and/or modify it under
467+ * the terms of the GNU General Public License as published by the Free Software
468+ * Foundation; either version 2 of the License, or (at your option) any later
469+ * version.
470+ *
471+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
472+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
473+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
474+ * should have received a copy of the GNU General Public License along with this
475+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
476+ * Suite 330, Boston, MA 02111-1307 USA
477+ */
478+
479+package org.goobi.webapi.resources;
480+
481+import com.sun.jersey.api.NotFoundException;
482+import org.goobi.webapi.beans.GoobiProcess;
483+import org.goobi.webapi.beans.GoobiProcessStep;
484+import org.goobi.webapi.beans.IdentifierPPN;
485+import org.goobi.webapi.dao.GoobiProcessDAO;
486+
487+import javax.ws.rs.GET;
488+import javax.ws.rs.Path;
489+import javax.ws.rs.PathParam;
490+import javax.ws.rs.Produces;
491+import javax.ws.rs.core.MediaType;
492+import java.util.ArrayList;
493+import java.util.List;
494+
495+@Path("/processes")
496+public class Processes {
497+
498+ @GET
499+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
500+ public List<GoobiProcess> getProcesses() {
501+ List<GoobiProcess> processes = new ArrayList<GoobiProcess>();
502+
503+ processes.addAll(GoobiProcessDAO.getAllProcesses());
504+
505+ return processes;
506+ }
507+
508+ @GET
509+ @Path("{ppnIdentifier}")
510+ public GoobiProcess getProcess(@PathParam("ppnIdentifier") IdentifierPPN ippn) {
511+
512+ GoobiProcess process = GoobiProcessDAO.getProcessByPPN(ippn);
513+
514+ if (process == null) {
515+ throw new NotFoundException("No such process.");
516+ }
517+
518+ return process;
519+ }
520+
521+ @GET
522+ @Path("{ppnIdentifier}/steps")
523+ public List<GoobiProcessStep> getProcessSteps(@PathParam("ppnIdentifier") IdentifierPPN ippn) {
524+
525+ List<GoobiProcessStep> resultList = GoobiProcessDAO.getAllProcessSteps(ippn);
526+
527+ if (resultList.isEmpty()) {
528+ throw new NotFoundException("No such process.");
529+ }
530+
531+ return resultList;
532+ }
533+
534+}
535
536=== added directory 'test/src/org/goobi/webapi'
537=== added directory 'test/src/org/goobi/webapi/beans'
538=== added file 'test/src/org/goobi/webapi/beans/IdentifierPPNTest.java'
539--- test/src/org/goobi/webapi/beans/IdentifierPPNTest.java 1970-01-01 00:00:00 +0000
540+++ test/src/org/goobi/webapi/beans/IdentifierPPNTest.java 2012-07-30 14:30:32 +0000
541@@ -0,0 +1,79 @@
542+/*
543+ * This file is part of the Goobi Application - a Workflow tool for the support of
544+ * mass digitization.
545+ *
546+ * Visit the websites for more information.
547+ * - http://gdz.sub.uni-goettingen.de
548+ * - http://www.goobi.org
549+ * - http://launchpad.net/goobi-production
550+ *
551+ * This program is free software; you can redistribute it and/or modify it under
552+ * the terms of the GNU General Public License as published by the Free Software
553+ * Foundation; either version 2 of the License, or (at your option) any later
554+ * version.
555+ *
556+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
557+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
558+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
559+ * should have received a copy of the GNU General Public License along with this
560+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
561+ * Suite 330, Boston, MA 02111-1307 USA
562+ */
563+
564+package org.goobi.webapi.beans;
565+
566+import junit.framework.Assert;
567+import org.junit.Test;
568+
569+public class IdentifierPPNTest {
570+
571+ @Test
572+ public void validPpnShouldValidateAsCorrect() {
573+ String identifier = "32578597X";
574+
575+ Assert.assertTrue("Given PPN " + identifier + " should be correct.", IdentifierPPN.isValid(identifier));
576+ }
577+
578+ @Test
579+ public void lowerCaseValidPpnShouldBeCorrect() {
580+ String identifier = "32578597x";
581+
582+ Assert.assertTrue("Given lowercase PPN " + identifier + " should be correct.", IdentifierPPN.isValid(identifier));
583+
584+ }
585+
586+ @Test
587+ public void invalidPpnShouldBeFalse() {
588+ String identifier = "32578597A";
589+
590+ Assert.assertFalse("Given PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
591+ }
592+
593+ @Test
594+ public void emptyStringValueShouldBeFalse() {
595+ String identifier = "";
596+
597+ Assert.assertFalse("Empty string value should be invalid.", IdentifierPPN.isValid(identifier));
598+ }
599+
600+ @Test
601+ public void nullValueValidatedAsFalse() {
602+ String identifier = null;
603+
604+ Assert.assertFalse("Null value should be invalid.", IdentifierPPN.isValid(identifier));
605+ }
606+
607+ @Test
608+ public void toShortPpnShouldNotBeCorrect() {
609+ String identifier = "123";
610+
611+ Assert.assertFalse("To short PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
612+ }
613+
614+ @Test
615+ public void toLongPpnShouldNotBeCorrect() {
616+ String identifier = "1234567890";
617+
618+ Assert.assertFalse("To long PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
619+ }
620+}

Subscribers

People subscribed via source and target branches

to all changes: