Skip to content

Commit

Permalink
MESSAGE MANIPULATION COMPLETE
Browse files Browse the repository at this point in the history
WORK ON TASK MANIPULATION
WORK ON DOCUMENT MANIPULATION
TODO:
REQUEST MANIPULATION
DOCUMENT FILE MANIPULATION
SHOW CONTROLLED TASK FOR USER
SHOW USERS TASK
STOREHOUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
REGISTER BAD PRODUCT
  • Loading branch information
FairWindCo committed Nov 4, 2015
1 parent dd4a3fa commit 123033c
Show file tree
Hide file tree
Showing 21 changed files with 1,179 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.*;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp;
import ua.pp.fairwind.favorid.internalDB.jgrid.Utils;
import ua.pp.fairwind.favorid.internalDB.model.Agreement;
import ua.pp.fairwind.favorid.internalDB.model.Contact;
import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
Expand Down Expand Up @@ -451,7 +452,8 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
@Transactional(readOnly = true)
@RequestMapping(value = "/showListAgreements", method = RequestMethod.GET)
@ResponseBody
public Object simpleAgrimentsList(@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,@RequestParam(required = false) Long counterpart_id) {
public Object simpleAgrimentsList(@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,HttpServletRequest request) {
Long counterpart_id= Utils.getLongParameter("counterpart_id",request);
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Sort sort=new Sort(Sort.Direction.ASC,"name");
PageRequest pager=null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
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.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp;
import ua.pp.fairwind.favorid.internalDB.jgrid.Utils;
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;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;
import ua.pp.fairwind.favorid.internalDB.model.document.DocumentFile;
import ua.pp.fairwind.favorid.internalDB.model.document.DocumentSecurity;
import ua.pp.fairwind.favorid.internalDB.model.document.DocumentSubscribe;
import ua.pp.fairwind.favorid.internalDB.model.document.*;
import ua.pp.fairwind.favorid.internalDB.model.proxy.DocumentProxy;
import ua.pp.fairwind.favorid.internalDB.repository.*;
import ua.pp.fairwind.favorid.internalDB.security.UserDetailsAdapter;
Expand Down Expand Up @@ -61,6 +57,8 @@ public class DocumentController {
DocumentSubscribeRepository documentSubscribeRepository;
@Autowired
DocumentFileRepository documentFileRepository;
@Autowired
AgrimentRepository agrimentRepository;


@Secured("ROLE_USER")
Expand Down Expand Up @@ -231,13 +229,42 @@ public JGridRowsResponse<DocumentFile> getFiles(HttpServletRequest request,HttpS
}
}



private boolean updateDocument(Document document,HttpServletRequest request,HttpServletResponse response){
Long typeId= Utils.getLongParameter("documentType_key",request);
if(typeId!=null){
DocumentType dt=documentTypeRepository.findOne(typeId);
if(dt!=null)document.setDocumentType(dt);
}
Long from_firm=Utils.getLongParameter("counterprty_id",request);
if(from_firm!=null){
Counterparty from=counterpartyRepository.findOne(from_firm);
if(from!=null)document.setCounterparty(from);
}
Long from_person=Utils.getLongParameter("person_id",request);
if(from_person!=null){
Person from=personRepository.findOne(from_person);
if(from!=null)document.setPerson(from);
}
Long agr=Utils.getLongParameter("agreement_id",request);
if(agr!=null){
Agreement agreement=agrimentRepository.findOne(agr);
if(agreement!=null)document.setAgreement(agreement);
}
Long security_model=Utils.getLongParameter("security_model",request);
if(security_model!=null){
document.setSecurity_model(DOCUMENT_SECURITY_MODEL.fromInteger(security_model.intValue()));
}
document.setName(request.getParameter("name"));
document.setDescription(request.getParameter("description"));
document.setNumber(request.getParameter("number"));
return true;
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Document document,BindingResult result,HttpServletRequest request,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
public void editor(@RequestParam String oper,@RequestParam(required = false)Long id,HttpServletRequest request,HttpServletResponse response)throws IOException {
UserDetailsAdapter userDetail=(UserDetailsAdapter)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(userDetail==null){
response.sendError(403, "FORBIDDEN!");
Expand All @@ -247,31 +274,8 @@ public void editor(@RequestParam String oper,Document document,BindingResult res
case "add":
if(userDetail.hasRole("ROLE_ADD_DOCUMENTS")) {
//document.setCreationUser(userDetail.getUserP());
Long typeId= Utils.getLongParameter("documentType_key",request);
if(typeId!=null){
DocumentType dt=documentTypeRepository.findOne(typeId);
if(dt!=null)document.setDocumentType(dt);
}
Long from_firm=Utils.getLongParameter("counterprty_from_id",request);
if(from_firm!=null){
Counterparty from=counterpartyRepository.findOne(from_firm);
if(from!=null)document.setCounterparty_from(from);
}
Long to_firm=Utils.getLongParameter("counterprty_to_id",request);
if(to_firm!=null){
Counterparty to=counterpartyRepository.findOne(to_firm);
if(to!=null)document.setCounterparty_to(to);
}
Long from_person=Utils.getLongParameter("person_from_id",request);
if(from_person!=null){
Person from=personRepository.findOne(from_person);
if(from!=null)document.setPerson_from(from);
}
Long to_person=Utils.getLongParameter("person_to_id",request);
if(to_person!=null){
Person to=personRepository.findOne(to_person);
if(to!=null)document.setPerson_to(to);
}
Document document=new Document();
if(updateDocument(document,request,response));
documentRepository.save(document);
response.setStatus(200);
} else {
Expand All @@ -280,52 +284,27 @@ public void editor(@RequestParam String oper,Document document,BindingResult res
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());
Long typeId= Utils.getLongParameter("documentType_key",request);
if(typeId!=null){
DocumentType dt=documentTypeRepository.findOne(typeId);
if(dt!=null)cpt.setDocumentType(dt);
}
Long from_firm=Utils.getLongParameter("counterprty_from_id",request);
if(from_firm!=null){
Counterparty from=counterpartyRepository.findOne(from_firm);
if(from!=null)cpt.setCounterparty_from(from);
Document cpt = documentRepository.findOne(id);
Long version=Utils.getLongParameter("version",request);
if (cpt != null&&version!=null) {
if (cpt.getVersion() <= version) {
if (updateDocument(cpt, request, response)) {
documentRepository.save(cpt);
response.setStatus(200);
}
Long to_firm=Utils.getLongParameter("counterprty_to_id",request);
if(to_firm!=null){
Counterparty to=counterpartyRepository.findOne(to_firm);
if(to!=null)cpt.setCounterparty_to(to);
}
Long from_person=Utils.getLongParameter("person_from_id",request);
if(from_person!=null){
Person from=personRepository.findOne(from_person);
if(from!=null)cpt.setPerson_from(from);
}
Long to_person=Utils.getLongParameter("person_to_id",request);
if(to_person!=null){
Person to=personRepository.findOne(to_person);
if(to!=null)cpt.setPerson_to(to);
}
documentRepository.save(cpt);
response.setStatus(200);
} else {
response.sendError(400, "ANOTHER TRANSACTION MODIFICATION!");
}
} else {
response.sendError(404, "NO Counterpart WITH ID " + document.getId() + " FOUND");
response.sendError(404, "NO Counterpart WITH ID " + id + " FOUND");
}
} else {
response.sendError(403, "FORBIDDEN!");
}
break;
case "del":
if(userDetail.hasRole("ROLE_DELETE_DOCUMENTS")) {
documentRepository.delete(document.getId());
documentRepository.delete(id);
response.setStatus(200);
} else {
response.sendError(403, "FORBIDDEN!");
Expand Down Expand Up @@ -512,6 +491,66 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/editSecurity", method = {RequestMethod.POST,RequestMethod.GET})
public void editorSecurity(@RequestParam String oper,@RequestParam(required = false) Long id,@RequestParam long documentID,@RequestParam(required = false) Long personID,HttpServletRequest request,HttpServletResponse response)throws IOException {
Document document=documentRepository.findOne(documentID);
if(document==null){
response.sendError(404,"Document not found!");
return;
}
switch (oper) {
case "add": {
if (personID == null) {
response.sendError(404, "Person not found!");
return;
}
DocumentSecurity ds =new DocumentSecurity();
Person person = personRepository.findOne(personID);
ds.setDocument(document);
ds.setPerson(person);
Long action_id=Utils.getLongParameter("action_id",request);
if(action_id!=null){
ds.setAction(SECURITY_ACTION.fromInteger(action_id.intValue()));
}
Long permision_id=Utils.getLongParameter("permision_id",request);
if(permision_id!=null){
ds.setPermission(SECURITY_PERMISSION.fromInteger(permision_id.intValue()));
}
documentSecurityRepository.save(ds);
documentRepository.save(document);
}break;
case "edit": {
DocumentSecurity ds = documentSecurityRepository.findOne(id);
if (personID == null || ds==null) {
response.sendError(404, "Person not found!");
return;
}
Person person = personRepository.findOne(personID);
ds.setDocument(document);
ds.setPerson(person);
Long action_id=Utils.getLongParameter("action_id",request);
if(action_id!=null){
ds.setAction(SECURITY_ACTION.fromInteger(action_id.intValue()));
}
Long permision_id=Utils.getLongParameter("permision_id",request);
if(permision_id!=null){
ds.setPermission(SECURITY_PERMISSION.fromInteger(permision_id.intValue()));
}
documentSecurityRepository.save(ds);
documentRepository.save(document);
}break;
case "del":
DocumentSecurity ds = documentSecurityRepository.findOne(id);
document.removeSecurity(ds);
documentSecurityRepository.delete(ds);
documentRepository.save(document);
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
Expand Up @@ -15,7 +15,9 @@
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.directories.DocumentType;
import ua.pp.fairwind.favorid.internalDB.jgrid.Utils;
import ua.pp.fairwind.favorid.internalDB.model.document.DOCUMENT_CLASS;
import ua.pp.fairwind.favorid.internalDB.model.document.DocumentType;
import ua.pp.fairwind.favorid.internalDB.repository.DocumentTypeRepository;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -161,4 +163,53 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
}
}

private DOCUMENT_CLASS getDocumentclass(HttpServletRequest request){
Long id= Utils.getLongParameter("class",request);
if(id==null)return DOCUMENT_CLASS.INTERNAL;
if(id==1L)return DOCUMENT_CLASS.IN;
if(id==2L)return DOCUMENT_CLASS.OUT;
return DOCUMENT_CLASS.INTERNAL;
}

@Transactional(readOnly = true)
@RequestMapping(value = "/showTypedList", 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,HttpServletRequest request) {
DOCUMENT_CLASS document_class=getDocumentclass(request);
// Retrieve all persons by delegating the call to PersonService
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Sort sort=new Sort(Sort.Direction.ASC,"name");
PageRequest pager=null;
if(page_num!=null && per_page!=null) {
page_num= page_num<1?1:page_num;
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<DocumentType> page;
if (qword != null && qword.length > 0) {
page = repositoryDocumentType.findByNameContainsAndDocumentClass(qword[0], document_class, pager);
} else {
page = repositoryDocumentType.findByDocumentClass(document_class, pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
DocumentType ft=null;
if(key!=null) {
ft = repositoryDocumentType.findOne(key);
}
return ft;
} else {
List<DocumentType> page;
if (qword != null && qword.length > 0) {
page = repositoryDocumentType.findByNameContainsAndDocumentClass(qword[0], document_class);
} else {
page = repositoryDocumentType.findByDocumentClass(document_class,sort);
}
return new JSComboExpenseResp<>(page);
}
}
}

}
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 04.11.2015.
*/
public enum DOCUMENT_CLASS {
INTERNAL,
IN,
OUT
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,29 @@
public enum DOCUMENT_SECURITY_MODEL {
ACCESS_FOR_ALL,
ACCESS_FOR_OWNER,
ACCESS_FOR_LIST
ACCESS_FOR_LIST;

public static DOCUMENT_SECURITY_MODEL fromInteger(int x) {
switch(x) {
case 0:
return ACCESS_FOR_ALL;
case 1:
return ACCESS_FOR_OWNER;
case 2:
return ACCESS_FOR_LIST;
}
return null;
}

public static Integer toInteger(DOCUMENT_SECURITY_MODEL x) {
switch(x) {
case ACCESS_FOR_ALL:
return 0;
case ACCESS_FOR_OWNER:
return 1;
case ACCESS_FOR_LIST:
return 2;
}
return null;
}
}
Loading

0 comments on commit 123033c

Please sign in to comment.