Skip to content

Commit

Permalink
create interface for contacttype, documenttype, position, tasktype, u…
Browse files Browse the repository at this point in the history
…ser, role
  • Loading branch information
FairWindCo committed Oct 11, 2015
1 parent 5e65913 commit ea17747
Show file tree
Hide file tree
Showing 82 changed files with 13,826 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package ua.pp.fairwind.favorid.internalDB.controllers;

import org.springframework.beans.factory.annotation.Autowired;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.model.directories.ContactType;
import ua.pp.fairwind.favorid.internalDB.repository.ContactTypeRepository;

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


/**
Expand All @@ -36,7 +37,45 @@ public String list(Model model) {
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<ContactType> getTable(HttpServletRequest request){
return new JGridRowsResponse<ContactType>(repositoryContactType.findAll());
//Pegeable
/*
nd:1444413790954
rows:10
page:1
sidx:id
sord:asc
filters:{"groupOp":"AND","rules":[{"field":"name","op":"bw","data":"dfadsfdasfd"}]}
*/
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){
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<ContactType>(repositoryContactType.findByNameContains(filterName, pageRequest));
} else
return new JGridRowsResponse<ContactType>(repositoryContactType.findAll(pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<ContactType>(repositoryContactType.findByNameContains(filterName));
} else
return new JGridRowsResponse<ContactType>(repositoryContactType.findAll());
}
}

@Transactional(readOnly = false)
Expand All @@ -49,4 +88,41 @@ public String add(@ModelAttribute ContactType contactType, BindingResult result)
repositoryContactType.save(contactType);
return "Success";
}

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

break;
case "del":
repositoryContactType.delete(contactType.getId());
response.setStatus(200);
break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ua.pp.fairwind.favorid.internalDB.controllers;

import org.springframework.beans.factory.annotation.Autowired;
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.model.directories.DocumentType;
import ua.pp.fairwind.favorid.internalDB.repository.DocumentTypeRepository;

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


/**
* Created by Ñåðãåé on 07.10.2015.
*/
@Controller
@RequestMapping("/documenttypes")
public class DocumentTypeController {
@Autowired
DocumentTypeRepository repositoryDocumentType;

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

@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<DocumentType> getTable(HttpServletRequest request){
//Pegeable
/*
nd:1444413790954
rows:10
page:1
sidx:id
sord:asc
filters:{"groupOp":"AND","rules":[{"field":"name","op":"bw","data":"dfadsfdasfd"}]}
*/
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){
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<>(repositoryDocumentType.findByNameContains(filterName, pageRequest));
} else
return new JGridRowsResponse<>(repositoryDocumentType.findAll(pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(repositoryDocumentType.findByNameContains(filterName));
} else
return new JGridRowsResponse<>(repositoryDocumentType.findAll());
}
}


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

break;
case "del":
repositoryDocumentType.delete(documentType.getId());
response.setStatus(200);
break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package ua.pp.fairwind.favorid.internalDB.controllers;

import org.springframework.beans.factory.annotation.Autowired;
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.model.directories.Position;
import ua.pp.fairwind.favorid.internalDB.repository.PositionRepository;

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


/**
* Created by Ñåðãåé on 07.10.2015.
*/
@Controller
@RequestMapping("/positions")
public class PositionController {
@Autowired
PositionRepository repositoryPosition;

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

@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Position> getTable(HttpServletRequest request){
//Pegeable
/*
nd:1444413790954
rows:10
page:1
sidx:id
sord:asc
filters:{"groupOp":"AND","rules":[{"field":"name","op":"bw","data":"dfadsfdasfd"}]}
*/
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){
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<>(repositoryPosition.findByNameContains(filterName, pageRequest));
} else
return new JGridRowsResponse<>(repositoryPosition.findAll(pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(repositoryPosition.findByNameContains(filterName));
} else
return new JGridRowsResponse<>(repositoryPosition.findAll());
}
}

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

break;
case "del":
repositoryPosition.delete(position.getId());
response.setStatus(200);
break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}

}
Loading

0 comments on commit ea17747

Please sign in to comment.