2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.synchronizer.task;
30 import java.util.function.Supplier;
32 import org.openecomp.cl.api.Logger;
33 import org.openecomp.sparky.dal.rest.OperationResult;
34 import org.openecomp.sparky.logging.AaiUiMsgs;
37 import com.fasterxml.jackson.databind.ObjectMapper;
40 * The Class PersistOperationResultToDisk.
42 public class PersistOperationResultToDisk implements Supplier<Void> {
44 private String fullPath;
45 private OperationResult dataToStore;
46 private ObjectMapper mapper;
47 private Logger logger;
48 private Map<String, String> contextMap;
51 * Instantiates a new persist operation result to disk.
53 * @param fullPath the full path
54 * @param dataToStore the data to store
55 * @param mapper the mapper
56 * @param logger the logger
58 public PersistOperationResultToDisk(String fullPath, OperationResult dataToStore,
59 ObjectMapper mapper, Logger logger) {
61 this.fullPath = fullPath;
63 this.dataToStore = dataToStore;
65 this.contextMap = MDC.getCopyOfContextMap();
69 * @see java.util.function.Supplier#get()
73 MDC.setContextMap(contextMap);
74 File file = new File(fullPath);
77 mapper.writeValue(new File(fullPath), dataToStore);
78 } catch (Exception exc) {
79 logger.error(AaiUiMsgs.DISK_DATA_WRITE_IO_ERROR, exc.toString());