Skip to content

Commit

Permalink
Create MODELS for storehouse
Browse files Browse the repository at this point in the history
Create Controllers for Contacts
FIX ajax combobox
  • Loading branch information
FairWindCo committed Oct 13, 2015
1 parent fb22060 commit cfb520f
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.springframework.web.bind.annotation.*;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.model.Agreement;
import ua.pp.fairwind.favorid.internalDB.model.Contact;
import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.repository.AgrimentRepository;
import ua.pp.fairwind.favorid.internalDB.repository.ContactRepository;
import ua.pp.fairwind.favorid.internalDB.repository.CounterpartyRepository;
import ua.pp.fairwind.favorid.internalDB.repository.PersonRepository;

Expand All @@ -38,6 +40,8 @@ public class ConterpartyController {
PersonRepository personRepository;
@Autowired
AgrimentRepository agreementRepository;
@Autowired
ContactRepository contactRepository;

@Secured("ROLE_USER")
@RequestMapping(value = "/list", method = RequestMethod.GET)
Expand Down Expand Up @@ -153,6 +157,36 @@ public JGridRowsResponse<Person> getPersons(HttpServletRequest request,@RequestP
}
}


@Transactional(readOnly = true)
@RequestMapping(value = "/contacts", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Contact> getContacts(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;
if(page<0)page=0;
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
}
}/**/
if(pageRequest!=null){
return new JGridRowsResponse<>(counterpartyRepository.getContacts(ID, pageRequest));
} else {
return new JGridRowsResponse<>(counterpartyRepository.getContacts(ID));
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Counterparty counterparty,BindingResult result,HttpServletResponse response)throws IOException{
Expand All @@ -175,6 +209,57 @@ public void editor(@RequestParam String oper,Counterparty counterparty,BindingRe
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/editcontact", method = {RequestMethod.POST,RequestMethod.GET})
public void contacteditor(@RequestParam String oper,@RequestParam long ID,Contact contact,BindingResult result,HttpServletResponse response)throws IOException{
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":{
Counterparty counterparty= counterpartyRepository.findOne(ID);
if(counterparty!=null) {
counterparty.addContact(contact);
contactRepository.save(contact);
counterpartyRepository.save(counterparty);
response.setStatus(200);
} else{
response.sendError(404, "NO COUNTERPART WITH ID " +ID+" FOUND");
}
}break;
case "edit": {
Contact agr = contactRepository.findOne(contact.getId());
if (agr != null && agr.getVersion() <= contact.getVersion()) {
agr.setContact(contact.getContact());
agr.setContactType(contact.getContactType());
contactRepository.save(agr);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + contact.getId() + " FOUND");
}
}break;
case "del": {
Counterparty counterparty = counterpartyRepository.findOne(ID);
if (counterparty != null) {
Contact agr=contactRepository.findOne(contact.getId());
if(agr!=null) {
counterparty.removeContact(agr);
contactRepository.delete(agr);
counterpartyRepository.save(counterparty);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + contact.getId() + " FOUND");
}
} else {
response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND");
}
}break;
default:
response.sendError(406, "UNKNOWN OPERATION");
}
}



@Transactional(readOnly = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
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.Contact;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.model.proxy.PersonProxy;
import ua.pp.fairwind.favorid.internalDB.repository.ContactRepository;
import ua.pp.fairwind.favorid.internalDB.repository.PersonRepository;

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

/**
Expand All @@ -25,6 +32,8 @@
public class PersonController {
@Autowired
PersonRepository personRepository;
@Autowired
ContactRepository contactRepository;

@Transactional(readOnly = true)
@RequestMapping(value = "/showList", method = RequestMethod.GET)
Expand Down Expand Up @@ -64,4 +73,85 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
}
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/contacts", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Contact> getContacts(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;
if(page<0)page=0;
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
}
}/**/
if(pageRequest!=null){
return new JGridRowsResponse<>(personRepository.getContacts(ID, pageRequest));
} else {
return new JGridRowsResponse<>(personRepository.getContacts(ID));
}
}


