}
rearrangeList(idsList, request);
return returnView();
}
Person author_editor = (Person) command;
if (request.getParameter("method") == null) {
List<String> errorsEncountered = verifyEachParameter(author_editor);
if (errorsEncountered.size() > 0) {
errorsEncountered.add(
0,
"Sorry, form could not be submissitted for reasons see below.");
request.getSession().setAttribute("errors", errorsEncountered);
return returnView();
}
author_editor.setFirstName(author_editor.getFirstName().trim());
author_editor.setLastName(author_editor.getLastName().trim());
if (author_editor.getMiddleName().trim().length() > 0) {
author_editor.setMiddleName(author_editor.getMiddleName().trim());
}
}
// Get the existing list of authors for the citation
Study study = ControllerUtil.findStudy(request, mStudyService);
Citation citation = study.getCitation();
if (citation == null) {
request.getSession().setAttribute(
"errors",
"Please provide the citataion for this study first.");
return showForm(request, response, bindExp);
}
// list of original author/editors associated with the citation
List<Person> currentPersons = getPeople(citation);
// Check permission that the user has the edit right:
// Currently it is not necessary since the only delete link can be hacked by direct editing
// the url.
// but the delete can only work with this particular study.
TBPermission perm = getStudyService().getPermission(request.getRemoteUser(), study.getId());
if (perm != TBPermission.WRITE) {
// Give error message and return
// return;
}
if (request.getParameter(ACTION_CANCEL) == null) {
// update the author list based the user selection
if (request.getParameter("method") != null
&& request.getParameter("method").equals(ACTION_DELETE)) {
String id = request.getParameter("id");
for (Person person : currentPersons) {
if (person.getId().equals(Long.parseLong((id)))) {
currentPersons.remove(person);
break;
}
}
}
else if (request.getParameter(ACTION_SUBMIT) != null
|| request.getParameter("Submit and Continue") != null) {
// look for match in "Person" table
Person p = mPersonService.findByExactMatch(author_editor);
// no match
if (p == null) {
// add "author" to Person table
mPersonService.createPerson(author_editor);
// add "author" to citation_author table