From 7f535078ef80a7b7efa3e3325bfccb994fbd00e8 Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Thu, 31 Aug 2017 15:16:38 -0400 Subject: Rename packages to org.onap in 1.4.0-SNAPSHOT 19 - remove openecomp 72 - remediate Sonar scan issues 79 - removed unwanted left menu under Report 90 - apply approved license text Issue: PORTAL-19, PORTAL-72, PORTAL-79, PORTAL-90 Change-Id: I41a0ef5fba623d2242574bd15f2d9fb8029a496c Signed-off-by: Christopher Lott (cl778h) --- .../core/web/socket/PeerBroadcastSocket.java | 104 ------ .../portalsdk/core/web/socket/WebRTCSocket.java | 143 -------- .../portalsdk/core/web/support/AppUtils.java | 213 ----------- .../core/web/support/ControllerProperties.java | 41 --- .../core/web/support/FeedbackMessage.java | 80 ----- .../portalsdk/core/web/support/JsonMessage.java | 118 ------ .../portalsdk/core/web/support/MessagesList.java | 92 ----- .../portalsdk/core/web/support/UserUtils.java | 395 --------------------- 8 files changed, 1186 deletions(-) delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/PeerBroadcastSocket.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/WebRTCSocket.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/AppUtils.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/ControllerProperties.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/FeedbackMessage.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/JsonMessage.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/MessagesList.java delete mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/PeerBroadcastSocket.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/PeerBroadcastSocket.java deleted file mode 100644 index ddf08c8f..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/PeerBroadcastSocket.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.socket; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Map; - -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; - -import com.fasterxml.jackson.databind.ObjectMapper; - -@ServerEndpoint("/contact") -public class PeerBroadcastSocket { - - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PeerBroadcastSocket.class); - - public static Map channelMap = new Hashtable(); - public Map sessionMap = new Hashtable(); - ObjectMapper mapper = new ObjectMapper(); - - @OnMessage - public void message(String message, Session session) { - try { - // JSONObject jsonObject = new JSONObject(message); - @SuppressWarnings("unchecked") - Map jsonObject = mapper.readValue(message, Map.class); - try { - Object from = jsonObject.get("from"); - if (from != null) { - channelMap.put(from.toString(), session); - sessionMap.put(session.getId(), from.toString()); - } - } catch (Exception je) { - logger.error(EELFLoggerDelegate.errorLogger, "Failed to read value" + je.getMessage()); - } - - try { - Object to = jsonObject.get("to"); - if (to == null) - return; - Object toSessionObj = channelMap.get(to); - if (toSessionObj != null) { - Session toSession = null; - toSession = (Session) toSessionObj; - toSession.getBasicRemote().sendText(message); - } - - } catch (Exception ex) { - logger.error(EELFLoggerDelegate.errorLogger, "Failed to send text" + ex.getMessage()); - } - - } catch (Exception ex) { - logger.error(EELFLoggerDelegate.errorLogger, "Failed" + ex.getMessage()); - } - - } - - @OnOpen - public void open(Session session) { - logger.info(EELFLoggerDelegate.debugLogger, "Channel opened"); - } - - @OnClose - public void close(Session session) { - String channel = sessionMap.get(session.getId()); - if (channel != null) { - Object sessObj = channelMap.get(channel); - if (sessObj != null) { - try { - ((Session) sessObj).close(); - } catch (IOException e) { - logger.error(EELFLoggerDelegate.errorLogger, "Failed to close" + e.getMessage()); - } - } - channelMap.remove(channel); - } - logger.info(EELFLoggerDelegate.debugLogger, "Channel closed"); - } - -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/WebRTCSocket.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/WebRTCSocket.java deleted file mode 100644 index 810cba5c..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/socket/WebRTCSocket.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.socket; - -import java.util.Hashtable; -import java.util.Map; - -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -import com.fasterxml.jackson.databind.ObjectMapper; - -@ServerEndpoint("/webrtc") -public class WebRTCSocket { - - - public static Map> channelMap = new Hashtable>(); - public Map sessionMap = new Hashtable(); - ObjectMapper mapper = new ObjectMapper(); - - - @OnMessage - public void message(String message, Session session) { - try { - //JSONObject jsonObject = new JSONObject(message); - @SuppressWarnings("unchecked") - Map jsonObject = mapper.readValue(message, Map.class); - try { - Object isOpen = jsonObject.get("open"); - if(isOpen != null && (Boolean)isOpen == true) { - String channel = (String) jsonObject.get("channel"); - Object value = channelMap.get(channel); - Hashtable sourceDestMap = null; - if(value == null) - sourceDestMap = new Hashtable(); - else - sourceDestMap = (Hashtable) value; - - sourceDestMap.put(session.getId(), new Object[]{session}); - channelMap.put(channel, sourceDestMap); - sessionMap.put(session.getId(), channel); - - - } - } - catch (Exception je) { - je.printStackTrace(); - } - - try{ - - Object dataObj = jsonObject.get("data"); - if(dataObj == null) - return; - Map dataMapObj = ( Map)dataObj; - //Object thisUserId = dataMapObj.get("userid"); - String channel = null; - try{ - Object channelObj = dataMapObj.get("sessionid"); - if(channelObj != null) - channel = (String) channelObj; - else - channel = (String) jsonObject.get("channel"); - } - catch(Exception json) { - json.printStackTrace(); - } - - /* - JSONObject dataMapObj = (JSONObject)dataObj; - Object thisUserId = dataMapObj.get("userid"); - String channel = (String) dataMapObj.get("sessionid"); - Hashtable sourceDestMap = sessionMap.get(channel); - - if(thisUserId != null && sourceDestMap.get((String)thisUserId) == null) { - sourceDestMap.put((String)thisUserId, new Object[] {message, session}); - } - - for(String userId : sourceDestMap.keySet()){ - if(!userId.equals(thisUserId)) { - Session otherSession = (Session) ((Object[])sourceDestMap.get(userId))[1]; - otherSession.getBasicRemote().sendText(message); - } - } - */ - - Hashtable sourceDestMap = channelMap.get(channel); - if(sourceDestMap != null) - for(String id : sourceDestMap.keySet()){ - if(!id.equals(session.getId())) { - Session otherSession = (Session) ((Object[])sourceDestMap.get(id))[0]; - if(otherSession.isOpen()) - otherSession.getBasicRemote().sendText(mapper.writeValueAsString(dataObj)); - } - - } - } - catch (Exception je) { - je.printStackTrace(); - } - - } - catch (Exception je) { - je.printStackTrace(); - } - //System.out.println("Message received:" + message); - } - - @OnOpen - public void open(Session session) { - // System.out.println("Channel opened"); - } - - @OnClose - public void close(Session session) { - String channel = sessionMap.get(session.getId()); - if (channel != null) { - channelMap.remove(channel); - } - // System.out.println("Channel closed"); - } - -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/AppUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/AppUtils.java deleted file mode 100644 index 295cff42..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/AppUtils.java +++ /dev/null @@ -1,213 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -import java.io.File; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Date; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.sql.DataSource; - -import org.hibernate.Session; -import org.openecomp.portalsdk.core.exception.SessionExpiredException; -import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager; -import org.openecomp.portalsdk.core.service.DataAccessService; -import org.openecomp.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.FileSystemResource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - - -public class AppUtils { - - - - private static DataAccessService dataAccessService; - - private static AbstractCacheManager cacheManager; - - private static boolean applicationLocked; - - private static Hashtable feedback = new Hashtable(); - - private static DataSource datasource; - - public static DataSource getDatasource() { - return datasource; - } - - @Autowired - public void setDatasource(DataSource datasource) { - AppUtils.datasource = datasource; - } - - public AppUtils() { - } - - public static HttpSession getSession(HttpServletRequest request) { - HttpSession session = null; - if (request != null) { - session = request.getSession(false); - if (session == null) { - throw new SessionExpiredException(); - } - } else { - throw new SessionExpiredException(); - } - return session; - } - - public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy) { - return getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupList - - public static List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy, Session session) { - String cacheKey = dbTable + "|" + dbValueCol + "|" + dbLabelCol + "|" + dbFilter + "|" + dbOrderBy; - List list = getLookupListFromCache(cacheKey); - if (list == null) { - list = getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - if (list != null) { - addLookupListToCache(cacheKey, list); - } - } // if - return list; - } // getLookupList - - private static List getLookupListFromCache(String key) { - return (List)getObjectFromCache(key); - } // getLookupListFromCache - - public static Object getObjectFromCache(String key) { - if (isCacheManagerAvailable()) { - return getCacheManager().getObject(key); - } else { - return null; - } - } // getObjectFromCache - - private static void addLookupListToCache(String key, List list) { - addObjectToCache(key, list); - } // addLookupListToCache - - public static void addObjectToCache(String key, Object o) { - if (isCacheManagerAvailable()) { - getCacheManager().putObject(key, o); - } - } // addObjectToCache - - @Autowired - public void setCacheManager(AbstractCacheManager cacheManager) { - this.cacheManager = cacheManager; - } - - public static AbstractCacheManager getCacheManager() { - return cacheManager; - } - - public static boolean isCacheManagerAvailable() { - return (getCacheManager() != null); - } - - public void setFeedback(Hashtable feedback) { - this.feedback = feedback; - } - - public static boolean isApplicationLocked() { - return applicationLocked; - } - - public static DataAccessService getDataAccessService() { - return dataAccessService; - } - - @Autowired - public void setDataAccessService(DataAccessService dataAccessService) { - this.dataAccessService = dataAccessService; - } - - public static void setApplicationLocked(boolean locked) { - applicationLocked = locked; - } - - public static String getLookupValueByLabel(String label, String dbTable, String dbValueCol, String dbLabelCol) { - if (label == null || label.equals("")) { - return ""; - } - - List lstResult = getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, dbLabelCol + "='" + label.replaceAll("'", "''") + "'", ""); - if (lstResult == null) { - return ""; - } - if (lstResult.size() > 0) { - return ((org.openecomp.portalsdk.core.domain.Lookup)lstResult.toArray()[0]).getValue(); - } else { - return ""; - } - } - - public static String getLookupValueByLabel(String label, List lookupList) { - Iterator i = null; - - if (label == null || label.equalsIgnoreCase("")) { - return ""; - } - - if (lookupList == null || lookupList.size() == 0) { - return ""; - } - - i = lookupList.iterator(); - while (i.hasNext()) { - org.openecomp.portalsdk.core.domain.Lookup lookup = (org.openecomp.portalsdk.core.domain.Lookup)i.next(); - - if (lookup.getLabel().equals(label)) { - return lookup.getValue(); - } - } - - return ""; -} - public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy) { - return getLookupListNoCache(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupListNoCache - - - public static List getLookupListNoCache(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy, Session session) { - return getDataAccessService().getLookupList(dbTable, dbValueCol, dbLabelCol, dbFilter, dbOrderBy, null); - } // getLookupListNoCache - - - -} // AppUtils diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/ControllerProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/ControllerProperties.java deleted file mode 100644 index 1d09eba0..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/ControllerProperties.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -public interface ControllerProperties { - - static final String TASK_GET = "get"; - static final String TASK_DELETE = "delete"; - static final String TASK_SAVE = "save"; - static final String TASK_PROCESS = "process"; - static final String TASK_TOGGLE_ACTIVE = "toggleActive"; - static final String TASK_DOWNLOAD = "download"; - static final String TASK_POPUP = "popup"; - static final String TASK_LOOKUP = "lookup"; - static final String TASK_ADD_ROW = "addRow"; - static final String TASK_APPROVE = "approve"; - static final String TASK_REJECT = "reject"; - static final String TASK_RESET = "reset"; - static final String TASK_ASSIGN = "assign"; - static final String TASK_CUT = "cut"; - static final String TASK_COPY = "copy"; - static final String TASK_PASTE = "paste"; - static final String TASK_SELECT = "select"; -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/FeedbackMessage.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/FeedbackMessage.java deleted file mode 100644 index d8993b03..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/FeedbackMessage.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -public class FeedbackMessage { - - private String message; - private int messageType; - private boolean keyed; - - public static final int MESSAGE_TYPE_ERROR = 10; - public static final int MESSAGE_TYPE_WARNING = 20; - public static final int MESSAGE_TYPE_INFO = 30; - public static final int MESSAGE_TYPE_SUCCESS = 40; - - public static final String DEFAULT_MESSAGE_SUCCESS = "Update successful."; - public static final String DEFAULT_MESSAGE_ERROR = "An error occurred while processing the request: "; - - public static final String DEFAULT_MESSAGE_SYSTEM_ADMINISTRATOR = "If the problem persists, please contact your Administrator."; - - public FeedbackMessage() { - } - - public FeedbackMessage(String message) { - this(message, MESSAGE_TYPE_ERROR); - } - - public FeedbackMessage(String message, int messageType) { - this(message, messageType, false); - } - - public FeedbackMessage(String message, int messageType, boolean keyed) { - this.message = message; - this.messageType = messageType; - this.keyed = keyed; - } - - public String getMessage() { - return message; - } - - public int getMessageType() { - return messageType; - } - - public boolean isKeyed() { - return keyed; - } - - public void setMessage(String message) { - this.message = message; - } - - public void setMessageType(int messageType) { - this.messageType = messageType; - } - - public void setKeyed(boolean keyed) { - this.keyed = keyed; - } - - -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/JsonMessage.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/JsonMessage.java deleted file mode 100644 index 5566bf90..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/JsonMessage.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.openecomp.portalsdk.core.onboarding.crossapi.PortalAPIResponse; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class JsonMessage { - - private String data; - private String data2; - private String data3; - public JsonMessage(String data) { - super(); - this.data = data; - } - public JsonMessage(String data,String data2) { - super(); - this.data = data; - this.data2 = data2; - } - - public JsonMessage(String data,String data2,String data3) { - super(); - this.data = data; - this.data2 = data2; - this.data3 = data3; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - public String getData2() { - return data2; - } - public void setData2(String data2) { - this.data2 = data2; - } - public String getData3() { - return data3; - } - public void setData3(String data3) { - this.data3 = data3; - } - - - /** - * Builds JSON object with status + message response body. - * - * @param success - * True to indicate success, false to signal failure. - * @param msg - * Message to include in the response object; ignored if null. - * @return - * - *
-	 * { "status" : "ok" (or "error"), "message": "some explanation" }
-	 *         
- */ - public static String buildJsonResponse(boolean success, String msg) { - PortalAPIResponse response = new PortalAPIResponse(success, msg); - String json = null; - try { - json = new ObjectMapper().writeValueAsString(response); - } catch (JsonProcessingException ex) { - // Truly should never, ever happen - json = "{ \"status\": \"error\",\"message\":\"" + ex.toString() + "\" }"; - } - return json; - } - - /** - * Builds JSON object with status of error and message containing stack - * trace for the specified throwable. - * - * @param t - * Throwable with stack trace to use as message - * @return - * - *
-	 * { "status" : "error", "message": "some-big-stacktrace" }
-	 *         
- */ - public static String buildJsonResponse(Throwable t) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - return buildJsonResponse(false, sw.toString()); - } - - -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/MessagesList.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/MessagesList.java deleted file mode 100644 index 0cf628aa..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/MessagesList.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ================================================================================ - * eCOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -import java.util.*; - -public class MessagesList { - - private boolean successMessageDisplayed = true; - private boolean includeCauseInCustomExceptions = false; - - private List successMessages; - private List exceptionMessages; - - public MessagesList() { - setExceptionMessages(new ArrayList()); - setSuccessMessages(new ArrayList()); - } - - public MessagesList(boolean displaySuccess) { - this(); - setSuccessMessageDisplayed(displaySuccess); - } - - public List getExceptionMessages() { - return exceptionMessages; - } - - public List getSuccessMessages() { - return successMessages; - } - - public boolean isSuccessMessageDisplayed() { - return successMessageDisplayed; - } - - public boolean isIncludeCauseInCustomExceptions() { - return includeCauseInCustomExceptions; - } - - - public void setExceptionMessages(List exceptionMessages) { - this.exceptionMessages = exceptionMessages; - } - - public void setSuccessMessages(List successMessages) { - this.successMessages = successMessages; - } - - public void setSuccessMessageDisplayed(boolean successMessageDisplayed) { - this.successMessageDisplayed = successMessageDisplayed; - } - - public void setIncludeCauseInCustomExceptions(boolean includeCauseInCustomExceptions) { - this.includeCauseInCustomExceptions = includeCauseInCustomExceptions; - } - - - public void addSuccessMessage(FeedbackMessage message) { - getSuccessMessages().add(message); - } - - public void addExceptionMessage(FeedbackMessage message) { - getExceptionMessages().add(message); - } - - public boolean hasExceptionMessages() { - return!getExceptionMessages().isEmpty(); - } - - public boolean hasSuccessMessages() { - return!getSuccessMessages().isEmpty(); - } - -} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java deleted file mode 100644 index a7850e34..00000000 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/web/support/UserUtils.java +++ /dev/null @@ -1,395 +0,0 @@ -/*- - * ================================================================================ - * ECOMP Portal SDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalsdk.core.web.support; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - -import org.openecomp.portalsdk.core.domain.Role; -import org.openecomp.portalsdk.core.domain.RoleFunction; -import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.exception.SessionExpiredException; -import org.openecomp.portalsdk.core.lm.FusionLicenseManager; -import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.openecomp.portalsdk.core.menu.MenuBuilder; -import org.openecomp.portalsdk.core.restful.domain.EcompRole; -import org.openecomp.portalsdk.core.restful.domain.EcompUser; -import org.openecomp.portalsdk.core.service.DataAccessService; -import org.openecomp.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; - -@SuppressWarnings("rawtypes") -public class UserUtils { - - static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserUtils.class); - - public static final String KEY_USER_ROLES_CACHE = "userRoles"; - - private static DataAccessService dataAccessService; - - public static void setUserSession(HttpServletRequest request, User user, Set applicationMenuData, - Set businessDirectMenuData, String loginMethod , List roleFunctionList) { - HttpSession session = request.getSession(true); - - UserUtils.clearUserSession(request); // let's clear the current user - // session to avoid any - // conflicts during the set - - session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); - session.setAttribute(SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_ATTRIBUTE_NAME), loginMethod); - - getRoleFunctions(request); - - session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_NAME), user.getFullName()); - session.setAttribute(SystemProperties.FIRST_NAME, user.getFirstName()); - session.setAttribute(SystemProperties.LAST_NAME, user.getLastName()); - session.setAttribute(SystemProperties.ROLE_FUNCTION_LIST, roleFunctionList); - - ServletContext context = session.getServletContext(); - int licenseVarificationFlag = 3; - try { - licenseVarificationFlag = (Integer) context.getAttribute("licenseVerification"); - } catch (Exception e) { - logger.error(EELFLoggerDelegate.debugLogger, "Error while get license varification " + e.getMessage()); - } - String displayName = ""; - if (SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME) != null) - displayName = SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME); - switch (licenseVarificationFlag) { - case FusionLicenseManager.DEVELOPER_LICENSE: - session.setAttribute(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME), - displayName + " [Development Version]"); - break; - case FusionLicenseManager.EXPIRED_LICENSE: - session.setAttribute(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME), - displayName + " [LICENSE EXPIRED]"); - break; - case FusionLicenseManager.VALID_LICENSE: - session.setAttribute(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME), displayName); - break; - default: - session.setAttribute(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME), - displayName + " [INVALID LICENSE]"); - break; - } - - session.setAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME), - MenuBuilder.filterMenu(applicationMenuData, request)); - session.setAttribute(SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_ATTRIBUTE_NAME), - MenuBuilder.filterMenu(businessDirectMenuData, request)); - } - - public static void clearUserSession(HttpServletRequest request) { - HttpSession session = AppUtils.getSession(request); - - if (session == null) { - throw new SessionExpiredException(); - } - - // removes all stored attributes from the current user's session - session.removeAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_ATTRIBUTE_NAME)); - session.removeAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTION_LIST)); - - } - - @SuppressWarnings("unchecked") - public static Set getRoleFunctions(HttpServletRequest request) { - HashSet roleFunctions = null; -// HashSet rolefun = null; - HttpSession session = request.getSession(); - roleFunctions = (HashSet) session - .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME)); - - if (roleFunctions == null) { - HashMap roles = getRoles(request); - roleFunctions = new HashSet(); - - Iterator i = roles.keySet().iterator(); - - while (i.hasNext()) { - Long roleKey = (Long) i.next(); - Role role = (Role) roles.get(roleKey); - - Iterator j = role.getRoleFunctions().iterator(); - - while (j.hasNext()) { - RoleFunction function = (RoleFunction) j.next(); - roleFunctions.add(function.getCode()); - } - } - session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME), - roleFunctions); - } - return roleFunctions; - } - - public static HashMap getRoles(HttpServletRequest request) { - HashMap roles = null; - - // HttpSession session = request.getSession(); - HttpSession session = AppUtils.getSession(request); - roles = (HashMap) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)); - - // if roles are not already cached, let's grab them from the user - // session - if (roles == null) { - User user = getUserSession(request); - - // get all user roles (including the tree of child roles) - roles = getAllUserRoles(user); - - session.setAttribute(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME), - getAllUserRoles(user)); - } - - return roles; - } - - public static User getUserSession(HttpServletRequest request) { - HttpSession session = AppUtils.getSession(request); - - if (session == null) { - throw new SessionExpiredException(); - } - - return (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)); - } - - @SuppressWarnings("unchecked") - public static HashMap getAllUserRoles(User user) { - HashMap roles = new HashMap(); - Iterator i = user.getRoles().iterator(); - - while (i.hasNext()) { - Role role = (Role) i.next(); - - if (role.getActive()) { - roles.put(role.getId(), role); - - // let's take a recursive trip down the tree to add all child - // roles - addChildRoles(role, roles); - } - } - - return roles; - } - - @SuppressWarnings("unchecked") - private static void addChildRoles(Role role, HashMap roles) { - Set childRoles = role.getChildRoles(); - if (childRoles != null && childRoles.size() > 0) { - Iterator j = childRoles.iterator(); - while (j.hasNext()) { - Role childRole = (Role) j.next(); - if (childRole.getActive()) { - roles.put(childRole.getId(), childRole); - addChildRoles(childRole, roles); - } - } - } - - } - - - - public static boolean hasRole(HttpServletRequest request, String roleKey) { - return getRoles(request).keySet().contains(new Long(roleKey)); - } - - public static boolean hasRole(User user, String roleKey) { - return getAllUserRoles(user).keySet().contains(new Long(roleKey)); - } - - public static boolean isAccessible(HttpServletRequest request, String functionKey) { - return getRoleFunctions(request).contains(functionKey); - } - - public static String getLoginMethod(HttpServletRequest request) { - HttpSession session = AppUtils.getSession(request); - - if (session == null) { - throw new SessionExpiredException(); - } - - return (String) session - .getAttribute(SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_ATTRIBUTE_NAME)); - } - - public static DataAccessService getDataAccessService() { - return dataAccessService; - } - - @Autowired - public void setDataAccessService(DataAccessService dataAccessService) { - UserUtils.dataAccessService = dataAccessService; - } - - public static int getUserId(HttpServletRequest request) { - return getUserIdAsLong(request).intValue(); - } - - public static Long getUserIdAsLong(HttpServletRequest request) { - Long userId = new Long(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)); - - if (request != null) { - if (getUserSession(request) != null) { - userId = getUserSession(request).getId(); - } - } - return userId; - } - - private static final Object stackTraceLock = new Object(); - - /** - * Serializes a stack trace of the specified throwable and returns it as a - * string. - * - * TODO: why is synchronization required? - * - * @param t - * @return String version of stack trace - */ - public static String getStackTrace(Throwable t) { - synchronized (stackTraceLock) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - return sw.toString(); - } - } - - /** - * Gets the full URL of the request by joining the request and any query - * string. - * - * @param request - * @return Full URL of the request including query parameters - */ - public static String getFullURL(HttpServletRequest request) { - if (request != null) { - StringBuffer requestURL = request.getRequestURL(); - String queryString = request.getQueryString(); - - if (queryString == null) { - return requestURL.toString(); - } else { - return requestURL.append('?').append(queryString).toString(); - } - } - return ""; - } - - /** - * Gets or generates a request ID by searching for header X-ECOMP-RequestID. - * If not found, generates a new random UUID. - * - * @param request - * @return Request ID for the specified request - */ - public static String getRequestId(HttpServletRequest request) { - Enumeration headerNames = request.getHeaderNames(); - - String requestId = ""; - try { - while (headerNames.hasMoreElements()) { - String headerName = (String) headerNames.nextElement(); - if (logger.isTraceEnabled()) - logger.trace(EELFLoggerDelegate.debugLogger, "getRequestId: header {} = {}", headerName, - request.getHeader(headerName)); - if (headerName.equalsIgnoreCase(SystemProperties.ECOMP_REQUEST_ID)) { - requestId = request.getHeader(headerName); - break; - } - } - } catch (Exception e) { - logger.error(EELFLoggerDelegate.debugLogger, "getRequestId: failed to get headder", e); - } - - if (requestId.isEmpty()) - requestId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, "getRequestId: result is {}", requestId); - return requestId; - } - - /** - * Converts a Hibernate-mapped User object to a JSON-serializable EcompUser - * object. - * - * @param user - * @return EcompUser with a subset of fields. - */ - public static EcompUser convertToEcompUser(User user) { - EcompUser userJson = new EcompUser(); - userJson.setEmail(user.getEmail()); - userJson.setFirstName(user.getFirstName()); - userJson.setHrid(user.getHrid()); - userJson.setJobTitle(user.getJobTitle()); - userJson.setLastName(user.getLastName()); - userJson.setLoginId(user.getLoginId()); - userJson.setOrgManagerUserId(user.getOrgManagerUserId()); - userJson.setMiddleInitial(user.getMiddleInitial()); - userJson.setOrgCode(user.getOrgCode()); - userJson.setOrgId(user.getOrgId()); - userJson.setPhone(user.getPhone()); - userJson.setOrgUserId(user.getOrgUserId()); - Set ecompRoles = new TreeSet(); - for (Role role : user.getRoles()) { - ecompRoles.add(convertToEcompRole(role)); - } - userJson.setRoles(ecompRoles); - return userJson; - } - - /** - * Converts a Hibernate-mapped Role object to a JSON-serializable EcompRole - * object. - * - * @param role - * @return EcompRole with a subset of fields: ID and name - */ - public static EcompRole convertToEcompRole(Role role) { - EcompRole ecompRole = new EcompRole(); - ecompRole.setId(role.getId()); - ecompRole.setName(role.getName()); - return ecompRole; - } - - } - - -- cgit 1.2.3-korg