@Transactional(readOnly = false)
@RequestMapping(value = "/editcontact", method = {RequestMethod.POST,RequestMethod.GET})
public void contacteditor(@RequestParam String oper,@RequestParam long ID,Contact contact,BindingResult result,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":{
Person person= personRepository.findOne(ID);
if(person!=null) {
person.addContact(contact);
contactRepository.save(contact);
personRepository.save(person);
response.setStatus(200);
} else{
response.sendError(404, "NO COUNTERPART WITH ID " +ID+" FOUND");
}
}break;
case "edit": {
Contact agr = contactRepository.findOne(contact.getId());
if (agr != null && agr.getVersion() <= contact.getVersion()) {
agr.setContact(contact.getContact());
agr.setContactType(contact.getContactType());
contactRepository.save(agr);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + contact.getId() + " FOUND");
}
}break;
case "del": {
Person person= personRepository.findOne(ID);
if (person != null) {
Contact agr=contactRepository.findOne(contact.getId());
if(agr!=null) {
person.removeContact(agr);
contactRepository.delete(agr);
personRepository.save(person);
response.setStatus(200);
} else {
response.sendError(404, "NO Agreement WITH ID " + contact.getId() + " FOUND");
}
} else {
response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND");
}
}break;
default:
response.sendError(406, "UNKNOWN OPERATION");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public String getContact() {
public void setContact(String contact) {
this.contact = contact;
}

public long getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Role {
@GeneratedValue
Long id;
String name;
String description;
@Version
long version;

Expand All @@ -31,6 +32,14 @@ public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public long getVersion() {
return version;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ua.pp.fairwind.favorid.internalDB.model.storehouses;

/**
* Created by Ñåðãåé on 13.10.2015.
*/
public enum MOVEMENT_TYPES {
ARRIVAL,
SHIPMENT,
MOVE,
DEFECTIVE,
UTILIZATION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package ua.pp.fairwind.favorid.internalDB.model.storehouses;

import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
import ua.pp.fairwind.favorid.internalDB.model.Person;

import javax.persistence.*;
import java.util.Date;

/**
* Created by Ñåðãåé on 13.10.2015.
*/
@Entity
@Table(name = "STOREHOUSE_MOVEMENT")
public class Movement {
@Id
@GeneratedValue
Long id;
MOVEMENT_TYPES typeMovement;
@ManyToOne
@JoinColumn(name = "responsible_person_ID")
Person responsiblePerson;
Date operationDate;
@ManyToOne
@JoinColumn(name = "from_storehouse_ID")
Storehouse fromStorehouse;
@ManyToOne
@JoinColumn(name = "counterparty_id")
Counterparty counterparty;
@ManyToOne
@JoinColumn(name = "to_storehouse_ID")
Storehouse toStorehouse;
@ManyToOne
@JoinColumn(name = "nomenclature_ID")
Nomenclature nomenclature;
long count;
String units;

public Long getId() {
return id;
}

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

public MOVEMENT_TYPES getTypeMovement() {
return typeMovement;
}

public void setTypeMovement(MOVEMENT_TYPES typeMovement) {
this.typeMovement = typeMovement;
}

public Person getResponsiblePerson() {
return responsiblePerson;
}

public void setResponsiblePerson(Person responsiblePerson) {
this.responsiblePerson = responsiblePerson;
}

public Date getOperationDate() {
return operationDate;
}

public void setOperationDate(Date operationDate) {
this.operationDate = operationDate;
}

public Storehouse getFromStorehouse() {
return fromStorehouse;
}

public void setFromStorehouse(Storehouse fromStorehouse) {
this.fromStorehouse = fromStorehouse;
}

public Counterparty getCounterparty() {
return counterparty;
}

public void setCounterparty(Counterparty counterparty) {
this.counterparty = counterparty;
}

public Storehouse getToStorehouse() {
return toStorehouse;
}

public void setToStorehouse(Storehouse toStorehouse) {
this.toStorehouse = toStorehouse;
}

public Nomenclature getNomenclature() {
return nomenclature;
}

public void setNomenclature(Nomenclature nomenclature) {
this.nomenclature = nomenclature;
}

public long getCount() {
return count;
}

public void setCount(long count) {
this.count = count;
}

public String getUnits() {
return units;
}

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

0 comments on commit cfb520f

Please sign in to comment.