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;
 
  24 import java.nio.file.Path;
 
  25 import java.nio.file.Paths;
 
  26 import java.util.Optional;
 
  29  * Resolves dblib properties files relative to the default file path.  In Unix, this is represented by:
 
  30  * <code>/opt/sdnc/data/properties</code>
 
  32 public class DblibDefaultFileResolver implements DblibPropertiesFileResolver {
 
  35      * Default path to look for the configuration directory
 
  37     private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("opt", "sdnc", "data", "properties");
 
  39     private final String successMessage;
 
  41     public DblibDefaultFileResolver(final String successMessage) {
 
  42         this.successMessage = successMessage;
 
  46      * Parse a properties file location based on the default properties location
 
  48      * @return an Optional File containing the location if it exists, or an empty Optional
 
  51     public Optional<File> resolveFile(final String dblibFileName) {
 
  52         final File fileFromDefaultDblibDir = DEFAULT_DBLIB_PROP_DIR.resolve(dblibFileName).toFile();
 
  53         if (fileFromDefaultDblibDir.exists()) {
 
  54             Optional.of(fileFromDefaultDblibDir);
 
  56         return Optional.empty();
 
  60     public String getSuccessfulResolutionMessage() {
 
  61         return this.successMessage;