Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pva/evsrestapi 538 add error tracking audits #325

Merged
merged 19 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ dependencies {
implementation "ca.uhn.hapi.fhir:hapi-fhir-structures-r5:7.4.5"
implementation "ca.uhn.hapi.fhir:hapi-fhir-server:7.4.5"
implementation("ca.uhn.hapi.fhir:hapi-fhir-jpaserver-base:7.4.5") {
exclude group: "net.minidev", module: "json-smart"
exclude group: "ca.uhn.hapi.fhir", module: "hapi-fhir-sql-migrate"
exclude group: "org.elasticsearch.client", module: "elasticsearch-rest-high-level-client"
exclude group: "org.elasticsearch.client", module: "elasticsearch-rest-client"
Expand Down Expand Up @@ -159,7 +160,9 @@ dependencies {
/*
* Test Dependencies
*/
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: "net.minidev", module: "json-smart"
}
testImplementation "org.opensearch.client:spring-data-opensearch-test-autoconfigure:1.5.3"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.5"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.5"
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/gov/nih/nci/evs/api/controller/BaseController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gov.nih.nci.evs.api.controller;

import gov.nih.nci.evs.api.model.Audit;
import gov.nih.nci.evs.api.service.ElasticOperationsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -15,18 +18,28 @@ public class BaseController {
/** The Constant log. */
private static final Logger logger = LoggerFactory.getLogger(BaseController.class);

/** The elastic operations service. */
@Autowired ElasticOperationsService elasticOperationsService;

/**
* Handle exception.
*
* @param e the e
* @throws Exception the exception
*/
public void handleException(final Exception e) throws Exception {
public void handleException(final Exception e, String terminology) throws Exception {
if (e instanceof ResponseStatusException) {
throw e;
}

logger.error("Unexpected error", e);
Audit.addAudit(
elasticOperationsService,
"Exception",
e.getStackTrace()[0].getClassName(),
terminology,
e.getMessage(),
"ERROR");
final String errorMessage =
"An error occurred in the system. Please contact the NCI help desk.";
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, errorMessage);
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/gov/nih/nci/evs/api/controller/ConceptController.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public class ConceptController extends BaseController {

return concepts;
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -376,7 +376,7 @@ public class ConceptController extends BaseController {
}
return concept.get();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ public class ConceptController extends BaseController {

return concept.get().getAssociations();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ public class ConceptController extends BaseController {

return concept.get().getInverseAssociations();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -776,7 +776,7 @@ public class ConceptController extends BaseController {

return subsets;
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -847,7 +847,7 @@ public class ConceptController extends BaseController {

return concept.get().getRoles();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -918,7 +918,7 @@ public class ConceptController extends BaseController {

return concept.get().getInverseRoles();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -992,7 +992,7 @@ public class ConceptController extends BaseController {

return concept.get().getParents();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ public class ConceptController extends BaseController {

return concept.get().getChildren();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ public class ConceptController extends BaseController {
return list.subList(fromIndex, toIndex);

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1264,7 +1264,7 @@ public class ConceptController extends BaseController {

return concept.get().getMaps();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1335,7 +1335,7 @@ public class ConceptController extends BaseController {

return concept.get();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ public class ConceptController extends BaseController {

return concept.get().getDisjointWith();
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1491,7 +1491,7 @@ public class ConceptController extends BaseController {

return list;
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public class ConceptController extends BaseController {

return ConceptUtils.convertPathsWithInclude(elasticQueryService, ip, term, paths, true);
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1791,7 +1791,7 @@ public class ConceptController extends BaseController {
return rootNodes;

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -1897,7 +1897,7 @@ public class ConceptController extends BaseController {
return nodes;

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -2015,7 +2015,7 @@ public class ConceptController extends BaseController {

return ConceptUtils.convertPathsWithInclude(elasticQueryService, ip, term, paths, false);
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -2145,7 +2145,7 @@ public class ConceptController extends BaseController {
return ConceptUtils.convertPathsWithInclude(elasticQueryService, ip, term, paths, false);

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -2265,7 +2265,7 @@ public class ConceptController extends BaseController {
fromRecord += pageSize;
}
} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -2294,7 +2294,7 @@ public class ConceptController extends BaseController {
// concept.setExtensions(mainTypeHierarchy.getExtensions(concept));
// return concept;
// } catch (Exception e) {
// handleException(e);
// handleException(e, terminology);
// return null;
// }
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class HistoryController extends BaseController {
return HistoryUtils.getReplacements(term, elasticQueryService, code);

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public class HistoryController extends BaseController {
term, elasticQueryService, Arrays.asList(list.split(",")));

} catch (final Exception e) {
handleException(e);
handleException(e, terminology);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class MapsetController extends BaseController {
final IncludeParam ip = new IncludeParam(include.orElse("minimal"));
return esQueryService.getMapsets(ip);
} catch (Exception e) {
handleException(e);
handleException(e, "ncit");
return null;
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public class MapsetController extends BaseController {
HttpStatus.NOT_FOUND, "Mapset not found for code = " + code);
}
} catch (Exception e) {
handleException(e);
handleException(e, "ncit");
return null;
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public class MapsetController extends BaseController {

return esSearchService.findConceptMappings(query, searchCriteria);
} catch (Exception e) {
handleException(e);
handleException(e, "ncit");
return null;
}
}
Expand Down
Loading