Skip to content

Commit 6965300

Browse files
authored
Merge pull request #30 from TAMULib/sprint3-post-demo-requests
post demo requests
2 parents 6ebf3d2 + 43371b6 commit 6965300

19 files changed

Lines changed: 55 additions & 24 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public ApiResponse remove(@ApiValidatedModel Note note) {
6464
@ApiMapping("/page")
6565
@Auth(role = "ROLE_ANONYMOUS")
6666
public ApiResponse page(@ApiData FilteredPageRequest filteredPageRequest) {
67-
return new ApiResponse(SUCCESS, noteRepo.findAll(filteredPageRequest.getPageRequest()));
67+
return new ApiResponse(SUCCESS, noteRepo.findAllByOrderByLastModifiedDesc(filteredPageRequest.getPageRequest()));
6868
}
6969

7070
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class NotificationController {
3434
@ApiMapping("/all")
3535
@Auth(role = "ROLE_STAFF")
3636
public ApiResponse getAllNotifications() {
37-
return new ApiResponse(SUCCESS, notificationRepo.findAll());
37+
return new ApiResponse(SUCCESS, notificationRepo.findAllByOrderByIdDesc());
3838
}
3939

4040
@ApiMapping("/{id}")
@@ -68,7 +68,7 @@ public ApiResponse remove(@ApiValidatedModel Notification notification) {
6868
@SkipAop
6969
@RequestMapping("/notification/active")
7070
public String getActiveNotifications(@RequestParam(value = "location", defaultValue = "ALL") String location) {
71-
return buildNotificationHtml(notificationRepo.activeNotificationsByLocation(location));
71+
return buildNotificationHtml(notificationRepo.activeNotificationsByLocation(location.toUpperCase()));
7272
}
7373

7474
private String buildNotificationHtml(List<Notification> notifications) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public class ServiceController {
3131
@ApiMapping("/all")
3232
@Auth(role = "ROLE_ANONYMOUS")
3333
public ApiResponse getAllServices() {
34-
return new ApiResponse(SUCCESS, serviceRepo.findAll());
34+
return new ApiResponse(SUCCESS, serviceRepo.findAllByOrderByIdDesc());
3535
}
3636

3737
@ApiMapping("/public")
3838
@Auth(role = "ROLE_ANONYMOUS")
3939
public ApiResponse getPublicServices() {
40-
return new ApiResponse(SUCCESS, serviceRepo.findByIsPublic(true));
40+
return new ApiResponse(SUCCESS, serviceRepo.findByIsPublicOrderByIdDesc(true));
4141
}
4242

4343
@ApiMapping("/{id}")

src/main/java/edu/tamu/app/job/ProcessSchedules.java renamed to src/main/java/edu/tamu/app/job/UpdateSchedules.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import edu.tamu.framework.model.ApiResponse;
2020

2121
@Service
22-
public class ProcessSchedules {
22+
public class UpdateSchedules {
2323

24-
private Logger logger = LoggerFactory.getLogger(ProcessSchedules.class);
24+
private Logger logger = LoggerFactory.getLogger(UpdateSchedules.class);
2525

2626
@Autowired
2727
private ScheduleRepo scheduleRepo;
@@ -35,8 +35,16 @@ public class ProcessSchedules {
3535
@Autowired
3636
private SimpMessagingTemplate simpMessagingTemplate;
3737

38-
@Scheduled(cron = "5 0/5 * * * ?")
39-
private void checkSchedules() {
38+
@Scheduled(cron = "5 0/1 * * * ?")
39+
private void updateSchedules() {
40+
41+
updateEndingSchedules();
42+
43+
updateStartingSchedules();
44+
45+
}
46+
47+
private synchronized void updateEndingSchedules() {
4048

4149
Date date = new Date();
4250
Long now = date.getTime();
@@ -48,9 +56,19 @@ private void checkSchedules() {
4856
scheduler.setWithinSchedule(false);
4957
scheduler = abstractSchedulerRepo.save(scheduler);
5058
logger.info("Ending schedule for " + scheduler);
59+
scheduler.removeSchedule(schedule);
60+
scheduler = abstractSchedulerRepo.save(scheduler);
61+
scheduleRepo.delete(schedule);
5162
broadcastUpdate(scheduler);
5263
});
5364

65+
}
66+
67+
private synchronized void updateStartingSchedules() {
68+
69+
Date date = new Date();
70+
Long now = date.getTime();
71+
5472
logger.info("Checking for starting schedules");
5573
scheduleRepo.findByScheduledPostingStartLessThanEqualAndScheduledPostingEndGreaterThanEqualAndSchedulerWithinScheduleFalse(now, now).forEach(schedule -> {
5674
AbstractScheduler scheduler = schedule.getScheduler();

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public interface NoteRepo extends JpaRepository<Note, Long>, NoteRepoCustom, Jpa
1515

1616
public Page<Note> findAll(Specification<Note> specification, Pageable pageable);
1717

18-
public List<Note> findAll(Specification<Note> specification);
19-
20-
public Page<Note> findAll(Pageable pageable);
18+
public Page<Note> findAllByOrderByLastModifiedDesc(Pageable pageable);
2119

2220
public List<Note> findAllByServiceId(Long id);
2321

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
public interface NotificationRepo extends JpaRepository<Notification, Long>, NotificationRepoCustom {
1212

13-
public List<Notification> findByActiveTrue();
13+
public List<Notification> findAllByOrderByIdDesc();
1414

15-
public List<Notification> findByActiveTrueAndLocations(NotificationLocation location);
15+
public List<Notification> findByActiveTrueOrderByIdDesc();
16+
17+
public List<Notification> findByActiveTrueAndLocationsOrderByIdDesc(NotificationLocation location);
1618

1719
public void delete(Notification notification);
1820

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
public interface ServiceRepo extends JpaRepository<Service, Long>, ServiceRepoCustom {
1212

13-
public List<Service> findByIsPublic(Boolean isPublic);
13+
public List<Service> findByIsPublicOrderByIdDesc(Boolean isPublic);
1414

1515
public List<Service> findByIsAuto(Boolean isAuto);
16+
17+
public List<Service> findAllByOrderByIdDesc();
1618

1719
public Long countByStatus(Status status);
1820

src/main/java/edu/tamu/app/model/repo/impl/NotificationRepoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public void delete(Notification notification) {
5050
public List<Notification> activeNotificationsByLocation(String location) {
5151
List<Notification> notifications = new ArrayList<Notification>();
5252
if (location.equals("ALL")) {
53-
notifications = notificationRepo.findByActiveTrue();
53+
notifications = notificationRepo.findByActiveTrueOrderByIdDesc();
5454
} else {
5555
try {
56-
notifications = notificationRepo.findByActiveTrueAndLocations(NotificationLocation.valueOf(location));
56+
notifications = notificationRepo.findByActiveTrueAndLocationsOrderByIdDesc(NotificationLocation.valueOf(location));
5757
} catch (IllegalArgumentException e) {
5858

5959
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public Predicate toPredicate(Root<E> root, CriteriaQuery<?> query, CriteriaBuild
5050
}
5151

5252
}
53+
54+
query.orderBy(cb.desc(root.get("lastModified")));
5355

5456
Predicate predicate;
5557

src/main/java/edu/tamu/app/model/validation/NotificationValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public NotificationValidator() {
1414
String bodyProperty = "body";
1515
this.addInputValidator(new InputValidator(InputValidationType.required, "Notifications require a body", bodyProperty, true));
1616
this.addInputValidator(new InputValidator(InputValidationType.minlength, "Notification body must be at least 3 characters", bodyProperty, 3));
17-
this.addInputValidator(new InputValidator(InputValidationType.maxlength, "Notifications must be no more than 140 cahracters", bodyProperty, 140));
17+
this.addInputValidator(new InputValidator(InputValidationType.maxlength, "Notifications must be no more than 5000 cahracters", bodyProperty, 5000));
1818

1919
String locationsProperty = "locations";
2020
this.addInputValidator(new InputValidator(InputValidationType.required, "Notifications must have a display location", locationsProperty, true));

0 commit comments

Comments
 (0)