Skip to content

Commit

Permalink
WORK ON DOCUMENT CONTROLLER
Browse files Browse the repository at this point in the history
CREATE NOMENCLATURE CONTROLLER
TODO:
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTEOLLED TASK FOR USER
SHOW USERS TASK
STOREHAUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
REGISTER BED PRODUCT
  • Loading branch information
FairWindCo committed Oct 19, 2015
1 parent c3c9c74 commit ee6bf42
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
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.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.storehouses.Nomenclature;
import ua.pp.fairwind.favorid.internalDB.repository.NomenclatureRepository;

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

/**
* Created by Ñåðãåé on 19.10.2015.
*/
@Controller
@RequestMapping("/nomenclature")
public class NomenlatureController {
@Autowired
NomenclatureRepository nomenclatureRepository;

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

@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Nomenclature> 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<>(nomenclatureRepository.find(filterName, pageRequest));
} else
return new JGridRowsResponse<>(nomenclatureRepository.findAll(pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(nomenclatureRepository.find(filterName));
} else
return new JGridRowsResponse<>(nomenclatureRepository.findAll());
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Nomenclature nomenclature,BindingResult result,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":
nomenclatureRepository.save(nomenclature);
response.setStatus(200);
break;
case "edit":
Nomenclature fromDB=nomenclatureRepository.getOne(nomenclature.getId());
if(fromDB!=null) {
nomenclatureRepository.save(nomenclature);
if(nomenclature.getVersion()>=fromDB.getVersion()) {
nomenclatureRepository.save(nomenclature);
response.setStatus(200);
} else {
response.sendError(406,"ANOTHER TRANSACTION MODIFICATION");
}
} else {
response.sendError(406,"NO CONTACT TYPE FOUND");
}

break;
case "del":
nomenclatureRepository.delete(nomenclature.getId());
response.setStatus(200);
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,@RequestParam long firmID) {
// 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) {
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<Nomenclature> page;
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.find(qword[0], pager);
} else {
page = nomenclatureRepository.findAll(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
Nomenclature ft=null;
if(key!=null) {
ft = nomenclatureRepository.findOne(key);
}
return ft;
} else {
List<Nomenclature> page;
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.find(qword[0],sort);
} else {
page = nomenclatureRepository.findAll(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.jgrid.Utils;
import ua.pp.fairwind.favorid.internalDB.model.Contact;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.model.proxy.PersonProxy;
Expand All @@ -38,9 +39,11 @@ public class PersonController {
@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,@RequestParam long firmID) {
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) {
// Retrieve all persons by delegating the call to PersonService
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Long firmID= Utils.getLongParameter("firmID",request);
if(firmID==null)firmID=1L;
Sort sort=new Sort(Sort.Direction.ASC,"surname");
PageRequest pager=null;
if(page_num!=null && per_page!=null) {
Expand Down
Loading

0 comments on commit ee6bf42

Please sign in to comment.