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;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
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;
36 import com.fasterxml.jackson.databind.ObjectMapper;
39 * The Class RetrieveOperationResultFromDisk.
41 public class RetrieveOperationResultFromDisk implements Supplier<OperationResult> {
43 private String fullPath;
44 private ObjectMapper mapper;
45 private Logger logger;
48 * Instantiates a new retrieve operation result from disk.
50 * @param fullPath the full path
51 * @param mapper the mapper
52 * @param logger the logger
54 public RetrieveOperationResultFromDisk(String fullPath, ObjectMapper mapper, Logger logger) {
56 this.fullPath = fullPath;
62 * @see java.util.function.Supplier#get()
65 public OperationResult get() {
68 File file = new File(fullPath);
70 if (logger.isDebugEnabled()) {
71 logger.debug(AaiUiMsgs.WILL_RETRIEVE_TXN, fullPath);
74 Path path = Paths.get(fullPath);
75 byte[] byteBuffer = Files.readAllBytes(path);
77 OperationResult opResult = mapper.readValue(byteBuffer, OperationResult.class);
81 logger.debug(AaiUiMsgs.FAILED_TO_RESTORE_TXN_FILE_MISSING, fullPath);
83 } catch (IOException exc) {
84 logger.error(AaiUiMsgs.DISK_CACHE_READ_IO_ERROR, exc.getLocalizedMessage());