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;
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.function.Supplier;
35 import org.openecomp.cl.api.Logger;
36 import org.openecomp.sparky.dal.rest.OperationResult;
37 import org.openecomp.sparky.logging.AaiUiMsgs;
39 import com.fasterxml.jackson.databind.ObjectMapper;
42 * The Class RetrieveOperationResultFromDisk.
44 public class RetrieveOperationResultFromDisk implements Supplier<OperationResult> {
46 private String fullPath;
47 private ObjectMapper mapper;
48 private Logger logger;
51 * Instantiates a new retrieve operation result from disk.
53 * @param fullPath the full path
54 * @param mapper the mapper
55 * @param logger the logger
57 public RetrieveOperationResultFromDisk(String fullPath, ObjectMapper mapper, Logger logger) {
59 this.fullPath = fullPath;
65 * @see java.util.function.Supplier#get()
68 public OperationResult get() {
71 File file = new File(fullPath);
73 if (logger.isDebugEnabled()) {
74 logger.debug(AaiUiMsgs.WILL_RETRIEVE_TXN, fullPath);
77 Path path = Paths.get(fullPath);
78 byte[] byteBuffer = Files.readAllBytes(path);
80 OperationResult opResult = mapper.readValue(byteBuffer, OperationResult.class);
84 logger.debug(AaiUiMsgs.FAILED_TO_RESTORE_TXN_FILE_MISSING, fullPath);
86 } catch (IOException exc) {
87 logger.error(AaiUiMsgs.DISK_CACHE_READ_IO_ERROR, exc.getLocalizedMessage());