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;
 
  23 import com.google.common.base.Strings;
 
  26 import java.nio.file.Paths;
 
  27 import java.util.Optional;
 
  30  * Resolves dblib properties files relative to the directory identified by the <code>SDNC_CONFIG_DIR</code>
 
  31  * environment variable.
 
  33 public class DblibEnvVarFileResolver implements DblibPropertiesFileResolver {
 
  36      * Key for environment variable representing the configuration directory
 
  38     private static final String SDNC_CONFIG_DIR_PROP_KEY = "SDNC_CONFIG_DIR";
 
  40     private final String successMessage;
 
  42     public DblibEnvVarFileResolver(final String successMessage) {
 
  43         this.successMessage = successMessage;
 
  47      * Parse a properties file location based on System environment variable
 
  49      * @return an Optional File containing the location if it exists, or an empty Optional
 
  52     public Optional<File> resolveFile(final String dblibFileName) {
 
  53         // attempt to resolve the property directory from the corresponding environment variable
 
  54         final String propDirectoryFromEnvVariable = System.getenv(SDNC_CONFIG_DIR_PROP_KEY);
 
  55         final File fileFromEnvVariable;
 
  56         if (!Strings.isNullOrEmpty(propDirectoryFromEnvVariable)) {
 
  57             fileFromEnvVariable = Paths.get(propDirectoryFromEnvVariable).resolve(dblibFileName).toFile();
 
  58             if(fileFromEnvVariable.exists()) {
 
  59                 return Optional.of(fileFromEnvVariable);
 
  62         return Optional.empty();
 
  66     public String getSuccessfulResolutionMessage() {
 
  67         return this.successMessage;