implemented sorting Employees based on keyword counts.
This commit is contained in:
parent
912b6c5e4b
commit
f0c09fd74f
@ -1,6 +1,8 @@
|
||||
package se.su.dsv.scipro.admin.panels.match;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
@ -60,7 +62,7 @@ public class AdminSupervisorKeywordPanel extends Panel {
|
||||
if(!supervisorName.toString().isEmpty()) {
|
||||
String addToSearch = "true";
|
||||
}
|
||||
if (sortDirection.toString().isEmpty() || sortDirection.toString().equals("ASC")) {
|
||||
if ((sortDirection.toString().isEmpty() && !orderBy.equals("keywords.all.size")) || sortDirection.toString().equals("ASC")) {
|
||||
sortDirection.delete(0, sortDirection.length());
|
||||
sortDirection.append("DESC");
|
||||
} else {
|
||||
@ -84,6 +86,38 @@ if(!supervisorName.toString().isEmpty()) {
|
||||
return employeeList;
|
||||
}
|
||||
|
||||
|
||||
private List<Employee> sortEmployeeList(final StringBuffer sortDirection, final StringBuffer orderBy, List<Employee> employeeList) {
|
||||
if(sortDirection.toString().equals("ASC")) {
|
||||
Collections.sort(employeeList, new Comparator<Employee>() {
|
||||
@Override
|
||||
public int compare(Employee o1, Employee o2) {
|
||||
if (o1.getKeywords().getAll().size() > o2.getKeywords().getAll().size()) {
|
||||
return -1;
|
||||
} else if (o2.getKeywords().getAll().size() > o1.getKeywords().getAll().size()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (orderBy.toString().equals("keywords.all.size") && sortDirection.toString().equals("DESC")) {
|
||||
Collections.sort(employeeList, new Comparator<Employee>() {
|
||||
@Override
|
||||
public int compare(Employee o1, Employee o2) {
|
||||
if (o1.getKeywords().getAll().size() > o2.getKeywords().getAll().size()) {
|
||||
return 1;
|
||||
} else if (o2.getKeywords().getAll().size() > o1.getKeywords().getAll().size()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return employeeList;
|
||||
}
|
||||
|
||||
private void setUpTable(final Dialog dialog, final WebMarkupContainer tableContainer, final StringBuffer supervisorName) {
|
||||
final StringBuffer sortDirection = new StringBuffer();
|
||||
final StringBuffer orderBy = new StringBuffer();
|
||||
@ -97,12 +131,16 @@ if(!supervisorName.toString().isEmpty()) {
|
||||
if (sortDirection.toString().isEmpty()) {
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.ASC, "user.lastName");
|
||||
} else if (sortDirection.toString().equals("ASC")) {
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.ASC, orderBy.toString());
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.ASC, "user.lastName");
|
||||
} else {
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.DESC, orderBy.toString());
|
||||
sorter = new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.DESC, "user.lastName");
|
||||
}
|
||||
List<Employee> employeeList = new ArrayList<Employee>();
|
||||
employeeList.addAll(supervisorService.findAllEmployees(sorter));
|
||||
|
||||
if(orderBy.toString().equals("keywords.all.size")) {
|
||||
employeeList = sortEmployeeList(sortDirection, orderBy, employeeList);
|
||||
}
|
||||
if(supervisorName.toString().isEmpty()) {
|
||||
return employeeList;
|
||||
}
|
||||
@ -157,7 +195,7 @@ if(!supervisorName.toString().isEmpty()) {
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
getSortOrder(sortDirection, orderBy, "keywords.all.size()", supervisorName);
|
||||
getSortOrder(sortDirection, orderBy, "keywords.all.size", supervisorName);
|
||||
target.addComponent(tableContainer);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user