Commit c64295a1 authored by Matija Obreza's avatar Matija Obreza
Browse files

Revision of UserAccessionList

parent 0f9229ad
......@@ -5,43 +5,35 @@ 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.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.VersionedAuditedModel;
import org.hibernate.annotations.Type;
@Entity
@Table(name = "user_accession_list")
public class UserAccessionList implements AclAwareModel {
@Table
public class UserAccessionList extends VersionedAuditedModel 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;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Column(name = "accessionIds", nullable = true)
private String accessionIdsStr;
@Transient
private Set<Long> accessionIds;
@Override
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
......@@ -90,4 +82,17 @@ public class UserAccessionList implements AclAwareModel {
}
}
public static class UserAccessionList_ {
public long id;
public String title;
public String description;
public static UserAccessionList_ from(UserAccessionList ual) {
UserAccessionList_ ul = new UserAccessionList_();
ul.id = ual.getId();
ul.title = ual.getTitle();
ul.description = ual.getDescription();
return ul;
}
}
}
......@@ -2,11 +2,7 @@ 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);
}
......@@ -12,7 +12,5 @@ public interface UserAccessionListService {
List<UserAccessionList> getAll();
void delete(Long id);
void update(UserAccessionList userAccessionList);
void delete(UserAccessionList userAccessionList);
}
......@@ -19,7 +19,7 @@ public class UserAccessionListServiceImpl implements UserAccessionListService {
@Override
public UserAccessionList getUserAccesionListById(Long id) {
return userAccessionListRepository.findById(id);
return userAccessionListRepository.findOne(id);
}
@Override
......@@ -33,21 +33,8 @@ public class UserAccessionListServiceImpl implements UserAccessionListService {
}
@Override
public void delete(Long id) {
userAccessionListRepository.delete(id);
public void delete(UserAccessionList userAccessionList) {
userAccessionListRepository.delete(userAccessionList);
}
@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);
}
}
......@@ -21,6 +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.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
......@@ -31,6 +32,8 @@ public class SelectionBean implements Serializable {
private final Set<Long> accessionIds = new HashSet<Long>();
private UserAccessionList_ userAccessionList;
public Set<Long> getAccessionIds() {
return accessionIds;
}
......@@ -62,4 +65,12 @@ public class SelectionBean implements Serializable {
public int size() {
return accessionIds.size();
}
public void setUserAccessionList(UserAccessionList_ userAccessionList) {
this.userAccessionList=userAccessionList;
}
public UserAccessionList_ getUserAccessionList() {
return userAccessionList;
}
}
......@@ -41,6 +41,7 @@ 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.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
......@@ -68,20 +69,32 @@ public class SelectionController extends BaseController {
@Autowired
private UserAccessionListService userAccessionListService;
@RequestMapping("/")
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
@RequestMapping(value = "/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("pagedData", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
model.addAttribute("selection", selectionBean);
if (SecurityContextHolder.getContext().getAuthentication().isAuthenticated())
model.addAttribute("userAccessionLists", userAccessionListService.getAll());
return "/selection/index";
}
@RequestMapping(value = "/", params = { "listId" })
@PreAuthorize("isAuthenticated()")
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);
selectionBean.setUserAccessionList(UserAccessionList.UserAccessionList_.from(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());
......@@ -137,7 +150,7 @@ public class SelectionController extends BaseController {
/**
* Download DwCA of selected accessions
*
*
* @param model
* @param cropName
* @param jsonFilter
......@@ -260,32 +273,27 @@ public class SelectionController extends BaseController {
}
@RequestMapping(value = "/userList", params = { "save" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
@PreAuthorize("isAuthenticated()")
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;
UserAccessionList userAccessionList = null;
if (listId != 0) {
userAccessionList = userAccessionListService.getUserAccesionListById(listId);
userAccessionList.setDescription(description);
userAccessionList.setTitle(title);
userAccessionList.setAccessionIds(selectionBean.copy());
userAccessionListService.update(userAccessionList);
} else {
}
if (userAccessionList == null) {
userAccessionList = new UserAccessionList();
userAccessionList.setDescription(description);
userAccessionList.setTitle(title);
userAccessionList.setAccessionIds(selectionBean.copy());
userAccessionListService.save(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());
......@@ -294,15 +302,14 @@ public class SelectionController extends BaseController {
}
@RequestMapping(value = "/userList", params = { "delete" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasRole('USER')")
@PreAuthorize("isAuthenticated()")
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");
userAccessionListService.delete(userAccessionListService.getUserAccesionListById(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());
......
......@@ -99,10 +99,10 @@
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"/>
<input type="submit" class="btn btn-primary" value="<spring:message code="user.accession.list.save"/>" 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"/>"/>
<input type="submit" class="btn" value="<spring:message code="user.accession.list.delete"/>" name="delete" />
</c:if>
</div>
<!-- CSRF protection -->
......
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