-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create interface for contacttype, documenttype, position, tasktype, u…
…ser, role
- Loading branch information
1 parent
5e65913
commit ea17747
Showing
82 changed files
with
13,826 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentTypeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/PositionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.