2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.synchronizer.task;
27 import java.util.function.Supplier;
29 import org.onap.aai.sparky.dal.rest.OperationResult;
30 import org.onap.aai.sparky.logging.AaiUiMsgs;
31 import org.onap.aai.cl.api.Logger;
34 import com.fasterxml.jackson.databind.ObjectMapper;
37 * The Class PersistOperationResultToDisk.
39 public class PersistOperationResultToDisk implements Supplier<Void> {
41 private String fullPath;
42 private OperationResult dataToStore;
43 private ObjectMapper mapper;
44 private Logger logger;
45 private Map<String, String> contextMap;
48 * Instantiates a new persist operation result to disk.
50 * @param fullPath the full path
51 * @param dataToStore the data to store
52 * @param mapper the mapper
53 * @param logger the logger
55 public PersistOperationResultToDisk(String fullPath, OperationResult dataToStore,
56 ObjectMapper mapper, Logger logger) {
58 this.fullPath = fullPath;
60 this.dataToStore = dataToStore;
62 this.contextMap = MDC.getCopyOfContextMap();
68 * @see java.util.function.Supplier#get()
72 MDC.setContextMap(contextMap);
73 File file = new File(fullPath);
76 mapper.writeValue(new File(fullPath), dataToStore);
77 } catch (Exception exc) {
78 logger.error(AaiUiMsgs.DISK_DATA_WRITE_IO_ERROR, exc.toString());
86 * @return the fullPath
88 public String getFullPath() {
93 * @param fullPath the fullPath to set
95 public void setFullPath(String fullPath) {
96 this.fullPath = fullPath;
100 * @return the dataToStore
102 public OperationResult getDataToStore() {
107 * @param dataToStore the dataToStore to set
109 public void setDataToStore(OperationResult dataToStore) {
110 this.dataToStore = dataToStore;
116 public ObjectMapper getMapper() {
121 * @param mapper the mapper to set
123 public void setMapper(ObjectMapper mapper) {
124 this.mapper = mapper;
130 public Logger getLogger() {
135 * @param logger the logger to set
137 public void setLogger(Logger logger) {
138 this.logger = logger;
142 * @return the contextMap
144 public Map<String, String> getContextMap() {
149 * @param contextMap the contextMap to set
151 public void setContextMap(Map<String, String> contextMap) {
152 this.contextMap = contextMap;