Skip to content

Commit

Permalink
SET USER SERVICE TO DB
Browse files Browse the repository at this point in the history
TODO:
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTEOLLED TASK FOR USER
SHOW USERS TASK
STOREHAUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
  • Loading branch information
FairWindCo committed Oct 16, 2015
1 parent e767c59 commit 2b4801c
Show file tree
Hide file tree
Showing 21 changed files with 999 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,24 @@ public void editor(@RequestParam String oper,Counterparty counterparty,BindingRe
}
switch (oper){
case "add":
case "edit":
counterpartyRepository.save(counterparty);
response.setStatus(200);
break;
case "edit":
Counterparty cpt = counterpartyRepository.findOne(counterparty.getId());
if (counterparty != null) {
if(cpt.getVersion() <= counterparty.getVersion()) {
cpt.setFullName(counterparty.getFullName());
cpt.setShortName(counterparty.getShortName());
counterpartyRepository.save(cpt);
response.setStatus(200);
} else {
response.sendError(400, "ANOTHER TRANSACTION MODIFICATION!");
}
} else {
response.sendError(404, "NO Counterpart WITH ID " + counterparty.getId() + " FOUND");
}

break;
case "del":
counterpartyRepository.delete(counterparty.getId());
Expand Down Expand Up @@ -316,6 +331,80 @@ public void agrimentsEditor(@RequestParam String oper,@RequestParam long ID,Agre
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/editperson", method = {RequestMethod.POST,RequestMethod.GET})
public void personsEditor(@RequestParam String oper,@RequestParam long ID,Person person,BindingResult result,HttpServletRequest request,HttpServletResponse response)throws IOException{
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":{
Counterparty counterparty= counterpartyRepository.findOne(ID);
if(counterparty!=null) {
counterparty.addPerson(person);
String headIDS=request.getParameter("headID_primary_key");
if(headIDS!=null && !headIDS.isEmpty()){
try {
Long headid=Long.getLong(headIDS);
Person headPerson=personRepository.findOne(headid);
person.setHead(headPerson);
} catch (NumberFormatException e){
//do nothing
}
}
personRepository.save(person);
counterpartyRepository.save(counterparty);
response.setStatus(200);
} else{
response.sendError(404, "NO COUNTERPART WITH ID " +ID+" FOUND");
}
}break;
case "edit": {
Person prsn = personRepository.findOne(person.getId());
if (prsn != null && prsn.getVersion() <= person.getVersion()) {
prsn.setSurname(person.getSurname());
prsn.setFirstName(person.getFirstName());
prsn.setMiddleName(person.getMiddleName());
prsn.setComments(person.getComments());
prsn.setDate_of_birth(person.getDate_of_birth());
String headIDS=request.getParameter("headID_primary_key");
if(headIDS!=null && !headIDS.isEmpty()){
try {
Long headid=Long.getLong(headIDS);
Person headPerson=personRepository.findOne(headid);
person.setHead(headPerson);
} catch (NumberFormatException e){
//do nothing
}
}
personRepository.save(prsn);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + person.getId() + " FOUND");
}
}break;
case "del": {
Counterparty counterparty = counterpartyRepository.findOne(ID);
if (counterparty != null) {
Person prsn=personRepository.findOne(person.getId());
if(prsn!=null) {
counterparty.removePerson(prsn);
personRepository.delete(prsn);
counterpartyRepository.save(counterparty);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + person.getId() + " FOUND");
}
} else {
response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND");
}
}break;
default:
response.sendError(406, "UNKNOWN OPERATION");
}
}

