Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 88f7a47

Browse files
Merge pull request #186 from tatlax3636/fix-empty-response
Add informative statuses instead of empty responses
2 parents f527cbe + 1707174 commit 88f7a47

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<artifactId>api-audit</artifactId>
55
<packaging>jar</packaging>
66
<name>${project.groupId}:${project.artifactId}</name>
7-
<version>3.7.30-SNAPSHOT</version>
7+
<version>3.7.31-SNAPSHOT</version>
88
<description>Hygieia Audit Rest API Layer</description>
99
<url>https://github.com/Hygieia/${repository.name}</url>
1010

@@ -60,7 +60,7 @@
6060
<repository.name>api-audit</repository.name>
6161

6262
<!-- Dependencies -->
63-
<com.capitalone.dashboard.core.version>3.15.42</com.capitalone.dashboard.core.version>
63+
<com.capitalone.dashboard.core.version>3.15.45</com.capitalone.dashboard.core.version>
6464
<spring-security.version>4.2.18.RELEASE</spring-security.version>
6565
<spring.cloud.version>1.3.1.RELEASE</spring.cloud.version>
6666
<tomcat.version>8.5.70</tomcat.version>

src/main/java/com/capitalone/dashboard/service/DashboardAuditServiceImpl.java

+42-1
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,49 @@ public JSONObject getAuditReport(DashboardAuditRequest dashboardAuditRequest) {
298298
businessApplication, businessService, auditType, identifierName, identifierVersion, identifierUrl);
299299
if (Objects.nonNull(auditReport) && Objects.nonNull(auditReport.getAuditResponse())) {
300300
return (JSONObject) auditReport.getAuditResponse();
301+
}else{
302+
Cmdb busServItem = cmdbRepository.findByConfigurationItemAndItemType(businessService, "app");
303+
Cmdb busAppItem = cmdbRepository.findByConfigurationItemAndItemType(businessApplication, "component");
304+
305+
if(busServItem == null){
306+
JSONObject invalidBAResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_INVALID_BA, businessApplication, businessService);
307+
return invalidBAResponse;
308+
}else if(busAppItem == null){
309+
JSONObject invalidComponentResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_INVALID_COMPONENT, businessApplication, businessService);
310+
return invalidComponentResponse;
311+
}else if(!componentInfoMatch(busServItem, businessApplication)){
312+
JSONObject componentBAMismatchResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_COMPONENT_BA_MISMATCH, businessApplication, businessService);
313+
return componentBAMismatchResponse;
314+
}else{
315+
JSONObject noDataResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_AUDIT_NO_DATA, businessApplication, businessService);
316+
return noDataResponse;
317+
}
318+
}
319+
320+
321+
}
322+
323+
private JSONObject createLookupResponseWhenEmpty(DashboardAuditStatus dashboardAuditStatus, String businessApplication, String businessService){
324+
JSONObject auditResponse = new JSONObject();
325+
auditResponse.put("businessApplication", businessApplication);
326+
auditResponse.put("businessService", businessService);
327+
auditResponse.put("auditStatuses", Collections.singleton(dashboardAuditStatus));
328+
auditResponse.put("lastUpdated", 0);
329+
auditResponse.put("auditEntity", new JSONObject());
330+
auditResponse.put("review", new JSONObject());
331+
return auditResponse;
332+
}
333+
334+
private boolean componentInfoMatch(Cmdb businessApplication, String businessService){
335+
if(businessApplication.getComponents() == null){
336+
return false;
301337
}
302-
return new JSONObject();
338+
339+
if(businessApplication.getComponents().contains(businessService)){
340+
return true;
341+
}
342+
343+
return false;
303344
}
304345

305346
private void validateParameters(String dashboardTitle, DashboardType dashboardType, String businessService, String businessApp, long beginDate, long endDate) throws AuditException{

0 commit comments

Comments
 (0)