Commit 0f9229ad authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

#16027 for review

parent 66a4cbef
package org.genesys2.server.model.impl;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.AclAwareModel;
@Entity
@Table(name = "user_accession_list")
public class UserAccessionList implements AclAwareModel {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false, length = 20)
private Long id;
@Column(name = "title", nullable = false)
private String title;
@Column(name = "description", nullable = true)
private String description;
@Column(name = "accessionIds", nullable = true)
private String accessionIdsStr;
@Transient
private Set<Long> accessionIds;
@Override
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAccessionIdsStr() {
return accessionIdsStr;
}
public void setAccessionIdsStr(String accessionIdsStr) {
this.accessionIdsStr = accessionIdsStr;
// TODO review
if (accessionIdsStr != null) {
accessionIds = new HashSet<>();
for (String id : accessionIdsStr.split(",")) {
accessionIds.add(Long.valueOf(id));
}
}
}
public Set<Long> getAccessionIds() {
if (accessionIdsStr != null) {
accessionIds = new HashSet<>();
for (String id : accessionIdsStr.split(",")) {
accessionIds.add(Long.valueOf(id));
}
}
return accessionIds;
}
public void setAccessionIds(Set<Long> accessionIds) {
this.accessionIds = accessionIds;
if (accessionIds != null) {
this.accessionIdsStr = StringUtils.join(accessionIds, ",");
}
}
}
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.impl.UserAccessionList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface UserAccessionListRepository extends JpaRepository<UserAccessionList, Long> {
@Query("select ual from UserAccessionList ual where ual.id = :id")
UserAccessionList findById(@Param("id") Long id);
}
package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.impl.UserAccessionList;
public interface UserAccessionListService {
UserAccessionList getUserAccesionListById(Long id);
void save(UserAccessionList userAccessionList);
List<UserAccessionList> getAll();
void delete(Long id);
void update(UserAccessionList userAccessionList);
}
package org.genesys2.server.service.impl;
import java.util.List;
import javax.transaction.Transactional;
import org.genesys2.server.model.impl.UserAccessionList;
import org.genesys2.server.persistence.domain.UserAccessionListRepository;
import org.genesys2.server.service.UserAccessionListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Transactional
public class UserAccessionListServiceImpl implements UserAccessionListService {
@Autowired
UserAccessionListRepository userAccessionListRepository;
@Override
public UserAccessionList getUserAccesionListById(Long id) {
return userAccessionListRepository.findById(id);
}
@Override
public void save(UserAccessionList userAccessionList) {
userAccessionListRepository.save(userAccessionList);
}
@Override
public List<UserAccessionList> getAll() {
return userAccessionListRepository.findAll();
}
@Override
public void delete(Long id) {
userAccessionListRepository.delete(id);
}
@Override
public void update(UserAccessionList userAccessionList) {
Long ualId = userAccessionList.getId();
UserAccessionList updateUserAccessionList = userAccessionListRepository.findById(ualId);
updateUserAccessionList.setTitle(userAccessionList.getTitle());
updateUserAccessionList.setAccessionIds(userAccessionList.getAccessionIds());
updateUserAccessionList.setAccessionIdsStr(userAccessionList.getAccessionIdsStr());
updateUserAccessionList.setDescription(userAccessionList.getDescription());
userAccessionListRepository.save(updateUserAccessionList);
}
}
......@@ -27,9 +27,11 @@ import javax.servlet.http.HttpServletResponse;
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.UserAccessionList;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.UserAccessionListService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
......@@ -38,7 +40,9 @@ 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.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -61,13 +65,27 @@ public class SelectionController extends BaseController {
@Autowired
private DownloadService downloadService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
@Autowired
private UserAccessionListService userAccessionListService;
@RequestMapping("/")
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "listId", defaultValue = "0") long listid) {
if (listid != 0) {
UserAccessionList userAccessionList = userAccessionListService.getUserAccesionListById(listid);
selectionBean.clear();
for (Long accessionId : userAccessionList.getAccessionIds()) {
selectionBean.add(accessionId);
}
model.addAttribute("userAccessionList", userAccessionList);
}
model.addAttribute("pagedData", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
model.addAttribute("selection", selectionBean);
model.addAttribute("userAccessionLists", userAccessionListService.getAll());
return "/selection/index";
}
......@@ -96,7 +114,7 @@ public class SelectionController extends BaseController {
final long accessionId = Long.parseLong(s);
final Accession accession = genesysService.getAccession(accessionId);
if (accession != null) {
selectionBean.add(accession.getId());
selectionBean.add(accessionId);
}
} catch (final NumberFormatException e) {
......@@ -119,7 +137,7 @@ public class SelectionController extends BaseController {
/**
* Download DwCA of selected accessions
*
*
* @param model
* @param cropName
* @param jsonFilter
......@@ -240,4 +258,56 @@ public class SelectionController extends BaseController {
public String accessionName;
public String instCode;
}
@RequestMapping(value = "/userList", params = { "save" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
public String saveAccessionList(@RequestParam(value = "listId", defaultValue = "0") long listId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam String title, @RequestParam String description,
Model model) {
UserAccessionList userAccessionList;
if (listId != 0) {
userAccessionList = userAccessionListService.getUserAccesionListById(listId);
userAccessionList.setDescription(description);
userAccessionList.setTitle(title);
userAccessionList.setAccessionIds(selectionBean.copy());
userAccessionListService.update(userAccessionList);
} else {
userAccessionList = new UserAccessionList();
userAccessionList.setDescription(description);
userAccessionList.setTitle(title);
userAccessionList.setAccessionIds(selectionBean.copy());
userAccessionListService.save(userAccessionList);
}
model.addAttribute("resultFromSave", "user.accession.list.saved-updated");
model.addAttribute("pagedData", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
model.addAttribute("selection", selectionBean);
model.addAttribute("userAccessionLists", userAccessionListService.getAll());
return "/selection/index";
}
@RequestMapping(value = "/userList", params = { "delete" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
public String deleteAccessionList(@RequestParam(value = "listId", defaultValue = "0") long listId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page, Model model) {
userAccessionListService.delete(listId);
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", userAccessionListService.getAll());
return "/selection/index";
}
}
......@@ -457,6 +457,11 @@ article.transifex-failed=An error occured while exchanging data with Transifex
article.translations-updated=Resource successfully updated with translated data!
article.share=Share this article
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
activitypost=Activity post
activitypost.add-new-post=Add new post
activitypost.post-title=Post title
......
......@@ -15,9 +15,22 @@
</div>
</c:if>
<c:if test="${pagedData != null}">
<div class="main-col-header clearfix">
<div class="form-group">
<div class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><c:out value="Browse"/> <b
class="caret"></b></a>
<ul class="dropdown-menu" role="menu" id="user-accession-lists">
<li><a href="<c:url value="/sel/"/>"></a></li>
<c:forEach items="${userAccessionLists}" var="userList">
<li><a href="/sel/?listId=${userList.id}">${userList.title}</a></li>
</c:forEach>
</ul>
</div>
</div>
<c:if test="${pagedData != null}">
<div class="main-col-header clearfix">
<div class="nav-header">
<div class="results"><spring:message code="accessions.number" arguments="${pagedData.totalElements}" /></div>
......@@ -70,6 +83,33 @@
</tbody>
</table>
<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/userList"/>" role="form">
<div class="form-group">
<label for="accessionListTitle">Title*</label>
<input id="accessionListTitle" type="text" name="title" class="form-control"
value="${userAccessionList.title}"/>
</div>
<div class="form-group">
<label for="accessionListDescr">Description</label>
<textarea name="description" rows="3" id="accessionListDescr"
class="form-control"><c:out value="${userAccessionList.description}"/></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Save list" name="save"/>
<c:if test="${userAccessionList.id ne null}">
<input type="hidden" name="listId" value="${userAccessionList.id}"/>
<input type="submit" class="btn" value="Delete" name="<spring:message code="user.accession.list.delete"/>"/>
</c:if>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
</div>
<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>
......
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