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 22, 2015
1 parent 42b8093 commit 1c24fd6
Show file tree
Hide file tree
Showing 22 changed files with 938 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


/**
* Created by Ñåðãåé on 07.10.2015.
* Created by ������ on 07.10.2015.
*/
@Controller
@RequestMapping("/contacttypes")
Expand Down Expand Up @@ -55,6 +55,7 @@ public JGridRowsResponse<ContactType> getTable(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand Down Expand Up @@ -137,6 +138,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
Sort sort=new Sort(Sort.Direction.ASC,"shortName");
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -333,6 +336,20 @@ public void editor(@RequestParam String oper,Document document,BindingResult res
}
}

private String form_file_path(MultipartFile file,Document document){
StringBuilder path_bulder=new StringBuilder("E:/DOCUMENTS/");
if(document.getDocumentType()!=null&&document.getDocumentType().getName()!=null&&!document.getDocumentType().getName().isEmpty()){
path_bulder.append(document.getDocumentType().getName());
path_bulder.append("/");
}
if(document.getName()!=null && !document.getName().isEmpty()){
path_bulder.append(document.getName());
path_bulder.append("/");
}
path_bulder.append(file.getOriginalFilename());
return path_bulder.toString();
}

@Transactional(readOnly = false)
@RequestMapping(value = "/editafile", method = {RequestMethod.POST,RequestMethod.GET})
public void fileEditor(@RequestParam String oper,@RequestParam Long document_id,@RequestParam Long id,@RequestParam MultipartFile file,HttpServletResponse response)throws IOException {
Expand All @@ -354,12 +371,26 @@ public void fileEditor(@RequestParam String oper,@RequestParam Long document_id,
}
if(userDetail.hasRole("ROLE_ADD_DOCUMENTS")||(creator!=null && creator.equals(userDetail.getUserP()))) {
DocumentFile fileInfo=new DocumentFile();
fileInfo.setFileName(file.getName());
fileInfo.setFileName(file.getOriginalFilename());
fileInfo.setMimeType(file.getContentType());
fileInfo.setSize(file.getSize());
fileInfo.setDocument(document);
String path="e:/"+(document.getDocumentType()!=null?document.getDocumentType().getName()+"/":"")+file.getName();
String path=form_file_path(file,document);
fileInfo.setFilePath(path);
File filesystem=new File(path);
if(filesystem.exists()){
response.sendError(406, "FILE EXIST: "+path);
return;
} else {
try {
Path pathToFile = Paths.get(path);
Files.createDirectories(pathToFile.getParent());
Files.createFile(pathToFile);
}catch (IOException ioe){
response.sendError(406, "ERROR: "+ioe.getLocalizedMessage());
return;
}
}
try(FileOutputStream stream=new FileOutputStream(path)) {
stream.write(file.getBytes());
stream.flush();
Expand Down Expand Up @@ -387,12 +418,26 @@ public void fileEditor(@RequestParam String oper,@RequestParam Long document_id,
return;
}
DocumentFile fileInfo=new DocumentFile();
fileInfo.setFileName(file.getName());
fileInfo.setFileName(file.getOriginalFilename());
fileInfo.setMimeType(file.getContentType());
fileInfo.setSize(file.getSize());
fileInfo.setDocument(document);
String path="e:/"+(document.getDocumentType()!=null?document.getDocumentType().getName()+"/":"")+file.getName();
String path=form_file_path(file,document);
fileInfo.setFilePath(path);
File filesystem=new File(path);
if(filesystem.exists()){
response.sendError(406, "FILE EXIST: "+path);
return;
} else {
try {
Path pathToFile = Paths.get(path);
Files.createDirectories(pathToFile.getParent());
Files.createFile(pathToFile);
}catch (IOException ioe){
response.sendError(406, "ERROR: "+ioe.getLocalizedMessage());
return;
}
}
try(FileOutputStream stream=new FileOutputStream(path)) {
stream.write(file.getBytes());
stream.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
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) {
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.storehouses.CombinedTemplate;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Nomenclature;
import ua.pp.fairwind.favorid.internalDB.repository.CombinedTemplatesRepository;
import ua.pp.fairwind.favorid.internalDB.repository.NomenclatureRepository;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -31,6 +33,8 @@
public class NomenlatureController {
@Autowired
NomenclatureRepository nomenclatureRepository;
@Autowired
CombinedTemplatesRepository combinedTemplatesRepository;

@Secured("ROLE_USER")
@RequestMapping(value = "/list", method = RequestMethod.GET)
Expand All @@ -48,6 +52,7 @@ public JGridRowsResponse<Nomenclature> getTable(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand Down Expand Up @@ -110,16 +115,65 @@ public void editor(@RequestParam String oper,Nomenclature nomenclature,BindingRe
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edittamplate", method = {RequestMethod.POST,RequestMethod.GET})
public void editorTemplate(@RequestParam String oper,@RequestParam long nmid,@RequestParam(required = false) Long nomenclature_id,@RequestParam(required = false) Long version,@RequestParam(required = false) Long count,@RequestParam(required = false) Long id,HttpServletResponse response)throws IOException {
Nomenclature nomenclature=nomenclatureRepository.findOne(nmid);
switch (oper) {
case "add": {
Nomenclature nomenclature_for_constract = nomenclature_id != null ? nomenclatureRepository.findOne(nomenclature_id) : null;
CombinedTemplate combined = new CombinedTemplate();
combined.setCount(count == null ? 0 : count);
combined.setNomenclature(nomenclature_for_constract);
combined.setParent(nomenclature);
combinedTemplatesRepository.save(combined);
nomenclatureRepository.save(nomenclature);
response.setStatus(200);
}
break;
case "edit": {
CombinedTemplate combined = combinedTemplatesRepository.findOne(id);
Nomenclature nomenclature_for_constract = nomenclature_id != null ? nomenclatureRepository.findOne(nomenclature_id) : null;
if (combined != null) {
if (combined.getVersion() <= version) {
combined.setCount(count == null ? 0 : count);
combined.setNomenclature(nomenclature_for_constract);
combinedTemplatesRepository.save(combined);
response.setStatus(200);
} else {
response.sendError(406, "ANOTHER TRANSACTION MODIFICATION");
}
} else {
response.sendError(406, "NO TEMPLATE FOUND");
}
}
break;
case "del": {
CombinedTemplate combined = combinedTemplatesRepository.findOne(id);
if (combined != null) {
combined.setParent(null);
nomenclatureRepository.save(nomenclature);
combinedTemplatesRepository.delete(id);
}
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) {
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,"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) {
Expand Down Expand Up @@ -149,4 +203,45 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
}
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/tamplates", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<CombinedTemplate> getTemplates(HttpServletRequest request,@RequestParam long id){
Nomenclature nm=nomenclatureRepository.getOne(id);
if(nm==null){
return null;
}
PageRequest pageRequest=null;
if(request.getParameter("page")!=null){
int rows=10;
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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<>(combinedTemplatesRepository.find(filterName,nm, pageRequest));
} else
return new JGridRowsResponse<>(combinedTemplatesRepository.find(nm,pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(combinedTemplatesRepository.find(filterName,nm));
} else
return new JGridRowsResponse<>(combinedTemplatesRepository.find(nm));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
Sort sort=new Sort(Sort.Direction.ASC,"surname");
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public JGridRowsResponse<Position> getTable(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand Down Expand Up @@ -129,6 +130,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
Sort sort=new Sort(Sort.Direction.ASC,"surname");
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public JGridRowsResponse<Role> getTable(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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.model.storehouses.Nomenclature;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Safekeeping;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Storehouse;
import ua.pp.fairwind.favorid.internalDB.repository.StoreHouseRepository;

Expand Down Expand Up @@ -49,6 +49,7 @@ public JGridRowsResponse<Storehouse> getTable(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand All @@ -75,6 +76,43 @@ public JGridRowsResponse<Storehouse> getTable(HttpServletRequest request){
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/state", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Safekeeping> getStates(HttpServletRequest request,@RequestParam long id){
PageRequest pageRequest=null;
if(request.getParameter("page")!=null){
int rows=10;
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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<>(storehouseRepository.getState(id, filterName, pageRequest));
} else
return new JGridRowsResponse<>(storehouseRepository.getState(id, pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(storehouseRepository.getState(id, filterName));
} else
return new JGridRowsResponse<>(storehouseRepository.getState(id));
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Storehouse storehouse,BindingResult result,HttpServletResponse response)throws IOException {
Expand Down Expand Up @@ -124,6 +162,7 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public JGridRowsResponse<Task> getTableExecuteTask(HttpServletRequest request){
int page;
try {
page = Integer.parseInt(request.getParameter("page")) - 1;
page= page<0?0:page;
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");
Expand Down
Loading

0 comments on commit 1c24fd6

Please sign in to comment.