From 030b9ff9fbe385d82990c86fe5eddcca2cd769c8 Mon Sep 17 00:00:00 2001 From: Akil Mahimwala Date: Wed, 10 Feb 2021 16:05:29 +0530 Subject: [PATCH 1/9] Changes for the ApiDocumenation --- pom.xml | 22 +- .../java/cc/altius/FASP/WebApplication.java | 13 + .../altius/FASP/jwt/JWTWebSecurityConfig.java | 9 +- .../rest/controller/BudgetRestController.java | 187 +++++----- .../controller/CountryRestController.java | 93 +++-- .../controller/CurrencyRestController.java | 125 +++++-- .../controller/DataSourceRestController.java | 175 ++++++--- .../DataSourceTypeRestController.java | 152 +++++--- .../controller/DimensionRestController.java | 145 ++++--- .../FASP/rest/controller/FileController.java | 23 +- .../ForecastingUnitRestController.java | 171 ++++++--- .../FundingSourceRestController.java | 195 +++++++--- .../controller/HealthAreaRestController.java | 276 +++++++++----- .../OrganisationRestController.java | 231 ++++++++---- .../ProcurementAgentRestController.java | 353 ++++++++++++------ .../ProcurementUnitRestController.java | 229 +++++++++--- .../ProductCategoryRestController.java | 119 ++++-- .../rest/controller/RealmRestController.java | 139 ++++--- .../rest/controller/RegionRestController.java | 128 ++++--- .../ShipmentStatusRestController.java | 16 - .../controller/SupplierRestController.java | 143 ++++--- .../rest/controller/SyncRestController.java | 2 +- .../TracerCategoryRestController.java | 186 ++++++--- .../rest/controller/UnitRestController.java | 128 ++++--- .../FASP/web/controller/LabelController.java | 6 +- src/main/resources/application.properties | 2 + src/main/resources/logback-spring.xml | 5 + 27 files changed, 2236 insertions(+), 1037 deletions(-) diff --git a/pom.xml b/pom.xml index 0f23fe529..25853e9bb 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.2.6.RELEASE + 2.3.8.RELEASE cc.altius.FASP.rest.webservice @@ -100,7 +100,12 @@ org.springdoc - springdoc-openapi-data-rest + springdoc-openapi-webmvc-core + 1.3.1 + + + org.springdoc + springdoc-openapi-security 1.3.1 @@ -154,6 +159,19 @@ true + diff --git a/src/main/java/cc/altius/FASP/WebApplication.java b/src/main/java/cc/altius/FASP/WebApplication.java index c6ee08307..3c1388a0d 100755 --- a/src/main/java/cc/altius/FASP/WebApplication.java +++ b/src/main/java/cc/altius/FASP/WebApplication.java @@ -1,11 +1,24 @@ package cc.altius.FASP; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Contact; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.info.License; +import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; +@OpenAPIDefinition( + info = @Info( + title = "Quantification and Analytics Tool", + description = "API's to access the QAT Server", + license = @License(name = "Apache 2.0", url = "https://foo.bar"), + contact = @Contact(url = "https://www.quantificationanalytics.org", name = "FASP team", email = "HSS_FASP_HQ@ghsc-psm.org") + ), servers = @Server(url = "https://www.quantificationanalytics.org", description = "Production server for QAT") + ) @SpringBootApplication @EnableScheduling @ComponentScan(basePackages = {"cc.altius.FASP"}) diff --git a/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java b/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java index fb698c410..f1094079b 100755 --- a/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java +++ b/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java @@ -74,13 +74,6 @@ protected void configure(HttpSecurity httpSecurity) throws Exception { .exceptionHandling().authenticationEntryPoint(jwtUnAuthorizedResponseAuthenticationEntryPoint).and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() .authorizeRequests() -// .antMatchers("/actuator/info").permitAll() - // .antMatchers("/api/healthArea/**").access("hasRole('ROLE_BF_UPDATE_REALM_MASTER')") - // .antMatchers("/api/organisation/**").access("hasRole('ROLE_BF_UPDATE_REALM_MASTER')") - // .antMatchers("/api/unit/**").access("hasRole('ROLE_BF_UPDATE_APPL_MASTER')") - // .antMatchers(HttpMethod.POST, "/api/realm/**").access("hasAnyRole('ROLE_BF_UPDATE_APPL_MASTER')") - // .antMatchers(HttpMethod.PUT, "/api/realm/**").access("hasAnyRole('ROLE_BF_UPDATE_APPL_MASTER', 'ROLE_BF_UPDATE_REALM_MASTER')") - // .antMatchers("/api/realmCountry/**").access("hasRole('ROLE_BF_UPDATE_REALM_MASTER')") .anyRequest().authenticated(); httpSecurity @@ -109,7 +102,7 @@ public void configure(WebSecurity webSecurity) throws Exception { .and().ignoring().antMatchers("/browser**") .and().ignoring().antMatchers("/file**") .and().ignoring().antMatchers("/file/**") - // .and().ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html**", "/swagger-resources/configuration/ui") + .and().ignoring().antMatchers("/v3/api-docs", "/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html**", "/swagger-resources/configuration/ui") .and().ignoring().antMatchers("/api/locales/*/**") .and().ignoring().antMatchers("/api/forgotPassword/**") .and().ignoring().antMatchers("/api/getForgotPasswordToken/**") diff --git a/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java b/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java index a35fdb380..9d53f1a14 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.BudgetService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +36,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/budget") public class BudgetRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -42,8 +45,42 @@ public class BudgetRestController { @Autowired private UserService userService; - @PostMapping(path = "/budget") - public ResponseEntity postBudget(@RequestBody Budget budget, Authentication auth) { + /** + * API used to get the complete Budget list + * + * @param auth + * @return returns the complete list of Budgets List + */ + @GetMapping("/") + @Operation(description = "Returns the complete list of Budgets List", summary = "Get Budget list", tags = ("budget")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Budget list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Budget list") + public ResponseEntity getBudgetList(Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + return new ResponseEntity(this.budgetService.getBudgetList(curUser), HttpStatus.OK); + } catch (Exception e) { + logger.error("Error while trying to get Budget list", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * API used to add a Budget to the Realm + * + * @param budget Budget object that you want to add to the Realm + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(path = "/") + @Operation(description = "API used to add a Budget to the Realm", summary = "Add Budget", tags = ("budget")) + @Parameters( + @Parameter(name = "budget", description = "The Budget object that you want to add to the Realm")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to add the Budget") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the some of the underlying data does not match. For instance the Funding Source Id specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addBudget(@RequestBody Budget budget, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); this.budgetService.addBudget(budget, curUser); @@ -60,8 +97,21 @@ public ResponseEntity postBudget(@RequestBody Budget budget, Authentication auth } } - @PutMapping(path = "/budget") - public ResponseEntity putBudget(@RequestBody Budget budget, Authentication auth) { + /** + * API used to update a Budget + * + * @param budget Budget object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Budget", summary = "Update Budget", tags = ("budget")) + @Parameters( + @Parameter(name = "budget", description = "The Budget object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to add the Budget") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateBudget(@RequestBody Budget budget, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); int rows = this.budgetService.updateBudget(budget, curUser); @@ -75,8 +125,21 @@ public ResponseEntity putBudget(@RequestBody Budget budget, Authentication auth) } } - @PostMapping("/budget/programIds") - public ResponseEntity getBudget(@RequestBody String[] programIds, Authentication auth) { + /** + * API used to get the Budget list for a list of Program Ids + * + * @param programIds List of ProgramIds that you want to the list of Budgets + * for + * @param auth + * @return returns the list of Budgets based on Program Ids specified + */ + @PostMapping("/programIds") + @Operation(description = "API used to get the Budget list for a list of Program Ids", summary = "Get Budget list for Program Ids", tags = ("budget")) + @Parameters( + @Parameter(name = "programIds", description = "List of Program Ids that you want to the Budgets for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Budget list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Budget list") + public ResponseEntity getBudgetForProgramIds(@RequestBody String[] programIds, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.budgetService.getBudgetListForProgramIds(programIds, curUser), HttpStatus.OK); @@ -86,19 +149,22 @@ public ResponseEntity getBudget(@RequestBody String[] programIds, Authentication } } - @GetMapping("/budget") - public ResponseEntity getBudget(Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.budgetService.getBudgetList(curUser), HttpStatus.OK); - } catch (Exception e) { - logger.error("Error while trying to get Budget list", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/budget/{budgetId}") - public ResponseEntity getBudget(@PathVariable("budgetId") int budgetId, Authentication auth) { + /** + * API used to get the Budget for a specific BudgetId + * + * @param budgetId BudgetId that you want the Budget Object for + * @param auth + * @return returns the list the Budget object based on BudgetId specified + */ + @GetMapping("/{budgetId}") + @Operation(description = "API used to get the Budget for a specific BudgetId", summary = "Get Budget for a BudgetId", tags = ("budget")) + @Parameters( + @Parameter(name = "budgetId", description = "BudgetId that you want to the Budget for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Budget") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Budget") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the BudgetId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Budget") + public ResponseEntity getBudgetById(@PathVariable("budgetId") int budgetId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.budgetService.getBudgetById(budgetId, curUser), HttpStatus.OK); @@ -114,7 +180,21 @@ public ResponseEntity getBudget(@PathVariable("budgetId") int budgetId, Authenti } } - @GetMapping("/budget/realmId/{realmId}") + /** + * API used to get all the Budgets for a specific Realm + * + * @param realmId RealmId that you want the List of Budgets for + * @param auth + * @return returns the list the Budgets based on RealmId specified + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the Budget for a specific BudgetId", summary = "Get Budget for a Realm", tags = ("budget")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the List of Budgets for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the List of Budgets for that Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Budget") public ResponseEntity getBudgetForRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -131,65 +211,4 @@ public ResponseEntity getBudgetForRealm(@PathVariable("realmId") int realmId, Au } } - @GetMapping(value = "/sync/budget/{lastSyncDate}") -// @Operation( -// summary = "Used to Sync the Budgets with users machines for Offline use", -// tags = {"Sync", "Budget"}, -// parameters = { -// @Parameter( -// in = ParameterIn.PATH, -// name = "lastSyncDate", -// required = true, -// description = "parameter description", -// allowEmptyValue = false, -// schema = @Schema( -// type = "string", -// format = "yyyy-MM-dd", -// description = "Last date that Budget data was synced. The Application will include all the Budgets where LastModifiedDate is greater than or equal to lastSyncDate. If you have not Synced before then use 2020-01-01.", -// accessMode = Schema.AccessMode.READ_ONLY) -// )}, -// responses = { -// @ApiResponse( -// responseCode = "200", -// description = "Success response", -// content = { -// @Content( -// mediaType = "application/json", -// array = @ArraySchema(schema = @Schema(implementation = Budget.class)) -// ) -// }), -// @ApiResponse( -// responseCode = "406", -// description = "Failed response, most probably the lastSyncDate was not in the required format of yyyy-MM-dd HH:mm:ss", -// content = { -// @Content( -// mediaType = "application/json", -// array = @ArraySchema(schema = @Schema(implementation = ResponseCode.class)) -// ) -// }), -// @ApiResponse( -// responseCode = "500", -// description = "Failed response, an unkown error occurred", -// content = { -// @Content( -// mediaType = "application/json", -// array = @ArraySchema(schema = @Schema(implementation = ResponseCode.class)) -// ) -// }) -// } -// ) - public ResponseEntity getBudgetListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.budgetService.getBudgetListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing budget", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing budget", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/CountryRestController.java b/src/main/java/cc/altius/FASP/rest/controller/CountryRestController.java index b5991ea4c..69e7961dd 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/CountryRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/CountryRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.CountryService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +36,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/country") public class CountryRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -42,7 +45,17 @@ public class CountryRestController { @Autowired private UserService userService; - @GetMapping(value = "/country") + /** + * API used to get the complete Country list. Will only return those + * Countries that are marked Active. + * + * @param auth + * @return returns the complete list of active Countries + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Country list. Will only return those Countries that are marked Active.", summary = "Get active Country list", tags = ("country")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Country list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Country list") public ResponseEntity getCountryList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -53,7 +66,16 @@ public ResponseEntity getCountryList(Authentication auth) { } } - @GetMapping(value = "/country/all") + /** + * API used to get the complete Country list. + * + * @param auth + * @return returns the complete list of Countries + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete Country list.", summary = "Get Country list", tags = ("country")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Country list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Country list") public ResponseEntity getCountryListAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -64,7 +86,20 @@ public ResponseEntity getCountryListAll(Authentication auth) { } } - @GetMapping(value = "/country/{countryId}") + /** + * API used to get the Country for a specific CountryId + * + * @param countryId CountryId that you want the Country Object for + * @param auth + * @return returns the list the Country object based on CountryId specified + */ + @GetMapping(value = "/{countryId}") + @Operation(description = "API used to get the Country for a specific CountryId", summary = "Get Country for a CountryId", tags = ("country")) + @Parameters( + @Parameter(name = "countryId", description = "CountryId that you want to the Country for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Country") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the CountryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Country") public ResponseEntity getCountryById(@PathVariable("countryId") int countryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -78,7 +113,20 @@ public ResponseEntity getCountryById(@PathVariable("countryId") int countryId, A } } - @PostMapping(value = "/country") + /** + * API used to add a Country + * + * @param country Country object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Country", summary = "Add Country", tags = ("country")) + @Parameters( + @Parameter(name = "country", description = "The Country object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the Country Code supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity addCountry(@RequestBody(required = true) Country country, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -99,8 +147,21 @@ public ResponseEntity addCountry(@RequestBody(required = true) Country country, } - @PutMapping(value = "/country") - public ResponseEntity editCountry(@RequestBody(required = true) Country country, Authentication auth) { + /** + * API used to update a Country + * + * @param country Country object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Country", summary = "Update Country", tags = ("country")) + @Parameters( + @Parameter(name = "country", description = "The Country object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the CountryCode supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateCountry(@RequestBody(required = true) Country country, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); int updatedId = this.countryService.updateCountry(country, curUser); @@ -119,18 +180,4 @@ public ResponseEntity editCountry(@RequestBody(required = true) Country country, } } - @GetMapping(value = "/sync/country/{lastSyncDate}") - public ResponseEntity getCountryListForSync(@PathVariable("lastSyncDate") String lastSyncDate) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - return new ResponseEntity(this.countryService.getCountryListForSync(lastSyncDate), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing country", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing country", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java b/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java index 26a5eab70..2d4c3bbc9 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.CurrencyService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +37,7 @@ * @author palash */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/currency") public class CurrencyRestController { @@ -45,34 +48,63 @@ public class CurrencyRestController { @Autowired private UserService userService; - @PostMapping(value = "/currency") - public ResponseEntity addCurrency(@RequestBody Currency currency, Authentication auth, HttpServletRequest request) { + /** + * API used to get the complete Currency list. Will only return those + * Currencies that are marked Active. + * + * @param auth + * @return returns the complete list of active Currencies + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Currency list. Will only return those Currencies that are marked Active.", summary = "Get active Currency list", tags = ("currency")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Currency list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Currency list") + public ResponseEntity getCurrency(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.currencyService.addCurrency(currency, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to add Currency", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); + return new ResponseEntity(this.currencyService.getCurrencyList(true, curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to add Currency", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to get Currency list", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = "/currency") - public ResponseEntity getCurrencyList(Authentication auth) { + /** + * API used to get the complete Currency list. Will only return those + * Currencies that are marked Active. + * + * @param auth + * @return returns the complete list of Currencies + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete Currency list.", summary = "Get Currency list", tags = ("currency")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Currency list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Currency list") + public ResponseEntity getCurrencyListAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.currencyService.getCurrencyList(true, curUser), HttpStatus.OK); + return new ResponseEntity(this.currencyService.getCurrencyList(false, curUser), HttpStatus.OK); } catch (Exception e) { logger.error("Error while trying to get Currency list", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = "/currency/{currencyId}") - public ResponseEntity getCurrencyList(@PathVariable("currencyId") int currencyId, Authentication auth) { + /** + * API used to get the Currency for a specific CurrencyId + * + * @param currencyId CurrencyId that you want the Currency Object for + * @param auth + * @return returns the list the Currency object based on CurrencyId specified + */ + @GetMapping(value = "/{currencyId}") + @Operation(description = "API used to get the Currency for a specific CurrencyId", summary = "Get Currency for a CurrencyId", tags = ("currency")) + @Parameters( + @Parameter(name = "currencyId", description = "CurrencyId that you want to the Currency for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Currency") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the CurrencyId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Currency") + public ResponseEntity getCurrencyById(@PathVariable("currencyId") int currencyId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.currencyService.getCurrencyById(currencyId, curUser), HttpStatus.OK); @@ -85,19 +117,49 @@ public ResponseEntity getCurrencyList(@PathVariable("currencyId") int currencyId } } - @GetMapping(value = "/currency/all") - public ResponseEntity getCurrencyListAll(Authentication auth) { + /** + * API used to add a Currency + * + * @param currency Currency object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Currency", summary = "Add Currency", tags = ("currency")) + @Parameters( + @Parameter(name = "currency", description = "The Currency object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the Currency Code supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addCurrency(@RequestBody Currency currency, Authentication auth, HttpServletRequest request) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.currencyService.getCurrencyList(false, curUser), HttpStatus.OK); + this.currencyService.addCurrency(currency, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to add Currency", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while trying to get Currency list", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Currency", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @PutMapping(value = "/currency") - public ResponseEntity editCurrency(@RequestBody Currency currency, Authentication auth) { + /** + * API used to update a Currency + * + * @param currency Currency object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Currency", summary = "Update Currency", tags = ("currency")) + @Parameters( + @Parameter(name = "currency", description = "The Currency object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the CurrencyCode supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateCurrency(@RequestBody Currency currency, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); this.currencyService.updateCurrency(currency, curUser); @@ -111,19 +173,4 @@ public ResponseEntity editCurrency(@RequestBody Currency currency, Authenticatio } } - @GetMapping(value = "/sync/currency/{lastSyncDate}") - public ResponseEntity getCurrencyListForSync(@PathVariable("lastSyncDate") String lastSyncDate) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - return new ResponseEntity(this.currencyService.getCurrencyListForSync(lastSyncDate), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing currency", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing currency", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/DataSourceRestController.java b/src/main/java/cc/altius/FASP/rest/controller/DataSourceRestController.java index bfd6a2cde..d807efdd0 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/DataSourceRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/DataSourceRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.DataSourceService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author palash */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/dataSource") public class DataSourceRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,25 +47,17 @@ public class DataSourceRestController { @Autowired private UserService userService; - @PostMapping(value = "/dataSource") - public ResponseEntity addDataSource(@RequestBody DataSource dataSource, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.dataSourceService.addDataSource(dataSource, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException e) { - logger.error("Error while trying to add DataSource", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to add DataSource", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add DataSource", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping(value = "/dataSource") + /** + * API used to get the complete DataSource list. Will only return those + * DataSources that are marked Active. + * + * @param auth + * @return returns the complete list of active DataSources + */ + @GetMapping("/") + @Operation(description = "API used to get the complete DataSource list. Will only return those DataSources that are marked Active.", summary = "Get active DataSource list", tags = ("dataSource")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSource list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSource list") public ResponseEntity getDataSourceList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -73,7 +68,17 @@ public ResponseEntity getDataSourceList(Authentication auth) { } } - @GetMapping(value = "/dataSource/all") + /** + * API used to get the complete DataSource list. Will only return those + * DataSources that are marked Active. + * + * @param auth + * @return returns the complete list of DataSources + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete DataSource list.", summary = "Get DataSource list", tags = ("dataSource")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSource list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSource list") public ResponseEntity getDataSourceListAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -84,8 +89,23 @@ public ResponseEntity getDataSourceListAll(Authentication auth) { } } - @GetMapping(value = "/dataSource/{dataSourceId}") - public ResponseEntity getDataSourceListAll(@PathVariable("dataSourceId") int dataSourceId, Authentication auth) { + /** + * API used to get the DataSource for a specific DataSourceId + * + * @param dataSourceId DataSourceId that you want the DataSource Object for + * @param auth + * @return returns the list the DataSource object based on DataSourceId + * specified + */ + @GetMapping(value = "/{dataSourceId}") + @Operation(description = "API used to get the DataSource for a specific DataSourceId", summary = "Get DataSource for a DataSourceId", tags = ("dataSource")) + @Parameters( + @Parameter(name = "dataSourceId", description = "DataSourceId that you want to the DataSource for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSource") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm or Program") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DataSourceId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSource") + public ResponseEntity getDataSourceById(@PathVariable("dataSourceId") int dataSourceId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.dataSourceService.getDataSourceById(dataSourceId, curUser), HttpStatus.OK); @@ -101,7 +121,26 @@ public ResponseEntity getDataSourceListAll(@PathVariable("dataSourceId") int dat } } - @GetMapping(value = "/dataSource/realmId/{realmId}/programId/{programId}") + /** + * API used to get the DataSource for a specific RealmId and ProgramId + * + * @param realmId RealmId that you want the DataSource Object for + * @param programId ProgramId that you want the DataSource Object for + * @param auth + * @return returns the list the DataSource object based on RealmId and + * ProgramId specified + */ + @GetMapping(value = "/realmId/{realmId}/programId/{programId}") + @Operation(description = "API used to get the DataSource for a specific RealmId and ProgramId", summary = "Get DataSource for RealmId and ProgramId", tags = ("dataSource")) + @Parameters( + { + @Parameter(name = "realmIdId", description = "RealmIdId that you want to the DataSource for"), + @Parameter(name = "programIdId", description = "ProgramId that you want to the DataSource for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSource") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm or Program") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DataSourceId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSource") + public ResponseEntity getDataSourceListForRealmIdProgramId(@PathVariable("realmId") int realmId, @PathVariable("programId") int programId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -118,7 +157,23 @@ public ResponseEntity getDataSourceListForRealmIdProgramId(@PathVariable("realmI } } - @GetMapping(value = "/dataSource/dataSourceTypeId/{dataSourceTypeId}") + /** + * API used to get the DataSource for a specific DataSourceTypeId + * + * @param dataSourceTypeId datasourceTypeId that you want the DataSource + * Object for + * @param auth + * @return returns the list the DataSource object based on DataSourceId + * specified + */ + @GetMapping(value = "/dataSourceTypeId/{dataSourceTypeId}") + @Operation(description = "API used to get the DataSource for a specific DataSourceId", summary = "Get DataSource for a DataSourceId", tags = ("dataSource")) + @Parameters( + @Parameter(name = "dataSourceTypeId", description = "DataSourceTypeId that you want to the DataSource for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSource") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DataSourceId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSource") + public ResponseEntity getDataSourceListForDataSourceTypeId(@PathVariable("dataSourceTypeId") int dataSourceTypeId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -135,8 +190,54 @@ public ResponseEntity getDataSourceListForDataSourceTypeId(@PathVariable("dataSo } } - @PutMapping(value = "/dataSource") - public ResponseEntity editDataSource(@RequestBody DataSource dataSource, Authentication auth) { + /** + * API used to add a DataSource + * + * @param dataSource DataSource object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a DataSource", summary = "Add DataSource", tags = ("dataSource")) + @Parameters( + @Parameter(name = "dataSource", description = "The DataSource object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm or Program") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the DataSource Code supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addDataSource(@RequestBody DataSource dataSource, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.dataSourceService.addDataSource(dataSource, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException e) { + logger.error("Error while trying to add DataSource", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to add DataSource", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add DataSource", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * API used to update a DataSource + * + * @param dataSource DataSource object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a DataSource", summary = "Update DataSource", tags = ("dataSource")) + @Parameters( + @Parameter(name = "dataSource", description = "The DataSource object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm or Program") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the DataSourceCode supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateDataSource(@RequestBody DataSource dataSource, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); this.dataSourceService.updateDataSource(dataSource, curUser); @@ -153,20 +254,4 @@ public ResponseEntity editDataSource(@RequestBody DataSource dataSource, Authent } } - @GetMapping(value = "/sync/dataSource/{lastSyncDate}") - public ResponseEntity getDataSourceListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.dataSourceService.getDataSourceListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing dataSource", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing dataSource", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/DataSourceTypeRestController.java b/src/main/java/cc/altius/FASP/rest/controller/DataSourceTypeRestController.java index 0af55640c..b6826586e 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/DataSourceTypeRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/DataSourceTypeRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.DataSourceTypeService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author palash */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/dataSourceType") public class DataSourceTypeRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,25 +47,17 @@ public class DataSourceTypeRestController { @Autowired private UserService userService; - @PostMapping(value = "/dataSourceType") - public ResponseEntity addDataSourceType(@RequestBody DataSourceType dataSourceType, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.dataSourceTypeService.addDataSourceType(dataSourceType, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException e) { - logger.error("Error while trying to add DataSourceType", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to add DataSourceType", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add DataSourceType", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping(value = "/dataSourceType") + /** + * API used to get the complete DataSourceType list. Will only return those + * DataSourceTypes that are marked Active. + * + * @param auth + * @return returns the complete list of active DataSourceTypes + */ + @GetMapping("/") + @Operation(description = "API used to get the complete DataSourceType list. Will only return those DataSourceTypes that are marked Active.", summary = "Get active DataSourceType list", tags = ("dataSourceType")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSourceType list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSourceType list") public ResponseEntity getDataSourceTypeList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -73,7 +68,17 @@ public ResponseEntity getDataSourceTypeList(Authentication auth) { } } - @GetMapping(value = "/dataSourceType/all") + /** + * API used to get the complete DataSourceType list. Will only return those + * DataSourceTypes that are marked Active. + * + * @param auth + * @return returns the complete list of DataSourceTypes + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete DataSourceType list.", summary = "Get DataSourceType list", tags = ("dataSourceType")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSourceType list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSourceType list") public ResponseEntity getDataSourceTypeListAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -83,8 +88,22 @@ public ResponseEntity getDataSourceTypeListAll(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping(value = "/dataSourceType/{dataSourceTypeId}") + + /** + * API used to get the DataSourceType for a specific DataSourceTypeId + * + * @param dataSourceTypeId DataSourceTypeId that you want the DataSourceType Object for + * @param auth + * @return returns the list the DataSourceType object based on DataSourceTypeId specified + */ + @GetMapping(value = "/{dataSourceTypeId}") + @Operation(description = "API used to get the DataSourceType for a specific DataSourceTypeId", summary = "Get DataSourceType for a DataSourceTypeId", tags = ("dataSourceType")) + @Parameters( + @Parameter(name = "dataSourceTypeId", description = "DataSourceTypeId that you want to the DataSourceType for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSourceType") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DataSourceTypeId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSourceType") public ResponseEntity getDataSourceTypeById(@PathVariable("dataSourceTypeId") int dataSourceTypeId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -101,7 +120,21 @@ public ResponseEntity getDataSourceTypeById(@PathVariable("dataSourceTypeId") in } } - @GetMapping(value = "/dataSourceType/realmId/{realmId}") + /** + * API used to get the DataSourceType for a specific DataSourceTypeId + * + * @param realmId RealmId that you want the DataSourceType Object for + * @param auth + * @return returns the list the DataSourceType object based on DataSourceTypeId specified + */ + @GetMapping(value = "/{realmId}") + @Operation(description = "API used to get the DataSourceType for a specific DataSourceTypeId", summary = "Get DataSourceType for a DataSourceTypeId", tags = ("dataSourceType")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the DataSourceType for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the DataSourceType") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of DataSourceType") public ResponseEntity getDataSourceTypeListForRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -118,8 +151,55 @@ public ResponseEntity getDataSourceTypeListForRealmId(@PathVariable("realmId") i } } - @PutMapping(value = "/dataSourceType") - public ResponseEntity editDataSourceType(@RequestBody DataSourceType dataSourceType, Authentication auth) { + /** + * API used to add a DataSourceType + * + * @param dataSourceType DataSourceType object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a DataSourceType", summary = "Add DataSourceType", tags = ("dataSourceType")) + @Parameters( + @Parameter(name = "dataSourceType", description = "The DataSourceType object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addDataSourceType(@RequestBody DataSourceType dataSourceType, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.dataSourceTypeService.addDataSourceType(dataSourceType, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException e) { + logger.error("Error while trying to add DataSourceType", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to add DataSourceType", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add DataSourceType", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * API used to update a DataSourceType + * + * @param dataSourceType DataSourceType object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a DataSourceType", summary = "Update DataSourceType", tags = ("dataSourceType")) + @Parameters( + @Parameter(name = "dataSourceType", description = "The DataSourceType object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DataSourceId does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + + public ResponseEntity updateDataSourceType(@RequestBody DataSourceType dataSourceType, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); this.dataSourceTypeService.updateDataSourceType(dataSourceType, curUser); @@ -136,20 +216,4 @@ public ResponseEntity editDataSourceType(@RequestBody DataSourceType dataSourceT } } -@GetMapping(value = "/sync/dataSourceType/{lastSyncDate}") - public ResponseEntity getDataSourceTypeListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.dataSourceTypeService.getDataSourceTypeListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing dataSourceType", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing dataSourceType", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/DimensionRestController.java b/src/main/java/cc/altius/FASP/rest/controller/DimensionRestController.java index b492a4609..544a5d1a4 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/DimensionRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/DimensionRestController.java @@ -8,8 +8,6 @@ import cc.altius.FASP.model.CustomUserDetails; import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.model.Dimension; -import java.text.ParseException; -import java.text.SimpleDateFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -27,13 +25,18 @@ import org.springframework.web.bind.annotation.RestController; import cc.altius.FASP.service.DimensionService; import cc.altius.FASP.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; /** * * @author palash */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/dimension") public class DimensionRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,40 +46,17 @@ public class DimensionRestController { @Autowired private UserService userService; - @PostMapping(path = "/dimension") - public ResponseEntity postDimension(@RequestBody Dimension dimension, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.dimensionService.addDimension(dimension, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to add Dimension", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Dimension", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/dimension") - public ResponseEntity putDimension(@RequestBody Dimension dimension, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.dimensionService.updateDimension(dimension, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (EmptyResultDataAccessException ae) { - logger.error("Error while trying to update Dimension ", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to update Dimension ", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Dimension", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/dimension") + /** + * API used to get the complete Dimension list. Will only return those + * Dimensions that are marked Active. + * + * @param auth + * @return returns the complete list of active Dimensions + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Dimension list. Will only return those Dimensions that are marked Active.", summary = "Get active Dimension list", tags = ("dimension")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Dimension list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Dimension list") public ResponseEntity getDimension(Authentication auth) { try { return new ResponseEntity(this.dimensionService.getDimensionList(false), HttpStatus.OK); @@ -86,7 +66,17 @@ public ResponseEntity getDimension(Authentication auth) { } } - @GetMapping("/dimension/all") + /** + * API used to get the complete Dimension list. Will only return those + * Dimensions that are marked Active. + * + * @param auth + * @return returns the complete list of Dimensions + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete Dimension list.", summary = "Get Dimension list", tags = ("dimension")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Dimension list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Dimension list") public ResponseEntity getDimensionAll(Authentication auth) { try { return new ResponseEntity(this.dimensionService.getDimensionList(true), HttpStatus.OK); @@ -96,7 +86,20 @@ public ResponseEntity getDimensionAll(Authentication auth) { } } - @GetMapping("/dimension/{dimensionId}") + /** + * API used to get the Dimension for a specific DimensionId + * + * @param dimensionId DimensionId that you want the Dimension Object for + * @param auth + * @return returns the list the Dimension object based on DimensionId specified + */ + @GetMapping(value = "/{dimensionId}") + @Operation(description = "API used to get the Dimension for a specific DimensionId", summary = "Get Dimension for a DimensionId", tags = ("dimension")) + @Parameters( + @Parameter(name = "dimensionId", description = "DimensionId that you want to the Dimension for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Dimension") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the DimensionId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Dimension") public ResponseEntity getDimension(@PathVariable("dimensionId") int dimensionId, Authentication auth) { try { return new ResponseEntity(this.dimensionService.getDimensionById(dimensionId), HttpStatus.OK); @@ -109,18 +112,62 @@ public ResponseEntity getDimension(@PathVariable("dimensionId") int dimensionId, } } - @GetMapping(value = "/sync/dimension/{lastSyncDate}") - public ResponseEntity getCountryListForSync(@PathVariable("lastSyncDate") String lastSyncDate) { + /** + * API used to add a Dimension + * + * @param dimension Dimension object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Dimension", summary = "Add Dimension", tags = ("dimension")) + @Parameters( + @Parameter(name = "dimension", description = "The Dimension object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the Dimension supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addDimension(@RequestBody Dimension dimension, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - return new ResponseEntity(this.dimensionService.getDimensionListForSync(lastSyncDate), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing dimension", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.dimensionService.addDimension(dimension, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to add Dimension", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing dimension", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Dimension", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * API used to update a Dimension + * + * @param dimension Dimension object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Dimension", summary = "Update Dimension", tags = ("dimension")) + @Parameters( + @Parameter(name = "dimension", description = "The Dimension object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the Dimension supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateDimension(@RequestBody Dimension dimension, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.dimensionService.updateDimension(dimension, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (EmptyResultDataAccessException ae) { + logger.error("Error while trying to update Dimension ", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to update Dimension ", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add Dimension", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/FileController.java b/src/main/java/cc/altius/FASP/rest/controller/FileController.java index 4153c42a9..d773e9dc5 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/FileController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/FileController.java @@ -5,6 +5,11 @@ */ package cc.altius.FASP.rest.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -42,10 +47,20 @@ public class FileController { private String ADJUSTMENT_DATA_ENTRY_TEMPLATE; @Value("${qat.shipmentDataEntryTemplate}") private String SHIPMENT_DATA_ENTRY_TEMPLATE; - + /** + * + * @param fileName Name of file that the user wants to get from the Server + * @return Returns the byte array of the file that was requested + * @throws FileNotFoundException if the file was not found + * @throws IOException if there was an error in reading the file from the + * server + */ + @Operation(description = "Returns the byte stream of the file that was requested", summary = "Get file from Server", tags = ("File")) + @Parameters(@Parameter(name = "fileName", description = "Name of file that the user wants to get from the Server")) + @ApiResponse(content = @Content(mediaType = "application/octet-stream"), responseCode = "200", description = "Returns the byte array of the file that was requested") @GetMapping("/file/{fileName}") - public byte[] getFile(@PathVariable("fileName") String fileName, HttpServletResponse response, Authentication auth) throws FileNotFoundException, IOException { + public byte[] getFile(@PathVariable(name = "fileName") String fileName, HttpServletResponse response, Authentication auth) throws FileNotFoundException, IOException { FileInputStream fin = null; switch (fileName) { case "qatUserGuide": @@ -77,7 +92,7 @@ public byte[] getFile(@PathVariable("fileName") String fileName, HttpServletResp response.setHeader("Content-Disposition", "attachment;filename=" + INVENTORY_DATA_ENTRY_TEMPLATE); response.setStatus(HttpServletResponse.SC_OK); fin = new FileInputStream(new File(QAT_FILE_PATH + QAT_ADDITIONAL_FILES + INVENTORY_DATA_ENTRY_TEMPLATE)); - break; + break; case "adjustmentsDataEntryTemplate": response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=" + ADJUSTMENT_DATA_ENTRY_TEMPLATE); @@ -89,7 +104,7 @@ public byte[] getFile(@PathVariable("fileName") String fileName, HttpServletResp response.setHeader("Content-Disposition", "attachment;filename=" + SHIPMENT_DATA_ENTRY_TEMPLATE); response.setStatus(HttpServletResponse.SC_OK); fin = new FileInputStream(new File(QAT_FILE_PATH + QAT_ADDITIONAL_FILES + SHIPMENT_DATA_ENTRY_TEMPLATE)); - break; + break; } return IOUtils.toByteArray(fin); } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ForecastingUnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ForecastingUnitRestController.java index 6be70d2df..af0998853 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ForecastingUnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ForecastingUnitRestController.java @@ -25,15 +25,18 @@ import org.springframework.web.bind.annotation.RestController; import cc.altius.FASP.service.ForecastingUnitService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; /** * * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/forecastingUnit") public class ForecastingUnitRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,41 +46,47 @@ public class ForecastingUnitRestController { @Autowired private UserService userService; - @PostMapping(path = "/forecastingUnit") - public ResponseEntity postForecastingUnit(@RequestBody ForecastingUnit forecastingUnit, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.forecastingUnitService.addForecastingUnit(forecastingUnit, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add ForecastingUnit", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add ForecastingUnit", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/forecastingUnit") - public ResponseEntity putForecastingUnit(@RequestBody ForecastingUnit forecastingUnit, Authentication auth) { + + /** + * API used to get the complete ForecastingUnit list. Will only return those + * ForecastingUnits that are marked Active. + * + * @param auth + * @return returns the complete list of active ForecastingUnits + */ + @GetMapping("/") + @Operation(description = "API used to get the complete ForecastingUnit list. Will only return those ForecastingUnits that are marked Active.", summary = "Get active ForecastingUnit list", tags = ("forecastingUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastingUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastingUnit list") + public ResponseEntity getForecastingUnit(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.forecastingUnitService.updateForecastingUnit(forecastingUnit, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + return new ResponseEntity(this.forecastingUnitService.getForecastingUnitList(true, curUser), HttpStatus.OK); } catch (AccessDeniedException ae) { logger.error("Error while trying to update ForecastingUnit", ae); return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while trying to update ForecastingUnit", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to list ForecastingUnit", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/forecastingUnit") - public ResponseEntity getForecastingUnit(Authentication auth) { + /** + * API used to get the complete ForecastingUnit list. + * + * @param auth + * @return returns the complete list of ForecastingUnits + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete ForecastingUnit list.", summary = "Get ForecastingUnit list", tags = ("forecastingUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastingUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastingUnit list") + public ResponseEntity getForecastingUnitAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.forecastingUnitService.getForecastingUnitList(true, curUser), HttpStatus.OK); + return new ResponseEntity(this.forecastingUnitService.getForecastingUnitList(false, curUser), HttpStatus.OK); } catch (AccessDeniedException ae) { logger.error("Error while trying to update ForecastingUnit", ae); return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); @@ -86,12 +95,29 @@ public ResponseEntity getForecastingUnit(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/forecastingUnit/all") - public ResponseEntity getForecastingUnitAll(Authentication auth) { + + /** + * API used to get the ForecastingUnit for a specific ForecastingUnitId + * + * @param forecastingUnitId ForecastingUnitId that you want the ForecastingUnit Object for + * @param auth + * @return returns the ForecastingUnit object based on ForecastingUnitId specified + */ + @GetMapping(value = "/{forecastingUnitId}") + @Operation(description = "API used to get the ForecastingUnit for a specific ForecastingUnitId", summary = "Get ForecastingUnit for a ForecastingUnitId", tags = ("forecastingUnit")) + @Parameters( + @Parameter(name = "forecastingUnitId", description = "ForecastingUnitId that you want to the ForecastingUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastingUnit") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ForecastingUnitId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastingUnit") + public ResponseEntity getForecastingUnitById(@PathVariable("forecastingUnitId") int forecastingUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.forecastingUnitService.getForecastingUnitList(false, curUser), HttpStatus.OK); + return new ResponseEntity(this.forecastingUnitService.getForecastingUnitById(forecastingUnitId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException er) { + logger.error("Error while trying to list ForecastingUnit", er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (AccessDeniedException ae) { logger.error("Error while trying to update ForecastingUnit", ae); return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); @@ -100,8 +126,22 @@ public ResponseEntity getForecastingUnitAll(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/forecastingUnit/realmId/{realmId}") + + /** + * API used to get the ForecastingUnit for a specific RealmId + * + * @param realmId RealmId that you want the ForecastingUnit List for + * @param auth + * @return returns the list the ForecastingUnit based on RealmId specified + */ + @GetMapping(value = "realmId/{realmId}") + @Operation(description = "API used to get all the ForecastingUnits for a specific RealmId", summary = "Get ForecastingUnit for a RealmId", tags = ("forecastingUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the ForecastingUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastingUnits list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastingUnit") public ResponseEntity getForecastingUnitForRealm(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -117,37 +157,62 @@ public ResponseEntity getForecastingUnitForRealm(@PathVariable(value = "realmId" return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + - @GetMapping("/forecastingUnit/{forecastingUnitId}") - public ResponseEntity getForecastingUnitById(@PathVariable("forecastingUnitId") int forecastingUnitId, Authentication auth) { + + /** + * API used to add a ForecastingUnit + * + * @param forecastingUnit ForecastingUnit object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a ForecastingUnit", summary = "Add ForecastingUnit", tags = ("forecastingUnit")) + @Parameters( + @Parameter(name = "forecastingUnit", description = "The ForecastingUnit object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addForecastingUnit(@RequestBody ForecastingUnit forecastingUnit, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.forecastingUnitService.getForecastingUnitById(forecastingUnitId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException er) { - logger.error("Error while trying to list ForecastingUnit", er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + this.forecastingUnitService.addForecastingUnit(forecastingUnit, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); } catch (AccessDeniedException ae) { - logger.error("Error while trying to update ForecastingUnit", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + logger.error("Error while trying to add ForecastingUnit", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while trying to list ForecastingUnit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add ForecastingUnit", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = "/sync/forecastingUnit/{lastSyncDate}") - public ResponseEntity getForecastingUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to update a ForecastingUnit + * + * @param forecastingUnit ForecastingUnit object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a ForecastingUnit", summary = "Update ForecastingUnit", tags = ("forecastingUnit")) + @Parameters( + @Parameter(name = "forecastingUnit", description = "The ForecastingUnit object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateForecastingUnit(@RequestBody ForecastingUnit forecastingUnit, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.forecastingUnitService.getForecastingUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing forecastingUnit", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.forecastingUnitService.updateForecastingUnit(forecastingUnit, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update ForecastingUnit", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while listing forecastingUnit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to update ForecastingUnit", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/FundingSourceRestController.java b/src/main/java/cc/altius/FASP/rest/controller/FundingSourceRestController.java index 981e417c3..e2b51cbfe 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/FundingSourceRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/FundingSourceRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.FundingSourceService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/fundingSource") public class FundingSourceRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,58 +46,76 @@ public class FundingSourceRestController { @Autowired private UserService userService; - @PostMapping(path = "/fundingSource") - public ResponseEntity postFundingSource(@RequestBody FundingSource fundingSource, Authentication auth) { + /** + * API used to get the complete FundingSource list. + * + * @param auth + * @return returns the complete list of FundingSources + */ + @GetMapping("/") + @Operation(description = "API used to get the complete FundingSource list.", summary = "Get FundingSource list", tags = ("fundingSource")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the FundingSource list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of FundingSource list") + public ResponseEntity getFundingSource(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.fundingSourceService.addFundingSource(fundingSource, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Funding source", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException d) { - logger.error("Error while trying to add Funding source", d); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + return new ResponseEntity(this.fundingSourceService.getFundingSourceList(curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to add Funding source", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to list Funding source", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @PutMapping(path = "/fundingSource") - public ResponseEntity putFundingSource(@RequestBody FundingSource fundingSource, Authentication auth) { + /** + * API used to get the FundingSource for a specific FundingSourceId + * + * @param fundingSourceId FundingSourceId that you want the FundingSource + * Object for + * @param auth + * @return returns the list the FundingSource object based on + * FundingSourceId specified + */ + @GetMapping(value = "/{fundingSourceId}") + @Operation(description = "API used to get the FundingSource for a specific FundingSourceId", summary = "Get FundingSource for a FundingSourceId", tags = ("fundingSource")) + @Parameters( + @Parameter(name = "fundingSourceId", description = "FundingSourceId that you want to the FundingSource for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the FundingSource") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the FundingSourceId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of FundingSource") + public ResponseEntity getFundingSource(@PathVariable("fundingSourceId") int fundingSourceId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.fundingSourceService.updateFundingSource(fundingSource, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + return new ResponseEntity(this.fundingSourceService.getFundingSourceById(fundingSourceId, curUser), HttpStatus.OK); } catch (EmptyResultDataAccessException ae) { - logger.error("Error while trying to update Funding source", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); + logger.error("Error while trying to get Funding source Id=" + fundingSourceId, ae); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (AccessDeniedException ae) { - logger.error("Error while trying to update Funding source", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException d) { - logger.error("Error while trying to update Funding source", d); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to update Funding source", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/fundingSource") - public ResponseEntity getFundingSource(Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.fundingSourceService.getFundingSourceList(curUser), HttpStatus.OK); + logger.error("Error while trying to get Funding source Id=" + fundingSourceId, ae); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while trying to list Funding source", e); + logger.error("Error while trying to get Funding source Id=" + fundingSourceId, e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/fundingSource/getDisplayName/realmId/{realmId}/name/{name}") - public ResponseEntity getFundingSourceDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { + + /** + * API used to get the FundingSource by providing the display name of the + * FundingSource and the Realm + * + * @param realmId RealmId that you want the Funding Source from + * @param name Display name of the Funding source you want to get + * @param auth + * @return returns the complete list of FundingSources + */ + @GetMapping("/getDisplayName/realmId/{realmId}/name/{name}") + @Operation(description = "API used to get the complete FundingSource by providing the display name of the FundingSource and the Realm", summary = "Get FundingSource by display name", tags = ("fundingSource")) + @Parameters({ + @Parameter(name = "realmId", description = "RealmId that you want to the FundingSource for"), + @Parameter(name = "name", description = "Display name that you want to the FundingSource for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the FundingSource") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of FundingSource") + public ResponseEntity getFundingSourceByDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.fundingSourceService.getDisplayName(realmId, name, curUser), HttpStatus.OK); @@ -104,7 +125,21 @@ public ResponseEntity getFundingSourceDisplayName(@PathVariable("realmId") int r } } - @GetMapping("/fundingSource/realmId/{realmId}") + /** + * API used to get the FundingSource list for a Realm + * + * @param realmId RealmId that you want the FundingSource List from + * @param auth + * @return returns the complete list of FundingSources + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete FundingSource list for a Realm", summary = "Get FundingSource list for Realm", tags = ("fundingSource")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the FundingSource for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the FundingSource list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of FundingSource list") public ResponseEntity getFundingSourceForRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -121,36 +156,72 @@ public ResponseEntity getFundingSourceForRealm(@PathVariable("realmId") int real } } - @GetMapping("/fundingSource/{fundingSourceId}") - public ResponseEntity getFundingSource(@PathVariable("fundingSourceId") int fundingSourceId, Authentication auth) { + /** + * API used to add a FundingSource + * + * @param fundingSource FundingSource object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a FundingSource", summary = "Add FundingSource", tags = ("fundingSource")) + @Parameters( + @Parameter(name = "fundingSource", description = "The FundingSource object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addFundingSource(@RequestBody FundingSource fundingSource, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.fundingSourceService.getFundingSourceById(fundingSourceId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException ae) { - logger.error("Error while trying to get Funding source Id=" + fundingSourceId, ae); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + this.fundingSourceService.addFundingSource(fundingSource, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); } catch (AccessDeniedException ae) { - logger.error("Error while trying to get Funding source Id=" + fundingSourceId, ae); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); + logger.error("Error while trying to add Funding source", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException d) { + logger.error("Error while trying to add Funding source", d); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while trying to get Funding source Id=" + fundingSourceId, e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Funding source", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = "/sync/fundingSource/{lastSyncDate}") - public ResponseEntity getFundingSourceListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to update a FundingSource + * + * @param fundingSource FundingSource object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a FundingSource", summary = "Update FundingSource", tags = ("fundingSource")) + @Parameters( + @Parameter(name = "fundingSource", description = "The FundingSource object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the FundingSourceId supplied does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateFundingSource(@RequestBody FundingSource fundingSource, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.fundingSourceService.getFundingSourceListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing fundingSource", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.fundingSourceService.updateFundingSource(fundingSource, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (EmptyResultDataAccessException ae) { + logger.error("Error while trying to update Funding source", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update Funding source", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException d) { + logger.error("Error while trying to update Funding source", d); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing fundingSource", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to update Funding source", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/HealthAreaRestController.java b/src/main/java/cc/altius/FASP/rest/controller/HealthAreaRestController.java index c16945cf5..be02e6cc2 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/HealthAreaRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/HealthAreaRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.HealthAreaService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/healthArea") public class HealthAreaRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,46 +47,16 @@ public class HealthAreaRestController { @Autowired private UserService userService; - @PostMapping(path = "/healthArea") - public ResponseEntity postHealthArea(@RequestBody HealthArea healthArea, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.healthAreaService.addHealthArea(healthArea, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Health Area", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException d) { - logger.error("Error while trying to add Health Area", d); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Health Area", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/healthArea") - public ResponseEntity putHealhArea(@RequestBody HealthArea healthArea, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.healthAreaService.updateHealthArea(healthArea, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (EmptyResultDataAccessException ae) { - logger.error("Error while trying to update Health Area", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to update Health Area", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException d) { - logger.error("Error while trying to update Health Area", d); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to update Health Area", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/healthArea") + /** + * API used to get the complete HealthArea list. + * + * @param auth + * @return returns the complete list of HealthAreas + */ + @GetMapping("/") + @Operation(description = "API used to get the complete HealthArea list.", summary = "Get HealthArea list", tags = ("healthArea")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea list") public ResponseEntity getHealthArea(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -94,38 +67,55 @@ public ResponseEntity getHealthArea(Authentication auth) { } } - @GetMapping("/healthArea/realmCountryId/{realmCountryId}") - public ResponseEntity getHealthAreaByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { + /** + * API used to get the HealthArea for a specific HealthAreaId + * + * @param healthAreaId HealthAreaId that you want the HealthArea + * Object for + * @param auth + * @return returns the HealthArea object based on + * HealthAreaId specified + */ + @GetMapping(value = "/{healthAreaId}") + @Operation(description = "API used to get the HealthArea for a specific HealthAreaId", summary = "Get HealthArea for a HealthAreaId", tags = ("healthArea")) + @Parameters( + @Parameter(name = "healthAreaId", description = "HealthAreaId that you want to the HealthArea for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the HealthAreaId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea") + public ResponseEntity getHealthAreaById(@PathVariable("healthAreaId") int healthAreaId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.healthAreaService.getHealthAreaListByRealmCountry(realmCountryId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException e) { + return new ResponseEntity(this.healthAreaService.getHealthAreaById(healthAreaId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException er) { + logger.error("Error while trying to get Health Area list", er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + } catch (AccessDeniedException e) { logger.error("Error while trying to get Health Area list", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { logger.error("Error while trying to get Health Area list", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } -// @GetMapping("/healthArea/program/realmId/{realmId}") -// public ResponseEntity getHealthAreaForRealmCountry(@PathVariable("realmId") int realmId, Authentication auth) { -// try { -// CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); -// return new ResponseEntity(this.healthAreaService.getHealthAreaForActiveProgramsList(realmId, curUser), HttpStatus.OK); -// } catch (EmptyResultDataAccessException e) { -// logger.error("Error while trying to get Health Area list", e); -// return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); -// } catch (AccessDeniedException e) { -// logger.error("Error while trying to get Health Area list", e); -// return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); -// } catch (Exception e) { -// logger.error("Error while trying to get Health Area list", e); -// return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); -// } -// } - @GetMapping("/healthArea/realmId/{realmId}") - public ResponseEntity getHealthAreaByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { + /** + * API used to get the HealthArea list for a Realm + * + * @param realmId RealmId that you want the HealthArea List from + * @param auth + * @return returns the complete list of HealthAreas + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete HealthArea list for a Realm", summary = "Get HealthArea list for Realm", tags = ("healthArea")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the HealthArea list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea list") + public ResponseEntity getHealthAreaByRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.healthAreaService.getHealthAreaListByRealmId(realmId, curUser), HttpStatus.OK); @@ -141,24 +131,49 @@ public ResponseEntity getHealthAreaByRealmId(@PathVariable("realmId") int realmI } } - @GetMapping("/healthArea/{healthAreaId}") - public ResponseEntity getHealthArea(@PathVariable("healthAreaId") int healthAreaId, Authentication auth) { + /** + * API used to get the HealthArea list for a RealmCountry + * + * @param realmCountryId RealmCountryId that you want the HealthArea + * List from + * @param auth + * @return returns the complete list of HealthAreas + */ + @GetMapping("/realmCountryId/{realmCountryId}") + @Operation(description = "API used to get the complete HealthArea list for a RealmCountry", summary = "Get HealthArea list for RealmCountry", tags = ("healthArea")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want to the HealthArea list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if the RealmCountryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea list") + public ResponseEntity getHealthAreaByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.healthAreaService.getHealthAreaById(healthAreaId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException er) { - logger.error("Error while trying to get Health Area list", er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); - } catch (AccessDeniedException e) { + return new ResponseEntity(this.healthAreaService.getHealthAreaListByRealmCountry(realmCountryId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException e) { logger.error("Error while trying to get Health Area list", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); } catch (Exception e) { logger.error("Error while trying to get Health Area list", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/healthArea/program") + /** + * API used to get the HealthArea list that are linked to active Programs + * + * @param auth + * @return returns the complete list of HealthAreas that are linked to + * active Programs + */ + @GetMapping("/program") + @Operation(description = "API used to get the complete HealthArea list that are linked to active Programs", summary = "Get HealthArea list for active Programs", tags = ("healthArea")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if the User has access to multiple Realms") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea list") public ResponseEntity getHealthAreaByForProgram(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -179,8 +194,23 @@ public ResponseEntity getHealthAreaByForProgram(Authentication auth) { } } - @GetMapping("/healthArea/program/realmId/{realmId}") - public ResponseEntity getHealthAreaForProgramByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { + /** + * API used to get the HealthArea list that are linked to active Programs + * + * @param realmId RealmId that you want the HealthArea List for + * @param auth + * @return returns the complete list of HealthAreas that are linked to + * active Programs + */ + @GetMapping("/program/realmId/{realmId}") + @Operation(description = "API used to get the complete HealthArea list that are linked to active Programs", summary = "Get HealthArea list for active Programs", tags = ("healthArea")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the HealthArea list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea list") + public ResponseEntity getHealthAreaForProgramByRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.healthAreaService.getHealthAreaListForProgramByRealmId(realmId, curUser), HttpStatus.OK); @@ -196,8 +226,23 @@ public ResponseEntity getHealthAreaForProgramByRealmId(@PathVariable("realmId") } } - @GetMapping("/healthArea/getDisplayName/realmId/{realmId}/name/{name}") - public ResponseEntity getHealthAreaDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { + /** + * API used to get the HealthArea by providing the display name of the + * HealthArea and the Realm + * + * @param realmId RealmId that you want the HealthArea from + * @param name Display name of the Funding source you want to get + * @param auth + * @return returns the complete list of HealthAreas + */ + @GetMapping("/getDisplayName/realmId/{realmId}/name/{name}") + @Operation(description = "API used to get the complete HealthArea by providing the display name of the HealthArea and the Realm", summary = "Get HealthArea by display name", tags = ("healthArea")) + @Parameters({ + @Parameter(name = "realmId", description = "RealmId that you want to the HealthArea for"), + @Parameter(name = "name", description = "Display name that you want to the HealthArea for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the HealthArea") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of HealthArea") + public ResponseEntity getHealthAreaByDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.healthAreaService.getDisplayName(realmId, name, curUser), HttpStatus.OK); @@ -207,19 +252,72 @@ public ResponseEntity getHealthAreaDisplayName(@PathVariable("realmId") int real } } - @GetMapping(value = "/sync/healthArea/{lastSyncDate}") - public ResponseEntity getHealthAreaListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to add a HealthArea + * + * @param healthArea HealthArea object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a HealthArea", summary = "Add HealthArea", tags = ("healthArea")) + @Parameters( + @Parameter(name = "healthArea", description = "The HealthArea object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addHealthArea(@RequestBody HealthArea healthArea, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.healthAreaService.getHealthAreaListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing healthArea", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.healthAreaService.addHealthArea(healthArea, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Health Area", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException d) { + logger.error("Error while trying to add Health Area", d); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing healthArea", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Health Area", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to update a HealthArea + * + * @param healthArea HealthArea object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a HealthArea", summary = "Update HealthArea", tags = ("healthArea")) + @Parameters( + @Parameter(name = "healthArea", description = "The HealthArea object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the HealthAreaId supplied does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateHealhArea(@RequestBody HealthArea healthArea, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.healthAreaService.updateHealthArea(healthArea, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (EmptyResultDataAccessException ae) { + logger.error("Error while trying to update Health Area", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update Health Area", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException d) { + logger.error("Error while trying to update Health Area", d); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to update Health Area", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java b/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java index 7079f8ca8..3770ebf14 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.OrganisationService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/organisation") public class OrganisationRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,46 +47,16 @@ public class OrganisationRestController { @Autowired private UserService userService; - @PostMapping(path = "/organisation") - public ResponseEntity postOrganisation(@RequestBody Organisation organisation, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.organisationService.addOrganisation(organisation, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Organisation", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to add Organisation", ae); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Organisation", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/organisation") - public ResponseEntity putOrganisation(@RequestBody Organisation organisation, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.organisationService.updateOrganisation(organisation, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (EmptyResultDataAccessException ae) { - logger.error("Error while trying to update Organisation", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to update Organisation", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to update Organisation", ae); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to update Organisation", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/organisation") + /** + * API used to get the complete Organisation list. + * + * @param auth + * @return returns the complete list of Organisations + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Organisation list.", summary = "Get Organisation list", tags = ("organisation")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation list") public ResponseEntity getOrganisation(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -93,22 +66,55 @@ public ResponseEntity getOrganisation(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/organisation/realmCountryId/{realmCountryId}") - public ResponseEntity getOrganisationByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { + + /** + * API used to get the Organisation for a specific OrganisationId + * + * @param organisationId OrganisationId that you want the Organisation + * Object for + * @param auth + * @return returns the list the Organisation object based on + * OrganisationId specified + */ + @GetMapping(value = "/{organisationId}") + @Operation(description = "API used to get the Organisation for a specific OrganisationId", summary = "Get Organisation for a OrganisationId", tags = ("organisation")) + @Parameters( + @Parameter(name = "organisationId", description = "OrganisationId that you want to the Organisation for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the OrganisationId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation") + public ResponseEntity getOrganisation(@PathVariable("organisationId") int organisationId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.organisationService.getOrganisationListByRealmCountry(realmCountryId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException e) { - logger.error("Error while trying to get Organisation list", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + return new ResponseEntity(this.organisationService.getOrganisationById(organisationId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException er) { + logger.error("Error while trying to get Organisation list", er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + } catch (AccessDeniedException er) { + logger.error("Error while trying to get Organisation list", er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { logger.error("Error while trying to get Organisation list", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/organisation/realmId/{realmId}") + /** + * API used to get the Organisation list for a Realm + * + * @param realmId RealmId that you want the Funding Source List from + * @param auth + * @return returns the complete list of Organisations + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete Organisation list for a Realm", summary = "Get Organisation list for Realm", tags = ("organisation")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the Organisation list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation list") public ResponseEntity getOrganisationByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -125,24 +131,51 @@ public ResponseEntity getOrganisationByRealmId(@PathVariable("realmId") int real } } - @GetMapping("/organisation/{organisationId}") - public ResponseEntity getOrganisation(@PathVariable("organisationId") int organisationId, Authentication auth) { + /** + * API used to get the Organisation list for a RealmCountry + * + * @param realmCountryId RealmCountryId that you want the Funding Source + * List from + * @param auth + * @return returns the complete list of Organisations + */ + @GetMapping("/realmCountryId/{realmCountryId}") + @Operation(description = "API used to get the complete Organisation list for a RealmCountry", summary = "Get Organisation list for RealmCountry", tags = ("organisation")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want to the Organisation list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if the RealmCountryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation list") + public ResponseEntity getOrganisationByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.organisationService.getOrganisationById(organisationId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException er) { - logger.error("Error while trying to get Organisation list", er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); - } catch (AccessDeniedException er) { - logger.error("Error while trying to get Organisation list", er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); + return new ResponseEntity(this.organisationService.getOrganisationListByRealmCountry(realmCountryId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException e) { + logger.error("Error while trying to get Organisation list", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); } catch (Exception e) { logger.error("Error while trying to get Organisation list", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/organisation/getDisplayName/realmId/{realmId}/name/{name}") + /** + * API used to get the Organisation by providing the display name of the + * Organisation and the Realm + * + * @param realmId RealmId that you want the Funding Source from + * @param name Display name of the Funding source you want to get + * @param auth + * @return returns the complete list of Organisations + */ + @GetMapping("/getDisplayName/realmId/{realmId}/name/{name}") + @Operation(description = "API used to get the complete Organisation by providing the display name of the Organisation and the Realm", summary = "Get Organisation by display name", tags = ("organisation")) + @Parameters({ + @Parameter(name = "realmId", description = "RealmId that you want to the Organisation for"), + @Parameter(name = "name", description = "Display name that you want to the Organisation for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation") public ResponseEntity getOrganisationDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -152,21 +185,73 @@ public ResponseEntity getOrganisationDisplayName(@PathVariable("realmId") int re return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - - @GetMapping(value = "/sync/organisation/{lastSyncDate}") - public ResponseEntity getOrganisatiionListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + + /** + * API used to add an Organisation + * + * @param organisation Organisation object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add an Organisation", summary = "Add Organisation", tags = ("organisation")) + @Parameters( + @Parameter(name = "organisation", description = "The Organisation object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addOrganisation(@RequestBody Organisation organisation, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.organisationService.getOrganisationListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing organisation", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.organisationService.addOrganisation(organisation, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Organisation", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to add Organisation", ae); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing organisation", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Organisation", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to update an Organisation + * + * @param organisation Organisation object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update an Organisation", summary = "Update Organisation", tags = ("organisation")) + @Parameters( + @Parameter(name = "organisation", description = "The Organisation object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the OrganisationId supplied does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateOrganisation(@RequestBody Organisation organisation, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.organisationService.updateOrganisation(organisation, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (EmptyResultDataAccessException ae) { + logger.error("Error while trying to update Organisation", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_FOUND); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update Organisation", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to update Organisation", ae); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to update Organisation", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java index 2248f04d6..4f7693f53 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java @@ -12,8 +12,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.ProcurementAgentService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +39,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/procurementAgent") public class ProcurementAgentRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -46,59 +49,96 @@ public class ProcurementAgentRestController { @Autowired private UserService userService; - @PostMapping(path = "/procurementAgent") - public ResponseEntity postProcurementAgent(@RequestBody ProcurementAgent procurementAgent, Authentication auth) { + /** + * API used to get the complete ProcurementAgent list. + * + * @param auth + * @return returns the complete list of ProcurementAgents + */ + @GetMapping("/") + @Operation(description = "API used to get the complete ProcurementAgent list.", summary = "Get ProcurementAgent list", tags = ("procurementAgent")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") + public ResponseEntity getProcurementAgent(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - int procurementAgentId = this.procurementAgentService.addProcurementAgent(procurementAgent, curUser); - if (procurementAgentId > 0) { - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } else { - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Procurement Agent", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to add Procurement Agent", e); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + return new ResponseEntity(this.procurementAgentService.getProcurementAgentList(true, curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to add Procurement Agent", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to list Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } - } - @PutMapping(path = "/procurementAgent") - public ResponseEntity putProcurementAgent(@RequestBody ProcurementAgent procurementAgent, Authentication auth) { + /** + * API used to get the ProcurementAgent for a specific ProcurementAgentId + * + * @param procurementAgentId ProcurementAgentId that you want the + * ProcurementAgent Object for + * @param auth + * @return returns the list the ProcurementAgent object based on + * ProcurementAgentId specified + */ + @GetMapping(value = "/{procurementAgentId}") + @Operation(description = "API used to get the ProcurementAgent for a specific ProcurementAgentId", summary = "Get ProcurementAgent for a ProcurementAgentId", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the ProcurementAgent for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProcurementAgentId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent") + public ResponseEntity getProcurementAgent(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - int rows = this.procurementAgentService.updateProcurementAgent(procurementAgent, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to update Procurement Agent", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to update Procurement Agent", e); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + return new ResponseEntity(this.procurementAgentService.getProcurementAgentById(procurementAgentId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException er) { + logger.error("Error while trying to get Procurement Agent Id" + procurementAgentId, er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (Exception e) { - logger.error("Error while trying to add Procurement Agent", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to list Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementAgent") - public ResponseEntity getProcurementAgent(Authentication auth) { + /** + * API used to get the ProcurementAgent by providing the display name of the + * ProcurementAgent and the Realm + * + * @param realmId RealmId that you want the ProcurementAgent from + * @param name Display name of the Funding source you want to get + * @param auth + * @return returns the complete list of ProcurementAgents + */ + @GetMapping("/getDisplayName/realmId/{realmId}/name/{name}") + @Operation(description = "API used to get the complete ProcurementAgent by providing the display name of the ProcurementAgent and the Realm", summary = "Get ProcurementAgent by display name", tags = ("procurementAgent")) + @Parameters({ + @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementAgent for"), + @Parameter(name = "name", description = "Display name that you want to the ProcurementAgent for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent") + public ResponseEntity getProcurementAgentDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getProcurementAgentList(true, curUser), HttpStatus.OK); + return new ResponseEntity(this.procurementAgentService.getDisplayName(realmId, name, curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to list Procurement Agent", e); + logger.error("Error while trying to get Funding source suggested display name", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementAgent/realmId/{realmId}") + /** + * API used to get the ProcurementAgent list for a Realm + * + * @param realmId RealmId that you want the ProcurementAgent List from + * @param auth + * @return returns the complete list of ProcurementAgents + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete ProcurementAgent list for a Realm", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementAgent for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgentForRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -115,21 +155,90 @@ public ResponseEntity getProcurementAgentForRealm(@PathVariable("realmId") int r } } - @GetMapping("/procurementAgent/{procurementAgentId}") - public ResponseEntity getProcurementAgent(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { + /** + * API used to add a ProcurementAgent + * + * @param procurementAgent ProcurementAgent object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a ProcurementAgent", summary = "Add ProcurementAgent", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgent", description = "The ProcurementAgent object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addProcurementAgent(@RequestBody ProcurementAgent procurementAgent, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getProcurementAgentById(procurementAgentId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException er) { - logger.error("Error while trying to get Procurement Agent Id" + procurementAgentId, er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + int procurementAgentId = this.procurementAgentService.addProcurementAgent(procurementAgent, curUser); + if (procurementAgentId > 0) { + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } else { + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Procurement Agent", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to add Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while trying to list Procurement Agent", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + + } + + /** + * API used to update a ProcurementAgent + * + * @param procurementAgent ProcurementAgent object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a ProcurementAgent", summary = "Update ProcurementAgent", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgent", description = "The ProcurementAgent object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateProcurementAgent(@RequestBody ProcurementAgent procurementAgent, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + int rows = this.procurementAgentService.updateProcurementAgent(procurementAgent, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update Procurement Agent", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to update Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add Procurement Agent", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @PutMapping("/procurementAgent/planningingUnit") + /** + * API used to save the ProcurementAgentPlanningUnits list + * + * @param procurementAgentPlanningUnits ProcurementAgentPlanningUnits list + * that you want to save + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping("/planningingUnit") + @Operation(description = "API used to save the ProcurementAgentPlanningUnits list", summary = "Update ProcurementAgent PlanningUnits", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentPlanningUnits", description = "The list of ProcurementAgentPlanningUnits that you want to save")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity savePlanningUnitForProcurementAgent(@RequestBody ProcurementAgentPlanningUnit[] procurementAgentPlanningUnits, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -145,7 +254,24 @@ public ResponseEntity savePlanningUnitForProcurementAgent(@RequestBody Procureme } } - @GetMapping("/procurementAgent/{procurementAgentId}/planningUnit") + /** + * API used to get the ProcurementAgent Planning Unit list for a Procurement + * Agent. Will only return those PlanningUnits that are marked active. + * + * @param procurementAgentId ProcurementAgentId that you want the + * PlanningUnit List for + * @param auth + * @return returns the list of PlanningUnits for the ProcurementAgent + * specified. Will only return those PlanningUnits that are marked active. + */ + @GetMapping("/{procurementAgentId}/planningUnit") + @Operation(description = "API used to get the ProcurementAgent Planning Unit list for a Procurement Agent. Will only return those PlanningUnits that are marked active.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgentPlanningUnitList(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -159,7 +285,24 @@ public ResponseEntity getProcurementAgentPlanningUnitList(@PathVariable("procure } } - @GetMapping("/procurementAgent/{procurementAgentId}/planningUnit/all") + /** + * API used to get the ProcurementAgent Planning Unit list for a Procurement + * Agent. + * + * @param procurementAgentId ProcurementAgentId that you want the + * PlanningUnit List for + * @param auth + * @return returns the list of PlanningUnits for the ProcurementAgent + * specified. + */ + @GetMapping("/{procurementAgentId}/planningUnit/all") + @Operation(description = "API used to get the ProcurementAgent Planning Unit list for a Procurement Agent.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgentPlanningUnitListAll(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -173,7 +316,21 @@ public ResponseEntity getProcurementAgentPlanningUnitListAll(@PathVariable("proc } } - @PutMapping("/procurementAgent/procurementUnit") + /** + * API used to save the ProcurementAgentProcurementUnits list + * + * @param procurementAgentProcurementUnits ProcurementAgentProcurementUnits + * list that you want to save + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping("/procurementUnit") + @Operation(description = "API used to save the ProcurementAgentProcurementUnits list", summary = "Update ProcurementAgent ProcurementUnits", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentProcurementUnits", description = "The list of ProcurementAgentProcurementUnits that you want to save")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity saveProcurementUnitForProcurementAgent(@RequestBody ProcurementAgentProcurementUnit[] procurementAgentProcurementUnits, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -188,7 +345,26 @@ public ResponseEntity saveProcurementUnitForProcurementAgent(@RequestBody Procur } } - @GetMapping("/procurementAgent/{procurementAgentId}/procurementUnit") + /** + * API used to get the ProcurementAgent Procurement Unit list for a + * Procurement Agent. Will only return those ProcurementUnits that are + * marked active. + * + * @param procurementAgentId ProcurementAgentId that you want the + * PlanningUnit List for + * @param auth + * @return returns the list of ProcurementUnits for the ProcurementAgent + * specified. Will only return those ProcurementUnits that are marked + * active. + */ + @GetMapping("/{procurementAgentId}/procurementUnit") + @Operation(description = "API used to get the ProcurementAgent ProcurementUnit list for a Procurement Agent. Will only return those ProcurementUnits that are marked active.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgentProcurementUnitList(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -202,7 +378,24 @@ public ResponseEntity getProcurementAgentProcurementUnitList(@PathVariable("proc } } - @GetMapping("/procurementAgent/{procurementAgentId}/procurementUnit/all") + /** + * API used to get the ProcurementAgent Procurement Unit list for a + * Procurement Agent. + * + * @param procurementAgentId ProcurementAgentId that you want the + * PlanningUnit List for + * @param auth + * @return returns the list of ProcurementUnits for the ProcurementAgent + * specified. + */ + @GetMapping("/{procurementAgentId}/procurementUnit/all") + @Operation(description = "API used to get the ProcurementAgent ProcurementUnit list for a Procurement Agent.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Parameters( + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -216,62 +409,4 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p } } - @GetMapping(value = "/sync/procurementAgent/planningUnit/{lastSyncDate}") - public ResponseEntity getProcurementAgentPlanningUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getProcurementAgentPlanningUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing procurementAgent", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing procurementAgent", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping(value = "/sync/procurementAgent/procurementUnit/{lastSyncDate}") - public ResponseEntity getProcurementAgentProcurementUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getProcurementAgentProcurementUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing procurementAgent", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing procurementAgent", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/procurementAgent/getDisplayName/realmId/{realmId}/name/{name}") - public ResponseEntity getProcurementAgentDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getDisplayName(realmId, name, curUser), HttpStatus.OK); - } catch (Exception e) { - logger.error("Error while trying to get Funding source suggested display name", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping(value = "/sync/procurementAgent/{lastSyncDate}") - public ResponseEntity getProcurementAgentListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementAgentService.getProcurementAgentListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing procurementAgent", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing procurementAgent", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java index 2b5f7853e..3c7cbc983 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.ProcurementUnitService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +36,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/procurementUnit") public class ProcurementUnitRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,59 +46,93 @@ public class ProcurementUnitRestController { @Autowired private UserService userService; - @PostMapping(path = "/procurementUnit") - public ResponseEntity postProcurementUnit(@RequestBody ProcurementUnit procurementUnit, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.procurementUnitService.addProcurementUnit(procurementUnit, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add ProcurementUnit", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add ProcurementUnit", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/procurementUnit") - public ResponseEntity putProcurementUnit(@RequestBody ProcurementUnit procurementUnit, Authentication auth) { + /** + * API used to get the complete ProcurementUnit list. Will only return those + * ProcurementUnits that are marked Active. + * + * @param auth + * @return returns the complete list of active ProcurementUnits + */ + @GetMapping("/") + @Operation(description = "API used to get the complete ProcurementUnit list. Will only return those ProcurementUnits that are marked Active.", summary = "Get active ProcurementUnit list", tags = ("procurementUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit list") + public ResponseEntity getProcurementUnit(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.procurementUnitService.updateProcurementUnit(procurementUnit, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to update ProcurementUnit", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + return new ResponseEntity(this.procurementUnitService.getProcurementUnitList(true, curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to update ProcurementUnit", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to list ProcurementUnit", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementUnit") - public ResponseEntity getProcurementUnit(Authentication auth) { + /** + * API used to get the complete ProcurementUnit list. + * + * @param auth + * @return returns the complete list of ProcurementUnits + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete ProcurementUnit list.", summary = "Get ProcurementUnit list", tags = ("procurementUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit list") + public ResponseEntity getProcurementUnitAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementUnitService.getProcurementUnitList(true, curUser), HttpStatus.OK); + return new ResponseEntity(this.procurementUnitService.getProcurementUnitList(false, curUser), HttpStatus.OK); } catch (Exception e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementUnit/all") - public ResponseEntity getProcurementUnitAll(Authentication auth) { + /** + * API used to get the ProcurementUnit for a specific ProcurementUnitId + * + * @param procurementUnitId ProcurementUnitId that you want the + * ProcurementUnit Object for + * @param auth + * @return returns the ProcurementUnit object based on + * ProcurementUnitId specified + */ + @GetMapping(value = "/{procurementUnitId}") + @Operation(description = "API used to get the ProcurementUnit for a specific ProcurementUnitId", summary = "Get ProcurementUnit for a ProcurementUnitId", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "procurementUnitId", description = "ProcurementUnitId that you want to the ProcurementUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProcurementUnitId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit") + public ResponseEntity getProcurementUnitById(@PathVariable("procurementUnitId") int procurementUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementUnitService.getProcurementUnitList(false, curUser), HttpStatus.OK); + return new ResponseEntity(this.procurementUnitService.getProcurementUnitById(procurementUnitId, curUser), HttpStatus.OK); + } catch (EmptyResultDataAccessException er) { + logger.error("Error while trying to list ProcurementUnit", er); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (Exception e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementUnit/realmId/{realmId}") + /** + * API used to get the ProcurementUnit for a specific RealmId. Will only + * return those ProcurementUnits that are marked active + * + * @param realmId RealmId that you want the ProcurementUnit List for + * @param auth + * @return returns the list the ProcurementUnit based on RealmId + * specified. Will only return those ProcurementUnits that are marked active + */ + @GetMapping(value = "realmId/{realmId}") + @Operation(description = "API used to get all the ProcurementUnits for a specific RealmId. Will only return those ProcurementUnits that are marked active", summary = "Get ProcurementUnit for a RealmId", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit") public ResponseEntity getProcurementUnitForRealm(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -103,13 +140,31 @@ public ResponseEntity getProcurementUnitForRealm(@PathVariable(value = "realmId" } catch (AccessDeniedException e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); + } catch (EmptyResultDataAccessException e) { + logger.error("Error while trying to list ProcurementUnit", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (Exception e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementUnit/realmId/{realmId}/all") + /** + * API used to get the ProcurementUnit for a specific RealmId + * + * @param realmId RealmId that you want the ProcurementUnit List for + * @param auth + * @return returns the list the ProcurementUnit list based on RealmId + * specified. + */ + @GetMapping(value = "/realmId/{realmId}/all") + @Operation(description = "API used to get all the ProcurementUnits for a specific RealmId.", summary = "Get ProcurementUnit for a RealmId", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit") public ResponseEntity getProcurementUnitForRealmAll(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -117,13 +172,34 @@ public ResponseEntity getProcurementUnitForRealmAll(@PathVariable(value = "realm } catch (AccessDeniedException e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.FORBIDDEN); + } catch (EmptyResultDataAccessException e) { + logger.error("Error while trying to list ProcurementUnit", e); + return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); } catch (Exception e) { logger.error("Error while trying to list ProcurementUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/procurementUnit/planningUnitId/{planningUnitId}") + /** + * API used to get the ProcurementUnit for a specific PlanningUnitId. Will + * only return those ProcurementUnits that are marked active + * + * @param realmId PlanningUnitId that you want the ProcurementUnit List + * for + * @param auth + * @return returns the list the ProcurementUnit list based on + * PlanningUnitId specified. Will only return those ProcurementUnits that + * are marked active + */ + @GetMapping("/planningUnitId/{planningUnitId}") + @Operation(description = "API used to get all the ProcurementUnits for a specific PlanningUnitId. Will only return those ProcurementUnits that are marked active", summary = "Get ProcurementUnit for a PlanningUnitId", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "realmId", description = "PlanningUnitId that you want to the ProcurementUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit") public ResponseEntity getProcurementUnitForPlanningUnit(@PathVariable(value = "planningUnitId", required = true) int planningUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -137,7 +213,23 @@ public ResponseEntity getProcurementUnitForPlanningUnit(@PathVariable(value = "p } } - @GetMapping("/procurementUnit/planningUnitId/{planningUnitId}/all") + /** + * API used to get the ProcurementUnits for a specific PlanningUnitId. + * + * @param realmId PlanningUnitId that you want the ProcurementUnit list + * for + * @param auth + * @return returns the list the ProcurementUnit list based on + * PlanningUnitId specified. + */ + @GetMapping("/planningUnitId/{planningUnitId}/all") + @Operation(description = "API used to get all the ProcurementUnits for a specific PlanningUnitId.", summary = "Get ProcurementUnit for a PlanningUnitId", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "realmId", description = "PlanningUnitId that you want to the ProcurementUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementUnit") public ResponseEntity getProcurementUnitForPlanningUnitAll(@PathVariable(value = "planningUnitId", required = true) int planningUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -151,34 +243,59 @@ public ResponseEntity getProcurementUnitForPlanningUnitAll(@PathVariable(value = } } - @GetMapping("/procurementUnit/{procurementUnitId}") - public ResponseEntity getProcurementUnitById(@PathVariable("procurementUnitId") int procurementUnitId, Authentication auth) { + /** + * API used to add a ProcurementUnit + * + * @param procurementUnit ProcurementUnit object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a ProcurementUnit", summary = "Add ProcurementUnit", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "procurementUnit", description = "The ProcurementUnit object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addProcurementUnit(@RequestBody ProcurementUnit procurementUnit, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementUnitService.getProcurementUnitById(procurementUnitId, curUser), HttpStatus.OK); - } catch (EmptyResultDataAccessException er) { - logger.error("Error while trying to list ProcurementUnit", er); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); + this.procurementUnitService.addProcurementUnit(procurementUnit, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add ProcurementUnit", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while trying to list ProcurementUnit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add ProcurementUnit", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping(value = "/sync/procurementUnit/{lastSyncDate}") - public ResponseEntity getProcurementUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to update a ProcurementUnit + * + * @param procurementUnit ProcurementUnit object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a ProcurementUnit", summary = "Update ProcurementUnit", tags = ("procurementUnit")) + @Parameters( + @Parameter(name = "procurementUnit", description = "The ProcurementUnit object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateProcurementUnit(@RequestBody ProcurementUnit procurementUnit, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.procurementUnitService.getProcurementUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing procurementUnit", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.procurementUnitService.updateProcurementUnit(procurementUnit, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to update ProcurementUnit", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while listing procurementUnit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to update ProcurementUnit", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProductCategoryRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProductCategoryRestController.java index 81ede2f89..d1cfed738 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProductCategoryRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProductCategoryRestController.java @@ -12,9 +12,12 @@ import cc.altius.FASP.service.ProductCategoryService; import cc.altius.FASP.service.UserService; import cc.altius.utils.TreeUtils.Node; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.io.Serializable; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +38,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/productCategory") public class ProductCategoryRestController extends BaseModel implements Serializable { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -45,22 +48,20 @@ public class ProductCategoryRestController extends BaseModel implements Serializ @Autowired private UserService userService; - @PutMapping(path = "/productCategory") - public ResponseEntity putProductCategory(@RequestBody Node[] productCategories, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.productCategoryService.saveProductCategoryList(productCategories, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException e) { - logger.error("Error while trying to update Product Category", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to update Product Category", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/productCategory/realmId/{realmId}") + /** + * API used to get the ProductCategory list for a Realm + * + * @param realmId RealmId that you want the ProductCategory List from + * @param auth + * @return returns the complete list of productCategories + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete ProductCategory list for a Realm", summary = "Get ProductCategory list for Realm", tags = ("productCategory")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the ProductCategory list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProductCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProductCategory list") public ResponseEntity getProductCategory(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -74,7 +75,29 @@ public ResponseEntity getProductCategory(@PathVariable(value = "realmId", requir } } - @GetMapping("/productCategory/realmId/{realmId}/list/{productCategoryId}/{includeCurrentLevel}/{includeAllChildren}") + /** + * API used to get the ProductCategory list for a Realm + * + * @param realmId RealmId that you want the ProductCategory List from + * @param productCategoryId ProductCategoryId that you want the Tree for + * @param includeCurrentLevel true indicates that you want to include the + * current node of the tree in the output, false will skip the current level + * and give all the child nodes + * @param includeAllChildren true will include all the child nodes in the + * tree in the response, false will only include the immediate child nodes + * @param auth + * @return returns the complete list of productCategories + */ + @GetMapping("/realmId/{realmId}/list/{productCategoryId}/{includeCurrentLevel}/{includeAllChildren}") + @Operation(description = "API used to get the complete ProductCategory list for a Realm", summary = "Get ProductCategory list for Realm", tags = ("productCategory")) + @Parameters( + { + @Parameter(name = "realmId", description = "RealmId that you want the ProductCategory list for"), + @Parameter(name = "productCategoryId", description = "ProductCategoryId that you want the Tree for"), + @Parameter(name = "includeCurrentLevel", description = "true indicates that you want to include the current node of the tree in the output, false will skip the current level and give all the child nodes"), + @Parameter(name = "includeAllChildren", description = "true will include all the child nodes in the tree in the response, false will only include the immediate child nodes")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProductCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProductCategory list") public ResponseEntity getProductCategoryByRealmId(@PathVariable(value = "realmId", required = true) int realmId, @PathVariable(value = "productCategoryId", required = true) int productCategoryId, @PathVariable(value = "includeCurrentLevel", required = false) Optional includeCurrentLevel, @PathVariable("includeAllChildren") Optional includeAllChildren, Authentication auth) { boolean bolIncludeCurrentLevel = true; boolean bolIncludeAllChildren = false; @@ -93,30 +116,58 @@ public ResponseEntity getProductCategoryByRealmId(@PathVariable(value = "realmId } } - @GetMapping(value = "/sync/productCategory/{lastSyncDate}") - public ResponseEntity getProductCategoryListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to get the ProductCategory list for a Realm and Program + * + * @param realmId RealmId that you want the ProductCategory List from + * @param programId ProgramId that you want the ProductCategory List from + * @param auth + * @return returns the complete list of productCategories + */ + @GetMapping("/realmId/{realmId}/programId/{programId}") + @Operation(description = "API used to get the complete ProductCategory list for a Realm and Program", summary = "Get ProductCategory list for Realm and Program", tags = ("productCategory")) + @Parameters( + { + @Parameter(name = "realmId", description = "RealmId that you want the ProductCategory list for"), + @Parameter(name = "programId", description = "ProgramId that you want the ProductCategory list for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProductCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProductCategory list") + public ResponseEntity getProductCategoryForProgram(@PathVariable(value = "realmId", required = true) int realmId, @PathVariable(value = "programId", required = true) int programId, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.productCategoryService.getProductCategoryListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing productCategory", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + return new ResponseEntity(this.productCategoryService.getProductCategoryListForProgram(curUser, realmId, programId), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while listing productCategory", e); + logger.error("Error while trying to list Product Category", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping("/productCategory/realmId/{realmId}/programId/{programId}") - public ResponseEntity getProductCategoryForProgram(@PathVariable(value = "realmId", required = true) int realmId, @PathVariable(value = "programId", required = true) int programId, Authentication auth) { + /** + * API used to update the ProductCategory tree + * + * @param productCategories Array of the ProductCategories that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update the ProductCategory tree", summary = "Update ProductCategory tree", tags = ("productCategory")) + @Parameters( + @Parameter(name = "productCategories", description = "The Array of ProductCategories that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateProductCategory(@RequestBody Node[] productCategories, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.productCategoryService.getProductCategoryListForProgram(curUser, realmId, programId), HttpStatus.OK); + this.productCategoryService.saveProductCategoryList(productCategories, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException e) { + logger.error("Error while trying to update Product Category", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while trying to list Product Category", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to update Product Category", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java b/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java index 7c136fbbc..b28d54eec 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.RealmService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/realm") public class RealmRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,40 +47,16 @@ public class RealmRestController { @Autowired private UserService userService; - @PostMapping(path = "/realm") - public ResponseEntity postRealm(@RequestBody Realm realm, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.realmService.addRealm(realm, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to add Realm", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Realm", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/realm") - public ResponseEntity putRealm(@RequestBody Realm realm, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.realmService.updateRealm(realm, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Realm", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to add Realm", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Realm", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/realm") + /** + * API used to get the complete Realm list. + * + * @param auth + * @return returns the complete list of Realms + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Realm list.", summary = "Get Realm list", tags = ("realm")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Realm list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Realm list") public ResponseEntity getRealm(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -88,8 +67,25 @@ public ResponseEntity getRealm(Authentication auth) { } } - @GetMapping("/realm/{realmId}") - public ResponseEntity getRealm(@PathVariable("realmId") int realmId, Authentication auth) { + /** + * API used to get the Realm for a specific RealmId + * + * @param realmId RealmId that you want the Realm + * Object for + * @param auth + * @return returns the Realm object based on + * RealmId specified + */ + @GetMapping(value = "/{realmId}") + @Operation(description = "API used to get the Realm for a specific RealmId", summary = "Get Realm for a RealmId", tags = ("realm")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want to the Realm for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Realm") + + public ResponseEntity getRealmById(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.realmService.getRealmById(realmId, curUser), HttpStatus.OK); @@ -105,19 +101,64 @@ public ResponseEntity getRealm(@PathVariable("realmId") int realmId, Authenticat } } - @GetMapping(value = "/sync/realm/{lastSyncDate}") - public ResponseEntity getRealmListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to add a Realm + * + * @param realm Realm object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Realm", summary = "Add Realm", tags = ("realm")) + @Parameters( + @Parameter(name = "realm", description = "The Realm object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addRealm(@RequestBody Realm realm, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.realmService.getRealmListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing realm", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.realmService.addRealm(realm, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to add Realm", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing realm", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Realm", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to update a Realm + * + * @param realm Realm object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Realm", summary = "Update Realm", tags = ("realm")) + @Parameters( + @Parameter(name = "realm", description = "The Realm object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateRealm(@RequestBody Realm realm, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.realmService.updateRealm(realm, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Realm", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to add Realm", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add Realm", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java b/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java index b56fabe57..b47d73226 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.RegionService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/region") public class RegionRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,42 +47,17 @@ public class RegionRestController { @Autowired private UserService userService; -// @PostMapping(value = "/region") -// public ResponseEntity addRegion(@RequestBody Region region, Authentication auth) { -// try { -// CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); -// this.regionService.addRegion(region, curUser); -// return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); -// } catch (AccessDeniedException e) { -// logger.error("Error while trying to add Region", e); -// return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); -// } catch (DuplicateKeyException e) { -// logger.error("Error while trying to add Region", e); -// return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); -// } catch (Exception e) { -// logger.error("Error while trying to add Region", e); -// return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); -// } -// } - @PutMapping(path = "/region") - public ResponseEntity putRegion(@RequestBody Region[] regions, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.regionService.saveRegions(regions, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException e) { - logger.error("Error while trying to update Region", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (DuplicateKeyException e) { - logger.error("Error while trying to update Region", e); - return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to update Region", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/region") + /** + * API used to get the complete Region list. + * + * @param auth + * @return returns the complete list of Regions + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Region list.", summary = "Get Region list", tags = ("region")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Region list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Region list") public ResponseEntity getRegion(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -93,8 +71,24 @@ public ResponseEntity getRegion(Authentication auth) { } } - @GetMapping("/region/{regionId}") - public ResponseEntity getRegion(@PathVariable("regionId") int regionId, Authentication auth) { + /** + * API used to get the Region for a specific RegionId + * + * @param regionId RegionId that you want the Region + * Object for + * @param auth + * @return returns the Region object based on + * RegionId specified + */ + @GetMapping(value = "/{regionId}") + @Operation(description = "API used to get the Region for a specific RegionId", summary = "Get Region for a RegionId", tags = ("region")) + @Parameters( + @Parameter(name = "regionId", description = "RegionId that you want to the Region for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Region") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RegionId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Region") + public ResponseEntity getRegionById(@PathVariable("regionId") int regionId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.regionService.getRegionById(regionId, curUser), HttpStatus.OK); @@ -110,7 +104,21 @@ public ResponseEntity getRegion(@PathVariable("regionId") int regionId, Authenti } } - @GetMapping("/region/realmCountryId/{realmCountryId}") + /** + * API used to get the Region list for a RealmCountry + * + * @param realmCountryId RealmCountryId that you want the Region List from + * @param auth + * @return returns the complete list of Regions + */ + @GetMapping("/realmCountryId/{realmCountryId}") + @Operation(description = "API used to get the complete Region list for a RealmCountry", summary = "Get Region list for a RealmCountry", tags = ("region")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want the Region list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Region list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Region list") public ResponseEntity getRegionByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -127,19 +135,35 @@ public ResponseEntity getRegionByRealmCountry(@PathVariable("realmCountryId") in } } - @GetMapping(value = "/sync/region/{lastSyncDate}") - public ResponseEntity getRegionListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to update Regions + * + * @param regions Array of Regions that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Region", summary = "Update Region", tags = ("region")) + @Parameters( + @Parameter(name = "regions", description = "The array of Regions that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity putRegion(@RequestBody Region[] regions, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.regionService.getRegionListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing region", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.regionService.saveRegions(regions, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException e) { + logger.error("Error while trying to update Region", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (DuplicateKeyException e) { + logger.error("Error while trying to update Region", e); + return new ResponseEntity(new ResponseCode("static.message.alreadExists"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing region", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to update Region", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java index 7a27f9143..ce673ce58 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java @@ -37,22 +37,6 @@ public class ShipmentStatusRestController { @Autowired private UserService userService; - @GetMapping(value = "/sync/shipmentStatus/{lastSyncDate}") - public ResponseEntity getShipmentStatusListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.shipmentStatusService.getShipmentStatusListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing Shipment status", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing Shipment status", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - @GetMapping(value = "/getShipmentStatusListActive") public ResponseEntity getShipmentStatusListActive(Authentication auth) { try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java index bcd1d0d59..27a6b9348 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java @@ -25,8 +25,11 @@ import org.springframework.web.bind.annotation.RestController; import cc.altius.FASP.service.SupplierService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; /** * @@ -43,37 +46,16 @@ public class SupplierRestController { @Autowired private UserService userService; - @PostMapping(path = "/supplier") - public ResponseEntity postSupplier(@RequestBody Supplier supplier, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.supplierService.addSupplier(supplier, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Supplier", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add Supplier", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/supplier") - public ResponseEntity putSupplier(@RequestBody Supplier supplier, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.supplierService.updateSupplier(supplier, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add Supplier", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add Supplier", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/supplier") + /** + * API used to get the complete Supplier list. + * + * @param auth + * @return returns the complete list of Suppliers + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Supplier list.", summary = "Get Supplier list", tags = ("supplier")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Supplier list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Supplier list") public ResponseEntity getSupplier(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -84,7 +66,23 @@ public ResponseEntity getSupplier(Authentication auth) { } } - @GetMapping("/supplier/{supplierId}") + /** + * API used to get the Supplier for a specific SupplierId + * + * @param supplierId SupplierId that you want the Supplier + * Object for + * @param auth + * @return returns the Supplier object based on + * SupplierId specified + */ + @GetMapping(value = "/{supplierId}") + @Operation(description = "API used to get the Supplier for a specific SupplierId", summary = "Get Supplier for a SupplierId", tags = ("supplier")) + @Parameters( + @Parameter(name = "supplierId", description = "SupplierId that you want to the Supplier for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Supplier") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the SupplierId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Supplier") public ResponseEntity getSupplier(@PathVariable("supplierId") int supplierId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -101,7 +99,21 @@ public ResponseEntity getSupplier(@PathVariable("supplierId") int supplierId, Au } } - @GetMapping("/supplier/realmId/{realmId}") + /** + * API used to get the Supplier list for a Realm + * + * @param realmId RealmId that you want the Supplier List from + * @param auth + * @return returns the complete list of Suppliers + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete Supplier list for a Realm", summary = "Get Supplier list for Realm", tags = ("supplier")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the Supplier list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Supplier list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Supplier list") public ResponseEntity getSupplierForRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -118,19 +130,60 @@ public ResponseEntity getSupplierForRealm(@PathVariable("realmId") int realmId, } } - @GetMapping(value = "/sync/supplier/{lastSyncDate}") - public ResponseEntity getSupplierListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to add a Supplier + * + * @param supplier Supplier object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Supplier", summary = "Add Supplier", tags = ("supplier")) + @Parameters( + @Parameter(name = "supplier", description = "The Supplier object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addSupplier(@RequestBody Supplier supplier, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.supplierService.getSupplierListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing supplier", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.supplierService.addSupplier(supplier, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Supplier", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while listing supplier", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Supplier", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * API used to update Suppliers + * + * @param supplier Object of Supplier that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Supplier", summary = "Update Supplier", tags = ("supplier")) + @Parameters( + @Parameter(name = "supplier", description = "The Supplier object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateSupplier(@RequestBody Supplier supplier, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.supplierService.updateSupplier(supplier, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add Supplier", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (Exception e) { + logger.error("Error while trying to add Supplier", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java index 2b64ab852..ea2b60458 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java @@ -1,4 +1,4 @@ -/* + /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. diff --git a/src/main/java/cc/altius/FASP/rest/controller/TracerCategoryRestController.java b/src/main/java/cc/altius/FASP/rest/controller/TracerCategoryRestController.java index 1aa632a66..b0fd2a132 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/TracerCategoryRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/TracerCategoryRestController.java @@ -25,16 +25,18 @@ import org.springframework.web.bind.annotation.RestController; import cc.altius.FASP.service.TracerCategoryService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.List; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; /** * * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/tracerCategory") public class TracerCategoryRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,37 +46,16 @@ public class TracerCategoryRestController { @Autowired private UserService userService; - @PostMapping(path = "/tracerCategory") - public ResponseEntity postTracerCategory(@RequestBody TracerCategory tracerCategory, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.tracerCategoryService.addTracerCategory(tracerCategory, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add TracerCategory", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add TracerCategory", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/tracerCategory") - public ResponseEntity putTracerCategory(@RequestBody TracerCategory tracerCategory, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.tracerCategoryService.updateTracerCategory(tracerCategory, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (AccessDeniedException ae) { - logger.error("Error while trying to add TracerCategory", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); - } catch (Exception e) { - logger.error("Error while trying to add TracerCategory", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/tracerCategory") + /** + * API used to get the complete TracerCategory list. + * + * @param auth + * @return returns the complete list of tracerCategories + */ + @GetMapping("/") + @Operation(description = "API used to get the complete TracerCategory list.", summary = "Get TracerCategory list", tags = ("tracerCategory")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the TracerCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of TracerCategory list") public ResponseEntity getTracerCategory(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -85,7 +66,22 @@ public ResponseEntity getTracerCategory(Authentication auth) { } } - @GetMapping("/tracerCategory/{tracerCategoryId}") + /** + * API used to get the TracerCategory for a specific TracerCategoryId + * + * @param tracerCategoryId TracerCategoryId that you want the TracerCategory Object for + * @param auth + * @return returns the TracerCategory object based on TracerCategoryId specified + */ + @GetMapping(value = "/{tracerCategoryId}") + @Operation(description = "API used to get the TracerCategory for a specific TracerCategoryId", summary = "Get TracerCategory for a TracerCategoryId", tags = ("tracerCategory")) + @Parameters( + @Parameter(name = "tracerCategoryId", description = "TracerCategoryId that you want to the TracerCategory for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the TracerCategory") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the TracerCategoryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of TracerCategory") + public ResponseEntity getTracerCategory(@PathVariable("tracerCategoryId") int tracerCategoryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -101,8 +97,22 @@ public ResponseEntity getTracerCategory(@PathVariable("tracerCategoryId") int tr return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/tracerCategory/realmId/{realmId}") + + /** + * API used to get the TracerCategory list for a Realm + * + * @param realmId RealmId that you want the TracerCategory List from + * @param auth + * @return returns the complete list of tracerCategories + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the complete TracerCategory list for a Realm", summary = "Get TracerCategory list for Realm", tags = ("tracerCategory")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the TracerCategory list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the TracerCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of TracerCategory list") public ResponseEntity getTracerCategoryForRealm(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -118,9 +128,25 @@ public ResponseEntity getTracerCategoryForRealm(@PathVariable("realmId") int rea return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - - @GetMapping("/tracerCategory/realmId/{realmId}/programId/{programId}") + + /** + * API used to get the TracerCategory list for a Realm and Program + * + * @param realmId RealmId that you want the TracerCategory List from + * @param programId ProgramId that you want the TracerCategory List from + * @param auth + * @return returns the complete list of tracerCategories + */ + @GetMapping("/realmId/{realmId}/programId/{programId}") + @Operation(description = "API used to get the complete TracerCategory list for a Realm and Program", summary = "Get TracerCategory list for Realm and Program", tags = ("tracerCategory")) + @Parameters( + { + @Parameter(name = "realmId", description = "RealmId that you want the TracerCategory list for"), + @Parameter(name = "programId", description = "ProgramId that you want the TracerCategory list for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the TracerCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of TracerCategory list") public ResponseEntity getTracerCategoryForRealmProgram(@PathVariable("realmId") int realmId, @PathVariable("programId") int programId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -136,8 +162,23 @@ public ResponseEntity getTracerCategoryForRealmProgram(@PathVariable("realmId") return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to get the TracerCategory list for a Realm. Only returns those Tracer Categories that are from Planning Units in active Programs + * + * @param realmId RealmId that you want the TracerCategory List from + * @param auth + * @return returns the complete list of tracerCategories + */ + @PostMapping("/realmId/{realmId}/programIds") + @Operation(description = "API used to get the TracerCategory list for a Realm. Only returns those Tracer Categories that are from Planning Units in active Programs", summary = "Get TracerCategory list for Realm and active ProgramPlanningUnits", tags = ("tracerCategory")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the TracerCategory list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the TracerCategory list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of TracerCategory list") - @PostMapping("/tracerCategory/realmId/{realmId}/programIds") public ResponseEntity getTracerCategoryForRealmPrograms(@PathVariable("realmId") int realmId, @RequestBody String[] programIds, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -154,19 +195,60 @@ public ResponseEntity getTracerCategoryForRealmPrograms(@PathVariable("realmId") } } - @GetMapping(value = "/sync/tracerCategory/{lastSyncDate}") - public ResponseEntity getTracerCategoryListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { + /** + * API used to add a TracerCategory + * + * @param tracerCategory TracerCategory object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a TracerCategory", summary = "Add TracerCategory", tags = ("tracerCategory")) + @Parameters( + @Parameter(name = "tracerCategory", description = "The TracerCategory object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addTracerCategory(@RequestBody TracerCategory tracerCategory, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.tracerCategoryService.getTracerCategoryListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing tracerCategory", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + this.tracerCategoryService.addTracerCategory(tracerCategory, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add TracerCategory", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - logger.error("Error while listing tracerCategory", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add TracerCategory", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to update a TracerCategory + * + * @param tracerCategory TracerCategory object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a TracerCategory", summary = "Update TracerCategory", tags = ("tracerCategory")) + @Parameters( + @Parameter(name = "tracerCategory", description = "The TracerCategory object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateTracerCategory(@RequestBody TracerCategory tracerCategory, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.tracerCategoryService.updateTracerCategory(tracerCategory, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (AccessDeniedException ae) { + logger.error("Error while trying to add TracerCategory", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); + } catch (Exception e) { + logger.error("Error while trying to add TracerCategory", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/UnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/UnitRestController.java index f98554154..510b8e8ac 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/UnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/UnitRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.Unit; import cc.altius.FASP.service.UnitService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +36,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/unit") public class UnitRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,37 +46,16 @@ public class UnitRestController { @Autowired private UserService userService; - @PostMapping(path = "/unit") - public ResponseEntity postUnit(@RequestBody Unit unit, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.unitService.addUnit(unit, curUser); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to add Unit", ae); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Unit", e); - return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @PutMapping(path = "/unit") - public ResponseEntity putUnit(@RequestBody Unit unit, Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - this.unitService.updateUnit(unit, curUser); - return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); - } catch (DuplicateKeyException ae) { - logger.error("Error while trying to update Unit ", ae); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_ACCEPTABLE); - } catch (Exception e) { - logger.error("Error while trying to add Unit", e); - return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/unit") + /** + * API used to get the complete Unit list. + * + * @param auth + * @return returns the complete list of Units + */ + @GetMapping("/") + @Operation(description = "API used to get the complete Unit list.", summary = "Get Unit list", tags = ("unit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Unit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Unit list") public ResponseEntity getUnit(Authentication auth) { try { return new ResponseEntity(this.unitService.getUnitList(), HttpStatus.OK); @@ -83,7 +65,22 @@ public ResponseEntity getUnit(Authentication auth) { } } - @GetMapping("/unit/{unitId}") + /** + * API used to get the Unit for a specific UnitId + * + * @param unitId UnitId that you want the Unit + * Object for + * @param auth + * @return returns the Unit object based on + * UnitId specified + */ + @GetMapping(value = "/{unitId}") + @Operation(description = "API used to get the Unit for a specific UnitId", summary = "Get Unit for a UnitId", tags = ("unit")) + @Parameters( + @Parameter(name = "unitId", description = "UnitId that you want to the Unit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Unit") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the UnitId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Unit") public ResponseEntity getUnit(@PathVariable("unitId") int unitId, Authentication auth) { try { return new ResponseEntity(this.unitService.getUnitById(unitId), HttpStatus.OK); @@ -95,19 +92,60 @@ public ResponseEntity getUnit(@PathVariable("unitId") int unitId, Authentication return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * API used to add a Unit + * + * @param unit Unit object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Unit", summary = "Add Unit", tags = ("unit")) + @Parameters( + @Parameter(name = "unit", description = "The Unit object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity addUnit(@RequestBody Unit unit, Authentication auth) { + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.unitService.addUnit(unit, curUser); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to add Unit", ae); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.NOT_ACCEPTABLE); + } catch (Exception e) { + logger.error("Error while trying to add Unit", e); + return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } - @GetMapping(value = "/sync/unit/{lastSyncDate}") - public ResponseEntity getUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate) { + /** + * API used to update a Unit + * + * @param unit Unit object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Unit", summary = "Update Unit", tags = ("unit")) + @Parameters( + @Parameter(name = "unit", description = "The Unit object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateUnit(@RequestBody Unit unit, Authentication auth) { try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - return new ResponseEntity(this.unitService.getUnitListForSync(lastSyncDate), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing unit", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + this.unitService.updateUnit(unit, curUser); + return new ResponseEntity(new ResponseCode("static.message.updateSuccess"), HttpStatus.OK); + } catch (DuplicateKeyException ae) { + logger.error("Error while trying to update Unit ", ae); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.NOT_ACCEPTABLE); } catch (Exception e) { - logger.error("Error while listing unit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); + logger.error("Error while trying to add Unit", e); + return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/cc/altius/FASP/web/controller/LabelController.java b/src/main/java/cc/altius/FASP/web/controller/LabelController.java index 0c4a793b4..0e0b89dfa 100755 --- a/src/main/java/cc/altius/FASP/web/controller/LabelController.java +++ b/src/main/java/cc/altius/FASP/web/controller/LabelController.java @@ -15,7 +15,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; -import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -32,7 +32,7 @@ public class LabelController { @Autowired private LabelService labelService; - @RequestMapping(value = "/getDatabaseLabelsListAll") + @GetMapping(value = "/getDatabaseLabelsListAll") public ResponseEntity getDatabaseLabelsList(Authentication auth) { try { CustomUserDetails curUser = (CustomUserDetails) auth.getPrincipal(); @@ -43,7 +43,7 @@ public ResponseEntity getDatabaseLabelsList(Authentication auth) { } } - @RequestMapping(value = "/getStaticLabelsListAll") + @GetMapping(value = "/getStaticLabelsListAll") public ResponseEntity getStaticLabelsList() { try { return new ResponseEntity(this.labelService.getStaticLabelsList(), HttpStatus.OK); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 823a41fc7..fa9c03f01 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -96,3 +96,5 @@ server.compression.min-response-size=4096 # Mime types that should be compressed server.compression.mime-types=text/html, text/xml, text/plain, text/css, text/javascript, application/javascript, application/json +# Packages to include +springdoc.packagesToScan=cc.altius.FASP.rest.controller \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 9e9012bea..372acbe84 100755 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -81,16 +81,19 @@ + + + @@ -99,12 +102,14 @@ + + \ No newline at end of file From 83a9774983e53bd8fc5f9c228db3ed17ca2e7476 Mon Sep 17 00:00:00 2001 From: Akil Mahimwala Date: Mon, 15 Feb 2021 13:05:52 +0530 Subject: [PATCH 2/9] Made changes in the files --- .../controller/DashboardRestController.java | 10 +- .../FASP/rest/controller/FileController.java | 2 +- .../controller/JiraAccountSyncController.java | 35 ------- .../JiraServiceDeskApiController.java | 43 ++++---- .../controller/LanguageRestController.java | 99 +++++++++++++------ .../rest/controller/LocaleRestController.java | 35 +++++++ .../controller/PipelineDbRestController.java | 31 +++--- .../QuantimedImportRestController.java | 18 +--- .../controller/ReportRestController.java} | 6 +- .../controller/SupplyPlanRestController.java | 1 - .../rest/controller/SyncRestController.java | 6 +- 11 files changed, 156 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/cc/altius/FASP/rest/controller/JiraAccountSyncController.java create mode 100644 src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java rename src/main/java/cc/altius/FASP/{web/controller/ReportController.java => rest/controller/ReportRestController.java} (99%) diff --git a/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java b/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java index 40580fc61..c49066e85 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java @@ -25,7 +25,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/dashboard") public class DashboardRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -35,7 +35,7 @@ public class DashboardRestController { private UserService userService; - @GetMapping(value = "/applicationLevelDashboard") + @GetMapping(value = "/application") public ResponseEntity applicationLevelDashboard(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -46,7 +46,7 @@ public ResponseEntity applicationLevelDashboard(Authentication auth) { } } - @GetMapping(value = "/realmLevelDashboard/{realmId}") + @GetMapping(value = "/realmId/{realmId}") public ResponseEntity realmLevelDashboard(@PathVariable("realmId") int realmId,Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -57,7 +57,7 @@ public ResponseEntity realmLevelDashboard(@PathVariable("realmId") int realmId,A } } - @GetMapping(value = "/applicationLevelDashboardUserList") + @GetMapping(value = "/application/user") public ResponseEntity applicationLevelDashboardUserList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -68,7 +68,7 @@ public ResponseEntity applicationLevelDashboardUserList(Authentication auth) { } } - @GetMapping(value = "/realmLevelDashboardUserList/{realmId}") + @GetMapping(value = "/realmId/{realmId}/user") public ResponseEntity realmLevelDashboardUserList(@PathVariable("realmId") int realmId,Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); diff --git a/src/main/java/cc/altius/FASP/rest/controller/FileController.java b/src/main/java/cc/altius/FASP/rest/controller/FileController.java index d773e9dc5..b6167fd2a 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/FileController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/FileController.java @@ -56,7 +56,7 @@ public class FileController { * @throws IOException if there was an error in reading the file from the * server */ - @Operation(description = "Returns the byte stream of the file that was requested", summary = "Get file from Server", tags = ("File")) + @Operation(description = "Returns the byte stream of the file that was requested", summary = "Get file from Server", tags = ("file")) @Parameters(@Parameter(name = "fileName", description = "Name of file that the user wants to get from the Server")) @ApiResponse(content = @Content(mediaType = "application/octet-stream"), responseCode = "200", description = "Returns the byte array of the file that was requested") @GetMapping("/file/{fileName}") diff --git a/src/main/java/cc/altius/FASP/rest/controller/JiraAccountSyncController.java b/src/main/java/cc/altius/FASP/rest/controller/JiraAccountSyncController.java deleted file mode 100644 index e38f02f47..000000000 --- a/src/main/java/cc/altius/FASP/rest/controller/JiraAccountSyncController.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package cc.altius.FASP.rest.controller; - -import cc.altius.FASP.service.JiraServiceDeskApiService; -import java.io.FileNotFoundException; -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.Authentication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -/** - * - * @author altius - */ -@RestController -public class JiraAccountSyncController { - - @Autowired - private JiraServiceDeskApiService jiraServiceDeskApiService; - - @GetMapping("/jira/syncJiraAccountIds") - public String syncUserJiraAccountId(HttpServletResponse response) throws FileNotFoundException, IOException { - - String result = this.jiraServiceDeskApiService.syncUserJiraAccountId(""); - - return result; - } -} diff --git a/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java b/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java index 564cc8faf..406a721da 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java @@ -9,10 +9,12 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.JiraServiceDeskApiService; import cc.altius.FASP.service.UserService; +import java.io.FileNotFoundException; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; @@ -30,29 +32,32 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/jira") public class JiraServiceDeskApiController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Autowired private JiraServiceDeskApiService jiraServiceDeskApiService; @Autowired private UserService userService; - @PostMapping(value = "/ticket/addIssue") + @GetMapping("/syncJiraAccountIds") + public String syncUserJiraAccountId(HttpServletResponse response) throws FileNotFoundException, IOException { + return this.jiraServiceDeskApiService.syncUserJiraAccountId(""); + } + + @PostMapping(value = "/jira/addIssue") public ResponseEntity addIssue(@RequestBody(required = true) String jsonData, Authentication auth) { - try { + try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); ResponseEntity response; response = this.jiraServiceDeskApiService.addIssue(jsonData, curUser); - if (response.getStatusCode() == HttpStatus.OK || response.getStatusCode() == HttpStatus.CREATED) { + if (response.getStatusCode() == HttpStatus.OK || response.getStatusCode() == HttpStatus.CREATED) { return new ResponseEntity(response.getBody(), HttpStatus.OK); - } else { + } else { return new ResponseEntity(response.getBody(), HttpStatus.INTERNAL_SERVER_ERROR); - } - + } } catch (Exception e) { logger.error("Error while creating issue", e); return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); @@ -60,10 +65,10 @@ public ResponseEntity addIssue(@RequestBody(required = true) String jsonData, Au } - @PostMapping(value = "/ticket/addIssueAttachment/{issueId}") + @PostMapping(value = "/addIssueAttachment/{issueId}") public ResponseEntity addIssueAttachment(@RequestParam("file") MultipartFile file, @PathVariable("issueId") String issueId, Authentication auth) { String message = ""; - try { + try { ResponseEntity response; response = this.jiraServiceDeskApiService.addIssueAttachment(file, issueId); if (response.getStatusCode() == HttpStatus.OK || response.getStatusCode() == HttpStatus.CREATED) { @@ -73,23 +78,21 @@ public ResponseEntity addIssueAttachment(@RequestParam("file") MultipartFile fil message = "Could not upload the file: " + file.getOriginalFilename() + "!"; return new ResponseEntity(new ResponseCode(message), HttpStatus.INTERNAL_SERVER_ERROR); } - - } catch (Exception e) { + } catch (Exception e) { logger.error("Error while upload the file", e); message = "Could not upload the file: " + file.getOriginalFilename() + "!"; return new ResponseEntity(new ResponseCode(message), HttpStatus.INTERNAL_SERVER_ERROR); } - } - - @GetMapping(value = "/ticket/openIssues") + } + + @GetMapping(value = "/openIssues") public ResponseEntity getOpenIssue(Authentication auth) { - try { - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.jiraServiceDeskApiService.getIssuesSummary(curUser), HttpStatus.OK); + try { + CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); + return new ResponseEntity(this.jiraServiceDeskApiService.getIssuesSummary(curUser), HttpStatus.OK); } catch (Exception e) { logger.error("Error while creating issue", e); return new ResponseEntity(new ResponseCode("static.message.addFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } - } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/LanguageRestController.java b/src/main/java/cc/altius/FASP/rest/controller/LanguageRestController.java index b8d756c79..89c680738 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/LanguageRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/LanguageRestController.java @@ -10,8 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.LanguageService; import cc.altius.FASP.service.UserService; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +36,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/language") public class LanguageRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -43,12 +46,16 @@ public class LanguageRestController { @Autowired private UserService userService; - @GetMapping("/locales/{languageCode}") - ResponseEntity getLanguageJson(@PathVariable("languageCode") String languageCode) { - return new ResponseEntity(this.languageService.getLanguageJsonForStaticLabels(languageCode), HttpStatus.OK); - } - - @GetMapping(value = "/language") + /** + * API used to get the list of Languages. Returns only those Languages that are marked as Active + * + * @param auth + * @return returns the list of Languages + */ + @GetMapping("/") + @Operation(description = "API used to get the Language list. Returns only those Languages that are marked as Active", summary = "Get Language list", tags = ("language")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Language list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Language list") public ResponseEntity getLanguageList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -59,7 +66,16 @@ public ResponseEntity getLanguageList(Authentication auth) { } } - @GetMapping(value = "/language/all") + /** + * API used to get the complete Language list. + * + * @param auth + * @return returns the complete list of Languages + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete Language list.", summary = "Get Language list", tags = ("language")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Language list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Language list") public ResponseEntity getLanguageListAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -70,7 +86,20 @@ public ResponseEntity getLanguageListAll(Authentication auth) { } } - @GetMapping(value = "/language/{languageId}") + /** + * API used to get the Language for a specific LanguageId + * + * @param languageId LanguageId that you want the Language Object for + * @param auth + * @return returns the Language object based on LanguageId specified + */ + @GetMapping(value = "/{languageId}") + @Operation(description = "API used to get the Language for a specific LanguageId", summary = "Get Language for a LanguageId", tags = ("language")) + @Parameters( + @Parameter(name = "languageId", description = "LanguageId that you want to the Language for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Language") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the LanguageId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Language") public ResponseEntity getLanguageById(@PathVariable("languageId") int languageId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -84,7 +113,20 @@ public ResponseEntity getLanguageById(@PathVariable("languageId") int languageId } } - @PostMapping(value = "/language") + /** + * API used to add a Language + * + * @param language Language object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(value = "/") + @Operation(description = "API used to add a Language", summary = "Add Language", tags = ("language")) + @Parameters( + @Parameter(name = "language", description = "The Language object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity addLanguage(@RequestBody(required = true) Language language, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -105,8 +147,22 @@ public ResponseEntity addLanguage(@RequestBody(required = true) Language languag } - @PutMapping(value = "/language") - public ResponseEntity editLanguage(@RequestBody(required = true) Language language, Authentication auth) { + /** + * API used to update a Language + * + * @param language Language object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a Language", summary = "Update Language", tags = ("language")) + @Parameters( + @Parameter(name = "language", description = "The Language object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + public ResponseEntity updateLanguage(@RequestBody(required = true) Language language, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); int updatedId = this.languageService.editLanguage(language, curUser); @@ -125,19 +181,4 @@ public ResponseEntity editLanguage(@RequestBody(required = true) Language langua } } - @GetMapping(value = "/sync/language/{lastSyncDate}") - public ResponseEntity getLanguageListForSync(@PathVariable("lastSyncDate") String lastSyncDate) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - return new ResponseEntity(this.languageService.getLanguageListForSync(lastSyncDate), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing language", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing language", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java new file mode 100644 index 000000000..1e41f1782 --- /dev/null +++ b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java @@ -0,0 +1,35 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package cc.altius.FASP.rest.controller; + +import cc.altius.FASP.service.LanguageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author akil + */ +@RestController("/api") +public class LocaleRestController { + + @Autowired + private LanguageService languageService; + + /** + * Api returns the complete file that the system uses for the Translations. Language is based on the Locale provided. + * @param languageCode + * @return + */ + @GetMapping("/locales/{languageCode}") + ResponseEntity getLanguageJson(@PathVariable("languageCode") String languageCode) { + return new ResponseEntity(this.languageService.getLanguageJsonForStaticLabels(languageCode), HttpStatus.OK); + } +} diff --git a/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java b/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java index a6984a5f6..323a28ed3 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java @@ -51,17 +51,17 @@ public class PipelineDbRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @PostMapping(path = "/pipelineJson/{fileName}") - public ResponseEntity postOrganisation(@RequestBody Pipeline pipeline,@PathVariable("fileName") String fileName, Authentication auth) throws IOException { + public ResponseEntity postOrganisation(@RequestBody Pipeline pipeline, @PathVariable("fileName") String fileName, Authentication auth) throws IOException { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { - String msg="static.message.pipeline.programExists"; - int duplicateCheckCount=this.pipelineDbService.savePipelineDbData(pipeline, curUser,fileName); - if(duplicateCheckCount==0){ + String msg = "static.message.pipeline.programExists"; + int duplicateCheckCount = this.pipelineDbService.savePipelineDbData(pipeline, curUser, fileName); + if (duplicateCheckCount == 0) { return new ResponseEntity(new ResponseCode(msg), HttpStatus.PRECONDITION_FAILED); - }else{ - return new ResponseEntity(this.pipelineDbService.savePipelineDbData(pipeline, curUser,fileName), HttpStatus.OK); + } else { + return new ResponseEntity(this.pipelineDbService.savePipelineDbData(pipeline, curUser, fileName), HttpStatus.OK); } - + } catch (Exception e) { logger.error("/api//", e); return new ResponseEntity(new ResponseCode("incorrectformat"), HttpStatus.INTERNAL_SERVER_ERROR); @@ -289,7 +289,7 @@ public ResponseEntity getQatTempPlanningUnitListInventoryCount(Authentication au } } - @PutMapping("/pipeline/datasource/{pipelineId}") + @PutMapping("/pipeline/datasource/{pipelineId}") public ResponseEntity saveDataSourceForProgram(@RequestBody QatTempDataSource[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -314,7 +314,8 @@ public ResponseEntity getQatTempDataSourceList(Authentication auth, @PathVariabl return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } -@PutMapping("/pipeline/fundingsource/{pipelineId}") + + @PutMapping("/pipeline/fundingsource/{pipelineId}") public ResponseEntity saveFundingSourceForProgram(@RequestBody QatTempFundingSource[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -340,7 +341,7 @@ public ResponseEntity getQatTempFundingSourceList(Authentication auth, @PathVari } } -@PutMapping("/pipeline/procurementagent/{pipelineId}") + @PutMapping("/pipeline/procurementagent/{pipelineId}") public ResponseEntity saveProcurementAgentForProgram(@RequestBody QatTempProcurementAgent[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -365,19 +366,17 @@ public ResponseEntity getQatTempProcurementAgentList(Authentication auth, @PathV return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + @PutMapping(path = "/pipeline/realmCountryPlanningUnit/{pipelineId}/{realmCountryId}") - public ResponseEntity createRealmCountryPlanningUnits(@PathVariable("pipelineId") int pipelineId,@PathVariable("realmCountryId") int realmCountryId ,Authentication auth) throws IOException { + public ResponseEntity createRealmCountryPlanningUnits(@PathVariable("pipelineId") int pipelineId, @PathVariable("realmCountryId") int realmCountryId, Authentication auth) throws IOException { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { - this.pipelineDbService.createRealmCountryPlanningUnits(pipelineId, curUser,realmCountryId); - return new ResponseEntity(new ResponseCode("static.message.addSuccess"),HttpStatus.OK); + this.pipelineDbService.createRealmCountryPlanningUnits(pipelineId, curUser, realmCountryId); + return new ResponseEntity(new ResponseCode("static.message.addSuccess"), HttpStatus.OK); } catch (Exception e) { logger.error("/api//", e); return new ResponseEntity(new ResponseCode(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); } } - - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/QuantimedImportRestController.java b/src/main/java/cc/altius/FASP/rest/controller/QuantimedImportRestController.java index e794047cd..6dd49d31c 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/QuantimedImportRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/QuantimedImportRestController.java @@ -38,7 +38,7 @@ public class QuantimedImportRestController { @Autowired private UserService userService; - @PostMapping(value = "/quantimed/quantimedImport/{programId}") + @PostMapping(value = "/quantimed/import/{programId}") public ResponseEntity quantimedImport(@RequestParam("file") MultipartFile file, @PathVariable("programId") String programId, Authentication auth) { String message = ""; try { @@ -51,20 +51,4 @@ public ResponseEntity quantimedImport(@RequestParam("file") MultipartFile file, return new ResponseEntity(new ResponseCode(message), HttpStatus.INTERNAL_SERVER_ERROR); } } - -// @PostMapping(value = "/quantimed/addQuantimedImport") -// public ResponseEntity addQuantimedImport(@RequestBody QuantimedImportDTO importDTO, Authentication auth) { -// String message = ""; -// try { -// ResponseEntity response; -// -// System.out.println("ProgramId : ================== "+importDTO); -// -// return new ResponseEntity("", HttpStatus.OK); -// } catch (Exception e) { -// logger.error("Error while upload the file", e); -// message = ""; -// return new ResponseEntity(new ResponseCode(message), HttpStatus.INTERNAL_SERVER_ERROR); -// } -// } } diff --git a/src/main/java/cc/altius/FASP/web/controller/ReportController.java b/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java similarity index 99% rename from src/main/java/cc/altius/FASP/web/controller/ReportController.java rename to src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java index 4c3c8a033..14455d8f3 100644 --- a/src/main/java/cc/altius/FASP/web/controller/ReportController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package cc.altius.FASP.web.controller; +package cc.altius.FASP.rest.controller; import cc.altius.FASP.model.CustomUserDetails; import cc.altius.FASP.model.report.GlobalConsumptionInput; @@ -52,14 +52,14 @@ */ @RestController @RequestMapping("/api/report/") -public class ReportController { +public class ReportRestController { @Autowired private ReportService reportService; @Autowired private UserService userService; - private final Logger logger = LoggerFactory.getLogger(ReportController.class); + private final Logger logger = LoggerFactory.getLogger(ReportRestController.class); // Report no 1 // Reports -> Program Catalog diff --git a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java index de861c803..ec8d065cf 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java @@ -17,7 +17,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -import java.util.logging.Level; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java index ea2b60458..284275bfb 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java @@ -54,7 +54,7 @@ * @author akil */ @Controller -@RequestMapping("/api") +@RequestMapping("/api/sync") public class SyncRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -110,7 +110,7 @@ public class SyncRestController { @Autowired private UserService userService; - @GetMapping(value = "/sync/allMasters/{lastSyncDate}") + @GetMapping(value = "/allMasters/{lastSyncDate}") public ResponseEntity getAllMastersForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth, HttpServletResponse response) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -171,7 +171,7 @@ private String getProgramIds(String[] programIds) { } } - @PostMapping(value = "/sync/allMasters/forPrograms/{lastSyncDate}") + @PostMapping(value = "/allMasters/forPrograms/{lastSyncDate}") public ResponseEntity getAllMastersForSyncWithProgramIds(@RequestBody String[] programIds, @PathVariable("lastSyncDate") String lastSyncDate, Authentication auth, HttpServletResponse response) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); From 00819abf3eaad949327bde95fbeb909a3bbdd8a2 Mon Sep 17 00:00:00 2001 From: Akil Mahimwala Date: Fri, 19 Feb 2021 14:29:35 +0530 Subject: [PATCH 3/9] Updated the getRegionByRealmCountry method --- .../FASP/rest/controller/RegionRestController.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java b/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java index 5d4e81032..361827906 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/RegionRestController.java @@ -104,17 +104,20 @@ public ResponseEntity getRegionById(@PathVariable("regionId") int regionId, Auth } /** - * API used to get the Region list for a RealmCountry + * API used to get the Region list for a list of RealmCountry Ids. Empty + * list means you want the complete list of Regions * - * @param realmCountryIds RealmCountryId that you want the Region List from + * @param realmCountryIds List of RealmCountryIds that you want the Region + * List from * @param auth - * @return returns the complete list of Regions + * @return returns the complete list of Regions, based on the + * RealmCountryIds that were passed */ @GetMapping("/realmCountryIds") - @Operation(description = "API used to get the complete Region list for a RealmCountry", summary = "Get Region list for a RealmCountry", tags = ("region")) + @Operation(description = "API used to get the Region list for a list of RealmCountry Ids. Empty list means you want the complete list of Regions", summary = "Get Region list based on RealmCountry list", tags = ("region")) @Parameters( @Parameter(name = "realmCountryIds", description = "List of RealmCountryIds that you want the Region list for")) - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Region list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Region list based on the RealmCountry list that was passed") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Region list") From 24800e8440ab30b1d3e1956a9fcb33d9739b145d Mon Sep 17 00:00:00 2001 From: Shrutika Kalbande Date: Sat, 1 May 2021 11:02:40 +0530 Subject: [PATCH 4/9] API doc for 4 controllers --- .../PlanningUnitRestController.java | 309 ++++++++++++++++-- .../controller/ProgramDataRestController.java | 241 +++++++++++++- .../controller/SupplyPlanRestController.java | 42 +++ .../rest/controller/SyncRestController.java | 39 ++- 4 files changed, 588 insertions(+), 43 deletions(-) diff --git a/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java index 333175797..0000f9b86 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java @@ -12,6 +12,11 @@ import cc.altius.FASP.service.PlanningUnitService; import cc.altius.FASP.service.ProcurementAgentService; import cc.altius.FASP.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.text.ParseException; import java.text.SimpleDateFormat; import org.slf4j.Logger; @@ -35,7 +40,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/planningUnit") public class PlanningUnitRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -47,7 +52,20 @@ public class PlanningUnitRestController { @Autowired private UserService userService; - @PostMapping(path = "/planningUnit") + /** + * API used to add a PlanningUnit. + * + * @param planningUnit PlanningUnit object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @PostMapping(path = "/") + @Operation(description = "API used to add a PlanningUnit", summary = "Add PlanningUnit", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "planningUnit", description = "The PlanningUnit object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity postPlanningUnit(@RequestBody PlanningUnit planningUnit, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -62,7 +80,20 @@ public ResponseEntity postPlanningUnit(@RequestBody PlanningUnit planningUnit, A } } - @PutMapping(path = "/planningUnit") + /** + * API used to update a PlanningUnit + * + * @param planningUnit PlanningUnit object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(path = "/") + @Operation(description = "API used to update a PlanningUnit", summary = "Update PlanningUnit", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "planningUnit", description = "The PlanningUnit object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity putPlanningUnit(@RequestBody PlanningUnit planningUnit, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -77,7 +108,16 @@ public ResponseEntity putPlanningUnit(@RequestBody PlanningUnit planningUnit, Au } } - @GetMapping("/planningUnit") + /** + * API used to get the list of active PlanningUnits. + * + * @param auth + * @return returns the list of active PlanningUnits + */ + @GetMapping("/") + @Operation(description = "API used to get the list of active PlanningUnits.", summary = "Get active PlanningUnit list", tags = ("planningUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of active PlanningUnit list") public ResponseEntity getPlanningUnit(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -88,7 +128,17 @@ public ResponseEntity getPlanningUnit(Authentication auth) { } } - @GetMapping("/planningUnit/all") + /** + * API used to get the complete PlanningUnit list. + * + * @param auth + * @return returns the complete list of PlanningUnit + */ + @GetMapping("/all") + @Operation(description = "API used to get the complete PlanningUnit list.", summary = "Get PlanningUnit list", tags = ("planningUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") + public ResponseEntity getPlanningUnitAll(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -99,11 +149,25 @@ public ResponseEntity getPlanningUnitAll(Authentication auth) { } } - @GetMapping("/planningUnit/realmId/{realmId}") + /** + * API used to get the list of active PlanningUnits for a Realm + * + * @param realmId RealmId that you want the PlanningUnit List from + * @param auth + * @return returns the list of active PlanningUnits + */ + @GetMapping("/realmId/{realmId}") + @Operation(description = "API used to get the list of active PlanningUnits for a Realm", summary = "Get active PlanningUnit list for Realm", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") public ResponseEntity getPlanningUnitForRealm(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.planningUnitService.getPlanningUnitList(realmId, false, curUser), HttpStatus.OK); + return new ResponseEntity(this.planningUnitService.getPlanningUnitList(realmId, true, curUser), HttpStatus.OK); } catch (EmptyResultDataAccessException e) { logger.error("Error while trying to list PlanningUnit", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); @@ -116,7 +180,21 @@ public ResponseEntity getPlanningUnitForRealm(@PathVariable(value = "realmId", r } } - @GetMapping("/planningUnit/realmId/{realmId}/all") + /** + * API used to get the PlanningUnit list for a Realm + * + * @param realmId RealmId that you want the PlanningUnit List from + * @param auth + * @return returns the complete list of PlanningUnit + */ + @GetMapping("/realmId/{realmId}/all") + @Operation(description = "API used to get the complete PlanningUnit list for a Realm", summary = "Get PlanningUnit list for Realm", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") public ResponseEntity getPlanningUnitForRealmAll(@PathVariable(value = "realmId", required = true) int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -133,7 +211,21 @@ public ResponseEntity getPlanningUnitForRealmAll(@PathVariable(value = "realmId" } } - @GetMapping("/planningUnit/{planningUnitId}") + /** + * API used to get the PlanningUnit for a specific PlanningUnitId + * + * @param planningUnitId PlanningUnit that you want the PlanningUnit Object + * for + * @param auth + * @return returns the PlanningUnit object based on PlanningUnitId specified + */ + @GetMapping("/{planningUnitId}") + @Operation(description = "API used to get the PlanningUnit for a specific PlanningUnitId", summary = "Get PlanningUnit for a PlanningUnitId", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "planningUnitId", description = "PlanningUnitId that you want to the PlanningUnit for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the HealthAreaId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit") public ResponseEntity getPlanningUnitById(@PathVariable("planningUnitId") int planningUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -147,7 +239,21 @@ public ResponseEntity getPlanningUnitById(@PathVariable("planningUnitId") int pl } } - @GetMapping(value = "/planningUnit/capacity/realmId/{realmId}") + /** + * API used to get PlanningUnitCapacity list for a Realm + * + * @param realmId realmId that you want a PlanningUnitCapacity list from + * @param auth + * @return returns list of PlanningUnitCapacity for a Realm + */ + @GetMapping(value = "/capacity/realmId/{realmId}") + @Operation(description = "API used to get PlanningUnitCapacity for a Realm", summary = "Get PlanningUnitCapacity for a Realm", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want a PlanningUnitCapacity from")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnitCapacity list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitCapacity list does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnitCapacity list") public ResponseEntity getPlanningUnitCapacityForRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -164,7 +270,31 @@ public ResponseEntity getPlanningUnitCapacityForRealmId(@PathVariable("realmId") } } - @GetMapping(value = "/planningUnit/capacity/realmId/{realmId}/between/{startDate}/{stopDate}") + /** + * API used to get PlanningUnitCapacity list for a Realm and a given date + * range + * + * @param realmId realmId that you want a PlanningUnitCapacity from + * @param startDate startDate the date you want the PlanningUnitCapacity + * data from + * @param stopDate stopDate the date you want the PlanningUnitCapacity data + * till + * @param auth + * @return returns list of PlanningUnitCapacity for a Realm and a given date + * range + */ + @GetMapping(value = "/capacity/realmId/{realmId}/between/{startDate}/{stopDate}") + @Operation(description = "API used to get PlanningUnitCapacity for a Realm and a given date range", summary = "Get PlanningUnitCapacity for a Realm and a given date range", tags = ("planningUnit")) + @Parameters({ + @Parameter(name = "realmId", description = "realmId that you want a PlanningUnitCapacity from"), + @Parameter(name = "startDate", description = "startDate the date you want the PlanningUnitCapacity data from"), + @Parameter(name = "stopDate", description = "stopDate the date you want the PlanningUnitCapacity data till")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnitCapacity list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to get the list does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitCapacity list does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnitCapacity list") + public ResponseEntity getPlanningUnitCapacityForRealmId(@PathVariable("realmId") int realmId, @PathVariable("startDate") String startDate, @PathVariable("stopDate") String stopDate, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -184,7 +314,22 @@ public ResponseEntity getPlanningUnitCapacityForRealmId(@PathVariable("realmId") } } - @GetMapping(value = "/planningUnit/capacity/{planningUnitId}") + /** + * API used to get PlanningUnitCapacity list for a PlanningUnitId + * + * @param planningUnitId planningUnitId that you want a PlanningUnitCapacity + * list for + * @param auth + * @return returns list of PlanningUnitCapacity list for a PlanningUnitId + */ + @GetMapping(value = "/capacity/{planningUnitId}") + @Operation(description = "API used to get PlanningUnitCapacity list for a PlanningUnitId", summary = "Get PlanningUnitCapacity list for a PlanningUnitId", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "planningUnitId", description = "planningUnitId that you want a PlanningUnitCapacity list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnitCapacity list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to get the list does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnitCapacity list") public ResponseEntity getPlanningUnitCapacityForId(@PathVariable("planningUnitId") int planningUnitId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -201,7 +346,31 @@ public ResponseEntity getPlanningUnitCapacityForId(@PathVariable("planningUnitId } } - @GetMapping(value = "/planningUnit/capacity/{planningUnitId}/between/{startDate}/{stopDate}") + /** + * API used to get PlanningUnitCapacity list for a PlanningUnitId and a + * given date range + * + * @param planningUnitId planningUnitId that you want a PlanningUnitCapacity + * list for + * @param startDate startDate the date you want the PlanningUnitCapacity + * data from + * @param stopDate stopDate the date you want the PlanningUnitCapacity data + * till + * @param auth + * @return returns list of PlanningUnitCapacity list for a PlanningUnitId + * and a given date range + */ + @GetMapping(value = "/capacity/{planningUnitId}/between/{startDate}/{stopDate}") + @Operation(description = "API used to get PlanningUnitCapacity list for a PlanningUnitId and a given date range", summary = "Get PlanningUnitCapacity list for a PlanningUnitId and a given date range", tags = ("planningUnit")) + @Parameters({ + @Parameter(name = "planningUnitId", description = "planningUnitId that you want a PlanningUnitCapacity list for"), + @Parameter(name = "startDate", description = "startDate the date you want the PlanningUnitCapacity data from"), + @Parameter(name = "stopDate", description = "stopDate the date you want the PlanningUnitCapacity data till")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnitCapacity list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to get the list does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitCapacity list does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnitCapacity list") public ResponseEntity getPlanningUnitCapacityForId(@PathVariable("planningUnitId") int planningUnitId, @PathVariable("startDate") String startDate, @PathVariable("stopDate") String stopDate, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -221,7 +390,18 @@ public ResponseEntity getPlanningUnitCapacityForId(@PathVariable("planningUnitId } } - @GetMapping(value = "/planningUnit/capacity/all") + /** + * API used to get a complete PlanningUnitCapacity list + * + * @param auth + * @return returns a complete list of PlanningUnitCapacity + */ + @GetMapping(value = "/capacity/all") + @Operation(description = "API used to get a complete PlanningUnitCapacity list", summary = "Get a complete PlanningUnitCapacity list", tags = ("planningUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnitCapacity list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitCapacity list does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnitCapacity list") public ResponseEntity getPlanningUnitCapacityList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -238,7 +418,23 @@ public ResponseEntity getPlanningUnitCapacityList(Authentication auth) { } } - @PutMapping(value = "/planningUnit/capacity") + /** + * API used to update PlanningUnitCapacity + * + * @param planningUnitCapacitys planningUnitCapacity objects that you want + * to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @PutMapping(value = "/capacity") + @Operation(description = "API used to update PlanningUnitCapacity", summary = "Update PlanningUnitCapacity", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "planningUnitCapacitys", description = "planningUnitCapacity objects that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to update the date does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the user does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitCapacity does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity savePlanningUnitCapacity(@RequestBody PlanningUnitCapacity[] planningUnitCapacitys, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -259,23 +455,52 @@ public ResponseEntity savePlanningUnitCapacity(@RequestBody PlanningUnitCapacity } } - @GetMapping(value = "/sync/planningUnit/{lastSyncDate}") - public ResponseEntity getPlanningUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.parse(lastSyncDate); - CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.planningUnitService.getPlanningUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); - } catch (ParseException p) { - logger.error("Error while listing planningUnit", p); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); - } catch (Exception e) { - logger.error("Error while listing planningUnit", e); - return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @GetMapping("/planningUnit/productCategory/{productCategoryId}/all") + /** + * API used to get list of planningUnits which are modified after given date + * + * @param lastSyncDate lastSyncDate that you want a planningUnits list + * modified after the date + * @param auth + * @return returns a complete list of PlanningUnits modified after given + * date + */ +// @GetMapping(value = "/sync/planningUnit/{lastSyncDate}") +// @Operation(description = "API used to get list of planningUnits which are modified after given date", summary = "Get list of planningUnits which are modified after given date", tags = ("planningUnit")) +// @Parameters( +// @Parameter(name = "lastSyncDate", description = "lastSyncDate that you want a planningUnits list modified after the date")) +// @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") +// @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to update the data does not met") +// @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") +// public ResponseEntity getPlanningUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { +// try { +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// sdf.parse(lastSyncDate); +// CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); +// return new ResponseEntity(this.planningUnitService.getPlanningUnitListForSync(lastSyncDate, curUser), HttpStatus.OK); +// } catch (ParseException p) { +// logger.error("Error while listing planningUnit", p); +// return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.PRECONDITION_FAILED); +// } catch (Exception e) { +// logger.error("Error while listing planningUnit", e); +// return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); +// } +// } + /** + * API used to get the PlanningUnit list for a ProductCategory + * + * @param productCategoryId productCategoryId that you want the PlanningUnit + * List for + * @param auth + * @return returns the complete list of PlanningUnit + */ + @GetMapping("/productCategory/{productCategoryId}/all") + @Operation(description = "API used to get the complete PlanningUnit list for a ProductCategory", summary = "Get PlanningUnit list for ProductCategory", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "productCategoryId", description = "productCategoryId that you want the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the productCategoryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") public ResponseEntity getPlanningUnitForproductCategoryAll(@PathVariable(value = "productCategoryId", required = true) int productCategoryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -291,8 +516,23 @@ public ResponseEntity getPlanningUnitForproductCategoryAll(@PathVariable(value = return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @GetMapping("/planningUnit/productCategory/{productCategoryId}/active") + + /** + * API used to get the list of active PlanningUnits for a ProductCategory + * + * @param productCategoryId productCategoryId that you want the PlanningUnit + * List for + * @param auth + * @return returns the list of active PlanningUnits + */ + @GetMapping("/productCategory/{productCategoryId}/active") + @Operation(description = "API used to get the list of active PlanningUnits for a ProductCategory", summary = "Get active PlanningUnit list for ProductCategory", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "productCategoryId", description = "productCategoryId that you want the PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the productCategoryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") public ResponseEntity getPlanningUnitForproductCategory(@PathVariable(value = "productCategoryId", required = true) int productCategoryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -309,6 +549,7 @@ public ResponseEntity getPlanningUnitForproductCategory(@PathVariable(value = "p } } + //TBD @GetMapping("/getPlanningUnitByTracerCategory/planningUnitId/{planningUnitId}/{procurementAgentId}/{term}") public ResponseEntity getPlanningUnitByTracerCategory(@PathVariable("planningUnitId") int planningUnitId, @PathVariable("procurementAgentId") int procurementAgentId, @PathVariable("term") String term, Authentication auth) { try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java index 3a785cfb3..fb74a0325 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java @@ -16,6 +16,11 @@ import cc.altius.FASP.service.ProgramDataService; import cc.altius.FASP.service.UserService; import com.fasterxml.jackson.annotation.JsonView; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; @@ -60,8 +65,25 @@ public class ProgramDataRestController { // @Value("${email.ccList}") // private String ccList; + /** + * API used to get ProgramData for ProgramId and VersionId + * + * @param programId programId that you want the ProgramData for + * @param versionId versionId that you want the ProgramData for + * @param auth + * @return return the ProgramData object based on specified ProgramId and + * VersionId + */ @JsonView(Views.InternalView.class) @GetMapping("/programData/programId/{programId}/versionId/{versionId}") + @Operation(description = "API used to get ProgramData for ProgramId and VersionId", summary = "Get ProgramData for a ProgramId and VersionId", tags = ("programData")) + @Parameters({ + @Parameter(name = "programId", description = "programId that you want to the ProgramData for"), + @Parameter(name = "versionId", description = "versionId that you want to the ProgramData for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProgramData") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProgramData specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProgramData") public ResponseEntity getProgramData(@PathVariable(value = "programId", required = true) int programId, @PathVariable(value = "versionId", required = true) int versionId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -77,9 +99,25 @@ public ResponseEntity getProgramData(@PathVariable(value = "programId", required return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + + /** + * API used to get ProgramData list for listed ProgramIds and VersionIds + * + * @param programVersionList programVersionList list of ProgramIds and + * VersionIds that you want a ProgramData list for + * @param auth + * @return return the ProgramData list for listed ProgramIds and VersionIds + * VersionId + */ @JsonView(Views.InternalView.class) @PostMapping("/programData") + @Operation(description = "API used to get ProgramData list for listed ProgramIds and VersionIds", summary = "Get ProgramData list for listed ProgramIds and VersionIds", tags = ("programData")) + @Parameters( + @Parameter(name = "programVersionList", description = "programVersionList list of ProgramIds and VersionIds that you want a ProgramData list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProgramData list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProgramData specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProgramData") public ResponseEntity getLoadProgramData(@RequestBody List programVersionList, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -96,8 +134,25 @@ public ResponseEntity getLoadProgramData(@RequestBody List programVersionList, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -339,9 +550,23 @@ public ResponseEntity checkNewerVersions(@RequestBody List pvList, Authentication auth) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java index 284275bfb..703d8847a 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SyncRestController.java @@ -1,4 +1,4 @@ - /* +/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. @@ -33,6 +33,11 @@ import cc.altius.FASP.service.TracerCategoryService; import cc.altius.FASP.service.UnitService; import cc.altius.FASP.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.text.ParseException; import java.text.SimpleDateFormat; import javax.servlet.http.HttpServletResponse; @@ -110,7 +115,22 @@ public class SyncRestController { @Autowired private UserService userService; + /** + * API used to get list of all masters which are modified after given date + * + * @param lastSyncDate lastSyncDate that you want a list of all masters + * modified after the date + * @param auth + * @param response + * @return list of of all masters + */ @GetMapping(value = "/allMasters/{lastSyncDate}") + @Operation(description = "API used to get list of all masters which are modified after given date", summary = "To get list of all masters which are modified after given date", tags = ("masters")) + @Parameters( + @Parameter(name = "lastSyncDate", description = "lastSyncDate that you want a list of all masters modified after the date")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the list of all masters") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to get the lists does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of list of all masters") public ResponseEntity getAllMastersForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth, HttpServletResponse response) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -171,7 +191,24 @@ private String getProgramIds(String[] programIds) { } } + /** + * API used to get list of all program specific masters which are modified + * after given date + * + * @param lastSyncDate lastSyncDate that you want a list of all masters + * modified after the date + * @param auth + * @param response + * @return list of of all masters + */ @PostMapping(value = "/allMasters/forPrograms/{lastSyncDate}") + @Operation(description = "API used to get list of all program specific masters which are modified", summary = "To get list of all program specific masters which are modified", tags = ("masters")) + @Parameters( + @Parameter(name = "lastSyncDate", description = "lastSyncDate that you want a list of all masters modified after the date")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the list of all masters") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if certain conditions to get the lists does not met") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of list of all masters") + public ResponseEntity getAllMastersForSyncWithProgramIds(@RequestBody String[] programIds, @PathVariable("lastSyncDate") String lastSyncDate, Authentication auth, HttpServletResponse response) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); From 0b787ef7a74c45624713cd99fdf475731f94acc6 Mon Sep 17 00:00:00 2001 From: Shrutika Kalbande Date: Wed, 12 May 2021 15:56:01 +0530 Subject: [PATCH 5/9] testing pull request --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test From 16f4e65487872a998bb647537cb55fe129f34118 Mon Sep 17 00:00:00 2001 From: Shrutika Date: Fri, 24 Sep 2021 13:17:44 +0530 Subject: [PATCH 6/9] api doc --- .../rest/controller/BudgetRestController.java | 3 +- .../controller/CurrencyRestController.java | 5 +- .../controller/DashboardRestController.java | 49 +- .../FASP/rest/controller/FileController.java | 4 +- .../IntegrationProgramRestController.java | 14 +- .../JiraServiceDeskApiController.java | 56 +- .../rest/controller/LocaleRestController.java | 8 +- .../OrganisationRestController.java | 12 +- .../OrganisationTypeRestController.java | 82 +++ .../controller/PipelineDbRestController.java | 389 +++++++++++- .../PlanningUnitRestController.java | 64 +- .../controller/ProblemRestController.java | 60 +- .../ProcurementAgentRestController.java | 78 ++- .../ProcurementUnitRestController.java | 10 +- .../controller/ProgramDataRestController.java | 52 +- .../controller/ProgramRestController.java | 552 +++++++++++++++++- .../QuantimedImportRestController.java | 37 +- .../RealmCountryRestController.java | 190 +++++- .../rest/controller/RealmRestController.java | 10 +- .../rest/controller/ReportRestController.java | 225 +++++-- .../ShipmentStatusRestController.java | 12 + .../controller/SupplierRestController.java | 2 +- .../controller/SupplyPlanRestController.java | 2 +- .../rest/controller/SyncRestController.java | 15 +- .../rest/controller/TestRestController.java | 33 ++ .../controller/UserManualRestController.java | 29 +- .../rest/controller/UserRestController.java | 284 ++++++++- 27 files changed, 2013 insertions(+), 264 deletions(-) diff --git a/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java b/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java index eaa10dcb7..6c8e47c1e 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/BudgetRestController.java @@ -78,7 +78,7 @@ public ResponseEntity getBudgetList(Authentication auth) { @Parameter(name = "budget", description = "The Budget object that you want to add to the Realm")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to add the Budget") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the some of the underlying data does not match. For instance the Funding Source Id specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the some of the underlying data does not match.") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") public ResponseEntity addBudget(@RequestBody Budget budget, Authentication auth) { try { @@ -211,7 +211,6 @@ public ResponseEntity getBudgetForRealm(@PathVariable("realmId") int realmId, Au } } - // @GetMapping(value = "/sync/budget/{lastSyncDate}") // @Operation( // summary = "Used to Sync the Budgets with users machines for Offline use", diff --git a/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java b/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java index 48fc1b871..3dc787055 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/CurrencyRestController.java @@ -95,7 +95,8 @@ public ResponseEntity getCurrencyListAll(Authentication auth) { * * @param currencyId CurrencyId that you want the Currency Object for * @param auth - * @return returns the list the Currency object based on CurrencyId specified + * @return returns the list the Currency object based on CurrencyId + * specified */ @GetMapping(value = "/{currencyId}") @Operation(description = "API used to get the Currency for a specific CurrencyId", summary = "Get Currency for a CurrencyId", tags = ("currency")) @@ -145,7 +146,7 @@ public ResponseEntity addCurrency(@RequestBody Currency currency, Authentication } } - /** + /** * API used to update a Currency * * @param currency Currency object that you want to update diff --git a/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java b/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java index 1745405fb..ea7409f63 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/DashboardRestController.java @@ -7,6 +7,10 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.DashboardService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -29,8 +33,16 @@ public class DashboardRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private DashboardService dashboardService; - + /** + * API used to get data for application level dashboard + * + * @param auth + * @return returns a map of required data for application level dashboard + */ + @Operation(description = "API used to get data for application level dashboard", summary = "Application level dashboard", tags = ("dashboard")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a map of required data for application level dashboard") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(value = "/application") public ResponseEntity applicationLevelDashboard(Authentication auth) { try { @@ -41,8 +53,19 @@ public ResponseEntity applicationLevelDashboard(Authentication auth) { } } + /** + * API used to get data for realm level dashboard + * + * @param realmId realm Id that you want data for + * @param auth + * @return returns a map of required data for realm level dashboard + */ + @Operation(description = "API used to get data for realm level dashboard", summary = "Realm level dashboard", tags = ("dashboard")) + @Parameter(name = "realmId", description = "The realm Id that you want data for") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a map of required data for realm level dashboard") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(value = "/realmId/{realmId}") - public ResponseEntity realmLevelDashboard(@PathVariable("realmId") int realmId,Authentication auth) { + public ResponseEntity realmLevelDashboard(@PathVariable("realmId") int realmId, Authentication auth) { try { return new ResponseEntity(this.dashboardService.getRealmLevelDashboard(realmId), HttpStatus.OK); } catch (Exception e) { @@ -51,6 +74,15 @@ public ResponseEntity realmLevelDashboard(@PathVariable("realmId") int realmId,A } } + /** + * API used to get user list for application level admin + * + * @param auth + * @return returns a list of users for application level admin + */ + @Operation(description = "API used to get user list for application level admin", summary = "Application level admin user list", tags = ("dashboard")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of users for application level admin") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(value = "/application/user") public ResponseEntity applicationLevelDashboardUserList(Authentication auth) { try { @@ -61,8 +93,19 @@ public ResponseEntity applicationLevelDashboardUserList(Authentication auth) { } } + /** + * API used to get user list for realm level admin + * + * @param realmId realm Id that you want data for + * @param auth + * @return returns a list of users for realm level admin + */ + @Operation(description = "API used to get user list for realm level admin", summary = "Realm level admin user list", tags = ("dashboard")) + @Parameter(name = "realmId", description = "The realm Id that you want data for") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of users for realm level admin") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(value = "/realmId/{realmId}/user") - public ResponseEntity realmLevelDashboardUserList(@PathVariable("realmId") int realmId,Authentication auth) { + public ResponseEntity realmLevelDashboardUserList(@PathVariable("realmId") int realmId, Authentication auth) { try { return new ResponseEntity(this.dashboardService.getUserListForRealmLevelAdmin(realmId), HttpStatus.OK); } catch (Exception e) { diff --git a/src/main/java/cc/altius/FASP/rest/controller/FileController.java b/src/main/java/cc/altius/FASP/rest/controller/FileController.java index b6167fd2a..f2e1d7791 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/FileController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/FileController.java @@ -51,13 +51,15 @@ public class FileController { /** * * @param fileName Name of file that the user wants to get from the Server + * @param auth * @return Returns the byte array of the file that was requested * @throws FileNotFoundException if the file was not found * @throws IOException if there was an error in reading the file from the * server */ @Operation(description = "Returns the byte stream of the file that was requested", summary = "Get file from Server", tags = ("file")) - @Parameters(@Parameter(name = "fileName", description = "Name of file that the user wants to get from the Server")) + @Parameters( + @Parameter(name = "fileName", description = "Name of file that the user wants to get from the Server")) @ApiResponse(content = @Content(mediaType = "application/octet-stream"), responseCode = "200", description = "Returns the byte array of the file that was requested") @GetMapping("/file/{fileName}") public byte[] getFile(@PathVariable(name = "fileName") String fileName, HttpServletResponse response, Authentication auth) throws FileNotFoundException, IOException { diff --git a/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java b/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java index 8d902e17d..94f6db982 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java @@ -64,10 +64,12 @@ public ResponseEntity getIntegrationProgram(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + /** * API used to get the complete Integration Program list for a ProgramId. * + * @param programId programId that you want to the Integration Program list + * for * @param auth * @return returns the complete list of Integration Programs for a ProgramId */ @@ -88,10 +90,11 @@ public ResponseEntity getIntegrationProgramForProgramId(@PathVariable("programId } /** - * API used to get the Integration Program for a specific IntegrationProgramId + * API used to get the Integration Program for a specific + * IntegrationProgramId * - * @param integrationProgramId IntegrationProgramId that you want the Integration Program for - * Object for + * @param integrationProgramId IntegrationProgramId that you want the + * Integration Program for Object for * @param auth * @return returns the list the Integration Program object based on * IntegrationProgramId specified @@ -155,7 +158,8 @@ public ResponseEntity getIntegrationProgram(@PathVariable("integrationProgramId" /** * API used to update an IntegrationProgram * - * @param integrationPrograms Array of IntegrationProgram that you want to update + * @param integrationPrograms Array of IntegrationProgram that you want to + * update * @param auth * @return returns a Success code if the operation was successful */ diff --git a/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java b/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java index 406a721da..e1859ea90 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/JiraServiceDeskApiController.java @@ -9,8 +9,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.JiraServiceDeskApiService; import cc.altius.FASP.service.UserService; -import java.io.FileNotFoundException; -import java.io.IOException; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,12 +45,33 @@ public class JiraServiceDeskApiController { @Autowired private UserService userService; + /** + * API used to sync user's Jira account id in user table + * + * @return returns the json object with Jira account details + */ + @Operation(description = "API used to sync user's Jira account id in user table.", summary = "Sync user's Jira account id", tags = ("jiraServiceDesk")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the json object with Jira account details") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/syncJiraAccountIds") - public String syncUserJiraAccountId(HttpServletResponse response) throws FileNotFoundException, IOException { + public String syncUserJiraAccountId(HttpServletResponse response) { return this.jiraServiceDeskApiService.syncUserJiraAccountId(""); } - @PostMapping(value = "/jira/addIssue") + /** + * API used to add issue in Jira + * + * @param jsonData Issue details to add in Jira in json format + * @param auth + * @return returns a response which we get after calling Jira API to add + * issue + */ + @Operation(description = "API used to add issue in Jira", summary = "Add issue in Jira", tags = ("jiraServiceDesk")) + @Parameters( + @Parameter(name = "jsonData", description = "Issue details to add in Jira in json format")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PostMapping(value = "/addIssue") public ResponseEntity addIssue(@RequestBody(required = true) String jsonData, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -65,6 +89,21 @@ public ResponseEntity addIssue(@RequestBody(required = true) String jsonData, Au } + /** + * API used to add attachment in the issue in Jira + * + * @param file Attachment which needs to be added in Jira issue + * @param issueId Issue id for which attachment needs to be added for + * @param auth + * @return returns a response which we get after calling Jira API to add + * attachment in Jira issue issue + */ + @Operation(description = "API used to add attachment in the issue in Jira", summary = "Add attachment in Jira issue", tags = ("jiraServiceDesk")) + @Parameters({ + @Parameter(name = "file", description = "Attachment which needs to be added in Jira issue"), + @Parameter(name = "issueId", description = "Issue id for which attachment needs to be added for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @PostMapping(value = "/addIssueAttachment/{issueId}") public ResponseEntity addIssueAttachment(@RequestParam("file") MultipartFile file, @PathVariable("issueId") String issueId, Authentication auth) { String message = ""; @@ -85,6 +124,15 @@ public ResponseEntity addIssueAttachment(@RequestParam("file") MultipartFile fil } } + /** + * API used to get number of open and addressed issues + * + * @param auth + * @return returns a number of open and addressed issues in json format + */ + @Operation(description = "API used to get number of open and addressed issues", summary = "Get number of open and addressed issues", tags = ("jiraServiceDesk")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(value = "/openIssues") public ResponseEntity getOpenIssue(Authentication auth) { try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java index 1e41f1782..fae4808fc 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java @@ -24,9 +24,11 @@ public class LocaleRestController { private LanguageService languageService; /** - * Api returns the complete file that the system uses for the Translations. Language is based on the Locale provided. - * @param languageCode - * @return + * Api returns the complete file that the system uses for the Translations. + * Language is based on the Locale provided. + * + * @param languageCode for which you need the language label for + * @return file containing labels for the Translations */ @GetMapping("/locales/{languageCode}") ResponseEntity getLanguageJson(@PathVariable("languageCode") String languageCode) { diff --git a/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java b/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java index 25e7f1db2..a0dd58408 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/OrganisationRestController.java @@ -103,7 +103,7 @@ public ResponseEntity getOrganisation(@PathVariable("organisationId") int organi /** * API used to get the Organisation list for a Realm * - * @param realmId RealmId that you want the Funding Source List from + * @param realmId RealmId that you want the Organisation List from * @param auth * @return returns the complete list of Organisations */ @@ -134,8 +134,8 @@ public ResponseEntity getOrganisationByRealmId(@PathVariable("realmId") int real /** * API used to get the Organisation list for a RealmCountry * - * @param realmCountryId RealmCountryId that you want the Funding Source - * List from + * @param realmCountryId RealmCountryId that you want the Organisation List + * from * @param auth * @return returns the complete list of Organisations */ @@ -164,8 +164,8 @@ public ResponseEntity getOrganisationByRealmCountry(@PathVariable("realmCountryI * API used to get the Organisation by providing the display name of the * Organisation and the Realm * - * @param realmId RealmId that you want the Funding Source from - * @param name Display name of the Funding source you want to get + * @param realmId RealmId that you want the Organisation from + * @param name Display name of the Organisation you want to get * @param auth * @return returns the complete list of Organisations */ @@ -181,7 +181,7 @@ public ResponseEntity getOrganisationDisplayName(@PathVariable("realmId") int re CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); return new ResponseEntity(this.organisationService.getDisplayName(realmId, name, curUser), HttpStatus.OK); } catch (Exception e) { - logger.error("Error while trying to get Funding source suggested display name", e); + logger.error("Error while trying to get organisation suggested display name", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/cc/altius/FASP/rest/controller/OrganisationTypeRestController.java b/src/main/java/cc/altius/FASP/rest/controller/OrganisationTypeRestController.java index a409c072e..8727715f7 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/OrganisationTypeRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/OrganisationTypeRestController.java @@ -10,6 +10,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.OrganisationTypeService; import cc.altius.FASP.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +47,20 @@ public class OrganisationTypeRestController { @Autowired private UserService userService; + /** + * API used to add an Organisation type + * + * @param organisationType OrganisationType object that you want to add + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to add an Organisation Type", summary = "Add Organisation Type", tags = ("organisationType")) + @Parameters( + @Parameter(name = "organisationType", description = "The OrganisationType object that you want to add")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @PostMapping(path = "/") public ResponseEntity postOrganisationType(@RequestBody OrganisationType organisationType, Authentication auth) { try { @@ -60,6 +79,21 @@ public ResponseEntity postOrganisationType(@RequestBody OrganisationType organis } } + /** + * API used to update an Organisation type + * + * @param organisationType OrganisationType object that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to update an Organisation type", summary = "Update Organisation Type", tags = ("organisationType")) + @Parameters( + @Parameter(name = "organisationType", description = "The OrganisationType object that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the OrganisationId supplied does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the data supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @PutMapping(path = "/") public ResponseEntity putOrganisationType(@RequestBody OrganisationType organisationType, Authentication auth) { try { @@ -81,6 +115,15 @@ public ResponseEntity putOrganisationType(@RequestBody OrganisationType organisa } } + /** + * API used to get the Organisation type list that are active. + * + * @param auth + * @return returns the list of Organisations type that are active + */ + @Operation(description = "API used to get the Organisation type list that are active.", summary = "Get Active Organisation type list", tags = ("organisationType")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation list") @GetMapping("/") public ResponseEntity getOrganisationTypeList(Authentication auth) { try { @@ -92,6 +135,15 @@ public ResponseEntity getOrganisationTypeList(Authentication auth) { } } + /** + * API used to get the complete Organisation type list. + * + * @param auth + * @return returns the complete list of Organisations type + */ + @Operation(description = "API used to get the complete Organisation type list.", summary = "Get complete Organisation type list", tags = ("organisationType")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation list") @GetMapping(value = "/all") public ResponseEntity getOrganisationTypeListAll(Authentication auth) { try { @@ -103,6 +155,20 @@ public ResponseEntity getOrganisationTypeListAll(Authentication auth) { } } + /** + * API used to get the Organisation type list for a Realm + * + * @param realmId RealmId that you want the Organisation Type List from + * @param auth + * @return returns the complete list of Organisations type + */ + @Operation(description = "API used to get the complete Organisation type list for a Realm", summary = "Get Organisation type list for Realm", tags = ("organisationType")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want the Organisation type list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation type list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation type list") @GetMapping("/realmId/{realmId}") public ResponseEntity getOrganisationTypeByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { @@ -120,6 +186,22 @@ public ResponseEntity getOrganisationTypeByRealmId(@PathVariable("realmId") int } } + /** + * API used to get the Organisation type for a specific OrganisationTypeId + * + * @param organisationTypeId OrganisationTypeId that you want the + * OrganisationType Object for + * @param auth + * @return returns the list the Organisation type object based on + * OrganisationTypeId specified + */ + @Operation(description = "API used to get the Organisation type for a specific OrganisationId", summary = "Get Organisation for a OrganisationTypeId", tags = ("organisationType")) + @Parameters( + @Parameter(name = "organisationTypeId", description = "OrganisationTypeId that you want to the Organisation type for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Organisation type") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the OrganisationTypeId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Organisation type") @GetMapping("/{organisationTypeId}") public ResponseEntity getOrganisationType(@PathVariable("organisationTypeId") int organisationTypeId, Authentication auth) { try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java b/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java index 27bc5ca46..1c751daec 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/PipelineDbRestController.java @@ -32,6 +32,11 @@ import cc.altius.FASP.model.pipeline.QatTempDataSource; import cc.altius.FASP.model.pipeline.QatTempFundingSource; import cc.altius.FASP.model.pipeline.QatTempProcurementAgent; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.DuplicateKeyException; @@ -41,7 +46,7 @@ * @author akil` */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/pipeline") public class PipelineDbRestController { @Autowired @@ -50,8 +55,23 @@ public class PipelineDbRestController { private UserService userService; private final Logger logger = LoggerFactory.getLogger(this.getClass()); + /** + * API used to save pipeline db data in to QAT adb(access database) tables + * + * @param pipeline Pipeline object which you need to save in adb tables + * @param fileName Filename to save in database + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save pipeline db data in to QAT adb(access database) tables", summary = "Save Pipeline Data", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "pipeline", description = "Pipeline object which you need to save in adb tables"), + @Parameter(name = "fileName", description = "Filename to save in database")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if the program specified already exists") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @PostMapping(path = "/pipelineJson/{fileName}") - public ResponseEntity postOrganisation(@RequestBody Pipeline pipeline, @PathVariable("fileName") String fileName, Authentication auth) throws IOException { + public ResponseEntity postPipelineData(@RequestBody Pipeline pipeline, @PathVariable("fileName") String fileName, Authentication auth) { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { String msg = "static.message.pipeline.programExists"; @@ -68,7 +88,16 @@ public ResponseEntity postOrganisation(@RequestBody Pipeline pipeline, @PathVari } } - @GetMapping("/pipeline") + /** + * API used to get pipeline program list from adb table + * + * @param auth + * @return returns a pipeline program list + */ + @Operation(description = "API used to get pipeline program list from adb table", summary = "Get Pipeline Program List", tags = ("pipeline")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a pipeline program list if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/") public ResponseEntity getPipelineProgramList(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -79,7 +108,21 @@ public ResponseEntity getPipelineProgramList(Authentication auth) { } } - @GetMapping("/pipeline/programInfo/{pipelineId}") + /** + * API used to get pipeline program info by pipelineId + * + * @param pipelineId PipelineId for which you need program info for + * @param auth + * @return returns a PplPrograminfo object in json format + */ + @Operation(description = "API used to get pipeline program info by pipelineId", summary = "Get Pipeline Program Info", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need program info for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a pipeline program info if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the Program info for the specified pipelineId does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/programInfo/{pipelineId}") public ResponseEntity getProgramInfo(@PathVariable("pipelineId") int pipelineId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -96,7 +139,22 @@ public ResponseEntity getProgramInfo(@PathVariable("pipelineId") int pipelineId, } } - @GetMapping("/pipeline/shipment/{pipelineId}") + /** + * API used to get pipeline shipment data by pipelineId from adb or temp + * table + * + * @param pipelineId PipelineId for which you need shipment data for + * @param auth + * @return returns a QatTempShipment object in json format + */ + @Operation(description = "API used to get pipeline shipment data by pipelineId", summary = "Get Pipeline Shipment Data", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need shipment data for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a pipeline shipment data if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the Shipment data for the specified pipelineId does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/shipment/{pipelineId}") public ResponseEntity getPipelineShipmentdata(@PathVariable("pipelineId") int pipelineId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -113,6 +171,21 @@ public ResponseEntity getPipelineShipmentdata(@PathVariable("pipelineId") int pi } } + /** + * API used to save pipeline program data into QAT temp tables + * + * @param program Program object which you need to save in temp table + * @param pipelineId PipelineId for which you need to save program for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save pipeline program data into QAT temp tables", summary = "Save Pipeline Program Data", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "program", description = "Program object which you need to save in temp table"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need to save program for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access to save program") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @PostMapping(path = "/qatTemp/program/{pipelineId}") public ResponseEntity postQatTempProgram(@RequestBody QatTempProgram program, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -128,6 +201,19 @@ public ResponseEntity postQatTempProgram(@RequestBody QatTempProgram program, Au } } + /** + * API used to get pipeline program data from QAT temp tables + * + * @param pipelineId PipelineId for which you need to temp program data for + * @param auth + * @return returns a QatTempProgram object in json format + */ + @Operation(description = "API used to get pipeline program data from QAT temp tables", summary = "Get QAT Temp Program", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to temp program data for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a QatTempProgram object if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping(path = "/qatTemp/program/{pipelineId}") public ResponseEntity getQatTempProgram(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -142,7 +228,19 @@ public ResponseEntity getQatTempProgram(Authentication auth, @PathVariable("pipe } } - @GetMapping("/pipeline/product/{pipelineId}") + /** + * API used to get planning unit list from adb tables + * + * @param pipelineId PipelineId for which you need to planning unit list for + * @param auth + * @return returns a planning unit list + */ + @Operation(description = "API used to get planning unit list from adb tables", summary = "Get Planning Unit List", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to planning unit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a planning unit list if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/product/{pipelineId}") public ResponseEntity getPlanningUnit(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -153,7 +251,23 @@ public ResponseEntity getPlanningUnit(Authentication auth, @PathVariable("pipeli } } - @PutMapping("/pipeline/planningUnit/{pipelineId}") + /** + * API used to save planning unit for specified program into temp table + * + * @param ppu Array of planning unit which needs to be saved + * @param pipelineId PipelineId for which you need planning units to save + * for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save planning unit for specified program into temp table", summary = "Save Planning Unit For Program", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of planning unit which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need planning units to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/planningUnit/{pipelineId}") public ResponseEntity savePlanningUnitForProgram(@RequestBody QatTempProgramPlanningUnit[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -168,6 +282,18 @@ public ResponseEntity savePlanningUnitForProgram(@RequestBody QatTempProgramPlan } } + /** + * API used to get planning unit list from temp tables + * + * @param pipelineId PipelineId for which you need to planning unit list for + * @param auth + * @return returns a planning unit list + */ + @Operation(description = "API used to get planning unit list from temp tables", summary = "Get QAT Temp Planning Unit List", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to planning unit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a planning unit list if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/planningUnitList/{pipelineId}") public ResponseEntity getQatTempPlanningUnitList(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -179,7 +305,19 @@ public ResponseEntity getQatTempPlanningUnitList(Authentication auth, @PathVaria } } - @GetMapping("/pipeline/consumption/{pipelineId}") + /** + * API used to get consumption data from adb tables + * + * @param pipelineId PipelineId for which you need to consumption data for + * @param auth + * @return returns a PplConsumption object in json format + */ + @Operation(description = "API used to get consumption data from adb tables", summary = "Get Consumtion Data", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to consumption data for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a PplConsumption object if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/consumption/{pipelineId}") public ResponseEntity getPlanningProgramConsumption(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -190,6 +328,18 @@ public ResponseEntity getPlanningProgramConsumption(Authentication auth, @PathVa } } + /** + * API used to get program region from temp table + * + * @param pipelineId PipelineId for which you need to program region for + * @param auth + * @return returns a Region object in json format + */ + @Operation(description = "API used to get program region from temp table", summary = "Get Program Region", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to program region for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Region object if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/regions/{pipelineId}") public ResponseEntity getQatTempProgramRegion(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -200,8 +350,23 @@ public ResponseEntity getQatTempProgramRegion(Authentication auth, @PathVariable return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - - @PutMapping("/pipeline/consumption/{pipelineId}") + + /** + * API used to save consumption for specified program into temp table + * + * @param ppu Array of consumption which needs to be saved + * @param pipelineId PipelineId for which you need consumption to save for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save consumption for specified program into temp table", summary = "Save Consumption For Program", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of consumption which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need consumption to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/consumption/{pipelineId}") public ResponseEntity saveConsumptionForProgram(@RequestBody QatTempConsumption[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -216,6 +381,18 @@ public ResponseEntity saveConsumptionForProgram(@RequestBody QatTempConsumption[ } } + /** + * API used to get consumption list from adb tables + * + * @param pipelineId PipelineId for which you need to consumption list for + * @param auth + * @return returns a list of QatTempConsumption object in json format + */ + @Operation(description = "API used to get consumption data from adb tables", summary = "Get Consumtion List", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to consumption list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of QatTempConsumption object if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/consumption/{pipelineId}") public ResponseEntity getQatTempConsumptionList(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -227,8 +404,22 @@ public ResponseEntity getQatTempConsumptionList(Authentication auth, @PathVariab } } - @PostMapping(path = "/pipeline/shipment/{pipelineId}") - public ResponseEntity saveShipmentData(@PathVariable("pipelineId") int pipelineId, @RequestBody QatTempShipment[] shipments, Authentication auth) throws IOException { + /** + * API used to save shipment for specified program into temp table + * + * @param pipelineId PipelineId for which you need shipment data to save for + * @param shipments Array of shipments which needs to be saved + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save shipment for specified program into temp table", summary = "Save Shipment Data For Program", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "pipelineId", description = "PipelineId for which you need shipment to save for"), + @Parameter(name = "shipments", description = "Array of shipments which needs to be saved")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PostMapping(path = "/shipment/{pipelineId}") + public ResponseEntity saveShipmentData(@PathVariable("pipelineId") int pipelineId, @RequestBody QatTempShipment[] shipments, Authentication auth) { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { return new ResponseEntity(this.pipelineDbService.saveShipmentData(pipelineId, shipments, curUser), HttpStatus.OK); @@ -238,7 +429,21 @@ public ResponseEntity saveShipmentData(@PathVariable("pipelineId") int pipelineI } } - @PostMapping(path = "/pipeline/programdata/{pipelineId}") + /** + * API used to save final program data into QAT tables from temp table for + * specified pipelineId + * + * @param pipelineId PipelineId for which you need program data to save for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save final program data into QAT tables from temp table for specified pipelineId", summary = "Save Final Program Data", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need program data to save for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the Program supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PostMapping(path = "/programdata/{pipelineId}") public ResponseEntity finalSaveProgramData(@PathVariable("pipelineId") int pipelineId, Authentication auth) throws IOException { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { @@ -252,7 +457,20 @@ public ResponseEntity finalSaveProgramData(@PathVariable("pipelineId") int pipel } } - @GetMapping("/pipeline/inventory/{pipelineId}") + /** + * API used to get pipeline inventory data from adb or temp tables + * + * @param pipelineId PipelineId for which you need to pipeline inventory + * data for + * @param auth + * @return returns a pipeline inventory data in json format + */ + @Operation(description = "API used to get pipeline inventory data from adb or temp tables", summary = "Get Pipeline Inventory Data", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need to pipeline inventory data for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a pipeline inventory data object if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @GetMapping("/inventory/{pipelineId}") public ResponseEntity getPipelineProgramInventory(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -263,7 +481,23 @@ public ResponseEntity getPipelineProgramInventory(Authentication auth, @PathVari } } - @PutMapping("/pipeline/inventory/{pipelineId}") + /** + * API used to save inventory for specified program into temp table + * + * @param ppu Array of inventory which needs to be saved + * @param pipelineId PipelineId for which you need inventory data to save + * for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save inventory for specified program into temp table", summary = "Save Inventory Data For Program", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of inventory which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need inventory to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/inventory/{pipelineId}") public ResponseEntity saveInventoryForProgram(@RequestBody QatTempInventory[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -278,6 +512,19 @@ public ResponseEntity saveInventoryForProgram(@RequestBody QatTempInventory[] pp } } + /** + * API used to get list of planning unit inventory count from temp tables + * + * @param pipelineId PipelineId for which you need the list of planning unit + * inventory count for + * @param auth + * @return returns a list of planning unit inventory count + */ + @Operation(description = "API used to get list of planning unit inventory count from temp tables", summary = "Get List of Planning Unit Inventory Count", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need the list of planning unit inventory count for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of planning unit inventory count if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/planningUnitListFinalInventry/{pipelineId}") public ResponseEntity getQatTempPlanningUnitListInventoryCount(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -289,7 +536,23 @@ public ResponseEntity getQatTempPlanningUnitListInventoryCount(Authentication au } } - @PutMapping("/pipeline/datasource/{pipelineId}") + /** + * API used to save data source for specified program into temp table + * + * @param ppu Array of data source which needs to be saved + * @param pipelineId PipelineId for which you need data source data to save + * for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save data source for specified program into temp table", summary = "Save QAT Temp Data Source", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of data source which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need data source to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/datasource/{pipelineId}") public ResponseEntity saveDataSourceForProgram(@RequestBody QatTempDataSource[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -304,6 +567,19 @@ public ResponseEntity saveDataSourceForProgram(@RequestBody QatTempDataSource[] } } + /** + * API used to get list of data source from temp tables + * + * @param pipelineId PipelineId for which you need the list of data source + * for + * @param auth + * @return returns a list of data source + */ + @Operation(description = "API used to get list of data source from temp tables", summary = "Get List of Data Source", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need the list of data source for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of data source if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/datasource/{pipelineId}") public ResponseEntity getQatTempDataSourceList(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -315,7 +591,23 @@ public ResponseEntity getQatTempDataSourceList(Authentication auth, @PathVariabl } } - @PutMapping("/pipeline/fundingsource/{pipelineId}") + /** + * API used to save funding source for specified program into temp table + * + * @param ppu Array of funding source which needs to be saved + * @param pipelineId PipelineId for which you need funding source to save + * for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save funding source for specified program into temp table", summary = "Save QAT Temp Funding Source", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of funding source which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need funding source to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/fundingsource/{pipelineId}") public ResponseEntity saveFundingSourceForProgram(@RequestBody QatTempFundingSource[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -330,6 +622,19 @@ public ResponseEntity saveFundingSourceForProgram(@RequestBody QatTempFundingSou } } + /** + * API used to get list of funding source from temp tables + * + * @param pipelineId PipelineId for which you need the list of funding + * source for + * @param auth + * @return returns a list of funding source + */ + @Operation(description = "API used to get list of funding source from temp tables", summary = "Get List of Funding Source", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need the list of funding source for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of funding source if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/fundingsource/{pipelineId}") public ResponseEntity getQatTempFundingSourceList(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -341,7 +646,23 @@ public ResponseEntity getQatTempFundingSourceList(Authentication auth, @PathVari } } - @PutMapping("/pipeline/procurementagent/{pipelineId}") + /** + * API used to save procurement agent for specified program into temp table + * + * @param ppu Array of procurement agent which needs to be saved + * @param pipelineId PipelineId for which you need procurement agent to save + * for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save procurement agent for specified program into temp table", summary = "Save QAT Temp Procurement Agent", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "ppu", description = "Array of procurement agent which needs to be saved"), + @Parameter(name = "pipelineId", description = "PipelineId for which you need procurement agent to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/procurementagent/{pipelineId}") public ResponseEntity saveProcurementAgentForProgram(@RequestBody QatTempProcurementAgent[] ppu, Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -356,6 +677,19 @@ public ResponseEntity saveProcurementAgentForProgram(@RequestBody QatTempProcure } } + /** + * API used to get list of procurement agent from temp tables + * + * @param pipelineId PipelineId for which you need the list of procurement + * agent for + * @param auth + * @return returns a list of procurement agent + */ + @Operation(description = "API used to get list of procurement agent from temp tables", summary = "Get List of Procurement Agent", tags = ("pipeline")) + @Parameters( + @Parameter(name = "pipelineId", description = "PipelineId for which you need the list of procurement agent for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a list of procurement agent if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @GetMapping("/qatTemp/procurementagent/{pipelineId}") public ResponseEntity getQatTempProcurementAgentList(Authentication auth, @PathVariable("pipelineId") int pipelineId) { try { @@ -367,8 +701,23 @@ public ResponseEntity getQatTempProcurementAgentList(Authentication auth, @PathV } } - @PutMapping(path = "/pipeline/realmCountryPlanningUnit/{pipelineId}/{realmCountryId}") - public ResponseEntity createRealmCountryPlanningUnits(@PathVariable("pipelineId") int pipelineId, @PathVariable("realmCountryId") int realmCountryId, Authentication auth) throws IOException { + /** + * API used to save planning unit for specified realm country + * + * @param pipelineId PipelineId for which you need planning unit to save for + * @param realmCountryId realmCountryId for which you need planning unit to + * save for + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save planning unit for specified realm country", summary = "Save Planning Unit For Realm Country", tags = ("pipeline")) + @Parameters({ + @Parameter(name = "pipelineId", description = "PipelineId for which you need planning unit to save for"), + @Parameter(name = "realmCountryId", description = "realmCountryId for which you need planning unit to save for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping(path = "/realmCountryPlanningUnit/{pipelineId}/{realmCountryId}") + public ResponseEntity createRealmCountryPlanningUnits(@PathVariable("pipelineId") int pipelineId, @PathVariable("realmCountryId") int realmCountryId, Authentication auth) { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); try { this.pipelineDbService.createRealmCountryPlanningUnits(pipelineId, curUser, realmCountryId); diff --git a/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java index 9e87e45cf..6d3394632 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/PlanningUnitRestController.java @@ -183,7 +183,7 @@ public ResponseEntity getPlanningUnitForRealm(@PathVariable(value = "realmId", r } /** - * API used to get the PlanningUnit list for a Realm + * API used to get the complete PlanningUnit list for a Realm * * @param realmId RealmId that you want the PlanningUnit List from * @param auth @@ -216,8 +216,8 @@ public ResponseEntity getPlanningUnitForRealmAll(@PathVariable(value = "realmId" /** * API used to get the PlanningUnit for a specific PlanningUnitId * - * @param planningUnitId PlanningUnit that you want the PlanningUnit Object - * for + * @param planningUnitId PlanningUnitId that you want the PlanningUnit + * Object for * @param auth * @return returns the PlanningUnit object based on PlanningUnitId specified */ @@ -225,8 +225,8 @@ public ResponseEntity getPlanningUnitForRealmAll(@PathVariable(value = "realmId" @Operation(description = "API used to get the PlanningUnit for a specific PlanningUnitId", summary = "Get PlanningUnit for a PlanningUnitId", tags = ("planningUnit")) @Parameters( @Parameter(name = "planningUnitId", description = "PlanningUnitId that you want to the PlanningUnit for")) - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the HealthAreaId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit object") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitId specified does not exist") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit") public ResponseEntity getPlanningUnitById(@PathVariable("planningUnitId") int planningUnitId, Authentication auth) { try { @@ -488,7 +488,7 @@ public ResponseEntity savePlanningUnitCapacity(@RequestBody PlanningUnitCapacity // } // } /** - * API used to get the PlanningUnit list for a ProductCategory + * API used to get the PlanningUnit list for a specified ProductCategory * * @param productCategoryId productCategoryId that you want the PlanningUnit * List for @@ -552,7 +552,22 @@ public ResponseEntity getPlanningUnitForproductCategory(@PathVariable(value = "p } } - @PostMapping("/planningUnit/productCategoryList/active") + /** + * API used to get the list of active PlanningUnits for a ProductCategory + * + * @param productCategoryIds array of productCategoryIds that you want the + * PlanningUnit List for + * @param auth + * @return returns the list of active PlanningUnits + */ + @Operation(description = "API used to get the list of active PlanningUnits for a ProductCategory", summary = "Get active PlanningUnit list for ProductCategory", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "productCategoryId", description = "array of productCategoryIds that you want the PlanningUnit")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the productCategoryId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") + @PostMapping("/productCategoryList/active") @JsonView(Views.ReportView.class) public ResponseEntity getPlanningUnitForproductCategoryList(@RequestBody String[] productCategoryIds, Authentication auth) { try { @@ -588,8 +603,24 @@ public ResponseEntity getPlanningUnitByTracerCategory(@PathVariable("planningUni } } + /** + * API used to get the list of active PlanningUnits for a tracerCategory and + * a program + * + * @param programAndTracerCategory object containing array of tracerCategory + * and program that you want the PlanningUnit List for + * @param auth + * @return returns the list of active PlanningUnits + */ + @Operation(description = "API used to get the list of active PlanningUnits for a tracerCategory and a program", summary = "Get active PlanningUnit list for a TracerCategory and a Program", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "programAndTracerCategory", description = "object containing array of tracerCategory and program that you want the PlanningUnit List for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the tracerCategories and programs specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") @JsonView(Views.ReportView.class) - @PostMapping("/planningUnit/tracerCategory/program/") + @PostMapping("/tracerCategory/program/") public ResponseEntity getPlanningUnitByTracerCategoryAndProgram(@RequestBody ProgramAndTracerCategoryDTO programAndTracerCategory, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -606,7 +637,22 @@ public ResponseEntity getPlanningUnitByTracerCategoryAndProgram(@RequestBody Pro } } - @GetMapping("/planningUnit/realmCountry/{realmCountryId}") + /** + * API used to get the list of active PlanningUnits for a realm country + * + * @param realmCountryId realmCountryId that you want the PlanningUnit List + * for + * @param auth + * @return returns the list of active PlanningUnits + */ + @Operation(description = "API used to get the list of active PlanningUnits for a realm country", summary = "Get active PlanningUnit list for a realm country", tags = ("planningUnit")) + @Parameters( + @Parameter(name = "realmCountryId", description = "realmCountryId that you want the PlanningUnit List for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the tracerCategories and programs specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") + @GetMapping("/realmCountry/{realmCountryId}") public ResponseEntity getPlanningUnitByRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProblemRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProblemRestController.java index adcc41869..6b1ed4579 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProblemRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProblemRestController.java @@ -9,6 +9,11 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.ProblemService; import cc.altius.FASP.service.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.io.Serializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,16 +33,30 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/problem") public class ProblemRestController implements Serializable { - + private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private ProblemService problemService; @Autowired private UserService userService; - - @GetMapping("/problem/realmId/{realmId}") + + /** + * API used to get the list of active problem list for a realm + * + * @param realmId realmId that you want the problem list for + * @param auth + * @return returns the list of active problem list + */ + @Operation(description = "API used to get the list of active problem list for a realm", summary = "Get active Problem list for a realm country", tags = ("problem")) + @Parameters( + @Parameter(name = "realmId", description = "realmId that you want the problem list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active Problem list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the realmId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Problem list") + @GetMapping("/realmId/{realmId}") public ResponseEntity getProblmeByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -53,7 +72,24 @@ public ResponseEntity getProblmeByRealmId(@PathVariable("realmId") int realmId, return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + + /** + * API used to get the list of active problem report list for a programId + * and versionId + * + * @param programId programId that you want the problem report list for + * @param versionId versionId that you want the problem report list for + * @param auth + * @return returns the list of active problem report list + */ + @Operation(description = "API used to get the list of active problem report list for a programId and versionId", summary = "Get active Problem Report list for a program and version", tags = ("problem")) + @Parameters({ + @Parameter(name = "programId", description = "programId that you want the problem report list for"), + @Parameter(name = "versionId", description = "versionId that you want the problem report list for")}) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the active Problem report list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the programId and versionId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Problem report list") @GetMapping("/problemReport/programId/{programId}/versionId/{versionId}") public ResponseEntity getProblmeReport(@PathVariable("programId") int programId, @PathVariable("versionId") int versionId, Authentication auth) { try { @@ -70,7 +106,7 @@ public ResponseEntity getProblmeReport(@PathVariable("programId") int programId, return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + // @GetMapping(value = "/sync/problem/lastSyncDate/{lastSyncDate}") // public ResponseEntity getProblemListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { @@ -118,7 +154,15 @@ public ResponseEntity getProblmeReport(@PathVariable("programId") int programId, // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - + /** + * API used to get the complete list of problem status + * + * @param auth + * @return returns the list of complete list of problem status + */ + @Operation(description = "API used to get the complete list of problem status", summary = "Get Problem Status list", tags = ("problem")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Problem Status list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Problem status list") @GetMapping(value = "/problemStatus") public ResponseEntity getProblemStatusList(Authentication auth) { try { @@ -129,5 +173,5 @@ public ResponseEntity getProblemStatusList(Authentication auth) { return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java index a5c3e31ec..3dabd70b4 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProcurementAgentRestController.java @@ -50,13 +50,13 @@ public class ProcurementAgentRestController { private UserService userService; /** - * API used to get the complete ProcurementAgent list. + * API used to get the complete list of ProcurementAgent. * * @param auth * @return returns the complete list of ProcurementAgents */ @GetMapping("/") - @Operation(description = "API used to get the complete ProcurementAgent list.", summary = "Get ProcurementAgent list", tags = ("procurementAgent")) + @Operation(description = "API used to get the complete list of ProcurementAgent.", summary = "Get Complete ProcurementAgent list", tags = ("procurementAgent")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") public ResponseEntity getProcurementAgent(Authentication auth) { @@ -75,8 +75,8 @@ public ResponseEntity getProcurementAgent(Authentication auth) { * @param procurementAgentId ProcurementAgentId that you want the * ProcurementAgent Object for * @param auth - * @return returns the list the ProcurementAgent object based on - * ProcurementAgentId specified + * @return returns the ProcurementAgent object based on ProcurementAgentId + * specified */ @GetMapping(value = "/{procurementAgentId}") @Operation(description = "API used to get the ProcurementAgent for a specific ProcurementAgentId", summary = "Get ProcurementAgent for a ProcurementAgentId", tags = ("procurementAgent")) @@ -103,12 +103,12 @@ public ResponseEntity getProcurementAgent(@PathVariable("procurementAgentId") in * ProcurementAgent and the Realm * * @param realmId RealmId that you want the ProcurementAgent from - * @param name Display name of the Funding source you want to get + * @param name Display name of the ProcurementAgent you want to get * @param auth - * @return returns the complete list of ProcurementAgents + * @return returns the ProcurementAgent */ @GetMapping("/getDisplayName/realmId/{realmId}/name/{name}") - @Operation(description = "API used to get the complete ProcurementAgent by providing the display name of the ProcurementAgent and the Realm", summary = "Get ProcurementAgent by display name", tags = ("procurementAgent")) + @Operation(description = "API used to get the ProcurementAgent by providing the display name of the ProcurementAgent and the Realm", summary = "Get ProcurementAgent by display name", tags = ("procurementAgent")) @Parameters({ @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementAgent for"), @Parameter(name = "name", description = "Display name that you want to the ProcurementAgent for")}) @@ -132,7 +132,7 @@ public ResponseEntity getProcurementAgentDisplayName(@PathVariable("realmId") in * @return returns the complete list of ProcurementAgents */ @GetMapping("/realmId/{realmId}") - @Operation(description = "API used to get the complete ProcurementAgent list for a Realm", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Operation(description = "API used to get the ProcurementAgent list for a Realm", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) @Parameters( @Parameter(name = "realmId", description = "RealmId that you want to the ProcurementAgent for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgent list") @@ -192,7 +192,6 @@ public ResponseEntity addProcurementAgent(@RequestBody ProcurementAgent procurem } - /** * API used to update a ProcurementAgent * @@ -228,15 +227,15 @@ public ResponseEntity updateProcurementAgent(@RequestBody ProcurementAgent procu /** * API used to save the ProcurementAgentPlanningUnits list * - * @param procurementAgentPlanningUnits ProcurementAgentPlanningUnits list - * that you want to save + * @param procurementAgentPlanningUnits array of + * ProcurementAgentPlanningUnits that you want to save * @param auth * @return returns a Success code if the operation was successful */ @PutMapping("/planningingUnit") @Operation(description = "API used to save the ProcurementAgentPlanningUnits list", summary = "Update ProcurementAgent PlanningUnits", tags = ("procurementAgent")) @Parameters( - @Parameter(name = "procurementAgentPlanningUnits", description = "The list of ProcurementAgentPlanningUnits that you want to save")) + @Parameter(name = "procurementAgentPlanningUnits", description = "Array of ProcurementAgentPlanningUnits that you want to save")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @@ -250,7 +249,6 @@ public ResponseEntity savePlanningUnitForProcurementAgent(@RequestBody Procureme logger.error("Error while trying to update PlanningUnit for Program", e); return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.FORBIDDEN); } catch (Exception e) { - e.printStackTrace(); logger.error("Error while trying to update PlanningUnit for Program", e); return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -267,13 +265,13 @@ public ResponseEntity savePlanningUnitForProcurementAgent(@RequestBody Procureme * specified. Will only return those PlanningUnits that are marked active. */ @GetMapping("/{procurementAgentId}/planningUnit") - @Operation(description = "API used to get the ProcurementAgent Planning Unit list for a Procurement Agent. Will only return those PlanningUnits that are marked active.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Operation(description = "API used to get the ProcurementAgent Planning Unit list for a Procurement Agent. Will only return those PlanningUnits that are marked active.", summary = "Get ProcurementAgent Planning Unit list for a Procurement Agent", tags = ("procurementAgent")) @Parameters( @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the procurementAgentId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent Planning Unit list") public ResponseEntity getProcurementAgentPlanningUnitList(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -288,8 +286,8 @@ public ResponseEntity getProcurementAgentPlanningUnitList(@PathVariable("procure } /** - * API used to get the ProcurementAgent Planning Unit list for a Procurement - * Agent. + * API used to get the complete ProcurementAgent Planning Unit list for a + * Procurement Agent. * * @param procurementAgentId ProcurementAgentId that you want the * PlanningUnit List for @@ -298,13 +296,13 @@ public ResponseEntity getProcurementAgentPlanningUnitList(@PathVariable("procure * specified. */ @GetMapping("/{procurementAgentId}/planningUnit/all") - @Operation(description = "API used to get the ProcurementAgent Planning Unit list for a Procurement Agent.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Operation(description = "API used to get the complete ProcurementAgent Planning Unit list for a Procurement Agent.", summary = "Get Complete ProcurementAgent Planning Unit list for a Procurement Agent", tags = ("procurementAgent")) @Parameters( @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProcurementAgentId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent Planning Unit list") public ResponseEntity getProcurementAgentPlanningUnitListAll(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -321,15 +319,15 @@ public ResponseEntity getProcurementAgentPlanningUnitListAll(@PathVariable("proc /** * API used to save the ProcurementAgentProcurementUnits list * - * @param procurementAgentProcurementUnits ProcurementAgentProcurementUnits - * list that you want to save + * @param procurementAgentProcurementUnits Array of + * ProcurementAgentProcurementUnits that you want to save * @param auth * @return returns a Success code if the operation was successful */ @PutMapping("/procurementUnit") @Operation(description = "API used to save the ProcurementAgentProcurementUnits list", summary = "Update ProcurementAgent ProcurementUnits", tags = ("procurementAgent")) @Parameters( - @Parameter(name = "procurementAgentProcurementUnits", description = "The list of ProcurementAgentProcurementUnits that you want to save")) + @Parameter(name = "procurementAgentProcurementUnits", description = "Array of ProcurementAgentProcurementUnits that you want to save")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") @@ -353,20 +351,20 @@ public ResponseEntity saveProcurementUnitForProcurementAgent(@RequestBody Procur * marked active. * * @param procurementAgentId ProcurementAgentId that you want the - * PlanningUnit List for + * Procurement Unit List for * @param auth * @return returns the list of ProcurementUnits for the ProcurementAgent * specified. Will only return those ProcurementUnits that are marked * active. */ @GetMapping("/{procurementAgentId}/procurementUnit") - @Operation(description = "API used to get the ProcurementAgent ProcurementUnit list for a Procurement Agent. Will only return those ProcurementUnits that are marked active.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Operation(description = "API used to get the ProcurementAgent ProcurementUnit list for a Procurement Agent. Will only return those ProcurementUnits that are marked active.", summary = "Get ProcurementAgent Procurement Unit list for a Procurement Agent.", tags = ("procurementAgent")) @Parameters( - @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the Procurement Unit list for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the procurementAgentId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent Procurement Unit list") public ResponseEntity getProcurementAgentProcurementUnitList(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -381,23 +379,23 @@ public ResponseEntity getProcurementAgentProcurementUnitList(@PathVariable("proc } /** - * API used to get the ProcurementAgent Procurement Unit list for a + * API used to get the complete ProcurementAgent Procurement Unit list for a * Procurement Agent. * * @param procurementAgentId ProcurementAgentId that you want the - * PlanningUnit List for + * Procurement unit List for * @param auth - * @return returns the list of ProcurementUnits for the ProcurementAgent - * specified. + * @return returns the complete list of ProcurementUnits for the + * ProcurementAgent specified. */ @GetMapping("/{procurementAgentId}/procurementUnit/all") - @Operation(description = "API used to get the ProcurementAgent ProcurementUnit list for a Procurement Agent.", summary = "Get ProcurementAgent list for Realm", tags = ("procurementAgent")) + @Operation(description = "API used to get the complete ProcurementAgent ProcurementUnit list for a Procurement Agent.", summary = "Get Complete ProcurementAgent Procurement Unit list for a Procurement Agent", tags = ("procurementAgent")) @Parameters( - @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the PlanningUnit list for")) + @Parameter(name = "procurementAgentId", description = "ProcurementAgentId that you want to the Procurement unit list for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnit list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") - @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgent list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the ProcurementAgentId specified does not exist") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Procurement Unit list") public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("procurementAgentId") int procurementAgentId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -411,7 +409,6 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p } } - // @GetMapping(value = "/sync/procurementAgent/planningUnit/{lastSyncDate}") // public ResponseEntity getProcurementAgentPlanningUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { @@ -427,7 +424,6 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - // @GetMapping(value = "/sync/procurementAgent/procurementUnit/{lastSyncDate}") // public ResponseEntity getProcurementAgentProcurementUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { @@ -443,7 +439,6 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - // @GetMapping("/procurementAgent/getDisplayName/realmId/{realmId}/name/{name}") // public ResponseEntity getProcurementAgentDisplayName(@PathVariable("realmId") int realmId, @PathVariable("name") String name, Authentication auth) { // try { @@ -454,7 +449,6 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - // @GetMapping(value = "/sync/procurementAgent/{lastSyncDate}") // public ResponseEntity getProcurementAgentListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { @@ -470,7 +464,6 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - // @GetMapping(value = "/sync/procurementAgent/planningUnit/{lastSyncDate}") // public ResponseEntity getProcurementAgentPlanningUnitListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { @@ -518,5 +511,4 @@ public ResponseEntity getProcurementAgentProcurementUnitListAll(@PathVariable("p // return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.INTERNAL_SERVER_ERROR); // } // } - } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java index 57f8ff929..aaa171e76 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProcurementUnitRestController.java @@ -185,7 +185,8 @@ public ResponseEntity getProcurementUnitForRealmAll(@PathVariable(value = "realm * API used to get the ProcurementUnit for a specific PlanningUnitId. Will * only return those ProcurementUnits that are marked active * - * @param realmId PlanningUnitId that you want the ProcurementUnit List for + * @param planningUnitId PlanningUnitId that you want the ProcurementUnit + * List for * @param auth * @return returns the list the ProcurementUnit list based on PlanningUnitId * specified. Will only return those ProcurementUnits that are marked active @@ -193,7 +194,7 @@ public ResponseEntity getProcurementUnitForRealmAll(@PathVariable(value = "realm @GetMapping("/planningUnitId/{planningUnitId}") @Operation(description = "API used to get all the ProcurementUnits for a specific PlanningUnitId. Will only return those ProcurementUnits that are marked active", summary = "Get ProcurementUnit for a PlanningUnitId", tags = ("procurementUnit")) @Parameters( - @Parameter(name = "realmId", description = "PlanningUnitId that you want to the ProcurementUnit for")) + @Parameter(name = "planningUnitId", description = "PlanningUnitId that you want to the ProcurementUnit for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitId specified does not exist") @@ -214,7 +215,8 @@ public ResponseEntity getProcurementUnitForPlanningUnit(@PathVariable(value = "p /** * API used to get the ProcurementUnits for a specific PlanningUnitId. * - * @param realmId PlanningUnitId that you want the ProcurementUnit list for + * @param planningUnitId PlanningUnitId that you want the ProcurementUnit + * list for * @param auth * @return returns the list the ProcurementUnit list based on PlanningUnitId * specified. @@ -222,7 +224,7 @@ public ResponseEntity getProcurementUnitForPlanningUnit(@PathVariable(value = "p @GetMapping("/planningUnitId/{planningUnitId}/all") @Operation(description = "API used to get all the ProcurementUnits for a specific PlanningUnitId.", summary = "Get ProcurementUnit for a PlanningUnitId", tags = ("procurementUnit")) @Parameters( - @Parameter(name = "realmId", description = "PlanningUnitId that you want to the ProcurementUnit for")) + @Parameter(name = "planningUnitId", description = "PlanningUnitId that you want to the ProcurementUnit for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementUnits list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the PlanningUnitId specified does not exist") diff --git a/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java index fa648555a..4cc74c91f 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ProgramDataRestController.java @@ -45,7 +45,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/programData") public class ProgramDataRestController { private final Logger logger = LoggerFactory.getLogger(ProgramDataRestController.class); @@ -75,7 +75,7 @@ public class ProgramDataRestController { * VersionId */ @JsonView(Views.InternalView.class) - @GetMapping("/programData/programId/{programId}/versionId/{versionId}") + @GetMapping("/programId/{programId}/versionId/{versionId}") @Operation(description = "API used to get ProgramData for ProgramId and VersionId", summary = "Get ProgramData for a ProgramId and VersionId", tags = ("programData")) @Parameters({ @Parameter(name = "programId", description = "programId that you want to the ProgramData for"), @@ -87,7 +87,7 @@ public class ProgramDataRestController { public ResponseEntity getProgramData(@PathVariable(value = "programId", required = true) int programId, @PathVariable(value = "versionId", required = true) int versionId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.programDataService.getProgramData(programId, versionId, curUser,false), HttpStatus.OK); + return new ResponseEntity(this.programDataService.getProgramData(programId, versionId, curUser, false), HttpStatus.OK); } catch (EmptyResultDataAccessException e) { logger.error("Error while trying to get ProgramData", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); @@ -110,7 +110,7 @@ public ResponseEntity getProgramData(@PathVariable(value = "programId", required * VersionId */ @JsonView(Views.InternalView.class) - @PostMapping("/programData") + @PostMapping("/") @Operation(description = "API used to get ProgramData list for listed ProgramIds and VersionIds", summary = "Get ProgramData list for listed ProgramIds and VersionIds", tags = ("programData")) @Parameters( @Parameter(name = "programVersionList", description = "programVersionList list of ProgramIds and VersionIds that you want a ProgramData list for")) @@ -144,7 +144,7 @@ public ResponseEntity getLoadProgramData(@RequestBody List realmCountryList, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -66,7 +83,21 @@ public ResponseEntity postRealmCountry(@RequestBody List realmCoun } } - @PutMapping(path = "/realmCountry") + /** + * API used to update a RealmCountry + * + * @param realmCountryList List of RealmCountry that you want to update + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to update a RealmCountry", summary = "Update RealmCountry", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmCountryList", description = "List of RealmCountry that you want to update")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "406", description = "Returns a HttpStatus.NOT_ACCEPTABLE if the RealmCountry supplied is not unique") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping(path = "/") public ResponseEntity putRealmCountry(@RequestBody List realmCountryList, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -84,7 +115,19 @@ public ResponseEntity putRealmCountry(@RequestBody List realmCount } } - @GetMapping("/realmCountry") + /** + * API used to get the complete RealmCountry list. Will only return those + * RealmCountries that are marked Active. + * + * @param auth + * @return returns the complete list of active RealmCountries + */ + @Operation(description = "API used to get the complete RealmCountry list. Will only return those RealmCountries that are marked Active.", summary = "Get active RealmCountry list", tags = ("realmCountry")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountry list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no RealmCountry found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountry list") + @GetMapping("/") public ResponseEntity getRealmCountry(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -101,7 +144,21 @@ public ResponseEntity getRealmCountry(Authentication auth) { } } - @GetMapping("/realmCountry/{realmCountryId}") + /** + * API used to get the RealmCountry for a specific RealmCountryId + * + * @param realmCountryId realmCountryId that you want RealmCountry for + * @param auth + * @return returns the RealmCountry object based on RealmCountryId specified + */ + @Operation(description = "API used to get the RealmCountry for a specific RealmCountryId", summary = "Get RealmCountry for a specific RealmCountryId", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want RealmCountry for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountry object") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no RealmCountryId found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountry object") + @GetMapping("/{realmCountryId}") public ResponseEntity getRealmCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -118,7 +175,21 @@ public ResponseEntity getRealmCountry(@PathVariable("realmCountryId") int realmC } } - @GetMapping("/realmCountry/realmId/{realmId}") + /** + * API used to get the RealmCountry list for a specific realmId + * + * @param realmId realmId that you want RealmCountry list for + * @param auth + * @return returns the RealmCountry list based on realmId specified + */ + @Operation(description = "API used to get the RealmCountry list for a specific realmId", summary = "Get RealmCountry list for a specific realmId", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want RealmCountry list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountry list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no realmId found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountry list") + @GetMapping("/realmId/{realmId}") public ResponseEntity getRealmCountryByRealmId(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -135,11 +206,26 @@ public ResponseEntity getRealmCountryByRealmId(@PathVariable("realmId") int real } } - @GetMapping("/realmCountry/{realmCountryId}/planningUnit") + /** + * API used to get the active PlanningUnit list for a specific + * realmCountryId + * + * @param realmCountryId realmCountryId that you want PlanningUnit list for + * @param auth + * @return returns the PlanningUnit list based on realmCountryId specified + */ + @Operation(description = "API used to get the active PlanningUnit list for a specific realmCountryId", summary = "Get PlanningUnit list for a specific realmCountryId", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no realmCountryId found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") + @GetMapping("/{realmCountryId}/planningUnit") public ResponseEntity getPlanningUnitForCountry(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); - return new ResponseEntity(this.realmCountryService.getPlanningUnitListForRealmCountryId(realmCountryId, false, curUser), HttpStatus.OK); + return new ResponseEntity(this.realmCountryService.getPlanningUnitListForRealmCountryId(realmCountryId, true, curUser), HttpStatus.OK); } catch (EmptyResultDataAccessException e) { logger.error("Error while trying to list PlanningUnit for Country", e); return new ResponseEntity(new ResponseCode("static.message.listFailed"), HttpStatus.NOT_FOUND); @@ -152,7 +238,24 @@ public ResponseEntity getPlanningUnitForCountry(@PathVariable("realmCountryId") } } - @PutMapping("/realmCountry/programIds/planningUnit") + /** + * API used to get the RealmCountryPlanningUnit list for a specific + * programIds + * + * @param programIds Array of programIds that you want + * RealmCountryPlanningUnit list for + * @param auth + * @return returns the RealmCountryPlanningUnit list based on programIds + * specified + */ + @Operation(description = "API used to get RealmCountryPlanningUnit list for a specific programIds", summary = "Get RealmCountryPlanningUnit list for a specific programIds", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "programIds", description = "Array of programIds that you want RealmCountryPlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountryPlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no programIds found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountryPlanningUnit list") + @PutMapping("/programIds/planningUnit") public ResponseEntity getPlanningUnitForProgramList(@RequestBody String[] programIds, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -169,7 +272,23 @@ public ResponseEntity getPlanningUnitForProgramList(@RequestBody String[] progra } } - @GetMapping("/realmCountry/{realmCountryId}/planningUnit/all") + /** + * API used to get the complete PlanningUnit list for a specific + * realmCountryId + * + * @param realmCountryId realmCountryId that you want PlanningUnit list for + * @param auth + * @return returns the complete PlanningUnit list based on realmCountryId + * specified + */ + @Operation(description = "API used to get the complete PlanningUnit list for a specific realmCountryId", summary = "Get Complete PlanningUnit list for a specific realmCountryId", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmCountryId", description = "RealmCountryId that you want PlanningUnit list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the PlanningUnit list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no realmCountryId found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of PlanningUnit list") + @GetMapping("/{realmCountryId}/planningUnit/all") public ResponseEntity getPlanningUnitForCountryAll(@PathVariable("realmCountryId") int realmCountryId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -186,7 +305,21 @@ public ResponseEntity getPlanningUnitForCountryAll(@PathVariable("realmCountryId } } - @PutMapping("/realmCountry/planningUnit") + /** + * API used to save PlanningUnit for RealmCountry + * + * @param realmCountryPlanningUnits Array of realmCountryPlanningUnits that + * you want to save + * @param auth + * @return returns a Success code if the operation was successful + */ + @Operation(description = "API used to save PlanningUnit for RealmCountry", summary = "Save PlanningUnit for RealmCountry", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmCountryPlanningUnits", description = "Array of realmCountryPlanningUnits that you want to save")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns a Success code if the operation was successful") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Returns a HttpStatus.INTERNAL_SERVER_ERROR if there was some other error that did not allow the operation to complete") + @PutMapping("/planningUnit") public ResponseEntity savePlanningUnitForCountry(@RequestBody RealmCountryPlanningUnit[] realmCountryPlanningUnits, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -201,7 +334,22 @@ public ResponseEntity savePlanningUnitForCountry(@RequestBody RealmCountryPlanni } } - @GetMapping("/realmCountry/program/realmId/{realmId}") + /** + * API used to get the RealmCountry list by specified reamId for active + * programs + * + * @param realmId realmId that you want RealmCountry list for + * @param auth + * @return returns the RealmCountry list by reamId for active programs + */ + @Operation(description = "API used to get the RealmCountry list by specified reamId for active programs", summary = "Get RealmCountry list by specified reamId for active programs", tags = ("realmCountry")) + @Parameters( + @Parameter(name = "realmId", description = "RealmId that you want RealmCountry list for")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountry list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no realmId found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountry list") + @GetMapping("/program/realmId/{realmId}") public ResponseEntity getRealmCountryByRealmIdForActivePrograms(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -218,7 +366,19 @@ public ResponseEntity getRealmCountryByRealmIdForActivePrograms(@PathVariable("r } } - @GetMapping("/realmCountry/program") + /** + * API used to get the RealmCountry list active programs + * + * @param auth + * @return returns the RealmCountry list active programs + */ + @Operation(description = "API used to get the RealmCountry list active programs", summary = "Get the RealmCountry list active programs", tags = ("realmCountry")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the RealmCountry list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "412", description = "Returns a HttpStatus.PRECONDITION_FAILED if a User with access to multiple Realms tried to access a RealmCountry Program list without specifying a Realm") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if no RealmCountry found") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of RealmCountry list") + @GetMapping("/program") public ResponseEntity getRealmCountryForActivePrograms(Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); diff --git a/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java b/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java index c41184486..e6e6f8a88 100755 --- a/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/RealmRestController.java @@ -70,11 +70,9 @@ public ResponseEntity getRealm(Authentication auth) { /** * API used to get the Realm for a specific RealmId * - * @param realmId RealmId that you want the Realm - * Object for + * @param realmId RealmId that you want the Realm Object for * @param auth - * @return returns the Realm object based on - * RealmId specified + * @return returns the Realm object based on RealmId specified */ @GetMapping(value = "/{realmId}") @Operation(description = "API used to get the Realm for a specific RealmId", summary = "Get Realm for a RealmId", tags = ("realm")) @@ -84,7 +82,7 @@ public ResponseEntity getRealm(Authentication auth) { @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "403", description = "Returns a HttpStatus.FORBIDDEN if the User does not have access") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "404", description = "Returns a HttpStatus.NOT_FOUND if the RealmId specified does not exist") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Realm") - + public ResponseEntity getRealmById(@PathVariable("realmId") int realmId, Authentication auth) { try { CustomUserDetails curUser = this.userService.getCustomUserByUserId(((CustomUserDetails) auth.getPrincipal()).getUserId()); @@ -101,7 +99,6 @@ public ResponseEntity getRealmById(@PathVariable("realmId") int realmId, Authent } } - /** * API used to add a Realm * @@ -162,7 +159,6 @@ public ResponseEntity updateRealm(@RequestBody Realm realm, Authentication auth) } } - // @GetMapping(value = "/sync/realm/{lastSyncDate}") // public ResponseEntity getRealmListForSync(@PathVariable("lastSyncDate") String lastSyncDate, Authentication auth) { // try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java index b7ada2707..8f09b6b5f 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ReportRestController.java @@ -38,6 +38,9 @@ import cc.altius.FASP.service.ReportService; import cc.altius.FASP.service.UserService; import com.fasterxml.jackson.annotation.JsonView; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.util.LinkedList; import java.util.List; import org.slf4j.Logger; @@ -58,7 +61,7 @@ * @author ekta */ @RestController -@RequestMapping("/api/report/") +@RequestMapping("/api/report") public class ReportRestController { @Autowired @@ -73,6 +76,7 @@ public class ReportRestController { // Report no 1 // Reports -> Program Catalog /** + * API used to get list of ProgramProductCatalogOutput *
      * Sample JSON {"productCategoryId": -1, "tracerCategoryId": -1, "programId": 2028 }
      * -- Program Id must be a valid Program Id, cannot be -1 (Any)      *
@@ -80,10 +84,13 @@ public class ReportRestController {
      * -- Return the list of Program-Planning Units and their corresponding fields
      * 
* - * @param ProgramProductCatalogInput + * @param ppc ProgramProductCatalogInput object * @param auth Authentication object from JWT - * @return ProgramProductCatalogOutput + * @return list of ProgramProductCatalogOutput */ + @Operation(description = "API used to get the ProgramProductCatalogOutput list.", summary = "get the ProgramProductCatalogOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProgramProductCatalogOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProgramProductCatalogOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/programProductCatalog") public ResponseEntity getProgramProductCatalog(@RequestBody ProgramProductCatalogInput ppc, Authentication auth) { @@ -99,6 +106,7 @@ public ResponseEntity getProgramProductCatalog(@RequestBody ProgramProductCatalo // Report no 2 // Reports -> Consumption Reports -> Consumption (Forecast vs Actual) /** + * API used to get list of ConsumptionForecastVsActualOutput *
      * Sample JSON
      * {"programId":2535, "versionId":1, "startDate":"2019-01-01", "stopDate":"2019-12-01", "planningUnitId":778, "reportView":1}
@@ -110,10 +118,13 @@ public ResponseEntity getProgramProductCatalog(@RequestBody ProgramProductCatalo
      * -- reportView = 2 - Data is reported in terms of Forecasting Unit
      * 
* - * @param ConsumptionForecastVsActualInput + * @param ppc ConsumptionForecastVsActualInput object * @param auth Authentication object from JWT - * @return ConsumptionForecastVsActualOutput + * @return list of ConsumptionForecastVsActualOutput */ + @Operation(description = "API used to get the ConsumptionForecastVsActualOutput list.", summary = "get the ConsumptionForecastVsActualOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ConsumptionForecastVsActualOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ConsumptionForecastVsActualOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/consumptionForecastVsActual") public ResponseEntity getConsumptionForecastVsActual(@RequestBody ConsumptionForecastVsActualInput ppc, Authentication auth) { @@ -130,6 +141,7 @@ public ResponseEntity getConsumptionForecastVsActual(@RequestBody ConsumptionFor // Reports -> Consumption Reports -> Consumption (Global) // Global Report /** + * API used to get list of GlobalConsumptionOutput *
      * Sample JSON
      * { "realmId": 1, "realmCountryIds": [5,51], "programIds": [2028,2029,2535], "planningUnitIds": [778,2692], "startDate": "2019-01-01", "stopDate": "2019-12-01", "reportView": 1, "useApprovedSupplyPlanOnly":0}
@@ -142,10 +154,13 @@ public ResponseEntity getConsumptionForecastVsActual(@RequestBody ConsumptionFor
      * -- reportView = 2 shows the Consumption in ForecastingUnits
      * 
* - * @param gci + * @param gci GlobalConsumptionInput object * @param auth - * @return + * @return list of GlobalConsumptionOutput */ + @Operation(description = "API used to get the GlobalConsumptionOutput list.", summary = "get the GlobalConsumptionOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the GlobalConsumptionOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of GlobalConsumptionOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/globalConsumption") public ResponseEntity getGlobalConsumption(@RequestBody GlobalConsumptionInput gci, Authentication auth) { @@ -161,6 +176,7 @@ public ResponseEntity getGlobalConsumption(@RequestBody GlobalConsumptionInput g // Report no 4 // Reports -> Consumption Reports -> Forecast Error (Monthly) /** + * API used to get list of ForecastMetricsMonthlyOutput *
      * Sample JSON
      * { "programId": 2003, "versionId":2, "planningUnitId": 772, "startDate": "2020-01-01", "stopDate": "2020-05-01", "previousMonths": 6}
@@ -175,10 +191,13 @@ public ResponseEntity getGlobalConsumption(@RequestBody GlobalConsumptionInput g
      * *
      * 
* - * @param fmi + * @param fmi ForecastMetricsMonthlyInput object * @param auth - * @return + * @return list of ForecastMetricsMonthlyOutput */ + @Operation(description = "API used to get the ForecastMetricsMonthlyOutput list.", summary = "get the ForecastMetricsMonthlyOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastMetricsMonthlyOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastMetricsMonthlyOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/forecastMetricsMonthly") public ResponseEntity getForecastMetricsMonthly(@RequestBody ForecastMetricsMonthlyInput fmi, Authentication auth) { @@ -195,6 +214,7 @@ public ResponseEntity getForecastMetricsMonthly(@RequestBody ForecastMetricsMont // Global Report // Reports -> Consumption Reports -> Forecast Error (by Planning Unit) /** + * API used to get list of ForecastMetricsComparisionOutput *
      * Sample JSON
      * { "realmId":1, "realmCountryIds":[2,5], "programIds":[2029,2521,2140], "tracerCategoryIds":[6,7],"planningUnitIds":[], "startDate":"2020-10-01", "previousMonths":3}
@@ -210,10 +230,13 @@ public ResponseEntity getForecastMetricsMonthly(@RequestBody ForecastMetricsMont
      * -- ((Abs(actual consumption month 1-forecasted consumption month 1)+ Abs(actual consumption month 2-forecasted consumption month 2)+ Abs(actual consumption month 3-forecasted consumption month 3)+ Abs(actual consumption month 4-forecasted consumption month 4)+ Abs(actual consumption month 5-forecasted consumption month 5)+ Abs(actual consumption month 6-forecasted consumption month 6)) / (Sum of all actual consumption in the last 6 months))
      * 
* - * @param fmi + * @param fmi ForecastMetricsComparisionInput object * @param auth - * @return + * @return list of ForecastMetricsComparisionOutput */ + @Operation(description = "API used to get the ForecastMetricsComparisionOutput list.", summary = "get the ForecastMetricsComparisionOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ForecastMetricsComparisionOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ForecastMetricsComparisionOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/forecastMetricsComparision") public ResponseEntity getForecastMetricsComparision(@RequestBody ForecastMetricsComparisionInput fmi, Authentication auth) { @@ -230,6 +253,8 @@ public ResponseEntity getForecastMetricsComparision(@RequestBody ForecastMetrics // Report no 7 // Reports -> Inventory Reports -> Warehouse Capacity (by Program) /** + * API used to get list of WarehouseCapacityOutput + * *
      * Sample JSON
      * { "realmCountryId":2, "programIds":[3]}
@@ -239,10 +264,13 @@ public ResponseEntity getForecastMetricsComparision(@RequestBody ForecastMetrics
      * -- List of all the Regions for the Programs selected and their capacity
      * 
* - * @param wci + * @param wci WarehouseCapacityInput object * @param auth - * @return + * @return list of WarehouseCapacityOutput */ + @Operation(description = "API used to get the WarehouseCapacityOutput list.", summary = "get the WarehouseCapacityOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the WarehouseCapacityOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of WarehouseCapacityOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/warehouseCapacityReport") public ResponseEntity getwarehouseCapacityReport(@RequestBody WarehouseCapacityInput wci, Authentication auth) { @@ -258,6 +286,8 @@ public ResponseEntity getwarehouseCapacityReport(@RequestBody WarehouseCapacityI //Report no // Reports -> Inventory Reports -> Warehouse Capcity (By Country) /** + * API used to get list of WarehouseByCountryOutput + * *
      * Sample JSON
      * { "realmCountryIds":[51,16,6]}
@@ -265,7 +295,14 @@ public ResponseEntity getwarehouseCapacityReport(@RequestBody WarehouseCapacityI
      * -- RealmCountryIds blank means you want to run it for all RealmCountryIds
      * -- List of all the Regions for the RealmCountryIds selected and their capacity
      * 
+ * + * @param wbc WarehouseByCountryInput object + * @param auth + * @return list of WarehouseByCountryOutput */ + @Operation(description = "API used to get the WarehouseByCountryOutput list.", summary = "get the WarehouseByCountryOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the WarehouseByCountryOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of WarehouseByCountryOutput list") @JsonView(Views.ReportView.class) @PostMapping("/warehouseByCountry") public ResponseEntity getWarehouseByCountry(@RequestBody WarehouseByCountryInput wbc, Authentication auth) { @@ -287,6 +324,8 @@ public ResponseEntity getWarehouseByCountry(@RequestBody WarehouseByCountryInput // Report no 8 // Reports -> Inventory Reports -> Cost of Inventory /** + * API used to get list of CostOfInventoryOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "dt":"2020-04-01", "includePlannedShipments":1}
@@ -299,10 +338,13 @@ public ResponseEntity getWarehouseByCountry(@RequestBody WarehouseByCountryInput
      * -- Cost = Closing inventory for that Planning Unit x Catalog Price
      * 
* - * @param cii + * @param cii CostOfInventoryInput * @param auth - * @return + * @return list of CostOfInventoryOutput */ + @Operation(description = "API used to get the CostOfInventoryOutput list.", summary = "get the CostOfInventoryOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the CostOfInventoryOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of CostOfInventoryOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/costOfInventory") public ResponseEntity getCostOfInventory(@RequestBody CostOfInventoryInput cii, Authentication auth) { @@ -318,6 +360,8 @@ public ResponseEntity getCostOfInventory(@RequestBody CostOfInventoryInput cii, // Report no 9 // Reports -> Inventory Reports -> Inventory Turns /** + * API used to get list of InventoryTurnsOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "dt":"2020-04-01", "includePlannedShipments":1}
@@ -329,10 +373,13 @@ public ResponseEntity getCostOfInventory(@RequestBody CostOfInventoryInput cii,
      * -- Inventory Turns = Total Consumption for the last 12 months (including current month) / Avg Stock during that period
      * 
* - * @param it + * @param it CostOfInventoryInput object * @param auth - * @return + * @return list of InventoryTurnsOutput */ + @Operation(description = "API used to get the InventoryTurnsOutput list.", summary = "get the InventoryTurnsOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the InventoryTurnsOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of InventoryTurnsOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/inventoryTurns") public ResponseEntity getInventoryTurns(@RequestBody CostOfInventoryInput it, Authentication auth) { @@ -348,6 +395,8 @@ public ResponseEntity getInventoryTurns(@RequestBody CostOfInventoryInput it, Au // Report no 11 // Reports -> Inventory Reports -> Expiries /** + * API used to get list of ExpiredStockOutput + * *
      * Sample JSON
      * {"programId":2535, "versionId":1, "startDt":"2017-01-01", "stopDt":"2021-12-01", "includePlannedShipments":1}
@@ -359,10 +408,13 @@ public ResponseEntity getInventoryTurns(@RequestBody CostOfInventoryInput it, Au
      * -- Include Planned Shipments = 0 means that Shipments that are in the Planned stages will not be considered in the report
      * 
* - * @param it + * @param esi ExpiredStockInput * @param auth - * @return + * @return list of ExpiredStockOutput */ + @Operation(description = "API used to get the ExpiredStockOutput list.", summary = "get the ExpiredStockOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ExpiredStockOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ExpiredStockOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/expiredStock") public ResponseEntity getExpiredStock(@RequestBody ExpiredStockInput esi, Authentication auth) { @@ -378,6 +430,8 @@ public ResponseEntity getExpiredStock(@RequestBody ExpiredStockInput esi, Authen // Report no 12 // Reports -> Inventory Reports -> Stock Adjustment /** + * API used to get list of StockAdjustmentReportOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-10-01", "planningUnitIds":[152,157]}
@@ -387,10 +441,13 @@ public ResponseEntity getExpiredStock(@RequestBody ExpiredStockInput esi, Authen
      * -- VAR_PLANNING_UNIT_IDS are the Quoted, Comma separated list of the Planning Unit Ids that you want to run the report for. If you want to run it for all Planning Units in the Program leave it empty
      * 
* - * @param si + * @param si StockAdjustmentReportInput * @param auth - * @return + * @return list of StockAdjustmentReportOutput */ + @Operation(description = "API used to get the StockAdjustmentReportOutput list.", summary = "get the StockAdjustmentReportOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockAdjustmentReportOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockAdjustmentReportOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/stockAdjustmentReport") public ResponseEntity getStockAdjustmentReport(@RequestBody StockAdjustmentReportInput si, Authentication auth) { @@ -405,6 +462,8 @@ public ResponseEntity getStockAdjustmentReport(@RequestBody StockAdjustmentRepor // Report no 13 /** + * API used to get list of ProcurementAgentShipmentReportOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-10-01", "planningUnitIds":[152,157], "includePlannedShipments":1, "procurementAgentId":1}
@@ -420,11 +479,14 @@ public ResponseEntity getStockAdjustmentReport(@RequestBody StockAdjustmentRepor
      *
      * 
* - * @param pari + * @param pari ProcurementAgentShipmentReportInput * @param auth - * @return + * @return list of ProcurementAgentShipmentReportOutput */ // Report -> Shipment Reports -> Shipment Cost Details (Procurement Agent view) + @Operation(description = "API used to get the ProcurementAgentShipmentReportOutput list.", summary = "get the ProcurementAgentShipmentReportOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProcurementAgentShipmentReportOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProcurementAgentShipmentReportOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/procurementAgentShipmentReport") public ResponseEntity getProcurementAgentShipmentReport(@RequestBody ProcurementAgentShipmentReportInput pari, Authentication auth) { @@ -440,6 +502,8 @@ public ResponseEntity getProcurementAgentShipmentReport(@RequestBody Procurement // Report no 14 // Report -> Shipment Reports -> Procurement Agent Lead Times /** + * API used to get list of ProgramLeadTimesOutput + * *
      * Sample JSON
      * {"programId":3, "procurementAgentIds":[1,3], "planningUnitIds":[157,152]}
@@ -450,8 +514,11 @@ public ResponseEntity getProcurementAgentShipmentReport(@RequestBody Procurement
      *
      * @param plt
      * @param auth
-     * @return
+     * @return list of ProgramLeadTimesOutput
      */
+    @Operation(description = "API used to get the ProgramLeadTimesOutput list.", summary = "get the ProgramLeadTimesOutput list", tags = ("report"))
+    @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ProgramLeadTimesOutput list")
+    @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ProgramLeadTimesOutput list")
     @JsonView(Views.ReportView.class)
     @PostMapping(value = "/programLeadTimes")
     public ResponseEntity getProgramLeadTimes(@RequestBody ProgramLeadTimesInput plt, Authentication auth) {
@@ -469,6 +536,8 @@ public ResponseEntity getProgramLeadTimes(@RequestBody ProgramLeadTimesInput plt
     // Report no 15
     // Report -> Shipment Reports -> Shipment Cost Details (Funding Source view)
     /**
+     * API used to get list of FundingSourceShipmentReportOutput
+     *
      * 
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-10-01", "planningUnitIds":[152,157], "includePlannedShipments":1, "fundingSourceId":3}
@@ -483,10 +552,13 @@ public ResponseEntity getProgramLeadTimes(@RequestBody ProgramLeadTimesInput plt
      * -- FreightPerc is in SUM(FREIGHT_COST)/SUM(PRODUCT_COST) for that ProcurementAgent and that PlanningUnit
      * 
* - * @param fsri + * @param fsri FundingSourceShipmentReportInput * @param auth - * @return + * @return list of FundingSourceShipmentReportOutput */ + @Operation(description = "API used to get the FundingSourceShipmentReportOutput list.", summary = "get the FundingSourceShipmentReportOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the FundingSourceShipmentReportOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of FundingSourceShipmentReportOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/fundingSourceShipmentReport") public ResponseEntity getFundingSourceShipmentReport(@RequestBody FundingSourceShipmentReportInput fsri, Authentication auth) { @@ -502,18 +574,23 @@ public ResponseEntity getFundingSourceShipmentReport(@RequestBody FundingSourceS // Report no 16 // Supply Planning -> Supply Plan Report /** + * API used to get list of StockStatusVerticalOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-07-01", "planningUnitId":152, "allPlanningUnits":true}
      * 
* - * @param ssv + * @param ssv list of StockStatusVerticalOutput * @param auth - * @return + * @return list of StockStatusVerticalOutput */ // ActualConsumption = 0 -- Forecasted Consumption // ActualConsumption = 1 -- Actual Consumption // ActualConsumption = null -- No consumption data + @Operation(description = "API used to get the StockStatusVerticalOutput list.", summary = "get the StockStatusVerticalOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockStatusVerticalOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockStatusVerticalOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/stockStatusVertical") public ResponseEntity getStockStatusVertical(@RequestBody StockStatusVerticalInput ssv, Authentication auth) { @@ -532,7 +609,7 @@ public ResponseEntity getStockStatusVertical(@RequestBody StockStatusVerticalInp } return new ResponseEntity(ssvoFullList, HttpStatus.OK); } else { - return new ResponseEntity(ssvoList, HttpStatus.OK); + return new ResponseEntity(ssvoList, HttpStatus.OK); } } catch (Exception e) { logger.error("/api/report/stockStatusVertical", e); @@ -543,6 +620,8 @@ public ResponseEntity getStockStatusVertical(@RequestBody StockStatusVerticalInp // Report no 17 // Reports -> Stock Status -> Stock Status Over Time /** + * API used to get list of StockStatusOverTimeOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-07-01", "planningUnitIds":[152,157], "mosPast":3, "mosFuture":6}
@@ -552,13 +631,16 @@ public ResponseEntity getStockStatusVertical(@RequestBody StockStatusVerticalInp
      * you give mosFuture = 6 it will take the AMC for Jan, Feb, Mar, Apr, May
      * and Jun
      *
-     * @param ssot
+     * @param ssot StockStatusOverTimeInput
      * @param auth
-     * @return
+     * @return list of StockStatusOverTimeOutput
      */
     // ActualConsumption = 0 -- Forecasted Consumption
     // ActualConsumption = 1 -- Actual Consumption
     // ActualConsumption = null -- No consumption data
+    @Operation(description = "API used to get the StockStatusOverTimeOutput list.", summary = "get the StockStatusOverTimeOutput list", tags = ("report"))
+    @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockStatusOverTimeOutput list")
+    @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockStatusOverTimeOutput list")
     @JsonView(Views.ReportView.class)
     @PostMapping(value = "/stockStatusOverTime")
     public ResponseEntity getStockStatusOverTime(@RequestBody StockStatusOverTimeInput ssot, Authentication auth) {
@@ -574,6 +656,8 @@ public ResponseEntity getStockStatusOverTime(@RequestBody StockStatusOverTimeInp
     // Report no 18
     // Reports -> Stock Status -> Stock Status Matrix
     /**
+     * API used to get list of StockStatusMatrixOutput
+     *
      * 
      * Sample JSON
      * {"programId":2030, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-07-01", "planningUnitIds":[4115], "tracerCategoryIds":[21,28], "includePlannedShipments":1}
@@ -587,10 +671,13 @@ public ResponseEntity getStockStatusOverTime(@RequestBody StockStatusOverTimeInp
      * -- Current month is always included in AMC
      * 
* - * @param ssm + * @param ssm StockStatusMatrixInput * @param auth - * @return + * @return list of StockStatusMatrixOutput */ + @Operation(description = "API used to get the StockStatusMatrixOutput list.", summary = "get the StockStatusMatrixOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockStatusMatrixOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockStatusMatrixOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/stockStatusMatrix") public ResponseEntity getStockStatusMatrix(@RequestBody StockStatusMatrixInput ssm, Authentication auth) { @@ -606,6 +693,8 @@ public ResponseEntity getStockStatusMatrix(@RequestBody StockStatusMatrixInput s // Report no 19 /** + * API used to get ShipmentDetailsOutput object + * *
      * Sample JSON
      * {    "programId": 2030,    "versionId": 9,    "startDate": "2019-10-01",    "stopDate": "2020-07-01",    "planningUnitIds": [1354],    "fundingSourceIds": [1,4],    "budgetIds": [8,9],    "reportView": 1}
@@ -617,11 +706,14 @@ public ResponseEntity getStockStatusMatrix(@RequestBody StockStatusMatrixInput s
      * -- Report view 1 = Planning Units, 2 = Forecasting Units
      * 
* - * @param sd + * @param sd ShipmentDetailsInput * @param auth - * @return + * @return ShipmentDetailsOutput object */ // Report -> Shipment Reports -> Shipment Details + @Operation(description = "API used to get the ShipmentDetailsOutput object.", summary = "get the ShipmentDetailsOutput object", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ShipmentDetailsOutput object") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ShipmentDetailsOutput object") @JsonView(Views.ReportView.class) @PostMapping(value = "/shipmentDetails") public ResponseEntity getShipmentDetails(@RequestBody ShipmentDetailsInput sd, Authentication auth) { @@ -638,15 +730,20 @@ public ResponseEntity getShipmentDetails(@RequestBody ShipmentDetailsInput sd, A // Report -> Shipment Reports -> Shipments Overview // Global Report /** + * API used to get ShipmentOverviewOutput object + * *
      * Sample JSON
      * {"curUser":20, "realmId":1,  "startDate":"2019-10-01", "stopDate":"2021-07-01", "shipmentStatusIds":[],"planningUnitIds":[], "fundingSourceIds":[], "procurementAgentIds":[], "useApprovedSupplyPlansOnly":0}
      * 
* - * @param so + * @param so ShipmentOverviewInput * @param auth - * @return + * @return ShipmentOverviewOutput object */ + @Operation(description = "API used to get the ShipmentOverviewOutput object.", summary = "get the ShipmentOverviewOutput object", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ShipmentOverviewOutput object") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ShipmentOverviewOutput object") @JsonView(Views.ReportView.class) @PostMapping(value = "/shipmentOverview") public ResponseEntity getShipmentOverview(@RequestBody ShipmentOverviewInput so, Authentication auth) { @@ -663,15 +760,20 @@ public ResponseEntity getShipmentOverview(@RequestBody ShipmentOverviewInput so, // Report -> Shipment Reports -> Shipments (Global) // Global Report /** + * API used to get ShipmentGlobalDemandOutput object + * *
      * Sample JSON
      * {"curUser": 20,"realmId": 1,"realmCountryIds": [5,51],"programIds": [2028,2029,2535],"planningUnitId": 2692,"startDate": 2019-01-01","stopDate": "2019-12-01","fundingSourceProcurementAgentIds": [],"reportView": 1,"useApprovedSupplyPlanOnly": 0,"includePlannedShipments": 1}
      * 
* - * @param sgd + * @param sgd ShipmentGlobalDemandInput * @param auth - * @return + * @return ShipmentGlobalDemandOutput object */ + @Operation(description = "API used to get the ShipmentGlobalDemandOutput object.", summary = "get the ShipmentGlobalDemandOutput object", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ShipmentGlobalDemandOutput object") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ShipmentGlobalDemandOutput object") @JsonView(Views.ReportView.class) @PostMapping(value = "/shipmentGlobalDemand") public ResponseEntity getShipmentGlobalDemand(@RequestBody ShipmentGlobalDemandInput sgd, Authentication auth) { @@ -687,6 +789,8 @@ public ResponseEntity getShipmentGlobalDemand(@RequestBody ShipmentGlobalDemandI // Report no 22 // Report -> Shipment Reports -> Shipment Cost Overview /** + * API used to get list of AnnualShipmentCostOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-07-01", "planningUnitId":152, "procurementAgentId":-1, "fundingSourceId":-1, "shipmentStatusId":-1}
@@ -697,10 +801,13 @@ public ResponseEntity getShipmentGlobalDemand(@RequestBody ShipmentGlobalDemandI
      * -- If ProcurementAgent has not been selected as yet in the Shipment, that Shipment will be excluded
      * 
* - * @param asci + * @param asci AnnualShipmentCostInput * @param auth - * @return + * @return list of AnnualShipmentCostOutput */ + @Operation(description = "API used to get the AnnualShipmentCostOutput list.", summary = "get the AnnualShipmentCostOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the AnnualShipmentCostOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of AnnualShipmentCostOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/annualShipmentCost") public ResponseEntity getAnnualShipmentCost(@RequestBody AnnualShipmentCostInput asci, Authentication auth) { @@ -715,6 +822,8 @@ public ResponseEntity getAnnualShipmentCost(@RequestBody AnnualShipmentCostInput // Report no 24 /** + * API used to get list of ShipmentReportOutput + * *
      * Sample JSON
      * {"programId":3, "versionId":2, "startDate":"2019-10-01", "stopDate":"2020-10-01", "planningUnitIds":[152,157], "includePlannedShipments":1}
@@ -728,11 +837,14 @@ public ResponseEntity getAnnualShipmentCost(@RequestBody AnnualShipmentCostInput
      * -- FreightPerc is in SUM(FREIGHT_COST)/SUM(PRODUCT_COST) for that ProcurementAgent and that PlanningUnit
      * 
* - * @param fsri + * @param fsri ShipmentReportInput * @param auth - * @return + * @return list of ShipmentReportOutput */ // Report -> Shipment Reports -> Shipment Cost Details (Planning Unit view) + @Operation(description = "API used to get the ShipmentReportOutput list.", summary = "get the ShipmentReportOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ShipmentReportOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ShipmentReportOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/aggregateShipmentByProduct") public ResponseEntity getAggregateShipmentByProduct(@RequestBody ShipmentReportInput fsri, Authentication auth) { @@ -748,6 +860,8 @@ public ResponseEntity getAggregateShipmentByProduct(@RequestBody ShipmentReportI // Report no 28 // Reports -> Stock Status -> Stock Status Snapshot /** + * API used to get list of StockStatusForProgramOutput + * *
      * Sample JSON
      * {"programId":2028, "versionId":1, "dt":"2019-10-01", "includePlannedShipments":1, "tracerCategoryIds":[]}
@@ -763,10 +877,13 @@ public ResponseEntity getAggregateShipmentByProduct(@RequestBody ShipmentReportI
      * -- MaxMonthsOfStock is Min of Min of MinMonthOfStock+ReorderFrequency and 15
      * 
* - * @param sspi + * @param sspi StockStatusForProgramInput * @param auth - * @return + * @return list of StockStatusForProgramOutput */ + @Operation(description = "API used to get the StockStatusForProgramOutput list.", summary = "get the StockStatusForProgramOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockStatusForProgramOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockStatusForProgramOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/stockStatusForProgram") public ResponseEntity getStockStatusForProgram(@RequestBody StockStatusForProgramInput sspi, Authentication auth) { @@ -782,13 +899,18 @@ public ResponseEntity getStockStatusForProgram(@RequestBody StockStatusForProgra // Report no 29 // Report -> Shipment Reports -> Budget reports /** + * API used to get list of BudgetReportOutput + * * Sample JSON {"programId":2028, "versionId":1, "startDate":"2019-01-01", * "stopDate":"2021-12-01", "fundingSourceIds":[], "shippingStatusIds":[]} * - * @param br + * @param br BudgetReportInput * @param auth - * @return + * @return list of BudgetReportOutput */ + @Operation(description = "API used to get the BudgetReportOutput list.", summary = "get the BudgetReportOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the BudgetReportOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of BudgetReportOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/budgetReport") public ResponseEntity getBudgetReport(@RequestBody BudgetReportInput br, Authentication auth) { @@ -805,6 +927,8 @@ public ResponseEntity getBudgetReport(@RequestBody BudgetReportInput br, Authent // Reports -> Stock Status -> Stock Status Snapshot (Global) // Global Report /** + * API used to get list of StockStatusAcrossProductsOutput + * *
      * Sample JSON
      * {    "curUser": 20,    "realmId": 1,    "realmCountryIds": [        5,        51    ],    "tracerCategoryIds":[], "dt":"2020-09-01"}
@@ -820,10 +944,13 @@ public ResponseEntity getBudgetReport(@RequestBody BudgetReportInput br, Authent
      * -- MaxMonthsOfStock is Min of Min of MinMonthOfStock+ReorderFrequency and 15
      * 
* - * @param sspi + * @param ssap StockStatusAcrossProductsInput * @param auth - * @return + * @return list of StockStatusAcrossProductsOutput */ + @Operation(description = "API used to get the StockStatusAcrossProductsOutput list.", summary = "get the StockStatusAcrossProductsOutput list", tags = ("report")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the StockStatusAcrossProductsOutput list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of StockStatusAcrossProductsOutput list") @JsonView(Views.ReportView.class) @PostMapping(value = "/stockStatusAcrossProducts") public ResponseEntity getStockStatusAcrossProducts(@RequestBody StockStatusAcrossProductsInput ssap, Authentication auth) { diff --git a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java index 20e6d2859..3c15ba843 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java @@ -7,6 +7,9 @@ import cc.altius.FASP.model.ResponseCode; import cc.altius.FASP.service.ShipmentStatusService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +33,15 @@ public class ShipmentStatusRestController { @Autowired private ShipmentStatusService shipmentStatusService; + /** + * API used to get the active ShipmentStatus list. + * + * @param auth + * @return returns the active ShipmentStatus list. + */ + @Operation(description = "API used to get the active ShipmentStatus list.", summary = "Get Active ShipmentStatus list.", tags = ("shipmentStatus")) + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the ShipmentStatus list") + @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of ShipmentStatus list") @GetMapping(value = "/getShipmentStatusListActive") public ResponseEntity getShipmentStatusListActive(Authentication auth) { try { diff --git a/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java index 6568465db..3ae195b2d 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SupplierRestController.java @@ -36,7 +36,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/supplier") public class SupplierRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java index dedc48e68..84b5666b1 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java @@ -154,7 +154,7 @@ public ResponseEntity rebuildSupplyPlans(@RequestBody List Date: Mon, 27 Sep 2021 17:17:34 +0530 Subject: [PATCH 7/9] added / --- .../IntegrationProgramRestController.java | 4 ++-- .../controller/IntegrationRestController.java | 16 ++++++++-------- .../rest/controller/LocaleRestController.java | 4 ++-- .../controller/ShipmentStatusRestController.java | 2 +- .../controller/SupplyPlanRestController.java | 15 ++++++--------- .../FASP/rest/controller/TestRestController.java | 2 +- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java b/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java index 94f6db982..e51832c51 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/IntegrationProgramRestController.java @@ -51,7 +51,7 @@ public class IntegrationProgramRestController { * @param auth * @return returns the complete list of Integration Programs */ - @GetMapping("") + @GetMapping("/") @Operation(description = "API used to get the complete Integration Program list.", summary = "Get Integration Program list", tags = ("integrationProgram")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Integration Program list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Integration Program list") @@ -163,7 +163,7 @@ public ResponseEntity getIntegrationProgram(@PathVariable("integrationProgramId" * @param auth * @return returns a Success code if the operation was successful */ - @PutMapping(path = "") + @PutMapping(path = "/") @Operation(description = "API used to update an IntegrationProgram", summary = "Update IntegrationProgram", tags = ("integrationProgram")) @Parameters( @Parameter(name = "integrationPrograms", description = "An array of Integration Program objects that you want to update")) diff --git a/src/main/java/cc/altius/FASP/rest/controller/IntegrationRestController.java b/src/main/java/cc/altius/FASP/rest/controller/IntegrationRestController.java index 8da79d615..a7113241f 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/IntegrationRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/IntegrationRestController.java @@ -52,7 +52,7 @@ public class IntegrationRestController { * @param auth * @return returns the complete list of Integrations */ - @GetMapping("") + @GetMapping("/") @Operation(description = "API used to get the complete Integration list.", summary = "Get Integration list", tags = ("integration")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the Integration list") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented the retreival of Integration list") @@ -69,11 +69,11 @@ public ResponseEntity getIntegration(Authentication auth) { /** * API used to get the Integration for a specific IntegrationId * - * @param integrationId IntegrationId that you want the Integration - * Object for + * @param integrationId IntegrationId that you want the Integration Object + * for * @param auth - * @return returns the list the Integration object based on - * IntegrationId specified + * @return returns the list the Integration object based on IntegrationId + * specified */ @GetMapping(value = "/{integrationId}") @Operation(description = "API used to get the Integration for a specific IntegrationId", summary = "Get Integration for an IntegrationId", tags = ("integration")) @@ -106,7 +106,7 @@ public ResponseEntity getIntegration(@PathVariable("integrationId") int integrat * @param auth * @return returns a Success code if the operation was successful */ - @PostMapping(value = "") + @PostMapping(value = "/") @Operation(description = "API used to add an Integration", summary = "Add Integration", tags = ("integration")) @Parameters( @Parameter(name = "integration", description = "The Integration object that you want to add")) @@ -138,7 +138,7 @@ public ResponseEntity addIntegration(@RequestBody Integration integration, Authe * @param auth * @return returns a Success code if the operation was successful */ - @PutMapping(path = "") + @PutMapping(path = "/") @Operation(description = "API used to update an Integration", summary = "Update Integration", tags = ("integration")) @Parameters( @Parameter(name = "integration", description = "The Integration object that you want to update")) @@ -166,7 +166,7 @@ public ResponseEntity updateIntegration(@RequestBody Integration integration, Au return new ResponseEntity(new ResponseCode("static.message.updateFailed"), HttpStatus.INTERNAL_SERVER_ERROR); } } - + /** * API used to get the complete Integration View list. * diff --git a/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java index fae4808fc..3eab16986 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/LocaleRestController.java @@ -17,7 +17,7 @@ * * @author akil */ -@RestController("/api") +@RestController("/api/locales") public class LocaleRestController { @Autowired @@ -30,7 +30,7 @@ public class LocaleRestController { * @param languageCode for which you need the language label for * @return file containing labels for the Translations */ - @GetMapping("/locales/{languageCode}") + @GetMapping("/{languageCode}") ResponseEntity getLanguageJson(@PathVariable("languageCode") String languageCode) { return new ResponseEntity(this.languageService.getLanguageJsonForStaticLabels(languageCode), HttpStatus.OK); } diff --git a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java index 3c15ba843..f293bd9a3 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/ShipmentStatusRestController.java @@ -25,7 +25,7 @@ * @author altius */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/shipmentStatus") public class ShipmentStatusRestController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java index 84b5666b1..8c04ea0fe 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/SupplyPlanRestController.java @@ -43,7 +43,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/supplyPlan") public class SupplyPlanRestController { @Autowired @@ -69,8 +69,6 @@ public class SupplyPlanRestController { // System.out.println(new Date()); // return new ResponseEntity(simplifiedSupplyPlan, HttpStatus.OK); // } - - /** * API is to rebuild supply plan based on rebuild true or false * @@ -82,7 +80,6 @@ public class SupplyPlanRestController { * @return returns success message if rebuild true, returns * SimplifiedSupplyPlan list if rebuild false */ - @GetMapping("/newSupplyPlan/programId/{programId}/versionId/{versionId}/rebuild/{rebuild}") @Operation(description = "API is to rebuild supply plan based on rebuild true or false ", summary = "To rebuild supply plan based on rebuild true or false ", tags = ("supplyPlan")) @Parameters({ @@ -131,21 +128,21 @@ public ResponseEntity buildNewSupplyPlan( } } - - /** * API is to rebuild supply plan for listed programIds and versionIds - * @param pvList pvList list of programIds and versionIds to rebuild supply plan for + * + * @param pvList pvList list of programIds and versionIds to rebuild supply + * plan for * @param auth * @return success/error message for rebuild supply plan */ @PostMapping("/rebuildSupplyPlans") @Operation(description = "API is to rebuild supply plan for listed programIds and versionIds ", summary = "To rebuild supply plan for listed programIds and versionIds ", tags = ("supplyPlan")) @Parameters( - @Parameter(name = "pvList", description = "pvList list of programIds and versionIds to rebuild supply plan for")) + @Parameter(name = "pvList", description = "pvList list of programIds and versionIds to rebuild supply plan for")) @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "200", description = "Returns the success/error message") @ApiResponse(content = @Content(mediaType = "text/json"), responseCode = "500", description = "Internal error that prevented rebuild supply plan") - + @ResponseBody public ResponseEntity rebuildSupplyPlans(@RequestBody List pvList, Authentication auth) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/main/java/cc/altius/FASP/rest/controller/TestRestController.java b/src/main/java/cc/altius/FASP/rest/controller/TestRestController.java index 134a68a0a..8a14a2b2b 100644 --- a/src/main/java/cc/altius/FASP/rest/controller/TestRestController.java +++ b/src/main/java/cc/altius/FASP/rest/controller/TestRestController.java @@ -31,7 +31,7 @@ * @author akil */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/acl") public class TestRestController { @Autowired From e47350541eef4e21dda0526e3c47c9d3069bb4bc Mon Sep 17 00:00:00 2001 From: Shrutika Date: Wed, 29 Sep 2021 15:33:09 +0530 Subject: [PATCH 8/9] security file changes --- .../java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java b/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java index e24c1a54f..95373000d 100755 --- a/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java +++ b/src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java @@ -104,12 +104,12 @@ public void configure(WebSecurity webSecurity) throws Exception { .and().ignoring().antMatchers("/file/**") .and().ignoring().antMatchers("/v3/api-docs", "/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html**", "/swagger-resources/configuration/ui") .and().ignoring().antMatchers("/api/locales/*/**") - .and().ignoring().antMatchers("/api/forgotPassword/**") + .and().ignoring().antMatchers("/api/user/forgotPassword/**") .and().ignoring().antMatchers("/api/getForgotPasswordToken/**") - .and().ignoring().antMatchers("/api/confirmForgotPasswordToken/**") - .and().ignoring().antMatchers("/api/updatePassword/**") + .and().ignoring().antMatchers("/api/user/confirmForgotPasswordToken/**") + .and().ignoring().antMatchers("/api/user/updatePassword/**") // .and().ignoring().antMatchers("/api/user/**") - .and().ignoring().antMatchers("/api/updateExpiredPassword/**") + .and().ignoring().antMatchers("/api/user/updateExpiredPassword/**") .and().ignoring().antMatchers("/exportSupplyPlan/**") .and().ignoring().antMatchers("/exportProgramData/**") .and().ignoring().antMatchers("/exportOrderData/**") From e0b3423442bc5d9bf250d7cafb683a94e415e282 Mon Sep 17 00:00:00 2001 From: Shrutika Date: Tue, 5 Oct 2021 16:34:33 +0530 Subject: [PATCH 9/9] nothing --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 350962cda..c283c0c08 100755 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ true -