-
Notifications
You must be signed in to change notification settings - Fork 3
story/VSPC-150 #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
story/VSPC-150 #370
Changes from 125 commits
36843b0
5df90f2
afbde02
4e7397f
73bda55
30f114b
4eb9091
9ccba7f
c6a3aac
806c6f3
ecc0a56
d79ca74
e78221a
0efa1c4
e35d814
ef356a5
1472da8
6cfd2dc
1f705ce
cd5de7c
23c7a6e
050434c
6a97e07
b911508
fa4b232
4ab456d
97de8e4
4701276
b6a6931
e011fd2
9cdcada
f9a8d02
12e017f
c127e4f
f1cba65
32fd3ec
8572b9e
e052749
2459455
fa9c77b
f742c0e
612e7e3
f8c00cb
24011d2
9d699a1
231eefc
0695d5f
2ad65f2
95eb77b
69cb8dc
b7905f7
052900c
e955bc5
ee06fdd
0624225
bef1adc
34343d9
5e4a5da
e91d0db
48808b9
dec778a
8e200fe
fc52e03
f086a2c
b42a8e7
a5f9720
fa76448
31188e9
eb55561
96de529
42b1273
4671b33
dc5ca80
2b47341
0b43db6
87ab2fe
57c9cfd
877353e
c17de2c
a402f07
6315712
5c44b28
2e095e6
655bbab
96c9d04
0ac18e2
762acd7
7351ed5
f51d67b
f7208eb
4641c9c
9e0947d
b35c925
fbe0a92
2f3787f
6f4fc4a
ef83e24
55a032f
252596c
c9cdd75
b806615
c6c167c
98d66d7
fd12d7a
9a72bf1
81003bc
8021682
ff999bd
e84f8ec
c07b3fa
f783d66
0465dcd
e927036
ccc2a21
63015c8
aa2d567
6913952
8aff7e5
3252d47
8bd3656
71d2682
5e32730
83641bb
3ef2b79
0b966e2
164b23a
2f939f4
c02ea35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,17 @@ | |
| 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.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import edu.asu.diging.vspace.core.data.ReferenceRepository; | ||
| import edu.asu.diging.vspace.core.model.IBiblioBlock; | ||
| import edu.asu.diging.vspace.core.model.IReference; | ||
| import edu.asu.diging.vspace.core.model.SortByField; | ||
| import edu.asu.diging.vspace.core.model.impl.BiblioBlock; | ||
| import edu.asu.diging.vspace.core.model.impl.Reference; | ||
| import edu.asu.diging.vspace.core.services.IContentBlockManager; | ||
|
|
@@ -27,9 +33,13 @@ | |
|
|
||
| @Autowired | ||
| private IContentBlockManager contentBlockManager; | ||
|
|
||
| @Value("${page_size}") | ||
| private int pageSize; | ||
|
|
||
| @Override | ||
| public IReference createReference(String biblioId, String title, String author,String year,String journal, String url, String volume,String issue, String pages,String editor, String type, String note) { | ||
| public IReference createReference(String biblioId, String title, String author,String year,String journal, String url, String volume,String issue, String pages,String editor, String type, String note, String visibility) { | ||
|
|
||
| IReference reference = new Reference(); | ||
| reference.setAuthor(author); | ||
| reference.setTitle(title); | ||
|
|
@@ -42,6 +52,13 @@ | |
| reference.setEditors(editor); | ||
| reference.setType(type); | ||
| reference.setNote(note); | ||
| if(visibility == "Private") { | ||
|
||
| reference.setVisibility(false); | ||
|
Check warning on line 56 in vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ReferenceManager.java
|
||
| } | ||
| else { | ||
| reference.setVisibility(true); | ||
|
Check warning on line 59 in vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ReferenceManager.java
|
||
| } | ||
|
|
||
| BiblioBlock biblio = contentBlockManager.getBiblioBlock(biblioId); | ||
| reference.getBiblios().add(biblio); | ||
| return referenceRepo.save((Reference) reference); | ||
|
|
@@ -81,4 +98,47 @@ | |
| public List<IReference> getReferencesForBiblio(String biblioId) { | ||
| return new ArrayList<>(referenceRepo.findByBiblios_Id(biblioId)); | ||
| } | ||
|
|
||
| @Override | ||
| public List<IReference> getAllReferences(int pageNo, String sortedBy, String order) { | ||
| Sort sortingParameters = getSortingParameters(sortedBy, order); | ||
| if (pageNo < 1) { | ||
| pageNo = 1; | ||
| } | ||
| Pageable pageable = PageRequest.of(pageNo - 1, pageSize, sortingParameters); | ||
| Page<Reference> references = referenceRepo.findAll(pageable); | ||
| if (references.getContent().size() == 0 && references.getTotalPages() > 0) { | ||
| pageable = PageRequest.of(references.getTotalPages() - 1, pageSize, sortingParameters); | ||
| references = referenceRepo.findAll(pageable); | ||
| } | ||
| List<IReference> results = new ArrayList<>(); | ||
| if (references != null) { | ||
| references.getContent().forEach(ref -> results.add(ref)); | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| @Override | ||
| public long getTotalReferenceCount() { | ||
| return referenceRepo.count(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getTotalPages() { | ||
| long count = referenceRepo.count(); | ||
| return (count % pageSize == 0) ? count / pageSize : (count / pageSize) + 1; | ||
| } | ||
|
|
||
| private Sort getSortingParameters(String sortedBy, String order) { | ||
| Sort sortingParameters = Sort.by(SortByField.CREATION_DATE.getValue()).descending(); | ||
| if (sortedBy != null && SortByField.getAllValues().contains(sortedBy)) { | ||
| sortingParameters = Sort.by(sortedBy); | ||
| } | ||
| if (order != null && order.equalsIgnoreCase(Sort.Direction.ASC.toString())) { | ||
| sortingParameters = sortingParameters.ascending(); | ||
| } else { | ||
| sortingParameters = sortingParameters.descending(); | ||
| } | ||
| return sortingParameters; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,8 @@ public class AddReferenceController { | |
|
|
||
| @RequestMapping(value = "/staff/module/{id}/slide/{slideId}/bibliography/{biblioId}/reference/add", | ||
| method = RequestMethod.POST) | ||
| public ResponseEntity<IReference> addReference(@PathVariable("id") String moduleId, | ||
| public ResponseEntity<Reference> addReference(@PathVariable("id") String moduleId, | ||
|
||
|
|
||
| @PathVariable("slideId") String slideId, | ||
| @PathVariable("biblioId") String biblioId, | ||
| @RequestBody ReferenceData referenceData, | ||
|
|
@@ -40,9 +41,10 @@ public ResponseEntity<IReference> addReference(@PathVariable("id") String module | |
| referenceData.getPages(), | ||
| referenceData.getEditors(), | ||
| referenceData.getType(), | ||
| referenceData.getNote() | ||
| referenceData.getNote(), | ||
| referenceData.getVisibility() | ||
| ); | ||
|
|
||
| return ResponseEntity.ok(ref); | ||
| return ResponseEntity.ok((Reference) ref); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package edu.asu.diging.vspace.web.staff; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
|
|
||
| import edu.asu.diging.vspace.core.model.IReference; | ||
| import edu.asu.diging.vspace.core.model.SortByField; | ||
| import edu.asu.diging.vspace.core.services.IReferenceManager; | ||
|
|
||
| @Controller | ||
| public class ListReferencesController { | ||
|
|
||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
|
||
| @Autowired | ||
| private IReferenceManager referenceManager; | ||
|
|
||
| @RequestMapping("/staff/references/list") | ||
| public String listReferencesWithoutNum(Model model, | ||
| @RequestParam(value = "sort", required = false) String sortedBy, | ||
| @RequestParam(value = "order", required = false) String order) { | ||
| return String.format("redirect:/staff/references/list/1?sort=%s&order=%s", | ||
| sortedBy, order); | ||
| } | ||
|
|
||
| @RequestMapping("/staff/references/list/{page}") | ||
| public String listReferences(@PathVariable(required = false) String page, | ||
| @RequestParam(value = "sort", required = false) String sortedBy, | ||
| @RequestParam(value = "order", required = false) String order, | ||
| Model model, | ||
| RedirectAttributes attributes) { | ||
| int pageNo; | ||
| page = StringUtils.isEmpty(page) ? "1" : page; | ||
|
|
||
| try { | ||
| pageNo = Integer.parseInt(page); | ||
| if (pageNo < 1) { | ||
| pageNo = 1; | ||
| } | ||
| } catch (NumberFormatException numberFormatException) { | ||
| pageNo = 1; | ||
| } | ||
|
|
||
| List<IReference> references = referenceManager.getAllReferences(pageNo, sortedBy, order); | ||
|
|
||
| model.addAttribute("totalPages", referenceManager.getTotalPages()); | ||
| model.addAttribute("currentPageNumber", pageNo); | ||
| model.addAttribute("totalReferenceCount", referenceManager.getTotalReferenceCount()); | ||
| model.addAttribute("references", references); | ||
| model.addAttribute("sortProperty", | ||
| (sortedBy == null || sortedBy.equals("")) | ||
| ? SortByField.CREATION_DATE.getValue() : sortedBy); | ||
| model.addAttribute("order", | ||
| (order == null || order.equals("")) | ||
| ? Sort.Direction.DESC.toString().toLowerCase() : order); | ||
|
|
||
| return "staff/references/referencelist"; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean variables should be adjectives so that the methods make sense when you call them
is...(i.e.isVisibilitydoes not make much sense...)