2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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.openecomp.policy.rest.util;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.openecomp.policy.rest.XACMLRestProperties;
32 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
33 import com.att.research.xacml.util.XACMLProperties;
35 import org.openecomp.policy.common.logging.eelf.MessageCodes;
36 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
38 public class Webapps {
39 private static String actionHome = null;
40 private static String configHome = null;
41 private static Log logger = LogFactory.getLog(Webapps.class);
46 public static String getConfigHome(){
49 } catch (Exception e) {
55 public static String getActionHome(){
58 } catch (Exception e) {
64 private static void loadWebapps() throws Exception{
65 if(actionHome == null || configHome == null){
66 Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS));
68 if (webappsPath == null) {
69 logger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
70 // TODO:EELF Cleanup - Remove logger
71 PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
72 throw new Exception("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
74 Path webappsPathConfig;
75 Path webappsPathAction;
76 if(webappsPath.toString().contains("\\"))
78 webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config");
79 webappsPathAction = Paths.get(webappsPath.toString()+"\\Action");
83 webappsPathConfig = Paths.get(webappsPath.toString()+"/Config");
84 webappsPathAction = Paths.get(webappsPath.toString()+"/Action");
86 if (Files.notExists(webappsPathConfig))
89 Files.createDirectories(webappsPathConfig);
90 } catch (IOException e) {
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
92 + webappsPathConfig.toAbsolutePath().toString(), e);
93 // TODO:EELF Cleanup - Remove logger
94 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory");
97 if (Files.notExists(webappsPathAction))
100 Files.createDirectories(webappsPathAction);
101 } catch (IOException e) {
102 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
103 + webappsPathAction.toAbsolutePath().toString(), e);
104 // TODO:EELF Cleanup - Remove logger
105 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory");
108 actionHome = webappsPathAction.toString();
109 configHome = webappsPathConfig.toString();