-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on documents manipulation
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
1 parent
173d2de
commit bd229eb
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/MessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/ua/pp/fairwind/favorid/internalDB/repository/MessageRecipientRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>{ | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/ua/pp/fairwind/favorid/internalDB/repository/MessageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>{ | ||
} |