Skip to content

Commit 6d5f63b

Browse files
authored
Merge pull request #17 from TAMULib/framework-upgrade
Framework upgrade
2 parents 0126bf8 + 3575224 commit 6d5f63b

20 files changed

Lines changed: 335 additions & 370 deletions

pom.xml

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
<project
2-
xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
53

6-
<modelVersion>4.0.0</modelVersion>
7-
<groupId>edu.tamu</groupId>
8-
<artifactId>status-system</artifactId>
9-
<version>0.0.1</version>
10-
<name>Library-Service-Status-System</name>
11-
<description>A System for monitoring and reporting the status of Library Services</description>
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>edu.tamu</groupId>
6+
<artifactId>status-system</artifactId>
7+
<version>0.0.1</version>
8+
<name>Library-Service-Status-System</name>
9+
<description>A System for monitoring and reporting the status of Library Services</description>
1210

13-
<parent>
14-
<groupId>edu.tamu.weaverframework</groupId>
15-
<artifactId>weaver-webservice-parent</artifactId>
16-
<version>1.2.0-RC2-SNAPSHOT</version>
17-
</parent>
11+
<parent>
12+
<groupId>edu.tamu.weaverframework</groupId>
13+
<artifactId>weaver-webservice-parent</artifactId>
14+
<version>1.2.0-RC-SNAPSHOT</version>
15+
</parent>
1816

19-
<properties>
20-
<start-class>edu.tamu.app.WebServerInit</start-class>
21-
</properties>
17+
<properties>
18+
<start-class>edu.tamu.app.WebServerInit</start-class>
19+
</properties>
2220

23-
<packaging>war</packaging>
21+
<packaging>war</packaging>
2422

25-
<repositories>
26-
<repository>
27-
<id>tamu-releases</id>
28-
<url>https://maven.library.tamu.edu/content/repositories/releases</url>
29-
</repository>
30-
<repository>
31-
<id>tamu-snapshots</id>
32-
<url>https://maven.library.tamu.edu/content/repositories/snapshots</url>
33-
</repository>
34-
</repositories>
23+
<repositories>
24+
<repository>
25+
<id>tamu-releases</id>
26+
<url>https://maven.library.tamu.edu/content/repositories/releases</url>
27+
</repository>
28+
<repository>
29+
<id>tamu-snapshots</id>
30+
<url>https://maven.library.tamu.edu/content/repositories/snapshots</url>
31+
</repository>
32+
</repositories>
3533

36-
<dependencies>
37-
<dependency>
38-
<groupId>edu.tamu.weaverframework</groupId>
39-
<artifactId>weaver-webservice-core</artifactId>
40-
<version>1.2.0-RC2-SNAPSHOT</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.postgresql</groupId>
44-
<artifactId>postgresql</artifactId>
45-
<version>9.4.1211</version>
46-
</dependency>
47-
</dependencies>
34+
<dependencies>
35+
<dependency>
36+
<groupId>edu.tamu.weaverframework</groupId>
37+
<artifactId>weaver-webservice-core</artifactId>
38+
<version>1.2.0-RC-SNAPSHOT</version>
39+
</dependency>
4840

49-
<build>
50-
<finalName>ROOT</finalName>
51-
<plugins>
52-
<plugin>
53-
<groupId>org.apache.maven.plugins</groupId>
54-
<artifactId>maven-compiler-plugin</artifactId>
55-
<configuration>
56-
<source>1.8</source>
57-
<target>1.8</target>
58-
</configuration>
59-
</plugin>
60-
<plugin>
61-
<groupId>org.springframework.boot</groupId>
62-
<artifactId>spring-boot-maven-plugin</artifactId>
63-
</plugin>
64-
<plugin>
65-
<groupId>org.apache.maven.plugins</groupId>
66-
<artifactId>maven-war-plugin</artifactId>
67-
<configuration>
68-
<failOnMissingWebXml>false</failOnMissingWebXml>
69-
</configuration>
70-
</plugin>
71-
</plugins>
72-
</build>
41+
<dependency>
42+
<groupId>org.postgresql</groupId>
43+
<artifactId>postgresql</artifactId>
44+
<version>9.4.1211</version>
45+
</dependency>
46+
47+
</dependencies>
48+
49+
<build>
50+
<finalName>ROOT</finalName>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<configuration>
56+
<source>1.8</source>
57+
<target>1.8</target>
58+
</configuration>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-war-plugin</artifactId>
67+
<configuration>
68+
<failOnMissingWebXml>false</failOnMissingWebXml>
69+
</configuration>
70+
</plugin>
71+
</plugins>
72+
</build>
7373

7474
</project>

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

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,22 @@
44
import static edu.tamu.framework.enums.BusinessValidationType.CREATE;
55
import static edu.tamu.framework.enums.BusinessValidationType.EXISTS;
66

7-
import java.util.HashMap;
8-
import java.util.Iterator;
9-
import java.util.Map;
10-
117
import org.springframework.beans.factory.annotation.Autowired;
128
import org.springframework.data.domain.Page;
13-
import org.springframework.data.domain.Sort;
14-
import org.springframework.data.domain.Sort.Direction;
15-
import org.springframework.messaging.simp.SimpMessagingTemplate;
169
import org.springframework.transaction.annotation.Transactional;
1710
import org.springframework.web.bind.annotation.RestController;
1811

19-
import com.fasterxml.jackson.databind.JsonNode;
20-
import com.fasterxml.jackson.databind.node.ArrayNode;
12+
import com.fasterxml.jackson.core.JsonProcessingException;
13+
import com.fasterxml.jackson.databind.ObjectMapper;
2114

2215
import edu.tamu.app.model.Note;
16+
import edu.tamu.app.model.Service;
2317
import edu.tamu.app.model.repo.NoteRepo;
24-
import edu.tamu.app.model.repo.ServiceRepo;
2518
import edu.tamu.app.model.request.FilteredPageRequest;
2619
import edu.tamu.framework.aspect.annotation.ApiCredentials;
2720
import edu.tamu.framework.aspect.annotation.ApiData;
2821
import edu.tamu.framework.aspect.annotation.ApiMapping;
22+
import edu.tamu.framework.aspect.annotation.ApiModel;
2923
import edu.tamu.framework.aspect.annotation.ApiValidatedModel;
3024
import edu.tamu.framework.aspect.annotation.ApiValidation;
3125
import edu.tamu.framework.aspect.annotation.ApiVariable;
@@ -39,20 +33,23 @@ public class NoteController {
3933

4034
@Autowired
4135
private NoteRepo noteRepo;
42-
43-
@Autowired
44-
private ServiceRepo serviceRepo;
4536

4637
@Autowired
47-
private SimpMessagingTemplate simpMessagingTemplate;
38+
private ObjectMapper objectMapper;
4839

4940
@ApiMapping("/all")
5041
@Auth(role = "ROLE_ANONYMOUS")
5142
public ApiResponse getAllNotes() {
5243
return new ApiResponse(SUCCESS, noteRepo.findAll());
5344
}
5445

55-
@ApiMapping("/get/{id}")
46+
@ApiMapping("/by-service")
47+
@Auth(role = "ROLE_ANONYMOUS")
48+
public ApiResponse getAllNotesByService(@ApiModel Service service) {
49+
return new ApiResponse(SUCCESS, noteRepo.findAllByService(service));
50+
}
51+
52+
@ApiMapping("/{id}")
5653
@Auth(role = "ROLE_ANONYMOUS")
5754
public ApiResponse getNote(@ApiVariable Long id) {
5855
return new ApiResponse(SUCCESS, noteRepo.findOne(id));
@@ -63,53 +60,27 @@ public ApiResponse getNote(@ApiVariable Long id) {
6360
@ApiValidation(business = { @ApiValidation.Business(value = CREATE), @ApiValidation.Business(value = EXISTS) })
6461
public ApiResponse create(@ApiValidatedModel Note note, @ApiCredentials Credentials credentials) {
6562
note = noteRepo.create(note, credentials);
66-
ApiResponse response = new ApiResponse(SUCCESS, note);
67-
simpMessagingTemplate.convertAndSend("/channel/note/new", response);
68-
return response;
63+
return new ApiResponse(SUCCESS, note);
6964
}
7065

7166
@ApiMapping("/update")
7267
@Auth(role = "ROLE_SERVICE_MANAGER")
7368
public ApiResponse update(@ApiValidatedModel Note note) {
74-
note = noteRepo.save(note);
75-
ApiResponse response = new ApiResponse(SUCCESS, noteRepo.getOne(note.getId()));
76-
simpMessagingTemplate.convertAndSend("/channel/note/" + note.getId(), response);
77-
return response;
69+
return new ApiResponse(SUCCESS, noteRepo.update(note));
7870
}
7971

8072
@Transactional
8173
@ApiMapping("/remove")
8274
@Auth(role = "ROLE_SERVICE_MANAGER")
8375
public ApiResponse remove(@ApiValidatedModel Note note) {
8476
noteRepo.delete(note);
85-
simpMessagingTemplate.convertAndSend("/channel/service" + note.getService().getId(), new ApiResponse(SUCCESS, serviceRepo.getOne(note.getService().getId())));
8677
return new ApiResponse(SUCCESS);
8778
}
88-
79+
8980
@ApiMapping("/page")
90-
@Auth(role="ROLE_ANONYMOUS")
91-
public ApiResponse page(@ApiData JsonNode dataNode) {
92-
Direction sortDirection;
93-
if (dataNode.get("direction").get("direction").asText().equals("ASC")) {
94-
sortDirection = Sort.Direction.ASC;
95-
} else {
96-
sortDirection = Sort.Direction.DESC;
97-
}
98-
99-
Map<String, String[]> filters = new HashMap<String, String[]>();
100-
filters.put("title", arrayNodeToStringArray((ArrayNode) dataNode.get("filters").get("title")));
101-
FilteredPageRequest filteredPageRequest = new FilteredPageRequest(dataNode.get("page").get("number").asInt(), dataNode.get("page").get("size").asInt(), sortDirection, dataNode.get("direction").get("properties").asText(), filters);
102-
Page<Note> notes = noteRepo.findAll(filteredPageRequest);
103-
return new ApiResponse(SUCCESS, notes);
104-
}
105-
106-
private String[] arrayNodeToStringArray(ArrayNode arrayNode) {
107-
String[] array = new String[arrayNode.size()];
108-
Iterator<JsonNode> arrayIterator = arrayNode.elements();
109-
int i = 0;
110-
while (arrayIterator.hasNext()) {
111-
array[i++] = arrayIterator.next().asText();
112-
}
113-
return array;
81+
@Auth(role = "ROLE_ANONYMOUS")
82+
public ApiResponse page(@ApiData FilteredPageRequest filteredPageRequest) {
83+
return new ApiResponse(SUCCESS, noteRepo.findAll(filteredPageRequest.toPageRequest()));
11484
}
85+
11586
}

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

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66
import static edu.tamu.framework.enums.BusinessValidationType.EXISTS;
77
import static edu.tamu.framework.enums.BusinessValidationType.NONEXISTS;
88
import static edu.tamu.framework.enums.BusinessValidationType.UPDATE;
9-
import static edu.tamu.app.enums.AppRole.ROLE_ANONYMOUS;
10-
import static edu.tamu.app.enums.AppRole.ROLE_USER;
119

1210
import org.springframework.beans.factory.annotation.Autowired;
13-
import org.springframework.messaging.simp.SimpMessagingTemplate;
1411
import org.springframework.web.bind.annotation.RestController;
1512

16-
import edu.tamu.app.model.AppUser;
1713
import edu.tamu.app.model.Service;
18-
import edu.tamu.app.model.repo.AppUserRepo;
1914
import edu.tamu.app.model.repo.ServiceRepo;
20-
import edu.tamu.app.service.SystemMonitorService;
2115
import edu.tamu.framework.aspect.annotation.ApiCredentials;
2216
import edu.tamu.framework.aspect.annotation.ApiMapping;
2317
import edu.tamu.framework.aspect.annotation.ApiValidatedModel;
@@ -30,73 +24,49 @@
3024
@RestController
3125
@ApiMapping("/service")
3226
public class ServiceController {
33-
34-
@Autowired
35-
private SimpMessagingTemplate simpMessagingTemplate;
3627

3728
@Autowired
3829
private ServiceRepo serviceRepo;
39-
40-
@Autowired
41-
private SystemMonitorService systemMonitorService;
42-
43-
@Autowired
44-
private AppUserRepo userRepo;
4530

4631
@ApiMapping("/all")
47-
@Auth(role="ROLE_ANONYMOUS")
32+
@Auth(role = "ROLE_ANONYMOUS")
4833
public ApiResponse getAllServices() {
4934
return new ApiResponse(SUCCESS, serviceRepo.findAll());
5035
}
51-
36+
5237
@ApiMapping("/public")
53-
@Auth(role="ROLE_ANONYMOUS")
38+
@Auth(role = "ROLE_ANONYMOUS")
5439
public ApiResponse getPublicServices() {
5540
return new ApiResponse(SUCCESS, serviceRepo.findByIsPublic(true));
5641
}
57-
58-
@ApiMapping("/get/{id}")
42+
43+
@ApiMapping("/{id}")
5944
@Auth(role = "ROLE_ANONYMOUS")
6045
public ApiResponse getService(@ApiVariable Long id) {
61-
Service service = serviceRepo.findOne(id);
62-
return new ApiResponse(SUCCESS, service);
46+
return new ApiResponse(SUCCESS, serviceRepo.findOne(id));
6347
}
64-
48+
6549
@ApiMapping("/create")
6650
@Auth(role = "ROLE_SERVICE_MANAGER")
6751
@ApiValidation(business = { @ApiValidation.Business(value = CREATE), @ApiValidation.Business(value = EXISTS) })
6852
public ApiResponse createService(@ApiValidatedModel Service service, @ApiCredentials Credentials credentials) {
6953
service = serviceRepo.create(service.getName(), service.getStatus(), service.getIsAuto(), service.getIsPublic(), service.getOnShortList(), service.getServiceUrl(), service.getDescription());
70-
simpMessagingTemplate.convertAndSend("/channel/service", new ApiResponse(SUCCESS, serviceRepo.findAll()));
71-
sendStatusUpdate(service, credentials);
7254
return new ApiResponse(SUCCESS, service);
7355
}
74-
56+
7557
@ApiMapping("/update")
7658
@Auth(role = "ROLE_SERVICE_MANAGER")
7759
@ApiValidation(business = { @ApiValidation.Business(value = UPDATE), @ApiValidation.Business(value = NONEXISTS) })
7860
public ApiResponse updateService(@ApiValidatedModel Service service, @ApiCredentials Credentials credentials) {
79-
service = serviceRepo.save(service);
80-
simpMessagingTemplate.convertAndSend("/channel/service/" + service.getId(), new ApiResponse(SUCCESS, service));
81-
sendStatusUpdate(service, credentials);
61+
service = serviceRepo.update(service);
8262
return new ApiResponse(SUCCESS, service);
8363
}
84-
85-
private void sendStatusUpdate(Service service, Credentials credentials) {
86-
AppUser user = userRepo.findByUin(credentials.getUin());
87-
if (user.getRole() == ROLE_ANONYMOUS || user.getRole() == ROLE_USER) {
88-
simpMessagingTemplate.convertAndSend("/channel/status/overall-public", new ApiResponse(SUCCESS, systemMonitorService.getOverallStatusPublic()));
89-
} else {
90-
simpMessagingTemplate.convertAndSend("/channel/status/overall-full", new ApiResponse(SUCCESS, systemMonitorService.getOverallStatus()));
91-
}
92-
}
93-
64+
9465
@ApiMapping("/remove")
9566
@Auth(role = "ROLE_SERVICE_MANAGER")
9667
@ApiValidation(business = { @ApiValidation.Business(value = DELETE), @ApiValidation.Business(value = NONEXISTS) })
9768
public ApiResponse removeService(@ApiValidatedModel Service service) {
9869
serviceRepo.delete(service);
99-
simpMessagingTemplate.convertAndSend("/channel/service", new ApiResponse(SUCCESS, serviceRepo.findAll()));
10070
return new ApiResponse(SUCCESS);
10171
}
10272
}

src/main/java/edu/tamu/app/model/AppUser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public AppUser(String uin) {
9191
*/
9292
public AppUser(String email, String firstName, String lastName, String role) {
9393
super();
94+
setUin(email);
9495
setEmail(email);
9596
setFirstName(firstName);
9697
setLastName(lastName);

0 commit comments

Comments
 (0)