Merge lp:~slub.team/goobi-production/bug-1032182 into lp:goobi-production/1.8

Proposed by Henning Gerhardt
Status: Merged
Merged at revision: 90
Proposed branch: lp:~slub.team/goobi-production/bug-1032182
Merge into: lp:goobi-production/1.8
Diff against target: 266 lines (+18/-157)
4 files modified
src/org/goobi/webapi/beans/IdentifierPPN.java (+0/-61)
src/org/goobi/webapi/dao/GoobiProcessDAO.java (+14/-12)
src/org/goobi/webapi/resources/Processes.java (+4/-5)
test/src/org/goobi/webapi/beans/IdentifierPPNTest.java (+0/-79)
To merge this branch: bzr merge lp:~slub.team/goobi-production/bug-1032182
Reviewer Review Type Date Requested Status
Matthias Ronge (community) Approve
Ralf Claussnitzer (community) Approve
Review via email: mp+117916@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ralf Claussnitzer (ralf-claussnitzer-deactivatedaccount) :
review: Approve
Revision history for this message
Ralf Claussnitzer (ralf-claussnitzer-deactivatedaccount) wrote :

Fix approved, but reveals more severe bug #1033580

Revision history for this message
Matthias Ronge (matthias-ronge) wrote :

Tested OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'src/org/goobi/webapi/beans/IdentifierPPN.java'
2--- src/org/goobi/webapi/beans/IdentifierPPN.java 2012-07-27 17:07:00 +0000
3+++ src/org/goobi/webapi/beans/IdentifierPPN.java 1970-01-01 00:00:00 +0000
4@@ -1,61 +0,0 @@
5-/*
6- * This file is part of the Goobi Application - a Workflow tool for the support of
7- * mass digitization.
8- *
9- * Visit the websites for more information.
10- * - http://gdz.sub.uni-goettingen.de
11- * - http://www.goobi.org
12- * - http://launchpad.net/goobi-production
13- *
14- * This program is free software; you can redistribute it and/or modify it under
15- * the terms of the GNU General Public License as published by the Free Software
16- * Foundation; either version 2 of the License, or (at your option) any later
17- * version.
18- *
19- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
20- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21- * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
22- * should have received a copy of the GNU General Public License along with this
23- * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24- * Suite 330, Boston, MA 02111-1307 USA
25- */
26-
27-package org.goobi.webapi.beans;
28-
29-import java.util.regex.Matcher;
30-import java.util.regex.Pattern;
31-
32-public class IdentifierPPN {
33-
34- private String ppn;
35-
36- public IdentifierPPN(String ppn) {
37- if (!isValid(ppn)) {
38- throw new IllegalArgumentException("Given string is not a valid PPN identifier.");
39- }
40- this.ppn = ppn;
41- }
42-
43- public static boolean isValid(String identifier) {
44- Boolean result;
45- int flags = Pattern.CASE_INSENSITIVE;
46- Pattern pattern;
47- Matcher matcher;
48-
49- if ((identifier == null) || (identifier.length() == 0)) {
50- result = false;
51- } else {
52- pattern = Pattern.compile("^[0-9]{8}[0-9LXYZ]{1}$", flags);
53- matcher = pattern.matcher(identifier);
54- result = matcher.matches();
55- }
56-
57- return result;
58- }
59-
60- public String toString() {
61- return ppn;
62- }
63-
64-
65-}
66
67=== modified file 'src/org/goobi/webapi/dao/GoobiProcessDAO.java'
68--- src/org/goobi/webapi/dao/GoobiProcessDAO.java 2012-07-30 14:03:15 +0000
69+++ src/org/goobi/webapi/dao/GoobiProcessDAO.java 2012-08-02 15:02:21 +0000
70@@ -28,7 +28,6 @@
71 import org.apache.log4j.Logger;
72 import org.goobi.webapi.beans.GoobiProcess;
73 import org.goobi.webapi.beans.GoobiProcessStep;
74-import org.goobi.webapi.beans.IdentifierPPN;
75 import org.hibernate.Criteria;
76 import org.hibernate.HibernateException;
77 import org.hibernate.Session;
78@@ -44,7 +43,7 @@
79
80 private static final Logger myLogger = Logger.getLogger(GoobiProcessDAO.class);
81
82- public static GoobiProcess getProcessByPPN(IdentifierPPN PPN) {
83+ public static GoobiProcess getProcessByIdentifier(String identifier) {
84 Session session;
85 GoobiProcess result = null;
86
87@@ -58,14 +57,15 @@
88 .createAlias("vorlagen.eigenschaften", "ve")
89 .createAlias("werkstuecke", "w")
90 .createAlias("werkstuecke.eigenschaften", "we")
91+ // key PPN digital a/f-Satz could contain any string value
92 .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
93 .add(Restrictions.eq("ve.titel", "Titel"))
94- .add(Restrictions.eq("we.wert", PPN.toString()))
95+ .add(Restrictions.eq("we.wert", identifier))
96 .addOrder(Order.asc("we.wert"))
97 .setProjection(Projections.projectionList()
98- .add(Projections.property("we.wert"), "identifier")
99- .add(Projections.property("ve.wert"), "title")
100- )
101+ .add(Projections.property("we.wert"), "identifier")
102+ .add(Projections.property("ve.wert"), "title")
103+ )
104 .setResultTransformer(Transformers.aliasToBean(GoobiProcess.class));
105
106 result = (GoobiProcess) criteria.uniqueResult();
107@@ -92,6 +92,7 @@
108 .createAlias("vorlagen.eigenschaften", "ve")
109 .createAlias("werkstuecke", "w")
110 .createAlias("werkstuecke.eigenschaften", "we")
111+ // key PPN digital a/f-Satz could contain any string value
112 .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
113 .add(Restrictions.eq("ve.titel", "Titel"))
114 .addOrder(Order.asc("we.wert"))
115@@ -114,7 +115,7 @@
116 return result;
117 }
118
119- public static List<GoobiProcessStep> getAllProcessSteps(IdentifierPPN PPN) {
120+ public static List<GoobiProcessStep> getAllProcessSteps(String identifier) {
121 List<GoobiProcessStep> result;
122 Session session;
123
124@@ -128,14 +129,15 @@
125 .createAlias("prozess", "p")
126 .createAlias("prozess.werkstuecke", "w")
127 .createAlias("prozess.werkstuecke.eigenschaften", "we")
128+ // key "PPN digital a/f-Satz" could contain any string value
129 .add(Restrictions.or(Restrictions.eq("we.titel", "PPN digital a-Satz"), Restrictions.eq("we.titel", "PPN digital f-Satz")))
130- .add(Restrictions.eq("we.wert", PPN.toString()))
131+ .add(Restrictions.eq("we.wert", identifier))
132 .addOrder(Order.asc("reihenfolge"))
133 .setProjection(Projections.projectionList()
134- .add(Projections.property("reihenfolge"), "sequence")
135- .add(Projections.property("bearbeitungsstatus"), "state")
136- .add(Projections.property("titel"), "title")
137- )
138+ .add(Projections.property("reihenfolge"), "sequence")
139+ .add(Projections.property("bearbeitungsstatus"), "state")
140+ .add(Projections.property("titel"), "title")
141+ )
142 .setResultTransformer(Transformers.aliasToBean(GoobiProcessStep.class));
143
144 @SuppressWarnings(value = "unchecked")
145
146=== modified file 'src/org/goobi/webapi/resources/Processes.java'
147--- src/org/goobi/webapi/resources/Processes.java 2012-07-30 14:01:10 +0000
148+++ src/org/goobi/webapi/resources/Processes.java 2012-08-02 15:02:21 +0000
149@@ -25,7 +25,6 @@
150 import com.sun.jersey.api.NotFoundException;
151 import org.goobi.webapi.beans.GoobiProcess;
152 import org.goobi.webapi.beans.GoobiProcessStep;
153-import org.goobi.webapi.beans.IdentifierPPN;
154 import org.goobi.webapi.dao.GoobiProcessDAO;
155
156 import javax.ws.rs.GET;
157@@ -51,9 +50,9 @@
158
159 @GET
160 @Path("{ppnIdentifier}")
161- public GoobiProcess getProcess(@PathParam("ppnIdentifier") IdentifierPPN ippn) {
162+ public GoobiProcess getProcess(@PathParam("ppnIdentifier") String identifier) {
163
164- GoobiProcess process = GoobiProcessDAO.getProcessByPPN(ippn);
165+ GoobiProcess process = GoobiProcessDAO.getProcessByIdentifier(identifier);
166
167 if (process == null) {
168 throw new NotFoundException("No such process.");
169@@ -64,9 +63,9 @@
170
171 @GET
172 @Path("{ppnIdentifier}/steps")
173- public List<GoobiProcessStep> getProcessSteps(@PathParam("ppnIdentifier") IdentifierPPN ippn) {
174+ public List<GoobiProcessStep> getProcessSteps(@PathParam("ppnIdentifier") String identifier) {
175
176- List<GoobiProcessStep> resultList = GoobiProcessDAO.getAllProcessSteps(ippn);
177+ List<GoobiProcessStep> resultList = GoobiProcessDAO.getAllProcessSteps(identifier);
178
179 if (resultList.isEmpty()) {
180 throw new NotFoundException("No such process.");
181
182=== removed directory 'test/src/org/goobi/webapi'
183=== removed directory 'test/src/org/goobi/webapi/beans'
184=== removed file 'test/src/org/goobi/webapi/beans/IdentifierPPNTest.java'
185--- test/src/org/goobi/webapi/beans/IdentifierPPNTest.java 2012-07-30 14:19:34 +0000
186+++ test/src/org/goobi/webapi/beans/IdentifierPPNTest.java 1970-01-01 00:00:00 +0000
187@@ -1,79 +0,0 @@
188-/*
189- * This file is part of the Goobi Application - a Workflow tool for the support of
190- * mass digitization.
191- *
192- * Visit the websites for more information.
193- * - http://gdz.sub.uni-goettingen.de
194- * - http://www.goobi.org
195- * - http://launchpad.net/goobi-production
196- *
197- * This program is free software; you can redistribute it and/or modify it under
198- * the terms of the GNU General Public License as published by the Free Software
199- * Foundation; either version 2 of the License, or (at your option) any later
200- * version.
201- *
202- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
203- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
204- * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
205- * should have received a copy of the GNU General Public License along with this
206- * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
207- * Suite 330, Boston, MA 02111-1307 USA
208- */
209-
210-package org.goobi.webapi.beans;
211-
212-import junit.framework.Assert;
213-import org.junit.Test;
214-
215-public class IdentifierPPNTest {
216-
217- @Test
218- public void validPpnShouldValidateAsCorrect() {
219- String identifier = "32578597X";
220-
221- Assert.assertTrue("Given PPN " + identifier + " should be correct.", IdentifierPPN.isValid(identifier));
222- }
223-
224- @Test
225- public void lowerCaseValidPpnShouldBeCorrect() {
226- String identifier = "32578597x";
227-
228- Assert.assertTrue("Given lowercase PPN " + identifier + " should be correct.", IdentifierPPN.isValid(identifier));
229-
230- }
231-
232- @Test
233- public void invalidPpnShouldBeFalse() {
234- String identifier = "32578597A";
235-
236- Assert.assertFalse("Given PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
237- }
238-
239- @Test
240- public void emptyStringValueShouldBeFalse() {
241- String identifier = "";
242-
243- Assert.assertFalse("Empty string value should be invalid.", IdentifierPPN.isValid(identifier));
244- }
245-
246- @Test
247- public void nullValueValidatedAsFalse() {
248- String identifier = null;
249-
250- Assert.assertFalse("Null value should be invalid.", IdentifierPPN.isValid(identifier));
251- }
252-
253- @Test
254- public void toShortPpnShouldNotBeCorrect() {
255- String identifier = "123";
256-
257- Assert.assertFalse("To short PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
258- }
259-
260- @Test
261- public void toLongPpnShouldNotBeCorrect() {
262- String identifier = "1234567890";
263-
264- Assert.assertFalse("To long PPN " + identifier + " should be invalid.", IdentifierPPN.isValid(identifier));
265- }
266-}

Subscribers

People subscribed via source and target branches

to all changes: