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.openecomp.sparky.synchronizer.task;
27 import java.util.function.Supplier;
29 import org.openecomp.cl.api.Logger;
30 import org.openecomp.sparky.dal.rest.OperationResult;
31 import org.openecomp.sparky.logging.AaiUiMsgs;
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();
66 * @see java.util.function.Supplier#get()
70 MDC.setContextMap(contextMap);
71 File file = new File(fullPath);
74 mapper.writeValue(new File(fullPath), dataToStore);
75 } catch (Exception exc) {
76 logger.error(AaiUiMsgs.DISK_DATA_WRITE_IO_ERROR, exc.toString());