66import static edu .tamu .framework .enums .BusinessValidationType .EXISTS ;
77import static edu .tamu .framework .enums .BusinessValidationType .NONEXISTS ;
88import 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 ;
911
1012import org .springframework .beans .factory .annotation .Autowired ;
1113import org .springframework .messaging .simp .SimpMessagingTemplate ;
1214import org .springframework .web .bind .annotation .RestController ;
1315
16+ import edu .tamu .app .model .AppUser ;
1417import edu .tamu .app .model .Service ;
18+ import edu .tamu .app .model .repo .AppUserRepo ;
1519import edu .tamu .app .model .repo .ServiceRepo ;
20+ import edu .tamu .app .service .SystemMonitorService ;
21+ import edu .tamu .framework .aspect .annotation .ApiCredentials ;
1622import edu .tamu .framework .aspect .annotation .ApiMapping ;
1723import edu .tamu .framework .aspect .annotation .ApiValidatedModel ;
1824import edu .tamu .framework .aspect .annotation .ApiValidation ;
1925import edu .tamu .framework .aspect .annotation .ApiVariable ;
2026import edu .tamu .framework .aspect .annotation .Auth ;
2127import edu .tamu .framework .model .ApiResponse ;
28+ import edu .tamu .framework .model .Credentials ;
2229
2330@ RestController
2431@ ApiMapping ("/service" )
@@ -29,6 +36,12 @@ public class ServiceController {
2936
3037 @ Autowired
3138 private ServiceRepo serviceRepo ;
39+
40+ @ Autowired
41+ private SystemMonitorService systemMonitorService ;
42+
43+ @ Autowired
44+ private AppUserRepo userRepo ;
3245
3346 @ ApiMapping ("/all" )
3447 @ Auth (role ="ROLE_ANONYMOUS" )
@@ -52,21 +65,33 @@ public ApiResponse getService(@ApiVariable Long id) {
5265 @ ApiMapping ("/create" )
5366 @ Auth (role = "ROLE_SERVICE_MANAGER" )
5467 @ ApiValidation (business = { @ ApiValidation .Business (value = CREATE ), @ ApiValidation .Business (value = EXISTS ) })
55- public ApiResponse createService (@ ApiValidatedModel Service service ) {
68+ public ApiResponse createService (@ ApiValidatedModel Service service , @ ApiCredentials Credentials credentials ) {
5669 service = serviceRepo .create (service .getName (), service .getStatus (), service .getIsAuto (), service .getIsPublic (), service .getOnShortList (), service .getServiceUrl ());
5770 simpMessagingTemplate .convertAndSend ("/channel/service" , new ApiResponse (SUCCESS , serviceRepo .findAll ()));
71+ sendStatusUpdate (service , credentials );
5872 return new ApiResponse (SUCCESS , service );
5973 }
6074
6175 @ ApiMapping ("/update" )
6276 @ Auth (role = "ROLE_SERVICE_MANAGER" )
6377 @ ApiValidation (business = { @ ApiValidation .Business (value = UPDATE ), @ ApiValidation .Business (value = NONEXISTS ) })
64- public ApiResponse updateService (@ ApiValidatedModel Service service ) {
78+ public ApiResponse updateService (@ ApiValidatedModel Service service , @ ApiCredentials Credentials credentials ) {
6579 service = serviceRepo .save (service );
6680 simpMessagingTemplate .convertAndSend ("/channel/service/" + service .getId (), new ApiResponse (SUCCESS , service ));
81+ sendStatusUpdate (service , credentials );
6782 return new ApiResponse (SUCCESS , service );
6883 }
6984
85+ private void sendStatusUpdate (Service service , Credentials credentials ) {
86+ System .out .println ("Uhhhh ya!" );
87+ AppUser user = userRepo .findByUin (credentials .getUin ());
88+ if (user .getRole () == ROLE_ANONYMOUS || user .getRole () == ROLE_USER ) {
89+ simpMessagingTemplate .convertAndSend ("/private/queue/status/overall-public" , new ApiResponse (SUCCESS , systemMonitorService .getOverallStatusPublic ()));
90+ } else {
91+ simpMessagingTemplate .convertAndSend ("/private/queue/status/overall-full" , new ApiResponse (SUCCESS , systemMonitorService .getOverallStatus ()));
92+ }
93+ }
94+
7095 @ ApiMapping ("/remove" )
7196 @ Auth (role = "ROLE_SERVICE_MANAGER" )
7297 @ ApiValidation (business = { @ ApiValidation .Business (value = DELETE ), @ ApiValidation .Business (value = NONEXISTS ) })
0 commit comments