Skip to content

Commit

Permalink
Start work on documents manipulation
Browse files Browse the repository at this point in the history
TODO:
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTEOLLED TASK FOR USER
SHOW USERS TASK
STOREHAUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
  • Loading branch information
FairWindCo committed Oct 19, 2015
1 parent ee6bf42 commit 1ca0101
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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.model.storehouses.Storehouse;
import ua.pp.fairwind.favorid.internalDB.repository.StoreHouseRepository;

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("/storehouses")
public class StorehouseController {
@Autowired
StoreHouseRepository storehouseRepository;

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

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

@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 {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":
storehouseRepository.save(storehouse);
response.setStatus(200);
break;
case "edit":
Storehouse fromDB= storehouseRepository.getOne(storehouse.getId());
if(fromDB!=null) {
storehouseRepository.save(storehouse);
if(storehouse.getVersion()>=fromDB.getVersion()) {
fromDB.setName(storehouse.getName());
fromDB.setLocation(storehouse.getLocation());
fromDB.setComments(storehouse.getComments());
storehouseRepository.save(fromDB);
response.setStatus(200);
} else {
response.sendError(406,"ANOTHER TRANSACTION MODIFICATION");
}
} else {
response.sendError(406,"NO CONTACT TYPE FOUND");
}

break;
case "del":
storehouseRepository.delete(storehouse.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<Storehouse> page;
if (qword != null && qword.length > 0) {
page = storehouseRepository.find(qword[0], pager);
} else {
page = storehouseRepository.findAll(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
Storehouse ft=null;
if(key!=null) {
ft = storehouseRepository.findOne(key);
}
return ft;
} else {
List<Storehouse> page;
if (qword != null && qword.length > 0) {
page = storehouseRepository.find(qword[0],sort);
} else {
page = storehouseRepository.findAll(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum MOVEMENT_TYPES {
SHIPMENT,
MOVE,
DEFECTIVE,
UTILIZATION
UTILIZATION,
COMBINED
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public class Movement {
@ManyToOne
@JoinColumn(name = "nomenclature_ID")
Nomenclature nomenclature;
@ManyToOne
@JoinColumn(name = "created_nomenclature_ID")
Nomenclature nomenclature_created;
long count;
String units;
Units units;
String comments;


public Long getId() {
return id;
Expand Down Expand Up @@ -107,11 +112,11 @@ public void setCount(long count) {
this.count = count;
}

public String getUnits() {
public Units getUnits() {
return units;
}

public void setUnits(String units) {
public void setUnits(Units units) {
this.units = units;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class Safekeeping {
@JoinColumn(name = "nomenclature_ID")
Nomenclature nomenclature;
long count;
String units;
Units units;
Date lastUpdate;
boolean defective=false;
String comments;

public Long getId() {
return id;
Expand All @@ -39,7 +41,7 @@ public void setStorehouse(Storehouse storehouse) {
if(storehouse!=null) {
storehouse.addSafekeeping(this);
} else {
storehouse.removeSafekeeping(this);
this.storehouse.removeSafekeeping(this);
}
}

Expand All @@ -51,7 +53,7 @@ public void setNomenclature(Nomenclature nomenclature) {
if(nomenclature!=null) {
nomenclature.addSafekeeping(this);
} else {
nomenclature.removeSafekeeping(this);
this.nomenclature.removeSafekeeping(this);
}
}

Expand All @@ -63,11 +65,11 @@ public void setCount(long count) {
this.count = count;
}

public String getUnits() {
public Units getUnits() {
return units;
}

public void setUnits(String units) {
public void setUnits(Units units) {
this.units = units;
}

Expand All @@ -78,4 +80,20 @@ public Date getLastUpdate() {
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}

public boolean isDefective() {
return defective;
}

public void setDefective(boolean defective) {
this.defective = defective;
}

public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public class Storehouse {
@OneToMany
@JsonIgnore
Set<Safekeeping> safekeeping=new HashSet<>();
@Version
long version=0;

public long getVersion() {
return version;
}

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

public Long getId() {
return id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ua.pp.fairwind.favorid.internalDB.model.storehouses;

/**
* Created by Ñåðãåé on 19.10.2015.
*/
public enum Units {
KILOGRAMS,
GRAMS,
TONS,
COUNT,
LITRES,
MILILITRES
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ua.pp.fairwind.favorid.internalDB.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Nomenclature;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Storehouse;

import java.util.List;

/**
* Created by Ñåðãåé on 07.10.2015.
*/

public interface StoreHouseRepository extends JpaRepository<Storehouse,Long>{
@Query("select n from Storehouse n where n.location like %:search% or n.name like %:search% or n.number like %:search%")
Page<Storehouse> find(@Param(value = "search") String name, Pageable pager);
@Query("select n from Storehouse n where n.location like %:search% or n.name like %:search% or n.number like %:search%")
List<Storehouse> find(@Param(value = "search") String name);
@Query("select n from Storehouse n where n.location like %:search% or n.name like %:search% or n.number like %:search%")
List<Storehouse> find(@Param(value = "search") String name, Sort sort);
}

0 comments on commit 1ca0101

Please sign in to comment.