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 23, 2015
1 parent 1c24fd6 commit 6be258a
Show file tree
Hide file tree
Showing 8 changed files with 578 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
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.*;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.NomenclatureTypes;
import ua.pp.fairwind.favorid.internalDB.repository.NomenclatureTypeRepository;

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


/**
* Created by ������ on 07.10.2015.
*/
@Controller
@RequestMapping("/nomenclaturetypes")
public class NomenclatureTypeController {
@Autowired
NomenclatureTypeRepository repositoryNomenclatureType;

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

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

@Transactional(readOnly = false)
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public String add(@ModelAttribute NomenclatureTypes nomenclatureType, BindingResult result){
if(result.hasErrors()){
return "ERROR:"+result.toString();
}
repositoryNomenclatureType.save(nomenclatureType);
return "Success";
}

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

break;
case "del":
repositoryNomenclatureType.delete(nomenclatureType.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) {
page_num= page_num<1?1:page_num;
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<NomenclatureTypes> page;
if (qword != null && qword.length > 0) {
page = repositoryNomenclatureType.findByNameContains(qword[0], pager);
} else {
page = repositoryNomenclatureType.findAll(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
NomenclatureTypes ft=null;
if(key!=null) {
ft = repositoryNomenclatureType.findOne(key);
}
return ft;
} else {
List<NomenclatureTypes> page;
if (qword != null && qword.length > 0) {
page = repositoryNomenclatureType.findByNameContains(qword[0],sort);
} else {
page = repositoryNomenclatureType.findAll(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
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.model.storehouses.NomenclatureTypes;
import ua.pp.fairwind.favorid.internalDB.repository.CombinedTemplatesRepository;
import ua.pp.fairwind.favorid.internalDB.repository.NomenclatureRepository;
import ua.pp.fairwind.favorid.internalDB.repository.NomenclatureTypeRepository;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -35,6 +37,8 @@ public class NomenlatureController {
NomenclatureRepository nomenclatureRepository;
@Autowired
CombinedTemplatesRepository combinedTemplatesRepository;
@Autowired
NomenclatureTypeRepository nomenclatureTypeRepository;

@Secured("ROLE_USER")
@RequestMapping(value = "/list", method = RequestMethod.GET)
Expand Down Expand Up @@ -244,4 +248,45 @@ public JGridRowsResponse<CombinedTemplate> getTemplates(HttpServletRequest reque
return new JGridRowsResponse<>(combinedTemplatesRepository.find(nm));
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/types", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<NomenclatureTypes> getTypes(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<>(nomenclatureTypeRepository.find(filterName,nm, pageRequest));
} else
return new JGridRowsResponse<>(nomenclatureTypeRepository.find(nm,pageRequest));
} else {
if(filterName!=null && !filterName.isEmpty()){
return new JGridRowsResponse<>(nomenclatureTypeRepository.find(filterName,nm));
} else
return new JGridRowsResponse<>(nomenclatureTypeRepository.find(nm));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class CombinedTemplate {
@ManyToOne
@JoinColumn(name = "nomenclature_id")
Nomenclature nomenclature;
@ManyToOne
@JoinColumn(name = "nomenclature_type_id")
NomenclatureTypes nomenclatureType;
long count=1;
@Version
long version=0;
Expand Down Expand Up @@ -71,4 +74,12 @@ public long getVersion() {
public void setVersion(long version) {
this.version = version;
}

public NomenclatureTypes getNomenclatureType() {
return nomenclatureType;
}

public void setNomenclatureType(NomenclatureTypes nomenclatureType) {
this.nomenclatureType = nomenclatureType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class Nomenclature {
@OneToMany
@JsonIgnore
final Set<Safekeeping> safekeeping=new HashSet<>();
@ManyToMany
@JsonIgnore
final Set<NomenclatureTypes> nomenclatureTypes=new HashSet<>();

@Version
long version=0;

Expand Down Expand Up @@ -90,10 +94,30 @@ public void removeSafekeeping(Safekeeping safekeeping){
}
}

public void addTypes(NomenclatureTypes types){
if(types!=null) {
if (this.nomenclatureTypes.add(types)) {
types.nomenclature.add(this);
}
}
}

public void removeTypes(NomenclatureTypes types){
if(types!=null) {
if (this.safekeeping.remove(types)) {
types.nomenclature.remove(this);
}
}
}

public Set<Safekeeping> getSafekeeping() {
return Collections.unmodifiableSet(safekeeping);
}

public Set<NomenclatureTypes> getTypes() {
return Collections.unmodifiableSet(nomenclatureTypes);
}

public boolean isCombined() {
return combined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ua.pp.fairwind.favorid.internalDB.model.storehouses;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
* Created by Ñåðãåé on 23.10.2015.
*/
@Entity
@Table(name = "NOMENCLATURE_TYPES")
public class NomenclatureTypes {
@Id
@GeneratedValue
Long id;
String name;
@Version
long version=0;

@ManyToMany
@JsonIgnore
final Set<Nomenclature> nomenclature=new HashSet<>();

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public long getVersion() {
return version;
}

public void setVersion(long version) {
this.version = version;
}

public void addNomenclature(Nomenclature nomenclature){
if(nomenclature!=null) {
if (this.nomenclature.add(nomenclature)) {
nomenclature.nomenclatureTypes.add(this);
}
}
}

public void removeNomenclature(Nomenclature nomenclature){
if(nomenclature!=null) {
if (this.nomenclature.remove(nomenclature)) {
nomenclature.nomenclatureTypes.remove(this);
}
}
}
}
Loading

0 comments on commit 6be258a

Please sign in to comment.