Commit 1698424d authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated management of accession lists in /sel

parent c3f89158
......@@ -14,36 +14,42 @@
* limitations under the License.
**/
package org.genesys2.server.model.impl;
package org.genesys2.server.model.json;
import java.io.Serializable;
import java.util.UUID;
import org.genesys2.server.model.impl.AccessionList;
public class UserAccessionList implements Serializable {
private static final long serialVersionUID = -2092185410372557368L;
private Long id;
public UUID uuid;
public String title;
public String description;
public static UserAccessionList from(AccessionList ual) {
UserAccessionList ul = new UserAccessionList();
ul.id = ual.getId();
ul.uuid = ual.getUuid();
ul.title = ual.getTitle();
ul.description = ual.getDescription();
return ul;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public Long getId() {
return id;
}
public class UserAccessionList {
public static class UserAccessionList_ implements Serializable {
private static final long serialVersionUID = -2092185410372557368L;
public long id;
public String title;
public String description;
public static UserAccessionList_ from(AccessionList ual) {
UserAccessionList_ ul = new UserAccessionList_();
ul.id = ual.getId();
ul.title = ual.getTitle();
ul.description = ual.getDescription();
return ul;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public long getId() {
return id;
}
public UUID getUuid() {
return uuid;
}
}
......@@ -2,7 +2,7 @@ package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.impl.UserAccessionList;
import org.genesys2.server.model.json.UserAccessionList;
public interface UserAccessionListService {
......
......@@ -21,7 +21,7 @@ import java.util.HashSet;
import java.util.Set;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.UserAccessionList.UserAccessionList_;
import org.genesys2.server.model.json.UserAccessionList;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
......@@ -32,7 +32,7 @@ public class SelectionBean implements Serializable {
private final Set<Long> accessionIds = new HashSet<Long>();
private UserAccessionList_ userAccessionList;
private UserAccessionList userAccessionList;
public Set<Long> getAccessionIds() {
return accessionIds;
......@@ -66,11 +66,11 @@ public class SelectionBean implements Serializable {
return accessionIds.size();
}
public void setUserAccessionList(UserAccessionList_ userAccessionList) {
public void setUserAccessionList(UserAccessionList userAccessionList) {
this.userAccessionList = userAccessionList;
}
public UserAccessionList_ getUserAccessionList() {
public UserAccessionList getUserAccessionList() {
return userAccessionList;
}
}
......@@ -21,14 +21,16 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.impl.AccessionList;
import org.genesys2.server.model.impl.UserAccessionList;
import org.genesys2.server.model.json.UserAccessionList;
import org.genesys2.server.service.AccessionListService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.FilterConstants;
......@@ -36,11 +38,13 @@ import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
......@@ -53,6 +57,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@Scope("request")
......@@ -71,6 +76,9 @@ public class SelectionController extends BaseController {
@Autowired
private AccessionListService accessionListService;
@Autowired
private PermissionEvaluator permissionEvaluator;
@RequestMapping(value = "/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......@@ -87,21 +95,24 @@ public class SelectionController extends BaseController {
return "/selection/index";
}
@RequestMapping(value = "/load", params = { "listId" })
@RequestMapping(value = "/load", params = { "list" })
@PreAuthorize("isAuthenticated()")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "listId", defaultValue = "0") long listid) {
@RequestParam(value = "list", required = true) UUID uuid) {
if (listid != 0) {
AccessionList list = accessionListService.getList(listid);
AccessionList list = accessionListService.getList(uuid);
if (list != null) {
Set<Long> accessionIds = accessionListService.getAccessionIds(list);
selectionBean.clear();
for (Long accessionId : accessionIds) {
selectionBean.add(accessionId);
}
// FIXME
// selectionBean.setUserAccessionList(UserAccessionList.UserAccessionList_.from(userAccessionList));
// If I have permissions to manage list:
if (permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), list, "WRITE")) {
_logger.info("User has WRITE parmission on AccessionList");
selectionBean.setUserAccessionList(UserAccessionList.from(list));
}
}
return "redirect:/sel/";
......@@ -125,17 +136,26 @@ public class SelectionController extends BaseController {
}
@RequestMapping(method = RequestMethod.POST, value = "add-many")
public String add(ModelMap model, @RequestParam(required = true, value = "accessionIds") String accessionIds) {
final String[] splits = accessionIds.split("\\s");
public String add(ModelMap model, RedirectAttributes redirectAttrs, @RequestParam(required = true, value = "instCode") String instCode,
@RequestParam(required = true, value = "accessionIds") String accessionIds) {
if (StringUtils.isBlank(instCode)) {
return "redirect:/sel/";
}
final String[] splits = accessionIds.split("[,;\\t\\n]+");
for (final String s : splits) {
System.err.println(">> '" + s.trim() + "'");
try {
final long accessionId = Long.parseLong(s);
final Accession accession = genesysService.getAccession(accessionId);
final Accession accession = genesysService.getAccession(instCode, s.trim());
if (accession != null) {
selectionBean.add(accessionId);
System.err.println("\t" + accession.getId());
selectionBean.add(accession.getId());
} else {
System.err.println("\t NF='" + s + "'");
}
} catch (final NumberFormatException e) {
} catch (NonUniqueAccessionException e) {
// Non-unique
}
}
return "redirect:/sel/";
......@@ -279,22 +299,21 @@ public class SelectionController extends BaseController {
@RequestMapping(value = "/userList", params = { "save" }, method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
public String saveAccessionList(@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam String title,
@RequestParam String description, ModelMap model) {
public String saveAccessionList(@RequestParam String title, @RequestParam String description, RedirectAttributes redirectAttrs) {
AccessionList accessionList = new AccessionList();
return saveOrUpdateList(page, title, description, model, accessionList);
return saveOrUpdateList(title, description, redirectAttrs, accessionList);
}
@RequestMapping(value = "/userList", params = { "update", "listId" }, method = RequestMethod.POST)
@RequestMapping(value = "/userList", params = { "update", "uuid" }, method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
public String updateAccessionList(@RequestParam(value = "listId") long listId, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam String title, @RequestParam String description, ModelMap model) {
public String updateAccessionList(@RequestParam(value = "uuid") UUID uuid, @RequestParam String title, @RequestParam String description,
RedirectAttributes redirectAttrs) {
AccessionList accessionList = accessionListService.getList(listId);
AccessionList accessionList = accessionListService.getList(uuid);
return saveOrUpdateList(page, title, description, model, accessionList);
return saveOrUpdateList(title, description, redirectAttrs, accessionList);
}
/**
......@@ -307,41 +326,35 @@ public class SelectionController extends BaseController {
* @param accessionList
* @return
*/
private String saveOrUpdateList(int page, String title, String description, ModelMap model, AccessionList accessionList) {
private String saveOrUpdateList(String title, String description, RedirectAttributes redirectAttrs, AccessionList accessionList) {
accessionList.setDescription(description);
accessionList.setTitle(title);
accessionListService.save(accessionList);
accessionListService.removeAll(accessionList);
accessionListService.addToList(accessionList, selectionBean.copy());
selectionBean.setUserAccessionList(UserAccessionList.UserAccessionList_.from(accessionList));
selectionBean.setUserAccessionList(UserAccessionList.from(accessionList));
model.addAttribute("resultFromSave", "user.accession.list.saved-updated");
redirectAttrs.addFlashAttribute("resultFromSave", "user.accession.list.saved-updated");
return view(model, page);
return "redirect:/sel/";
}
@RequestMapping(value = "/userList", params = { "delete" }, method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
public String deleteAccessionList(@RequestParam(value = "listId", defaultValue = "0") long listId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page, Model model) {
public String deleteAccessionList(@RequestParam(value = "uuid") UUID uuid, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
Model model, RedirectAttributes redirectAttrs) {
accessionListService.delete(accessionListService.getList(listId));
accessionListService.delete(accessionListService.getList(uuid));
selectionBean.setUserAccessionList(null);
model.addAttribute("resultFromSave", "user.accession.list.deleted");
model.addAttribute("pagedData", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
model.addAttribute("selection", selectionBean);
model.addAttribute("userAccessionLists", accessionListService.getMyLists());
return "/selection/index";
redirectAttrs.addFlashAttribute("resultFromSave", "user.accession.list.deleted");
return "redirect:/sel/";
}
@RequestMapping(value = "/userList", params = { "disconnect" }, method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
public String disconnectAccessionList(@RequestParam(value = "listId", defaultValue = "0") long listId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page, Model model) {
public String disconnectAccessionList(Model model) {
selectionBean.setUserAccessionList(null);
......
......@@ -352,8 +352,10 @@ selection.reload-list=Reload the list
selection.map=Show accession map
selection.send-request=Send request for germplasm
selection.empty-list-warning=You have not added any accessions to the list.
selection.add-many=Check and add
selection.add-many.accessionIds=List accession IDs as used in Genesys separated by space or new line.
selection.add-many=Add multiple accessions
selection.add-many.accessionIds=List accession numbers (ACCENUMB) as recorded in Genesys, separated by comma, semicolon or new line.
selection.add-many.instCode=Holding institute WIEWS code
selection.add-many.button=Add to selection list
savedmaps=Remember current map
savedmaps.list=Map list
......@@ -462,6 +464,7 @@ user.accession.list.saved-updated=Your list of accessions successful saved.
user.accession.list.deleted=Your list of accessions successful deleted from server.
user.accession.list.create-update=Save
user.accession.list.delete=Delete
user.accession.list.title=Accession List
activitypost=Activity post
activitypost.add-new-post=Add new post
......@@ -721,3 +724,4 @@ userlist.title=List title
userlist.description=List description
userlist.disconnect=Disconnect list
userlist.update-list=Save updated list
userlist.make-new-list=Create new list
......@@ -106,3 +106,7 @@ html[dir="rtl"] {
.text-clip {
@include text-overflow;
}
.btn-default {
background-color: #eee;
}
\ No newline at end of file
......@@ -9,6 +9,10 @@
<body>
<cms:informative-h1 title="selection.page.title" fancy="true" info="selection.page.intro" />
<c:if test="${resultFromSave ne null}">
<div class="alert alert-warning"><spring:message code="${resultFromSave}" /></div>
</c:if>
<c:if test="${pagedData == null}">
<div class="alert alert-info">
<spring:message code="selection.empty-list-warning"/>
......@@ -20,7 +24,7 @@
<spring:message code="userlist.list-my-lists" />
<ul class="funny-list" role="" id="user-accession-lists">
<c:forEach items="${userAccessionLists}" var="userList">
<li><a href="/sel/load?listId=${userList.id}">${userList.title}</a>
<li><a href="/sel/load?list=${userList.uuid}">${userList.title}</a>
<div class="pull-right"><c:out value="${userList.description}" /></div>
</li>
</c:forEach>
......@@ -58,20 +62,6 @@
</div>
</div>
<security:authorize access="isAuthenticated()">
<div class="form-group">
<div class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><spring:message code="userlist.list-my-lists" /> <b
class="caret"></b></a>
<ul class="dropdown-menu" role="menu" id="user-accession-lists">
<c:forEach items="${userAccessionLists}" var="userList">
<li><a href="/sel/load?listId=${userList.id}">${userList.title}</a></li>
</c:forEach>
</ul>
</div>
</div>
</security:authorize>
<table class="accessions">
<thead>
<tr>
......@@ -99,11 +89,71 @@
</tbody>
</table>
<security:authorize access="isAuthenticated()">
<div class="form-group">
<c:if test="${resultFromSave ne null}">
<div class="alert alert-warning"><spring:message code="${resultFromSave}" /></div>
</c:if>
<form method="post" action="<c:url value="/sel/order" />" class="form-vertical">
<div class="form-actions">
<a href="<c:url value="/sel/" />"><button class="btn btn-default" type="button"><spring:message code="selection.reload-list" /></button></a>
<button class="btn btn-primary" type="submit"><spring:message code="selection.send-request" /></button>
<a href="<c:url value="/sel/clear" />" class="btn btn-default"><spring:message code="selection.clear" /></a>
<a href="<c:url value="/sel/map" />" class="btn btn-default"><spring:message code="selection.map" /></a>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</c:if>
<div style="margin-top: 60px">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#tab-add-many" aria-controls="tab-add-many" role="tab" data-toggle="tab"><spring:message code="selection.add-many" /></a></li>
<security:authorize access="isAuthenticated()">
<li role="presentation"><a href="#tab-manage-list" aria-controls="tab-manage-list" role="tab" data-toggle="tab"><spring:message code="user.accession.list.title" /></a></li>
</security:authorize>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tab-add-many">
<form method="post" action="<c:url value="/sel/add-many" />" class="">
<div class="form-group">
<label for="accessionIds" class="control-label"><spring:message code="selection.add-many.accessionIds" /></label>
<div class="controls">
<textarea class="form-control" placeholder="IG 523121, TMB-1" name="accessionIds"></textarea>
</div>
</div>
<div class="form-group">
<label for="accessionIds" class="control-label"><spring:message code="selection.add-many.instCode" /></label>
<div class="controls">
<input class="form-control" placeholder="XXX000" name="instCode" />
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="<spring:message code="selection.add-many.button" />" />
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</div>
<security:authorize access="isAuthenticated()">
<div role="tabpanel" class="tab-pane" id="tab-manage-list">
<div class="form-group">
<div class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><spring:message code="userlist.list-my-lists" /> <b
class="caret"></b></a>
<ul class="dropdown-menu" role="menu" id="user-accession-lists">
<c:forEach items="${userAccessionLists}" var="userList">
<li><a href="/sel/load?list=${userList.uuid}">${userList.title}</a></li>
</c:forEach>
</ul>
</div>
</div>
<div class="form-group">
<form method="post" action="<c:url value="/sel/userList"/>" role="form">
<div class="form-group">
<label for="accessionListTitle"><spring:message code="userlist.title" /></label>
......@@ -116,50 +166,28 @@
class="form-control"><c:out value="${selection.userAccessionList.description}"/></textarea>
</div>
<div class="form-group">
<c:if test="${selection.userAccessionList.id ne null}">
<input type="hidden" name="listId" value="${selection.userAccessionList.id}"/>
<c:if test="${selection.userAccessionList.uuid ne null}">
<input type="hidden" name="uuid" value="${selection.userAccessionList.uuid}"/>
<input type="submit" class="btn btn-primary" value="<spring:message code="userlist.update-list"/>" name="update" />
<input type="submit" class="btn btn-primary" value="<spring:message code="userlist.disconnect"/>" name="disconnect" />
<input type="submit" class="btn" value="<spring:message code="delete"/>" name="delete" />
<input type="submit" class="btn btn-default" value="<spring:message code="userlist.disconnect"/>" name="disconnect" />
<input type="submit" class="btn btn-default" value="<spring:message code="delete"/>" name="delete" />
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#selection.userAccessionList, 'ADMINISTRATOR')">
<a class="btn btn-default" href="<c:url value="/acl/org.genesys2.server.model.impl.AccessionList/${selection.userAccessionList.id}/permissions"><c:param name="back"><c:url value="/sel" /></c:param></c:url>">
<spring:message code="edit-acl"/>
</a>
</security:authorize>
</c:if>
<input type="submit" class="btn" value="<spring:message code="add"/>" name="save"/>
<input type="submit" class="btn btn-default" value="<spring:message code="userlist.make-new-list"/>" name="save"/>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</div>
</security:authorize>
<form method="post" action="<c:url value="/sel/order" />" class="form-vertical">
<div class="form-actions">
<a href="<c:url value="/sel/" />"><button class="btn" type="button"><spring:message code="selection.reload-list" /></button></a>
<button class="btn btn-primary" type="submit"><spring:message code="selection.send-request" /></button>
<a href="<c:url value="/sel/clear" />"><button class="btn" type="button"><spring:message code="selection.clear" /></button></a>
<a href="<c:url value="/sel/map" />"><button class="btn" type="button"><spring:message code="selection.map" /></button></a>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</c:if>
<%--
<c:if test="${pagedData eq null or pagedData.number eq 0}">
<h4 style="margin-top: 3em">Add multiple accessions</h4>
<form method="post" action="<c:url value="/sel/add-many" />" class="form-horizontal">
<div class="control-group">
<label for="accessionIds" class="control-label"><spring:message code="selection.add-many.accessionIds" /></label>
<div class="controls">
<textarea class="form-control" placeholder="12345 123545 423231" name="accessionIds"></textarea>
</div>
</div>
<div class="form-actions clearfix">
<input type="submit" class="btn" value="<spring:message code="selection.add-many" />" />
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</c:if>
--%>
</form>
</div>
</div>
</security:authorize>
</div>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment