2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
25 import java.util.Optional;
26 import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
29 * Resolves dblib properties files relative to the karaf root directory.
31 public class DblibKarafRootFileResolver implements DblibPropertiesFileResolver {
33 final DBLIBResourceProvider dblibResourceProvider;
35 private final String successMessage;
37 public DblibKarafRootFileResolver(final String successMessage, final DBLIBResourceProvider dblibResourceProvider) {
38 this.successMessage = successMessage;
39 this.dblibResourceProvider = dblibResourceProvider;
43 * Parse a properties file location relative to the karaf root
45 * @return an Optional File containing the location if it exists, or an empty Optional
48 public Optional<File> resolveFile(final String dblibFileName) {
49 final URL fromKarafRoot = dblibResourceProvider.getClass().getResource(dblibFileName);
50 if (fromKarafRoot != null) {
51 final File propertiesFile = new File(fromKarafRoot.getFile());
52 if (propertiesFile.exists()) {
53 return Optional.of(propertiesFile);
55 return Optional.empty();
57 return Optional.empty();
61 public String getSuccessfulResolutionMessage() {
62 return this.successMessage;