Skip to content

Commit 566973a

Browse files
authored
Merge pull request #58 from TAMULib/sprint5-staging
Sprint 5 staging
2 parents 199531e + f6806d8 commit 566973a

29 files changed

Lines changed: 440 additions & 44 deletions

src/main/java/edu/tamu/app/controller/NoteController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ public ApiResponse getById(@PathVariable Long id) {
4141
}
4242

4343
@RequestMapping("/create")
44-
@PreAuthorize("hasRole('SERVICE_MANAGER')")
44+
@PreAuthorize("hasRole('WEB_MANAGER')")
4545
@WeaverValidation(business = { @WeaverValidation.Business(value = CREATE) })
4646
public ApiResponse create(@WeaverValidatedModel Note note, @WeaverCredentials Credentials credentials) throws UserNotFoundException {
4747
return new ApiResponse(SUCCESS, noteRepo.create(note, credentials));
4848
}
4949

5050
@RequestMapping("/update")
51-
@PreAuthorize("hasRole('SERVICE_MANAGER')")
51+
@PreAuthorize("hasRole('WEB_MANAGER')")
5252
public ApiResponse update(@WeaverValidatedModel Note note) {
5353
return new ApiResponse(SUCCESS, noteRepo.update(note));
5454
}
5555

5656
@Transactional
5757
@RequestMapping("/remove")
58-
@PreAuthorize("hasRole('SERVICE_MANAGER')")
58+
@PreAuthorize("hasRole('WEB_MANAGER')")
5959
public ApiResponse remove(@WeaverValidatedModel Note note) {
6060
noteRepo.delete(note);
6161
return new ApiResponse(SUCCESS);

src/main/java/edu/tamu/app/controller/NotificationController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ public ApiResponse getById(@PathVariable Long id) {
4040
}
4141

4242
@RequestMapping("/create")
43-
@PreAuthorize("hasRole('WEB_MANAGER')")
43+
@PreAuthorize("hasAnyRole('ADMIN','SERVICE_ADMIN','NOTICE_MANAGER')")
4444
@WeaverValidation(business = { @WeaverValidation.Business(value = CREATE) })
4545
public ApiResponse create(@WeaverValidatedModel Notification notification) {
4646
return new ApiResponse(SUCCESS, notificationRepo.create(notification));
4747
}
4848

4949
@RequestMapping("/update")
50-
@PreAuthorize("hasRole('WEB_MANAGER')")
50+
@PreAuthorize("hasAnyRole('ADMIN','SERVICE_ADMIN','NOTICE_MANAGER')")
5151
@WeaverValidation(business = { @WeaverValidation.Business(value = UPDATE) })
5252
public ApiResponse update(@WeaverValidatedModel Notification notification) {
5353
return new ApiResponse(SUCCESS, notificationRepo.update(notification));
5454
}
5555

5656
@RequestMapping("/remove")
57-
@PreAuthorize("hasRole('WEB_MANAGER')")
57+
@PreAuthorize("hasAnyRole('ADMIN','SERVICE_ADMIN','NOTICE_MANAGER')")
5858
@WeaverValidation(business = { @WeaverValidation.Business(value = DELETE) })
5959
public ApiResponse remove(@WeaverValidatedModel Notification notification) {
6060
notificationRepo.delete(notification);

src/main/java/edu/tamu/app/controller/ServiceController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import edu.tamu.app.model.Service;
1818
import edu.tamu.app.model.repo.IdeaRepo;
1919
import edu.tamu.app.model.repo.ServiceRepo;
20+
import edu.tamu.app.model.request.FilteredPageRequest;
2021
import edu.tamu.app.model.request.IssueRequest;
2122
import edu.tamu.app.model.request.ServiceRequest;
2223
import edu.tamu.app.service.ProjectService;
@@ -52,6 +53,12 @@ public ApiResponse getPublicServices() {
5253
return new ApiResponse(SUCCESS, serviceRepo.findByIsPublicOrderByStatusDescNameAsc(true));
5354
}
5455

56+
@RequestMapping("/page")
57+
@PreAuthorize("hasRole('ANONYMOUS')")
58+
public ApiResponse page(@RequestBody FilteredPageRequest filteredPageRequest) {
59+
return new ApiResponse(SUCCESS, serviceRepo.findAll(filteredPageRequest.getServiceSpecification(), filteredPageRequest.getPageRequest()));
60+
}
61+
5562
@RequestMapping("/{id}")
5663
@PreAuthorize("hasRole('ANONYMOUS')")
5764
public ApiResponse getService(@PathVariable Long id) {

src/main/java/edu/tamu/app/controller/UserController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ApiResponse getUser(@WeaverUser User user) {
7878
* @throws Exception
7979
*/
8080
@RequestMapping
81-
@PreAuthorize("hasRole('WEB_MANAGER')")
81+
@PreAuthorize("hasRole('ADMIN')")
8282
public ApiResponse allUsers() throws Exception {
8383
return new ApiResponse(SUCCESS, userRepo.findAll());
8484
}
@@ -90,7 +90,7 @@ public ApiResponse allUsers() throws Exception {
9090
* @throws Exception
9191
*/
9292
@RequestMapping("/update")
93-
@PreAuthorize("hasRole('WEB_MANAGER')")
93+
@PreAuthorize("hasRole('ADMIN')")
9494
public ApiResponse updateUser(@RequestBody User user) throws Exception {
9595
user = userRepo.save(user);
9696
simpMessagingTemplate.convertAndSend("/channel/user", new ApiResponse(SUCCESS, userRepo.findAll()));

src/main/java/edu/tamu/app/enums/Role.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
public enum Role implements IRole {
66

7-
ROLE_ADMIN, ROLE_WEB_MANAGER, ROLE_SERVICE_MANAGER, ROLE_STAFF, ROLE_USER, ROLE_ANONYMOUS
7+
ROLE_ADMIN, ROLE_SERVICE_ADMIN, ROLE_SERVICE_MANAGER, ROLE_WEB_MANAGER, ROLE_NOTICE_MANAGER, ROLE_STAFF, ROLE_USER, ROLE_ANONYMOUS
88

99
}

src/main/java/edu/tamu/app/model/repo/ServiceRepo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.List;
44

5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.jpa.domain.Specification;
58
import org.springframework.data.jpa.repository.JpaRepository;
69

710
import edu.tamu.app.enums.Status;
@@ -10,6 +13,8 @@
1013

1114
public interface ServiceRepo extends JpaRepository<Service, Long>, ServiceRepoCustom {
1215

16+
public Page<Service> findAll(Specification<Service> specification, Pageable pageable);
17+
1318
public List<Service> findByIsPublicOrderByStatusDescNameAsc(Boolean isPublic);
1419

1520
public List<Service> findByIsAuto(Boolean isAuto);

src/main/java/edu/tamu/app/model/repo/specification/AbstractSpecification.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ public Predicate toPredicate(Root<E> root, CriteriaQuery<?> query, CriteriaBuild
4949
}
5050
}
5151

52-
query.orderBy(cb.desc(root.get("lastModified")));
52+
toPredicateDefaultQueryOrderBy(root, query, cb);
5353

5454
return builder.build(cb);
5555
}
5656

57+
/**
58+
* Allow implementing classes to control order by in case lastModified is non-existent.
59+
*/
60+
protected void toPredicateDefaultQueryOrderBy(Root<E> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
61+
query.orderBy(cb.desc(root.get("lastModified")));
62+
}
63+
5764
private class PredicateBuilder {
5865

5966
private final Map<String, List<Predicate>> predicates;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package edu.tamu.app.model.repo.specification;
2+
3+
import java.util.Map;
4+
5+
import javax.persistence.criteria.CriteriaBuilder;
6+
import javax.persistence.criteria.CriteriaQuery;
7+
import javax.persistence.criteria.Root;
8+
9+
public class ServiceSpecification<E> extends AbstractSpecification<E> {
10+
11+
public ServiceSpecification(Map<String, String[]> filters) {
12+
super(filters);
13+
}
14+
15+
@Override
16+
protected void toPredicateDefaultQueryOrderBy(Root<E> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
17+
query.orderBy(cb.desc(root.get("name")));
18+
}
19+
}

src/main/java/edu/tamu/app/model/request/FilteredPageRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import edu.tamu.app.model.FeatureProposal;
1414
import edu.tamu.app.model.Idea;
1515
import edu.tamu.app.model.Note;
16+
import edu.tamu.app.model.Service;
1617
import edu.tamu.app.model.repo.specification.FeatureProposalSpecification;
1718
import edu.tamu.app.model.repo.specification.IdeaSpecification;
1819
import edu.tamu.app.model.repo.specification.NoteSpecification;
20+
import edu.tamu.app.model.repo.specification.ServiceSpecification;
1921

2022
public class FilteredPageRequest {
2123

@@ -42,6 +44,11 @@ public IdeaSpecification<Idea> getIdeaSpecification() {
4244
return new IdeaSpecification<Idea>(filters);
4345
}
4446

47+
@JsonIgnore
48+
public ServiceSpecification<Service> getServiceSpecification() {
49+
return new ServiceSpecification<Service>(filters);
50+
}
51+
4552
@JsonIgnore
4653
public FeatureProposalSpecification<FeatureProposal> getFeatureProposalSpecification() {
4754
return new FeatureProposalSpecification<FeatureProposal>(filters);

src/main/java/edu/tamu/app/service/SystemMonitorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void updateAll() {
4848
if (serviceStatus != service.getStatus()) {
4949
logger.debug("Updating the status of [" + service.getName() + "] to: " + serviceStatus);
5050
service.setStatus(serviceStatus);
51-
serviceRepo.save(service);
51+
serviceRepo.update(service);
5252
}
5353
} catch (MalformedURLException e) {
5454
logger.error("Did not check the status of [" + service.getName() + "] due to a malformed URL: " + service.getServiceUrl());

0 commit comments

Comments
 (0)