Skip to content

Commit 139dd5a

Browse files
committed
resolved merge conflicts
2 parents 367a302 + 61cb719 commit 139dd5a

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@
77
import static edu.tamu.framework.enums.BusinessValidationType.NONEXISTS;
88
import static edu.tamu.framework.enums.BusinessValidationType.UPDATE;
99

10+
import java.util.ArrayList;
11+
import java.util.List;
12+
1013
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RequestParam;
1116
import org.springframework.web.bind.annotation.RestController;
1217

18+
import edu.tamu.app.enums.NotificationLocation;
1319
import edu.tamu.app.model.Notification;
1420
import edu.tamu.app.model.repo.NotificationRepo;
1521
import edu.tamu.framework.aspect.annotation.ApiMapping;
1622
import edu.tamu.framework.aspect.annotation.ApiValidatedModel;
1723
import edu.tamu.framework.aspect.annotation.ApiValidation;
1824
import edu.tamu.framework.aspect.annotation.ApiVariable;
1925
import edu.tamu.framework.aspect.annotation.Auth;
26+
import edu.tamu.framework.aspect.annotation.SkipAop;
2027
import edu.tamu.framework.model.ApiResponse;
2128

2229
@RestController
@@ -61,4 +68,27 @@ public ApiResponse remove(@ApiValidatedModel Notification notification) {
6168
notificationRepo.delete(notification);
6269
return new ApiResponse(SUCCESS);
6370
}
71+
72+
@SkipAop
73+
@RequestMapping("/notification/active")
74+
public String getActiveNotifications(@RequestParam(value = "location", defaultValue = "ALL") String locationString) {
75+
String notificationString = "";
76+
List<Notification> notificationList;
77+
if (locationString.equals("ALL")) {
78+
notificationList = notificationRepo.findByActive(true);
79+
} else {
80+
try {
81+
NotificationLocation location = NotificationLocation.valueOf(locationString);
82+
notificationList = notificationRepo.findByActiveAndLocations(true, location);
83+
} catch (IllegalArgumentException e) {
84+
notificationList = new ArrayList<Notification>();
85+
}
86+
}
87+
for (Notification notification : notificationList) {
88+
notificationString += "<p>" + notification.getBody() + "</p>";
89+
}
90+
91+
return notificationString;
92+
}
93+
6494
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
public enum NotificationLocation {
44

5-
EVANS,
5+
MAIN,
66
CUSHING,
77
MSL,
8-
WCL
8+
WCL,
9+
PSEL,
10+
QATAR
911
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package edu.tamu.app.model.repo;
22

3+
import java.util.List;
4+
35
import org.springframework.data.jpa.repository.JpaRepository;
46

7+
import edu.tamu.app.enums.NotificationLocation;
58
import edu.tamu.app.model.Notification;
69
import edu.tamu.app.model.repo.custom.NotificationRepoCustom;
710

811
public interface NotificationRepo extends JpaRepository<Notification, Long>, NotificationRepoCustom {
912

13+
public List<Notification> findByActive(Boolean active);
14+
15+
public List<Notification> findByActiveAndLocations(Boolean active, NotificationLocation location);
16+
1017
public void delete(Notification notification);
1118

1219
}

src/test/java/controller/NotificationControllerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class NotificationControllerTest {
3939
protected static final String TEST_NOTIFICATION2_BODY = "Test Notification Body 2";
4040
protected static final String TEST_NOTIFICATION3_BODY = "Test Notification Body 3";
4141
protected static final String TEST_MODIFIED_NOTIFICATION_BODY = "Test Modified Notification Body";
42+
43+
protected static final String TEST_QUERY_PARAM = "CUSHING";
44+
protected static final String TEST_NOTIFICATION_TEXT = "<p>Test Notification Body 1</p><p>Test Notification Body 2</p><p>Test Notification Body 3</p>";
45+
protected static final boolean TEST_IS_ACTIVE = true;
46+
protected static final boolean TEST_ALTERNATIVE_IS_ACTIVE = false;
47+
4248
protected static final List<NotificationLocation> TEST_LOCATIONS = Arrays.asList(new NotificationLocation[] { NotificationLocation.CUSHING });
4349

4450
protected static Notification TEST_NOTIFICATION1 = new Notification(TEST_NOTIFICATION1_NAME, TEST_NOTIFICATION1_BODY, TEST_LOCATIONS);
@@ -67,6 +73,7 @@ public void setUp() {
6773
when(notificationRepo.findOne(any(Long.class))).thenReturn(TEST_NOTIFICATION1);
6874
when(notificationRepo.create(any(Notification.class))).thenReturn(TEST_NOTIFICATION1);
6975
when(notificationRepo.update(any(Notification.class))).thenReturn(TEST_MODIFIED_NOTIFICATION);
76+
when(notificationRepo.findByActiveAndLocations(any(Boolean.class), any(NotificationLocation.class))).thenReturn(mockNotificationList);
7077
doNothing().when(notificationRepo).delete(any(Notification.class));
7178
}
7279

@@ -110,6 +117,12 @@ public void testRemove() {
110117
assertEquals("Not successful at removing Notification", SUCCESS, response.getMeta().getType());
111118
}
112119

120+
@Test
121+
public void testActiveNotifications() {
122+
String notifications = notificationController.getActiveNotifications(TEST_QUERY_PARAM);
123+
assertEquals("Active Notifications not returned correctly", TEST_NOTIFICATION_TEXT, notifications);
124+
}
125+
113126
@After
114127
public void cleanUp() {
115128
response = null;

0 commit comments

Comments
 (0)