Skip to content

Commit

Permalink
WORK ON MESSAGES
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 Nov 2, 2015
1 parent bd229eb commit cb44ad0
Show file tree
Hide file tree
Showing 27 changed files with 2,163 additions and 378 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,86 @@ public Object simpleClientList(@RequestParam(required = false) Integer page_num,
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/documentSubscriber", method = RequestMethod.GET)
@ResponseBody
public Object documentSubscriberList(@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,HttpServletRequest request) {
// Retrieve all persons by delegating the call to PersonService
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Sort sort=new Sort(Sort.Direction.ASC,"surname");
PageRequest pager=null;
if(page_num!=null && per_page!=null) {
page_num= page_num<1?1:page_num;
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<PersonProxy> page;
if (qword != null && qword.length > 0) {
page = personRepository.findSubscriberProxyBySurname("%" + qword[0] + "%", pager);
} else {
page = personRepository.findSubscriberProxy(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
Person ft=null;
if(key!=null) {
ft = personRepository.findOne(key);
}
return ft;
} else {
List<PersonProxy> page;
if (qword != null && qword.length > 0) {
page = personRepository.findSubscriberProxyBySurname("%" + qword[0] + "%", sort);
} else {
page = personRepository.findSubscriberProxy(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/userPersons", method = RequestMethod.GET)
@ResponseBody
public Object userPersonsList(@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,HttpServletRequest request) {
// Retrieve all persons by delegating the call to PersonService
//Sort sort= FormSort.formSortFromSortDescription(orderby);
Sort sort=new Sort(Sort.Direction.ASC,"surname");
PageRequest pager=null;
if(page_num!=null && per_page!=null) {
page_num= page_num<1?1:page_num;
pager = new PageRequest(page_num - 1, per_page, sort);
}
if(pager!=null) {
Page<PersonProxy> page;
if (qword != null && qword.length > 0) {
page = personRepository.findUsersProxyBySurname("%" + qword[0] + "%", pager);
} else {
page = personRepository.findUsersProxy(pager);
}
return new JSComboExpenseResp<>(page);
} else {
if(pkey!=null && !pkey.isEmpty()){
Long key=Long.valueOf(pkey);
Person ft=null;
if(key!=null) {
ft = personRepository.findOne(key);
}
return ft;
} else {
List<PersonProxy> page;
if (qword != null && qword.length > 0) {
page = personRepository.findUsersProxyBySurname("%" + qword[0] + "%", sort);
} else {
page = personRepository.findUsersProxy(sort);
}
return new JSComboExpenseResp<>(page);
}
}
}

@Transactional(readOnly = true)
@RequestMapping(value = "/contacts", method = RequestMethod.POST)
@ResponseBody
Expand Down
214 changes: 214 additions & 0 deletions src/main/java/ua/pp/fairwind/favorid/internalDB/jgrid/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package ua.pp.fairwind.favorid.internalDB.jgrid;

import org.springframework.data.domain.Sort;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
* Created by Ñåðãåé on 17.10.2015.
Expand All @@ -19,4 +24,213 @@ public static Long getLongParameter(String name,HttpServletRequest request){
}
return val;
}

public static Sort getJComboSortOrder(HttpServletRequest request){
Sort sort=null;
String order_string=request.getParameter("order_by");
if(order_string!=null && !order_string.isEmpty()){
sort=formSortFromSortDescription(order_string);
}
if(sort==null) {
String[] values = request.getParameterValues("order_by");
if (values != null && values.length > 0) {
sort = formSortFromSortDescription(values);
}
}
if(sort==null) {
String[] values = request.getParameterValues("order_by[]");
if (values != null && values.length > 0) {
sort = formSortFromSortDescription(values);
}
}
if(sort==null) {
order_string = request.getParameter("order_by[]");
if (order_string != null && !order_string.isEmpty()) {
sort = formSortFromSortDescription(order_string);
}
}
return sort;
}

public static Sort formSortFromSortDescription(String[] sortdescription){
if(sortdescription!=null && sortdescription.length>0) {
ArrayList<Sort.Order> listorder = new ArrayList<>();
for (String declaration : sortdescription) {
String[] oneDescription=declaration.split(" ");
if (oneDescription != null) {
if (oneDescription.length > 1) {
switch (oneDescription[1]) {
case "ASC":
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[0]));
case "DESC":
listorder.add(new Sort.Order(Sort.Direction.DESC, oneDescription[0]));
default:
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[0]));
}
} else if (oneDescription.length == 1) {
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[0]));
}
if (listorder.size() > 0) {
return new Sort(listorder.toArray(new Sort.Order[listorder.size()]));
}
} else {
return null;
}
}
}
return null;
}

public static Sort formSortFromSortDescription(String[][] sortdescription){
if(sortdescription!=null && sortdescription.length>0) {
ArrayList<Sort.Order> listorder = new ArrayList<>();
for (String[] oneDescription : sortdescription) {
if (oneDescription != null) {
if (oneDescription.length > 1) {
switch (oneDescription[0]) {
case "ASC":
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[1]));
case "DESC":
listorder.add(new Sort.Order(Sort.Direction.DESC, oneDescription[1]));
default:
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[1]));
}
} else if (oneDescription.length == 1) {
listorder.add(new Sort.Order(Sort.Direction.ASC, oneDescription[0]));
}
if (listorder.size() > 0) {
return new Sort(listorder.toArray(new Sort.Order[listorder.size()]));
}
} else {
return null;
}
}
}
return null;
}

public static Sort formSortFromSortDescription(String sortdescription){

if(sortdescription!=null && !sortdescription.isEmpty()){
sortdescription=sortdescription.trim();
if(sortdescription.contains(",")) {
String[] sortorders = sortdescription.split(",");
ArrayList<Sort.Order> listorder=new ArrayList<>();
for(String sortorder:sortorders){
Sort.Order order=formOrder(sortdescription);
if(order!=null){
listorder.add(order);
}
}
if(listorder.size()>0){
return new Sort(listorder.toArray(new Sort.Order[listorder.size()]));
}
} else {
Sort.Order order=formOrder(sortdescription);
if(order!=null){
return new Sort(order);
}
}

}
return null;
}



public static Sort.Order formOrder(String orderDeclaration){
if(orderDeclaration==null || orderDeclaration.isEmpty()) return null;
String[] delaration=orderDeclaration.trim().split(" ");
if(delaration==null || delaration.length!=2){
return null;
} else {
switch (delaration[1]){
case "ASC" :return new Sort.Order(Sort.Direction.ASC ,delaration[0]);
case "DESC":return new Sort.Order(Sort.Direction.DESC,delaration[0]);
default:
return new Sort.Order(Sort.Direction.ASC ,delaration[0]);
}
}
}



public static void main(String[] args) {
System.out.println(formSortFromSortDescription("filesTypeName%20ASC"));
System.out.println(formSortFromSortDescription("filesTypeName ASC"));
}

public static Long getLongFromString(String str){
if(str==null || str.isEmpty()) return null;
try {
return new Long(str);
} catch (NumberFormatException e){
return null;
}
}

public static Set<Long> getIDsFromRequest(HttpServletRequest request,String paramName){
if(request==null || paramName==null) return null;
Set<Long> set=null;
String idsString=request.getParameter(paramName);
if(idsString!=null){
set=getIdFromString(idsString);
}
if(set==null) {
String[] values = request.getParameterValues(paramName);
if (values != null && values.length > 0) {
set = new HashSet<>();
for (String id : values) {
try {
Long val = new Long(id);
set.add(val);
} catch (NumberFormatException e) {
//do nothing
}
}
if (set.size() == 0) set = null;
}
}
if(set==null) {
String[] values = request.getParameterValues(paramName+"[]");
if (values != null && values.length > 0) {
set = new HashSet<>();
for (String id : values) {
try {
Long val = new Long(id);
set.add(val);
} catch (NumberFormatException e) {
//do nothing
}
}
if (set.size() == 0) set = null;
}
}
if(set==null) {
idsString=request.getParameter(paramName+"[]");
if(idsString!=null){
set=getIdFromString(idsString);
}
}
return set;
}


public static Set<Long> getIdFromString(String s){
if(s==null || s.length()==0)return null;
String[] ids=s.split(",");
if(ids==null | ids.length==0)return null;
Set<Long> set=new HashSet<>();
for (String id:ids){
try {
Long val=new Long(id);
set.add(val);
}catch (NumberFormatException e){
//do nothing
}
}
if(set.size()==0)return null;
return set;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ private long getLevelNode(Person node){
return getLevelNode(node.getHead())+1;
}

public String getFio(){
return (surname==null?"":surname)+" "+(firstName==null?"":firstName)+" "+(middleName==null?"":middleName);
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class User {

@JsonSerialize
public String getFIO(){
if(person==null) return null;
return person.getSurname()==null?"":person.getSurname()+" "+person.getFirstName()==null?"":person.getFirstName()+" "+person.getMiddleName()==null?"":person.getMiddleName();
if(person==null) return "";
return (person.getSurname()==null?"":person.getSurname())+" "+(person.getFirstName()==null?"":person.getFirstName())+" "+(person.getMiddleName()==null?"":person.getMiddleName());
}

@JsonSerialize
Expand Down
Loading

0 comments on commit cb44ad0

Please sign in to comment.