Skip to content

Commit

Permalink
WORK ON REQUEST
Browse files Browse the repository at this point in the history
TODO:
REQUEST MANIPULATION
MESSAGE MANIPULATION
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTROLLED TASK FOR USER
SHOW USERS TASK
STOREHOUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
REGISTER BAD PRODUCT
  • Loading branch information
FairWindCo committed Oct 30, 2015
1 parent 4caa62e commit 173d2de
Show file tree
Hide file tree
Showing 18 changed files with 1,812 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Object createdList(@RequestParam(required = false) Integer page_num, @Req
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.findCreated(qword[0], pager);
} else {
page = nomenclatureRepository.findCreated(pager);
page = nomenclatureRepository.findByCombined(true, pager);
}
return new JSComboExpenseResp<>(page);
} else {
Expand All @@ -249,7 +249,7 @@ public Object createdList(@RequestParam(required = false) Integer page_num, @Req
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.findCreated(qword[0], sort);
} else {
page = nomenclatureRepository.findCreated(sort);
page = nomenclatureRepository.findByCombined(true, sort);
}
return new JSComboExpenseResp<>(page);
}
Expand All @@ -273,7 +273,7 @@ public Object arrivalList(@RequestParam(required = false) Integer page_num, @Req
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.findArrival(qword[0], pager);
} else {
page = nomenclatureRepository.findArrival(pager);
page = nomenclatureRepository.findByCombined(false,pager);
}
return new JSComboExpenseResp<>(page);
} else {
Expand All @@ -289,7 +289,7 @@ public Object arrivalList(@RequestParam(required = false) Integer page_num, @Req
if (qword != null && qword.length > 0) {
page = nomenclatureRepository.findArrival(qword[0], sort);
} else {
page = nomenclatureRepository.findArrival(sort);
page = nomenclatureRepository.findByCombined(false,sort);
}
return new JSComboExpenseResp<>(page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.List;

/**
* Created by Ñåðãåé on 19.10.2015.
* Created by ������ on 19.10.2015.
*/
@Controller
@RequestMapping("/requests")
Expand All @@ -55,6 +55,20 @@ public String list(Model model) {
return "requests/request_list";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/detail", method = RequestMethod.GET)
public String list(Model model,@RequestParam long id) throws IOException {
Request request=requestRepository.findOne(id);
if(request==null) {
return "error404";
}
//Set<RequestItems> items=request.getItems();
//model.addAttribute("itemsObject",items);
model.addAttribute("requestObject",request);

return "requests/request_detail";
}

@Secured("ROLE_USER")
@RequestMapping(value = "/list_purchase", method = RequestMethod.GET)
public String listPurchase(Model model) {
Expand Down Expand Up @@ -300,7 +314,7 @@ public void subscribe(@RequestParam long id,HttpServletResponse response)throws
response.sendError(404, "REQUEST NOT FOUND!");
return;
}
if (request.isExecuted() || request.getApprovedPerson() != null) {
if (request.isSubscribed() || request.getApprovedPerson() != null) {
response.sendError(403, "FORBIDDEN!");
return;
}
Expand All @@ -309,6 +323,25 @@ public void subscribe(@RequestParam long id,HttpServletResponse response)throws
requestRepository.save(request);
}

@Transactional(readOnly = false)
@RequestMapping(value = "/commite", method = {RequestMethod.POST,RequestMethod.GET})
public void commite(@RequestParam long id,HttpServletResponse response)throws IOException {
UserDetailsAdapter userDetail=(UserDetailsAdapter) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Request request = requestRepository.findOne(id);
if (request == null) {
response.sendError(404, "REQUEST NOT FOUND!");
return;
}
if (request.isExecuted() || request.getApprovedPerson() != null) {
response.sendError(403, "FORBIDDEN!");
return;
}
request.setExecuted(true);
request.setExecutedDate(new Date());
request.setExecutedPerson(userDetail.getUserPerson());
requestRepository.save(request);
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,@RequestParam Long id,HttpServletRequest req,HttpServletResponse response)throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.security.core.context.SecurityContextHolder;
import ua.pp.fairwind.favorid.internalDB.model.Agreement;
import ua.pp.fairwind.favorid.internalDB.model.Counterparty;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.security.UserDetailsAdapter;

import javax.persistence.*;
import java.util.Collections;
Expand Down Expand Up @@ -33,10 +36,14 @@ public class Request {
@ManyToOne
@JoinColumn(name = "agreement_ID")
Agreement agreement;
@OneToMany(cascade = CascadeType.ALL)
@OneToMany(cascade = CascadeType.ALL,mappedBy = "request")
@JsonIgnore
Set<RequestItems> items=new HashSet<>();
boolean executed=false;
Date executedDate;
@ManyToOne
@JoinColumn(name = "executed_person_ID")
Person executedPerson;
@ManyToOne
@JoinColumn(name = "approved_person_ID")
Person approvedPerson;
Expand All @@ -52,6 +59,64 @@ public class Request {
Set<Request> requests=new HashSet<>();
String comments;

private boolean testSubscribe(UserDetailsAdapter userDetail){
switch (typeRequest){
case PRODUCTION:
return userDetail.hasRole("ROLE_SUBSCRIBE_REQUEST_PRODUCTION");
case SHIPMENT:
return userDetail.hasRole("ROLE_SUBSCRIBE_REQUEST_SHIPMENT");
case PURCHASE:
return userDetail.hasRole("ROLE_SUBSCRIBE_REQUEST_PURCHASE");
case REPAIR:
return userDetail.hasRole("ROLE_SUBSCRIBE_REQUEST_REPAIR");
default:
return false;
}
}

private boolean testCommite(UserDetailsAdapter userDetail){
switch (typeRequest){
case PRODUCTION:
return userDetail.hasRole("ROLE_COMMIT_REQUEST_PRODACTION");
case SHIPMENT:
return userDetail.hasRole("ROLE_COMMIT_REQUEST_STOREHOUSE");
case PURCHASE:
return userDetail.hasRole("ROLE_COMMIT_REQUEST_STOREHOUSE");
case REPAIR:
return userDetail.hasRole("ROLE_COMMIT_REQUEST_REPAIR");
default:
return false;
}
}

@JsonSerialize
public boolean isCanSubscribe(){
UserDetailsAdapter userDetail=(UserDetailsAdapter) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(responsiblePerson!=null && userDetail!=null && userDetail.getUserPerson()!=null){
if(responsiblePerson.equals(userDetail))return false;
if((approvedDate != null || approvedPerson != null)) return false;
return testSubscribe(userDetail);
} else {
return false;
}
}

@JsonSerialize
public boolean isSubscribed(){
return approvedDate!=null || approvedPerson!=null;
}

@JsonSerialize
public boolean isCanCommite(){
if((executed || executedPerson != null || executedDate!= null)) return false;
UserDetailsAdapter userDetail=(UserDetailsAdapter) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(userDetail!=null && userDetail.getUserPerson()!=null){
return testCommite(userDetail);
} else {
return false;
}
}


public Long getId() {
return id;
Expand Down Expand Up @@ -187,4 +252,20 @@ public String getComments() {
public void setComments(String comments) {
this.comments = comments;
}

public Date getExecutedDate() {
return executedDate;
}

public void setExecutedDate(Date executedDate) {
this.executedDate = executedDate;
}

public Person getExecutedPerson() {
return executedPerson;
}

public void setExecutedPerson(Person executedPerson) {
this.executedPerson = executedPerson;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,21 @@ public interface NomenclatureRepository extends JpaRepository<Nomenclature,Long>
List<Nomenclature> find(@Param(value = "search")String name, Sort sort);


@Query("select n from Nomenclature n where n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
@Query("select n from Nomenclature n where (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%) and n.combined=true")
Page<Nomenclature> findCreated(@Param(value = "search")String name, Pageable pager);
@Query("select n from Nomenclature n where n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
List<Nomenclature> findCreated(@Param(value = "search")String name);
@Query("select n from Nomenclature n where n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
@Query("select n from Nomenclature n where (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%) and n.combined=true")
List<Nomenclature> findCreated(@Param(value = "search")String name, Sort sort);
@Query("select n from Nomenclature n where n.combined")
Page<Nomenclature> findCreated(Pageable pager);
@Query("select n from Nomenclature n where n.combined")
List<Nomenclature> findCreated();
@Query("select n from Nomenclature n where n.combined")
List<Nomenclature> findCreated(Sort sort);

@Query("select n from Nomenclature n where not n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
@Query("select n from Nomenclature n where (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%) and n.combined=false")
Page<Nomenclature> findArrival(@Param(value = "search")String name, Pageable pager);
@Query("select n from Nomenclature n where not n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
List<Nomenclature> findArrival(@Param(value = "search")String name);
@Query("select n from Nomenclature n where not n.combined and (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%)")
@Query("select n from Nomenclature n where (n.code like %:search% or n.name like %:search% or n.country like %:search% or n.manufacturer like %:search%) and n.combined=false")
List<Nomenclature> findArrival(@Param(value = "search")String name, Sort sort);
@Query("select n from Nomenclature n where not n.combined")
Page<Nomenclature> findArrival(Pageable pager);
@Query("select n from Nomenclature n where not n.combined")
List<Nomenclature> findArrival();
@Query("select n from Nomenclature n where not n.combined")
List<Nomenclature> findArrival(Sort sort);



Page<Nomenclature> findByCombined(boolean combined,Pageable pager);
List<Nomenclature> findByCombined(boolean combined,Sort sort);




}
11 changes: 10 additions & 1 deletion src/main/resources/label_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,13 @@ label.MILLILITRES=MILLILITRES
label.METERS=METERS
label.MILLIMETERS=MILLIMETERS
label.requests.nomenclature=Nomenclature
label.requests.items.comments=Comments
label.requests.items.comments=Comments
label.requests.responsePerson=Modification Person
label.requests.modificationDate=Modification Date
label.requests.approvedPerson=Approved Person
label.requests.approvedDate=Approved
label.requests.commitedPerson=Commited Peroson
label.requests.commitedDate=Commited
label.requests.items.count=count
label.requests.items.unit=unit
label.requests.items.date=date
11 changes: 10 additions & 1 deletion src/main/resources/label_ru_RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,13 @@ label.MILLILITRES=MILLILITRES
label.METERS=METERS
label.MILLIMETERS=MILLIMETERS
label.requests.nomenclature=Nomenclature
label.requests.items.comments=Comments
label.requests.items.comments=Comments
label.requests.responsePerson=Modification Person
label.requests.modificationDate=Modification Date
label.requests.approvedPerson=Approved Person
label.requests.approvedDate=Approved
label.requests.commitedPerson=Commited Peroson
label.requests.commitedDate=Commited
label.requests.items.count=count
label.requests.items.unit=unit
label.requests.items.date=date
11 changes: 10 additions & 1 deletion src/main/resources/label_ua_UA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,13 @@ label.MILLILITRES=MILLILITRES
label.METERS=METERS
label.MILLIMETERS=MILLIMETERS
label.requests.nomenclature=Nomenclature
label.requests.items.comments=Comments
label.requests.items.comments=Comments
label.requests.responsePerson=Modification Person
label.requests.modificationDate=Modification Date
label.requests.approvedPerson=Approved Person
label.requests.approvedDate=Approved
label.requests.commitedPerson=Commited Peroson
label.requests.commitedDate=Commited
label.requests.items.count=count
label.requests.items.unit=unit
label.requests.items.date=date
Loading

0 comments on commit 173d2de

Please sign in to comment.