Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ResponseEntity<String> getCollectionsByGroupId(@RequestHeader HttpHeaders
@PathVariable("zoteroGroupId") String groupId,
@PathVariable(value = "collectionId", required = false) String collectionId,
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sort,
@RequestParam(required = false, value = "columns") String[] columns, Principal principal)
throws GroupDoesNotExistException {
Integer pageInt = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -15,8 +17,6 @@
import javax.transaction.Transactional;

import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
Expand Down Expand Up @@ -47,6 +47,7 @@
import edu.asu.diging.citesphere.model.bib.ICitation;
import edu.asu.diging.citesphere.model.bib.ICitationCollection;
import edu.asu.diging.citesphere.model.bib.ICitationGroup;
import edu.asu.diging.citesphere.model.bib.IPerson;
import edu.asu.diging.citesphere.model.bib.IReference;
import edu.asu.diging.citesphere.model.bib.ItemType;
import edu.asu.diging.citesphere.model.bib.impl.BibField;
Expand Down Expand Up @@ -93,11 +94,68 @@ public class CitationManager implements ICitationManager {
@PostConstruct
public void init() {
sortFunctions = new HashMap<>();
sortFunctions.put("title", ((o1, o2) -> {
String o1Title = o1 != null && o1.getTitle() != null ? o1.getTitle() : "";
String o2Title = o2 != null && o2.getTitle() != null ? o2.getTitle() : "";
return o1Title.toLowerCase().compareTo(o2Title.toLowerCase());
}));
// Title
sortFunctions.put("title", (o1, o2) -> {
String t1 = Optional.ofNullable(o1).map(ICitation::getTitle).orElse("").toLowerCase();
String t2 = Optional.ofNullable(o2).map(ICitation::getTitle).orElse("").toLowerCase();
return t1.compareTo(t2);
});
// Type
sortFunctions.put("type", (o1, o2) -> {
String s1 = Optional.ofNullable(o1)
.map(ICitation::getItemType)
.map(Enum::name)
.orElse("");
String s2 = Optional.ofNullable(o2)
.map(ICitation::getItemType)
.map(Enum::name)
.orElse("");
return s1.compareToIgnoreCase(s2);
});
// Author
sortFunctions.put("author", (o1, o2) -> {
List<IPerson> authors1 = o1 != null && o1.getAuthors() != null
? new ArrayList<>(o1.getAuthors())
: Collections.emptyList();
List<IPerson> authors2 = o2 != null && o2.getAuthors() != null
? new ArrayList<>(o2.getAuthors())
: Collections.emptyList();

int minSize = Math.min(authors1.size(), authors2.size());

for (int i = 0; i < minSize; i++) {
IPerson p1 = authors1.get(i);
IPerson p2 = authors2.get(i);
if(p1!=null && p2!=null) {
String ln1 = p1.getLastName() != null ? p1.getLastName().replaceAll("\\s+", " ").trim() : "";
String ln2 = p2.getLastName() != null ? p2.getLastName().replaceAll("\\s+", " ").trim() : "";

int cmp = ln1.compareToIgnoreCase(ln2);
if (cmp != 0) return cmp;

String fn1 = p1.getFirstName() != null ? p1.getFirstName().replaceAll("\\s+", " ").trim() : "";
String fn2 = p2.getFirstName() != null ? p2.getFirstName().replaceAll("\\s+", " ").trim() : "";

cmp = fn1.compareToIgnoreCase(fn2);
if (cmp != 0) return cmp;
}
}
return Integer.compare(authors1.size(), authors2.size());
});

// Date (dateFreetext)
sortFunctions.put("date", (o1, o2) -> {
String d1 = Optional.ofNullable(o1).map(ICitation::getDateFreetext).orElse("");
String d2 = Optional.ofNullable(o2).map(ICitation::getDateFreetext).orElse("");
return d1.compareToIgnoreCase(d2);
});

// URL
sortFunctions.put("url", (o1, o2) -> {
String u1 = Optional.ofNullable(o1).map(ICitation::getUrl).orElse("").toLowerCase();
String u2 = Optional.ofNullable(o2).map(ICitation::getUrl).orElse("").toLowerCase();
return u1.compareToIgnoreCase(u2);
});
}

@Override
Expand Down Expand Up @@ -443,6 +501,11 @@ public CitationResults getGroupItems(IUser user, String groupId, String collecti
total = citations.size();
}
}
BiFunction<ICitation, ICitation, Integer> sorter = sortFunctions.get(sortBy);
if (sorter != null) {
Comparator<ICitation> comparator = sorter::apply;
citations.sort(comparator);
}
results.setCitations(citations != null ? citations : new ArrayList<>());
results.setTotalResults(total);
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CollectionItemsController {

public String show(Authentication authentication, Model model, @PathVariable("zoteroGroupId") String groupId,
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort)
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sort)
throws GroupDoesNotExistException, ZoteroHttpStatusException {
Integer pageInt = 1;
try {
Expand All @@ -49,7 +49,7 @@ public String show(Authentication authentication, Model model, @PathVariable("zo
model.addAttribute("totalPages", Math.ceil(new Float(results.getTotalResults()) / new Float(zoteroPageSize)));
model.addAttribute("currentPage", pageInt);
model.addAttribute("zoteroGroupId", groupId);
model.addAttribute("citationCollections", collectionManager.getCitationCollections(user, groupId, null, pageInt, "title").getCitationCollections());
model.addAttribute("citationCollections", collectionManager.getCitationCollections(user, groupId, null, pageInt, sort).getCitationCollections());

return "auth/group/items";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class FetchItemsController {
public @ResponseBody String show(Authentication authentication, @PathVariable("zoteroGroupId") String groupId,
@PathVariable(value = "collectionId", required = false) String collectionId,
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sort,
@RequestParam(required = false, value = "columns") String[] columns) {
Integer pageInt = 1;
try {
Expand Down Expand Up @@ -93,7 +93,7 @@ public class FetchItemsController {

try {
itemsData.setCitationCollections(
collectionManager.getAllCollections(user, groupId, collectionId, "title", 200));
collectionManager.getAllCollections(user, groupId, collectionId, sort, 200));
} catch (GroupDoesNotExistException e) {
logger.error("Group does not exist exception occured while fecting items data", e);
return "error/404";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class GroupItemsController {
public String show(Authentication authentication, Model model, @PathVariable("zoteroGroupId") String groupId,
@PathVariable(value="collectionId", required=false) String collectionId,
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sortBy,
@RequestParam(required = false, value = "columns") String[] columns,
@RequestParam(required = false, defaultValue = "", value = "conceptIds") String[] conceptIds) {
Integer pageInt = 1;
Expand All @@ -70,7 +70,7 @@ public String show(Authentication authentication, Model model, @PathVariable("zo
IUser user = (IUser) authentication.getPrincipal();
CitationResults results;
try {
results = citationManager.getGroupItems(user, groupId, collectionId, pageInt, sort, Arrays.asList(conceptIds));
results = citationManager.getGroupItems(user, groupId, collectionId, pageInt, sortBy, Arrays.asList(conceptIds));
} catch(ZoteroHttpStatusException e) {
logger.error("Exception occured", e);
return "error/500";
Expand All @@ -86,11 +86,11 @@ public String show(Authentication authentication, Model model, @PathVariable("zo
model.addAttribute("zoteroGroupId", groupId);
model.addAttribute("group", groupManager.getGroup(user, groupId));
model.addAttribute("collectionId", collectionId);
model.addAttribute("sort", sort);
model.addAttribute("sortBy", sortBy);
model.addAttribute("results", results);
// more than 200 really don't make sense here, this needs to be changed
try {
model.addAttribute("citationCollections", collectionManager.getAllCollections(user, groupId, collectionId, "title", 200));
model.addAttribute("citationCollections", collectionManager.getAllCollections(user, groupId, collectionId, sortBy, 200));
} catch(GroupDoesNotExistException e) {
logger.error("Exception occured", e);
return "error/404";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ public class MoveItemsController {
})
public @ResponseBody Sync startSync(Authentication authentication,
@PathVariable("zoteroGroupId") String zoteroGroupId, @PathVariable("targetCollectionId") String collectionId,
@RequestParam(defaultValue = "1", required = false, value = "page") String page) {
@RequestParam(defaultValue = "1", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sortBy) {
try {
citationManager.getGroupItems((IUser) authentication.getPrincipal(), zoteroGroupId, collectionId,
new Integer(page), null, null);
new Integer(page), sortBy, null);
Sync sync = new Sync();
sync.setStatus("sync-started");
return sync;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SearchController {
public @ResponseBody String search(@PathVariable String zoteroGroupId,
@RequestParam(value = "searchTerm", required = false) String searchTerm, Model model,
@RequestParam(defaultValue = "0", required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sort,
@RequestParam(required = false, value = "columns") String[] columns, Authentication authentication) {

IUser user = (IUser) authentication.getPrincipal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String getCitationsList(Authentication authentication, Model model,
@PathVariable("zoteroGroupId") String zoteroGroupId,
@PathVariable(value="collectionId", required=false) String collectionId,
@RequestParam(required = false, value = "page") String page,
@RequestParam(defaultValue = "title", required = false, value = "sort") String sort,
@RequestParam(defaultValue = "title", required = false, value = "sortBy") String sort,
@RequestParam(required = false, value = "columns") String columns) throws GroupDoesNotExistException {
if (page == null || page.trim().isEmpty()) {
page = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<div layout:fragment="content">
<ol class="breadcrumb">
<li><a th:href="@{/}">Home</a></li>
<li><a th:href="@{|/auth/group/${zoteroGroupId}/items|}">[[${group.name}]]</a></li>
<li><a th:href="@{|/auth/group/${zoteroGroupId}/items?page=${page}&sortBy=${sortBy}|}">[[${group.name}]]</a></li>
<li class="active">[[${citation.key}]]</li>
</ol>

Expand Down
Loading