1 package org.onap.so.adapters.tasks.audit;
3 import java.io.IOException;
5 import java.util.Optional;
6 import org.onap.so.audit.beans.AuditInventory;
7 import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
8 import org.onap.so.db.request.beans.RequestProcessingData;
9 import org.onap.so.db.request.client.RequestsDbClient;
10 import org.onap.so.objects.audit.AAIObjectAuditList;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component;
13 import com.fasterxml.jackson.core.JsonParseException;
14 import com.fasterxml.jackson.core.JsonProcessingException;
15 import com.fasterxml.jackson.databind.JsonMappingException;
18 public class AuditDataService {
20 private static final String AUDIT_STACK_DATA = "AuditStackData";
23 private RequestsDbClient requestsDbClient;
26 * Checks to see if an entry already exist for the given heat stack and writes audit stack data to the request
27 * database if it doesn't.
29 * @throws JsonProcessingException
31 public void writeStackDataToRequestDb(AuditInventory auditInventory, AAIObjectAuditList auditList)
32 throws JsonProcessingException {
33 List<RequestProcessingData> requestProcessingDataList =
34 requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(),
35 auditInventory.getHeatStackName(), AUDIT_STACK_DATA);
36 if (requestProcessingDataList.isEmpty()) {
37 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
38 String auditListString = objectMapper.getMapper().writeValueAsString(auditList);;
40 RequestProcessingData requestProcessingData = new RequestProcessingData();
41 requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId());
42 requestProcessingData.setGroupingId(auditInventory.getVfModuleId());
43 requestProcessingData.setName(auditInventory.getHeatStackName());
44 requestProcessingData.setTag(AUDIT_STACK_DATA);
45 requestProcessingData.setValue(auditListString);
47 requestsDbClient.saveRequestProcessingData(requestProcessingData);
52 * Retrieves audit stack data from the request database.
55 * @throws JsonMappingException
56 * @throws JsonParseException
58 public Optional<AAIObjectAuditList> getStackDataFromRequestDb(AuditInventory auditInventory) throws IOException {
60 List<RequestProcessingData> requestProcessingDataList =
61 requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(),
62 auditInventory.getHeatStackName(), AUDIT_STACK_DATA);
63 if (!requestProcessingDataList.isEmpty()) {
64 RequestProcessingData requestProcessingData = requestProcessingDataList.get(0);
65 String auditListString = requestProcessingData.getValue();
67 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
68 AAIObjectAuditList auditList =
69 objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
71 return Optional.of(auditList);
73 return Optional.empty();