|
27 | 27 | import com.google.common.collect.Sets;
|
28 | 28 | import org.apache.commons.collections.CollectionUtils;
|
29 | 29 | import org.apache.commons.collections4.IterableUtils;
|
| 30 | +import org.apache.commons.lang3.ObjectUtils; |
30 | 31 | import org.apache.commons.lang3.StringUtils;
|
31 | 32 | import org.json.simple.JSONObject;
|
32 | 33 | import org.springframework.beans.factory.annotation.Autowired;
|
@@ -296,10 +297,51 @@ public JSONObject getAuditReport(DashboardAuditRequest dashboardAuditRequest) {
|
296 | 297 |
|
297 | 298 | AuditReport auditReport = auditReportRepository.findTop1ByBusinessApplicationAndBusinessServiceAndAuditTypeAndIdentifierNameAndIdentifierVersionAndIdentifierUrlOrderByTimestampDesc(
|
298 | 299 | businessApplication, businessService, auditType, identifierName, identifierVersion, identifierUrl);
|
299 |
| - if (Objects.nonNull(auditReport) && Objects.nonNull(auditReport.getAuditResponse())) { |
| 300 | + if (Objects.nonNull(auditReport) && !ObjectUtils.isEmpty(auditReport.getAuditResponse())) { |
300 | 301 | return (JSONObject) auditReport.getAuditResponse();
|
| 302 | + }else{ |
| 303 | + Cmdb busServItem = cmdbRepository.findByConfigurationItemAndItemType(businessService, "app"); |
| 304 | + Cmdb busAppItem = cmdbRepository.findByConfigurationItemAndItemType(businessApplication, "component"); |
| 305 | + |
| 306 | + if(busServItem == null){ |
| 307 | + JSONObject invalidBAResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_INVALID_BA, businessApplication, businessService); |
| 308 | + return invalidBAResponse; |
| 309 | + }else if(busAppItem == null){ |
| 310 | + JSONObject invalidComponentResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_INVALID_COMPONENT, businessApplication, businessService); |
| 311 | + return invalidComponentResponse; |
| 312 | + }else if(!componentInfoMatch(busServItem, businessApplication)){ |
| 313 | + JSONObject componentBAMismatchResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_COMPONENT_BA_MISMATCH, businessApplication, businessService); |
| 314 | + return componentBAMismatchResponse; |
| 315 | + }else{ |
| 316 | + JSONObject noDataResponse = createLookupResponseWhenEmpty(DashboardAuditStatus.DASHBOARD_AUDIT_NO_DATA, businessApplication, businessService); |
| 317 | + return noDataResponse; |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + |
| 322 | + } |
| 323 | + |
| 324 | + private JSONObject createLookupResponseWhenEmpty(DashboardAuditStatus dashboardAuditStatus, String businessApplication, String businessService){ |
| 325 | + JSONObject auditResponse = new JSONObject(); |
| 326 | + auditResponse.put("businessApplication", businessApplication); |
| 327 | + auditResponse.put("businessService", businessService); |
| 328 | + auditResponse.put("auditStatuses", Collections.singleton(dashboardAuditStatus)); |
| 329 | + auditResponse.put("lastUpdated", 0); |
| 330 | + auditResponse.put("auditEntity", new JSONObject()); |
| 331 | + auditResponse.put("review", new JSONObject()); |
| 332 | + return auditResponse; |
| 333 | + } |
| 334 | + |
| 335 | + private boolean componentInfoMatch(Cmdb businessApplication, String businessService){ |
| 336 | + if(businessApplication.getComponents() == null){ |
| 337 | + return false; |
301 | 338 | }
|
302 |
| - return new JSONObject(); |
| 339 | + |
| 340 | + if(businessApplication.getComponents().contains(businessService)){ |
| 341 | + return true; |
| 342 | + } |
| 343 | + |
| 344 | + return false; |
303 | 345 | }
|
304 | 346 |
|
305 | 347 | private void validateParameters(String dashboardTitle, DashboardType dashboardType, String businessService, String businessApp, long beginDate, long endDate) throws AuditException{
|
|
0 commit comments