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 31, 2015
1 parent 173d2de commit bd229eb
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public String index(Model model) {

@RequestMapping(value = "/notfound", method = RequestMethod.GET)
public String eror404(Model model) {
return "error404";
return "error404rror404";
}

@RequestMapping(value = "/error403", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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.messages.Message;
import ua.pp.fairwind.favorid.internalDB.repository.MessageRecipientRepository;
import ua.pp.fairwind.favorid.internalDB.repository.MessageRepository;

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

/**
* Created by Ñåðãåé on 31.10.2015.
*/
@Controller
@RequestMapping("/messages")
public class MessageController {
@Autowired
MessageRepository messageRepository;
@Autowired
MessageRecipientRepository messageRecipientRepository;

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

@Transactional(readOnly = true)
@RequestMapping(value = "/listing", method = RequestMethod.POST)
@ResponseBody
public JGridRowsResponse<Message> 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
}

}/**/
if(pageRequest!=null){
return new JGridRowsResponse<>(messageRepository.findAll(pageRequest));
} else {
return new JGridRowsResponse<>(messageRepository.findAll());
}
}

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Message message,BindingResult result,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":
messageRepository.save(message);
response.setStatus(200);
break;
case "edit":
Message fromDB= messageRepository.getOne(message.getId());
if(fromDB!=null) {
fromDB.setMessageText(message.getMessageText());
fromDB.setActual(message.getActual());
fromDB.getRecipientSet().forEach(messageRecipient -> {
messageRecipient.setValidationDate(null);
messageRecipientRepository.save(messageRecipient);
});
messageRepository.save(fromDB);
response.setStatus(200);
} else {
response.sendError(406,"NO CONTACT TYPE FOUND");
}

break;
case "del":
messageRepository.delete(message.getId());
response.setStatus(200);
break;
default:
response.sendError(406,"UNKNOWN OPERATION");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ua.pp.fairwind.favorid.internalDB.model.messages;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.data.annotation.CreatedBy;
import ua.pp.fairwind.favorid.internalDB.model.administrative.User;

import javax.persistence.*;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -29,6 +31,10 @@ public class Message {
@JoinColumn(name = "created_user_id")
User creationUser;

@JsonSerialize
public String userName(){
return creationUser.getFIO();
}


public Long getId() {
Expand Down Expand Up @@ -70,4 +76,8 @@ public User getCreationUser() {
public void setCreationUser(User creationUser) {
this.creationUser = creationUser;
}

public Set<MessageRecipient> getRecipientSet() {
return Collections.unmodifiableSet(recipientSet);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ua.pp.fairwind.favorid.internalDB.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import ua.pp.fairwind.favorid.internalDB.model.messages.Message;
import ua.pp.fairwind.favorid.internalDB.model.messages.MessageRecipient;

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

public interface MessageRecipientRepository extends JpaRepository<MessageRecipient,Long>{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ua.pp.fairwind.favorid.internalDB.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import ua.pp.fairwind.favorid.internalDB.model.Contact;
import ua.pp.fairwind.favorid.internalDB.model.messages.Message;

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

public interface MessageRepository extends JpaRepository<Message,Long>{
}

0 comments on commit bd229eb

Please sign in to comment.