@InitBinder
private void dateBinder(WebDataBinder binder) {
//The date format to parse or output your dates
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,175 @@
package ua.pp.fairwind.favorid.internalDB.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
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 ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;
import ua.pp.fairwind.favorid.internalDB.model.proxy.DocumentProxy;
import ua.pp.fairwind.favorid.internalDB.repository.DocumentRepository;
import ua.pp.fairwind.favorid.internalDB.security.UserDetailsAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* Created by Ñåðãåé on 14.10.2015.
*/
@Controller
@RequestMapping("/documents")
public class DocumentController {
@Autowired
DocumentRepository documentRepository;
@Autowired
SecurityContext securityContext;

@Secured("ROLE_USER")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
return "documents_list";
}

@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Document> getTable(HttpServletRequest request){
PageRequest pageRequest=null;
if(request.getParameter("page")!=null){
int rows=10;
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
rows = request.getParameter("rows") == null ? 10 : Integer.parseInt(request.getParameter("rows"));
if(request.getParameter("sidx")!=null && !request.getParameter("sidx").isEmpty()){
String direction=request.getParameter("sord");
pageRequest=new PageRequest(page,rows,"asc".equals(direction)? Sort.Direction.ASC: Sort.Direction.DESC,request.getParameter("sidx"));
} else {
pageRequest=new PageRequest(page,rows);
}
}catch (NumberFormatException ex){
//do nothing
}

}/**/
String filterName=request.getParameter("name");
if(pageRequest!=null){
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(documentRepository.findByName(filterName, pageRequest));
} else
return new JGridRowsResponse<>(documentRepository.findAll(pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(documentRepository.findByName(filterName));
} else
return new JGridRowsResponse<>(documentRepository.findAll());
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Document document,BindingResult result,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
UserDetailsAdapter userDetail=(UserDetailsAdapter)securityContext.getAuthentication().getDetails();
if(userDetail==null){
response.sendError(403, "FORBIDDEN!");
return;
}
switch (oper){
case "add":
if(userDetail.hasRole("ROLE_ADD_DOCUMENTS")) {
//document.setCreationUser(userDetail.getUserP());
documentRepository.save(document);
response.setStatus(200);
} else {
response.sendError(403, "FORBIDDEN!");
}
break;
case "edit":
if(userDetail.hasRole("ROLE_EDIT_DOCUMENTS")) {
Document cpt = documentRepository.findOne(document.getId());
if (document != null) {
if (cpt.getVersion() <= document.getVersion()) {
cpt.setNumber(document.getNumber());
cpt.setName(document.getName());
cpt.setDescription(document.getDescription());
documentRepository.save(cpt);
response.setStatus(200);
} else {
response.sendError(400, "ANOTHER TRANSACTION MODIFICATION!");
}
} else {
response.sendError(404, "NO Counterpart WITH ID " + document.getId() + " FOUND");
}
} else {
response.sendError(403, "FORBIDDEN!");
}
break;
case "del":
if(userDetail.hasRole("ROLE_DELETE_DOCUMENTS")) {
documentRepository.delete(document.getId());
response.setStatus(200);
} else {
response.sendError(403, "FORBIDDEN!");
}
break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/showList", method = RequestMethod.GET)
@ResponseBody
public Object simpleClientList(@RequestParam(required = false) Integer page_num, @RequestParam(required = false) Integer per_page,@RequestParam(value = "pkey_val[]",required = false) String pkey,@RequestParam(value = "q_word[]",required = false) String[] qword) {
// Retrieve all persons by delegating the call to PersonService
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Sort sort=new Sort(Sort.Direction.ASC,"surname");
PageRequest pager=null;
if(page_num!=null && per_page!=null) {
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<DocumentProxy> page;
if (qword != null && qword.length > 0) {
page = documentRepository.findProxy(qword[0], pager);
} else {
page = documentRepository.findProxy(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
Document ft=null;
if(key!=null) {
ft = documentRepository.findOne(key);
}
return ft;
} else {
List<DocumentProxy> page;
if (qword != null && qword.length > 0) {
page = documentRepository.findProxy(qword[0], sort);
} else {
page = documentRepository.findProxy(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.annotation.LastModifiedDate;
import ua.pp.fairwind.favorid.internalDB.model.administrative.User;
import ua.pp.fairwind.favorid.internalDB.model.directories.TaskType;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;

import javax.persistence.*;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ua.pp.fairwind.favorid.internalDB.model.document;

/**
* Created by Ñåðãåé on 16.10.2015.
*/
public enum DOCUMENT_SECURITY_MODEL {
ACCESS_FOR_ALL,
ACCESS_FOR_OWNER,
ACCESS_FOR_LIST
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package ua.pp.fairwind.favorid.internalDB.model;
package ua.pp.fairwind.favorid.internalDB.model.document;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import ua.pp.fairwind.favorid.internalDB.model.Agreement;
import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.model.administrative.User;
import ua.pp.fairwind.favorid.internalDB.model.directories.DocumentType;

Expand Down Expand Up @@ -59,10 +62,15 @@ public class Document {
@JsonManagedReference
final Set<Document> atachments=new HashSet<>();

@OneToMany
@OneToMany(mappedBy = "document")
@JsonManagedReference
final Set<DocumentFile> documentFiles=new HashSet<>();

DOCUMENT_SECURITY_MODEL security_model;
@OneToMany(mappedBy = "document")
@JsonManagedReference
final Set<DocumentSecurity> securities=new HashSet<>();

Date creationDate=new Date();
@LastModifiedDate
Date modificationDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ua.pp.fairwind.favorid.internalDB.model;
package ua.pp.fairwind.favorid.internalDB.model.document;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.util.Date;

/**
Expand All @@ -20,6 +19,10 @@ public class DocumentFile {
String mimeType;
long size;
Date creationDate=new Date();
@ManyToOne
@JsonManagedReference
@JoinColumn(name = "document_id")
Document document;

public Long getId() {
return id;
Expand Down Expand Up @@ -68,4 +71,12 @@ public Date getCreationDate() {
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}

public Document getDocument() {
return document;
}

public void setDocument(Document document) {
this.document = document;
}
}
Loading

0 comments on commit 2b4801c

Please sign in to comment.