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.onap.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.onap.policy.rest.XACMLRestProperties;
32 import org.onap.policy.xacml.api.XACMLErrorConstants;
34 import com.att.research.xacml.api.pap.PAPException;
35 import com.att.research.xacml.util.XACMLProperties;
37 import org.onap.policy.common.logging.eelf.MessageCodes;
38 import org.onap.policy.common.logging.eelf.PolicyLogger;
40 public class Webapps {
41 private static String actionHome = null;
42 private static String configHome = null;
43 private static Log logger = LogFactory.getLog(Webapps.class);
48 public static String getConfigHome(){
51 } catch (PAPException e) {
52 logger.error("Exception Occured while loading webapps",e);
58 public static String getActionHome(){
61 } catch (PAPException e) {
62 logger.error("Exception Occured while loading webapps",e);
68 private static void loadWebapps() throws PAPException{
69 String errorMessageName = "Invalid Webapps Path Location property :";
70 if(actionHome == null || configHome == null){
71 Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS));
73 if (webappsPath == null) {
74 logger.error(errorMessageName + XACMLRestProperties.PROP_PAP_WEBAPPS);
75 PolicyLogger.error(errorMessageName + XACMLRestProperties.PROP_PAP_WEBAPPS);
76 throw new PAPException(errorMessageName + XACMLRestProperties.PROP_PAP_WEBAPPS);
78 Path webappsPathConfig;
79 Path webappsPathAction;
80 if(webappsPath.toString().contains("\\")){
81 webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config");
82 webappsPathAction = Paths.get(webappsPath.toString()+"\\Action");
84 webappsPathConfig = Paths.get(webappsPath.toString()+"/Config");
85 webappsPathAction = Paths.get(webappsPath.toString()+"/Action");
88 checkConfigActionHomeExists(webappsPathConfig, webappsPathAction);
90 actionHome = webappsPathAction.toString();
91 configHome = webappsPathConfig.toString();
95 private static void checkConfigActionHomeExists(Path webappsPathConfig, Path webappsPathAction){
96 if (!webappsPathConfig.toFile().exists()){
98 Files.createDirectories(webappsPathConfig);
99 } catch (IOException e) {
100 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
101 + webappsPathConfig.toAbsolutePath().toString(), e);
102 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory");
106 if (!webappsPathAction.toFile().exists()){
108 Files.createDirectories(webappsPathAction);
109 } catch (IOException e) {
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
111 + webappsPathAction.toAbsolutePath().toString(), e);
112 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory");