Using a native SQL query to sort the Employees based on keywords in the statistics page.
This commit is contained in:
parent
2066e433e9
commit
eb9d2a52ce
@ -48,7 +48,6 @@ public class AdminSupervisorKeywordPanel extends Panel {
|
||||
StringBuffer supervisorName = new StringBuffer();
|
||||
add(new FilterForm(tableContainer, supervisorField, supervisorName));
|
||||
setUpTable(dialog, tableContainer, supervisorName);
|
||||
|
||||
}
|
||||
|
||||
private void setUpDialog(Dialog dialog) {
|
||||
@ -65,12 +64,12 @@ public class AdminSupervisorKeywordPanel extends Panel {
|
||||
if(!supervisorName.toString().isEmpty()) {
|
||||
String addToSearch = "true";
|
||||
}
|
||||
if ((sortDirection.toString().isEmpty() && !orderBy.equals("keywords.all.size")) || sortDirection.toString().equals("ASC")) {
|
||||
if ((sortDirection.toString().isEmpty() && !orderBy.equals("keywords.all.size")) || sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||
sortDirection.delete(0, sortDirection.length());
|
||||
sortDirection.append("DESC");
|
||||
sortDirection.append("desc");
|
||||
} else {
|
||||
sortDirection.delete(0, sortDirection.length());
|
||||
sortDirection.append("ASC");
|
||||
sortDirection.append("asc");
|
||||
}
|
||||
orderBy__.delete(0, orderBy__.length());
|
||||
orderBy__.append(orderBy);
|
||||
@ -90,6 +89,29 @@ if(!supervisorName.toString().isEmpty()) {
|
||||
return employeeList;
|
||||
}
|
||||
|
||||
private void loadEmployeeList(List<Employee> employeeList, StringBuffer orderBy, StringBuffer sortDirection) {
|
||||
KeywordType keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||
if(orderBy.toString().equals("keywords.all.size")) {
|
||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||
} else if (orderBy.toString().equals("areas.all.size")) {
|
||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA);
|
||||
}
|
||||
|
||||
if(sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "asc")) {
|
||||
if(!employeeList.contains(employee)) {
|
||||
employeeList.add(employee);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "desc")) {
|
||||
if(!employeeList.contains(employee)) {
|
||||
employeeList.add(employee);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpTable(final Dialog dialog, final WebMarkupContainer tableContainer, final StringBuffer supervisorName) {
|
||||
final StringBuffer sortDirection = new StringBuffer();
|
||||
final StringBuffer orderBy = new StringBuffer();
|
||||
@ -100,38 +122,17 @@ if(!supervisorName.toString().isEmpty()) {
|
||||
@Override
|
||||
protected List<Employee> load() {
|
||||
List<Employee> employeeList = new ArrayList<Employee>();
|
||||
org.springframework.data.domain.Sort sorter;
|
||||
|
||||
if(!orderBy.toString().equals("areas.all.size") && !orderBy.toString().equals("keywords.all.size")) {
|
||||
if (sortDirection.toString().isEmpty() || sortDirection.toString().equals("ASC")) {
|
||||
org.springframework.data.domain.Sort sorter;
|
||||
if (sortDirection.toString().isEmpty() || sortDirection.toString().equalsIgnoreCase("asc")) {
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.ASC, "user.lastName");
|
||||
employeeList.addAll(supervisorService.findAllEmployees(sorter));
|
||||
} else {
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.DESC, "user.lastName");
|
||||
employeeList.addAll(supervisorService.findAllEmployees(sorter));
|
||||
}
|
||||
}
|
||||
KeywordType keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||
if(orderBy.toString().equals("keywords.all.size") || orderBy.toString().equals("areas.all.size")) {
|
||||
if(orderBy.toString().equals("keywords.all.size")) {
|
||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.REGULAR);
|
||||
} else if (orderBy.toString().equals("areas.all.size")) {
|
||||
keywordType = keywordTypeDao.findByType(KeywordTypeDao.TYPE.RESEARCH_AREA);
|
||||
}
|
||||
|
||||
if(sortDirection.toString().equals("ASC")) {
|
||||
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "asc")) {
|
||||
if(!employeeList.contains(employee)) {
|
||||
employeeList.add(employee);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Employee employee : supervisorService.findSupervisorBySQL(keywordType.getName(), "desc")) {
|
||||
if(!employeeList.contains(employee)) {
|
||||
employeeList.add(employee);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loadEmployeeList(employeeList, orderBy, sortDirection);
|
||||
}
|
||||
if(supervisorName.toString().isEmpty()) {
|
||||
return employeeList;
|
||||
|
Loading…
x
Reference in New Issue
Block a user