a7797d9f79c2d9d30563fbb96294e99b6ad740c9
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * onap
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
22
23 import java.io.File;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.util.Optional;
27
28 /**
29  * Resolves dblib properties files relative to the default file path.  In Unix, this is represented by:
30  * <code>/opt/sdnc/data/properties</code>
31  */
32 public class DblibDefaultFileResolver implements DblibPropertiesFileResolver {
33
34     /**
35      * Default path to look for the configuration directory
36      */
37     private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("opt", "sdnc", "data", "properties");
38
39     private final String successMessage;
40
41     public DblibDefaultFileResolver(final String successMessage) {
42         this.successMessage = successMessage;
43     }
44
45     /**
46      * Parse a properties file location based on the default properties location
47      *
48      * @return an Optional File containing the location if it exists, or an empty Optional
49      */
50     @Override
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);
55         }
56         return Optional.empty();
57     }
58
59     @Override
60     public String getSuccessfulResolutionMessage() {
61         return this.successMessage;
62     }
63 }