forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSPStartSubmissionLookupStep.java
272 lines (252 loc) · 10.8 KB
/
JSPStartSubmissionLookupStep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.webui.submit.step;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.webui.submit.JSPStep;
import org.dspace.app.webui.submit.JSPStepManager;
import org.dspace.app.webui.util.JSPManager;
import org.dspace.app.webui.util.UIUtil;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.submit.lookup.SubmissionLookupDataLoader;
import org.dspace.submit.lookup.SubmissionLookupService;
import org.dspace.submit.step.StartSubmissionLookupStep;
import org.dspace.utils.DSpace;
/**
* Step which controls selecting an item from external database service to auto
* fill metadata for DSpace JSP-UI
* <P>
* This JSPStep class works with the SubmissionController servlet for the JSP-UI
* <P>
* The following methods are called in this order:
* <ul>
* <li>Call doPreProcessing() method</li>
* <li>If showJSP() was specified from doPreProcessing(), then the JSP specified
* will be displayed</li>
* <li>If showJSP() was not specified from doPreProcessing(), then the
* doProcessing() method is called an the step completes immediately</li>
* <li>Call doProcessing() method on appropriate AbstractProcessingStep after
* the user returns from the JSP, in order to process the user input</li>
* <li>Call doPostProcessing() method to determine if more user interaction is
* required, and if further JSPs need to be called.</li>
* <li>If there are more "pages" in this step then, the process begins again
* (for the new page).</li>
* <li>Once all pages are complete, control is forwarded back to the
* SubmissionController, and the next step is called.</li>
* </ul>
*
* @see org.dspace.app.webui.servlet.SubmissionController
* @see org.dspace.app.webui.submit.JSPStep
* @see org.dspace.submit.step.StartSubmissionLookupStep
*
* @author Andrea Bollini
* @version $Revision$
*/
public class JSPStartSubmissionLookupStep extends JSPStep
{
/** JSP which displays HTML for this Class * */
private static final String START_LOOKUP_JSP = "/submit/start-lookup-submission.jsp";
/** log4j logger */
private static Logger log = Logger
.getLogger(JSPStartSubmissionLookupStep.class);
SubmissionLookupService slService = new DSpace().getServiceManager()
.getServiceByName(SubmissionLookupService.class.getCanonicalName(),
SubmissionLookupService.class);
/**
* Do any pre-processing to determine which JSP (if any) is used to generate
* the UI for this step. This method should include the gathering and
* validating of all data required by the JSP. In addition, if the JSP
* requires any variable to passed to it on the Request, this method should
* set those variables.
* <P>
* If this step requires user interaction, then this method must call the
* JSP to display, using the "showJSP()" method of the JSPStepManager class.
* <P>
* If this step doesn't require user interaction OR you are solely using
* Manakin for your user interface, then this method may be left EMPTY,
* since all step processing should occur in the doProcessing() method.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*/
public void doPreProcessing(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
if (request.getAttribute("no.collection") == null
|| !(Boolean) request.getAttribute("no.collection"))
{
request.setAttribute("s_uuid", UUID.randomUUID().toString());
}
/*
* Possible parameters from JSP:
*
* collection= <collection_id> - a collection that has already been
* selected (to use as preference! it is not the final choice!!!)
*
* collectionid = the FINAL chosed collection!!!
*
* With no parameters, this servlet prepares for display of the Select
* Collection JSP.
*/
int collection_id = UIUtil.getIntParameter(request, "collection");
int collectionID = UIUtil.getIntParameter(request, "collectionid");
Collection col = null;
if (collectionID != -1)
{
col = Collection.find(context, collectionID);
}
// if we already have a valid collection, then we can forward directly
// to post-processing
if (col != null)
{
log.debug("Select Collection page skipped, since a Collection ID was already found. Collection ID="
+ collectionID);
}
else
{
// gather info for JSP page
Community com = UIUtil.getCommunityLocation(request);
Collection[] collections;
if (com != null)
{
// In a community. Show collections in that community only.
collections = Collection.findAuthorized(context, com,
Constants.ADD);
}
else
{
// Show all collections
collections = Collection.findAuthorized(context, null,
Constants.ADD);
}
// save collections to request for JSP
request.setAttribute("collections", collections);
request.setAttribute("collection_id", collection_id);
request.setAttribute("collectionID", collectionID);
Map<String, List<String>> identifiers2providers = slService
.getProvidersIdentifiersMap();
List<String> searchProviders = slService.getSearchProviders();
List<String> fileProviders = slService.getFileProviders();
request.setAttribute("identifiers2providers", identifiers2providers);
request.setAttribute("searchProviders", searchProviders);
request.setAttribute("fileLoaders", fileProviders);
request.setAttribute("identifiers", slService.getIdentifiers());
// we need to load the select collection JSP
JSPStepManager
.showJSP(request, response, subInfo, START_LOOKUP_JSP);
}
}
/**
* Do any post-processing after the step's backend processing occurred (in
* the doProcessing() method).
* <P>
* It is this method's job to determine whether processing completed
* successfully, or display another JSP informing the users of any potential
* problems/errors.
* <P>
* If this step doesn't require user interaction OR you are solely using
* Manakin for your user interface, then this method may be left EMPTY,
* since all step processing should occur in the doProcessing() method.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
* @param status
* any status/errors reported by doProcessing() method
*/
public void doPostProcessing(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo, int status)
throws ServletException, IOException, SQLException,
AuthorizeException
{
// if the user didn't select a collection,
// send him/her back to "select a collection" page
if (status == StartSubmissionLookupStep.STATUS_NO_COLLECTION)
{
// specify "no collection" error message should be displayed
request.setAttribute("no.collection", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
}
else if (status == StartSubmissionLookupStep.STATUS_INVALID_COLLECTION)
{
JSPManager.showInvalidIDError(request, response,
request.getParameter("collectionid"), Constants.COLLECTION);
}
else if (status == StartSubmissionLookupStep.STATUS_NO_SUUID)
{
// specify "no suuid" error message should be displayed
request.setAttribute("no.suuid", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
}
else if (status == StartSubmissionLookupStep.STATUS_SUBMISSION_EXPIRED)
{
// specify "no collection" error message should be displayed
request.setAttribute("expired", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
}
else if (status != StartSubmissionLookupStep.STATUS_COMPLETE)
{
// specify "no suuid" error message should be displayed
request.setAttribute("no.suuid", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
}
}
/**
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP which
* will review the information that was gathered in this Step.
* <P>
* This Review JSP is loaded by the 'Verify' Step, in order to dynamically
* generate a submission verification page consisting of the information
* gathered in all the enabled submission steps.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*/
public String getReviewJSP(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
{
return NO_JSP; // at this time, you cannot review what collection you
// selected.
}
}