1313import org .springframework .beans .factory .annotation .Autowired ;
1414
1515import ca .bc .gov .nrs .common .persistence .dao .DaoException ;
16- import ca .bc .gov .nrs .wfone .common .rest .endpoints .BaseEndpointsImpl ;
1716import ca .bc .gov .nrs .common .rest .resource .Messages ;
1817import ca .bc .gov .nrs .common .service .ConflictException ;
1918import ca .bc .gov .nrs .common .service .ForbiddenException ;
2019import ca .bc .gov .nrs .common .service .NotFoundException ;
2120import ca .bc .gov .nrs .common .service .ValidationFailureException ;
22- import ca .bc .gov .nrs .wfnews .service .api .v1 .IncidentsService ;
2321import ca .bc .gov .nrs .wfnews .api .rest .v1 .endpoints .ExternalUriEndpoint ;
2422import ca .bc .gov .nrs .wfnews .api .rest .v1 .endpoints .security .Scopes ;
2523import ca .bc .gov .nrs .wfnews .api .rest .v1 .resource .ExternalUriResource ;
2624import ca .bc .gov .nrs .wfnews .api .rest .v1 .resource .PublishedIncidentResource ;
25+ import ca .bc .gov .nrs .wfnews .service .api .v1 .IncidentsService ;
26+ import ca .bc .gov .nrs .wfone .common .rest .endpoints .BaseEndpointsImpl ;
2727
2828public class ExternalUriEndpointImpl extends BaseEndpointsImpl implements ExternalUriEndpoint {
29-
29+
3030 private static final Logger logger = LoggerFactory .getLogger (ExternalUriEndpointImpl .class );
31-
31+
3232 @ Autowired
3333 private IncidentsService incidentsService ;
34-
34+
3535 @ Override
3636 public Response createExternalUri (ExternalUriResource resource )
3737 throws NotFoundException , ForbiddenException , ConflictException {
3838 Response response = null ;
39-
39+
4040 logRequest ();
41-
42- if (!hasAuthority (Scopes .CREATE_EXTERNAL_URI )) {
41+
42+ if (!hasAuthority (Scopes .CREATE_EXTERNAL_URI )) {
4343 return Response .status (Status .FORBIDDEN ).build ();
4444 }
45-
45+
4646 try {
4747 ExternalUriResource result = incidentsService .createExternalUri (resource , getFactoryContext ());
48-
48+
4949 URI createdUri = URI .create (result .getSelfLink ());
50-
50+
5151 response = Response .created (createdUri ).entity (result ).tag (result .getUnquotedETag ()).build ();
52-
52+
5353 // Now we should also update the Incident
5454 // This will ensure we fetch this on update checks
55- PublishedIncidentResource incident = incidentsService .getPublishedIncident (result .getSourceObjectUniqueId (), null , getWebAdeAuthentication (), getFactoryContext ());
55+ PublishedIncidentResource incident = incidentsService .getPublishedIncidentByIncidentGuid (
56+ result .getSourceObjectUniqueId (), getWebAdeAuthentication (), getFactoryContext ());
5657 incident .setUpdateDate (new Date ());
5758 incident .setLastUpdatedTimestamp (new Date ());
5859 incidentsService .updatePublishedWildfireIncident (incident , getFactoryContext ());
59- } catch (ValidationFailureException e ) {
60+ } catch (ValidationFailureException e ) {
6061 response = Response .status (Status .BAD_REQUEST ).entity (new Messages (e .getValidationErrors ())).build ();
6162 } catch (Throwable t ) {
6263 response = getInternalServerErrorResponse (t );
6364 }
64-
65+
6566 logResponse (response );
6667
6768 return response ;
6869 }
6970
70-
7171 @ Override
7272 public Response updateExternalUri (ExternalUriResource resource , String externalResourceGuid )
7373 throws NotFoundException , ForbiddenException , ConflictException {
7474 Response response = null ;
75-
75+
7676 logRequest ();
77-
78- if (!hasAuthority (Scopes .UPDATE_EXTERNAL_URI )) {
77+
78+ if (!hasAuthority (Scopes .UPDATE_EXTERNAL_URI )) {
7979 return Response .status (Status .FORBIDDEN ).build ();
8080 }
81-
81+
8282 try {
8383 ExternalUriResource result = incidentsService .updateExternalUri (resource , getFactoryContext ());
84-
84+
8585 URI createdUri = URI .create (result .getSelfLink ());
86-
86+
8787 response = Response .created (createdUri ).entity (result ).tag (result .getUnquotedETag ()).build ();
88-
88+
8989 // Now we should also update the Incident
9090 // This will ensure we fetch this on update checks
91- PublishedIncidentResource incident = incidentsService .getPublishedIncident (result .getSourceObjectUniqueId (), null , getWebAdeAuthentication (), getFactoryContext ());
91+ PublishedIncidentResource incident = incidentsService .getPublishedIncidentByIncidentGuid (
92+ result .getSourceObjectUniqueId (), getWebAdeAuthentication (), getFactoryContext ());
9293 incident .setUpdateDate (new Date ());
9394 incident .setLastUpdatedTimestamp (new Date ());
9495 incidentsService .updatePublishedWildfireIncident (incident , getFactoryContext ());
95- } catch (ValidationFailureException e ) {
96+ } catch (ValidationFailureException e ) {
9697 response = Response .status (Status .BAD_REQUEST ).entity (new Messages (e .getValidationErrors ())).build ();
9798 } catch (Throwable t ) {
9899 response = getInternalServerErrorResponse (t );
99100 }
100-
101+
101102 logResponse (response );
102103
103104 return response ;
@@ -106,17 +107,18 @@ public Response updateExternalUri(ExternalUriResource resource, String externalR
106107 @ Override
107108 public Response deleteExternalUri (String externalUriGuid ) throws NotFoundException , ConflictException , DaoException {
108109 Response response = null ;
109-
110+
110111 logRequest ();
111-
112- if (!hasAuthority (Scopes .DELETE_EXTERNAL_URI )) {
112+
113+ if (!hasAuthority (Scopes .DELETE_EXTERNAL_URI )) {
113114 return Response .status (Status .FORBIDDEN ).build ();
114115 }
115-
116- try {
117- ExternalUriResource current = incidentsService .getExternalUri (externalUriGuid , getWebAdeAuthentication (), getFactoryContext ());
116+
117+ try {
118+ ExternalUriResource current = incidentsService .getExternalUri (externalUriGuid , getWebAdeAuthentication (),
119+ getFactoryContext ());
118120 EntityTag currentTag = EntityTag .valueOf (current .getQuotedETag ());
119-
121+
120122 ResponseBuilder responseBuilder = this .evaluatePreconditions (currentTag );
121123
122124 if (responseBuilder == null ) {
@@ -136,13 +138,12 @@ public Response deleteExternalUri(String externalUriGuid) throws NotFoundExcepti
136138 } catch (Throwable t ) {
137139 response = getInternalServerErrorResponse (t );
138140 }
139-
141+
140142 logResponse (response );
141143
142144 logger .debug (">deletePublishedIncident " + response .getStatus ());
143-
145+
144146 return response ;
145147 }
146-
147-
148+
148149}
0 commit comments