diff options
author | talasila <talasila@research.att.com> | 2017-02-07 11:47:55 -0500 |
---|---|---|
committer | talasila <talasila@research.att.com> | 2017-02-07 12:51:32 -0500 |
commit | 1faf201e8608dfa4d7af3460fd3d1fc7ebec398b (patch) | |
tree | 2208f76271cc6b1a81dbfb9143cd7118b071a909 /ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter | |
parent | ca23569858b8cc9f60010e193b7041feb2d3227b (diff) |
Initial OpenECOMP Portal SDK commit
Change-Id: I66a3491600a4b9ea241128dc29267eed6a78ed76
Signed-off-by: talasila <talasila@research.att.com>
Diffstat (limited to 'ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter')
8 files changed, 1065 insertions, 0 deletions
diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java new file mode 100644 index 00000000..1e2de464 --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java @@ -0,0 +1,39 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + +import java.util.LinkedHashMap; + +public class AdapterSessionFactoryContainer { + + private LinkedHashMap sessionFactories; + + public AdapterSessionFactoryContainer() { + } + + public LinkedHashMap getSessionFactories() { + return sessionFactories; + } + + public void setSessionFactories(LinkedHashMap sessionFactories) { + this.sessionFactories = sessionFactories; + } + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/DateUtils.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/DateUtils.java new file mode 100644 index 00000000..a9ea0979 --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/DateUtils.java @@ -0,0 +1,287 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + + +import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import org.openecomp.portalsdk.core.FusionObject; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; + + +public class DateUtils implements Serializable, FusionObject{ + + public static final String US_PACIFIC = "US/Pacific"; + public static final String US_MOUNTAIN = "US/Mountain"; + public static final String US_CENTRAL = "US/Central"; + public static final String US_EASTERN = "US/Eastern"; + public static final String US_HAWAII = "US/Hawaii"; + public static final String US_ALASKA = "US/Alaska"; + + //Arizona State has Mountain Time with no Daylight Savings + public static final String US_ARIZONA = "America/Phoenix"; + + private static final String DB_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private static final String GET_CURRENT_DATE = "getCurrentDate"; + + private static DataAccessService dataAccessService; + + public static DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + /** + * Parses a date value with given pattern, + * to return a Date Object + * + * @param dateValue + * @param inPattern + * @return Date Object + * @throws Exception + * + */ + public static Date parseDate(String dateValue,String inPattern) throws Exception{ + return parseDate(dateValue,inPattern,null); + } + + /** + * Parses a date value with the given pattern for the specific TimeZone, + * to return a Date Object + * + * @param dateValue + * @param inPattern + * @param currentTimeZone + * @return Date Object + * @throws Exception + * + */ + public static Date parseDate(String dateValue,String inPattern, + String currentTimeZone) throws Exception{ + DateFormat df = new SimpleDateFormat(inPattern); + if(currentTimeZone !=null && !(currentTimeZone.trim().equals(""))){ + df.setTimeZone(TimeZone.getTimeZone(currentTimeZone)); + } + Date date = df.parse(dateValue); + return date; + } + + /** + * Parses a date value with the given pattern for the specific User(in User TimeZone), + * to return a Date Object + * + * @param dateValue + * @param inPattern + * @param userId + * @return Date Object + * @throws Exception + * + */ + public static Date parseUserDate(String dateValue, String inPattern, Long userId) throws Exception{ + User user = (User)getDataAccessService().getDomainObject(User.class, userId, null); + + String userTimeZone = null; + Long timezoneId = user.getTimeZoneId(); + + if (timezoneId != null) { + userTimeZone = AppUtils.getLookupValueByLabel(timezoneId.toString(), "fn_lu_timezone", "timezone_id", "timezone_value"); + } + + return parseDate(dateValue,inPattern,userTimeZone); + } + + /** + * Formats a given date object to the desired pattern + * + * @param date + * @param outPattern + * @return Formatted date value + * @throws Exception + */ + public static String formatDate(Date date,String outPattern)throws Exception{ + return formatDate(date,outPattern,null); + } + + /** + * Formats a date value with the given pattern into a date value with the desired pattern + * + * @param dateValue + * @param inPattern + * @param outPattern + * @return Formatted date value + * @throws Exception + * + */ + public static String formatDate(String dateValue,String inPattern, + String outPattern) throws Exception{ + return formatDate(dateValue,inPattern,null,outPattern,null); + } + + /** + * Formats a given date object to the desired pattern for the TimeZone provided + * @param date + * @param outPattern + * @param requiredTimeZone + * @return Formatted date value + * @throws Exception + */ + public static String formatDate(Date date,String outPattern, + String requiredTimeZone) throws Exception{ + DateFormat df = new SimpleDateFormat(outPattern); + if(requiredTimeZone != null && !requiredTimeZone.trim().equals("")){ + df.setTimeZone(TimeZone.getTimeZone(requiredTimeZone)); + } + return df.format(date); + } + + /** + * Formats a date value with the given pattern + * into a date value with the desired pattern for the TimeZone provided + * + * @param dateValue + * @param inPattern + * @param outPattern + * @param requiredTimeZone + * @return Formatted date value + * @throws Exception + * + */ + public static String formatDate(String dateValue,String inPattern, + String outPattern,String requiredTimeZone) throws Exception{ + return formatDate(dateValue,inPattern,null,outPattern,requiredTimeZone); + } + + /** + * Formats a date value with the given pattern for a specific TimeZone, + * into a date value with the desired pattern for the TimeZone provided + * + * @param dateValue + * @param inPattern + * @param currentTimeZone + * @param outPattern + * @param requiredTimeZone + * @return Formatted date value + * @throws Exception + * + */ + public static String formatDate(String dateValue,String inPattern,String currentTimeZone, + String outPattern,String requiredTimeZone) throws Exception{ + Date date = parseDate(dateValue,inPattern,currentTimeZone); + return formatDate(date,outPattern,requiredTimeZone); + } + + /** + * Formats a date value with the given pattern, for a specific User(in User TimeZone), + * into a date value with the desired pattern for the TimeZone provided + * + * @param dateValue + * @param inPattern + * @param userId + * @param outPattern + * @param requiredTimeZone + * @return Formatted date value + * @throws Exception + * + */ + public static String formatUserDate(String dateValue,String inPattern, Long userId,String outPattern,String requiredTimeZone) throws Exception{ + User user = (User)getDataAccessService().getDomainObject(User.class, userId, null); + + String userTimeZone = null; + Long timezoneId = user.getTimeZoneId(); + + if (timezoneId != null) { + userTimeZone = AppUtils.getLookupValueByLabel(timezoneId.toString(), "fn_lu_timezone", "timezone_id", "timezone_value"); + } + + return formatDate(dateValue,inPattern,userTimeZone,outPattern,requiredTimeZone); + } + + /** + * Formats a date value with a given pattern for a specific User(User TimeZone), + * into a date value with the desired pattern for Database TimeZone + * + * @param dateValue + * @param inPattern + * @param userId + * @param outPattern + * @return Formatted date value + * @throws Exception + * + */ + public static String formatUserDateForDBTimeZone(String dateValue,String inPattern, Long userId,String outPattern) throws Exception{ + User user = (User)getDataAccessService().getDomainObject(User.class, userId, null); + + String userTimeZone = null; + Long timezoneId = user.getTimeZoneId(); + + /*if (timezoneId != null) { + userTimeZone = AppUtils.getLookupValueByLabel(timezoneId.toString(), "fn_lu_timezone", "timezone_id", "timezone_value"); + }*/ + + String dbTimeZone = SystemProperties.getProperty(SystemProperties.DATABASE_TIME_ZONE); + + return formatDate(dateValue,inPattern,userTimeZone,outPattern,dbTimeZone); + } + + /** + * Get the current database Date/Time + * @return Date object + */ + public static Date getCurrentDBDate()throws Exception{ + String dbTimeZone = SystemProperties.getProperty(SystemProperties.DATABASE_TIME_ZONE); + List results = (List)getDataAccessService().executeNamedQuery(GET_CURRENT_DATE, null, null); + return parseDate(((Object[])results.get(0))[0]+" "+((Object[])results.get(0))[1],DB_DATE_FORMAT,dbTimeZone); + } + + /** + * Get the current date value formatted for the User's TimeZone in the desired pattern + * + * @param outPattern + * @param userId + * @return Date value + * @throws Exception + */ + public static String getCurrentDBDateForUser(String outPattern,Long userId)throws Exception{ + User user = (User)getDataAccessService().getDomainObject(User.class, userId, null); + + String userTimeZone = null; + Long timezoneId = user.getTimeZoneId(); + + /*if (timezoneId != null) { + userTimeZone = AppUtils.getLookupValueByLabel(timezoneId.toString(), "fn_lu_timezone", "timezone_id", "timezone_value"); + }*/ + + Date dbDate = getCurrentDBDate(); + + return formatDate(dbDate,outPattern,userTimeZone); + } + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java new file mode 100644 index 00000000..33b6ec2d --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java @@ -0,0 +1,135 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + +import java.sql.Connection; +import java.util.Map; + +import javax.servlet.ServletContext; + +import org.openecomp.portalsdk.core.FusionObject; +import org.springframework.beans.factory.annotation.Autowired; + +import com.mchange.v2.c3p0.ComboPooledDataSource; + +public class FusionAdapter implements FusionObject { + + public static final String LOCAL_SESSION_FACTORY_KEY = "local"; + + + private ComboPooledDataSource dataSource; + private Map<String,ComboPooledDataSource> dataSourceMap; + + //private SessionFactory sessionFactory; + private ServletContext servletContext; + + // private static Connection connection = null; + + //private static AdapterSessionFactoryContainer sessionFactoryContainer; + + + public FusionAdapter() { + } + + + public ServletContext getServletContext() { + return servletContext; + } + + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + + // public static AdapterSessionFactoryContainer getSessionFactoryContainer() { + // return sessionFactoryContainer; + // } + + //public static LinkedHashMap getSessionFactories() { + // return getSessionFactoryContainer().getSessionFactories(); + //} + + + //public void setSessionFactoryContainer(AdapterSessionFactoryContainer sessionFactoryContainer) { + // this.sessionFactoryContainer = sessionFactoryContainer; + //} + + + /** Gets connection to the database **/ + public Connection getConnection() { + //Session session = sessionFactory.getCurrentSession(); + Connection connection = null; + try { + connection = getDataSource().getConnection(); + } catch(Exception ex) { + ex.printStackTrace(); + } + + return connection; + } + + + /** Gets connection to the database indicated via the session factory key **/ + public synchronized Connection getConnection(String schemaId) { + Connection connection = null; + try { + connection = getDataSourceMap().get(schemaId).getConnection(); + } catch (Exception e) { + e.printStackTrace(); + } + + return connection; + } + + + /** Releases connection to the database **/ + public void releaseConnection(Connection conn) { + try { + conn.close(); + //logger.debug("releasing connection from adapter..."); + } + catch (Exception e) { + //logger.error("Error while closing the connection."); + e.printStackTrace(); + } + } + + + public ComboPooledDataSource getDataSource() { + return dataSource; + } + + + @Autowired + public void setDataSource(ComboPooledDataSource dataSource) { + this.dataSource = dataSource; + } + + public Map<String,ComboPooledDataSource> getDataSourceMap() { + if(dataSourceMap==null) + dataSourceMap = (Map<String,ComboPooledDataSource>)SpringContext.getApplicationContext().getBean("dataSourceMap"); + + return dataSourceMap; + } + + public void setdataSourceMap(Map<String,ComboPooledDataSource> dataSourceMap) { + this.dataSourceMap = dataSourceMap; + } + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java new file mode 100644 index 00000000..5b4af3f9 --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java @@ -0,0 +1,59 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + +import org.openecomp.portalsdk.core.domain.support.DomainVo; + +/** + * <p>IdName.java</p> + * <p>Represents a id/name data object.</p> +*/ +public class IdName extends DomainVo { + + private String name; + private Long id; + + public IdName() {} + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int compareTo(Object obj){ + String c1 = getName(); + String c2 = ((IdName)obj).getName(); + + return (c1 == null || c2 == null) ? 1 : c1.compareTo(c2); + } + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Item.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Item.java new file mode 100644 index 00000000..71663bc2 --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Item.java @@ -0,0 +1,55 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + + +public class Item { + private String _id; + private String _name; + + public Item() { + } + + public Item(String id, String name) { + this._id = id; + this._name = name; + } + + public String getId() { + return _id; + } + + public void setId(String id) { + this._id = id; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + this._name = name; + } + + public String toString() { + return _name; + } +} + diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java new file mode 100644 index 00000000..ac6cd16c --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java @@ -0,0 +1,85 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + + +import java.io.Serializable; + +import org.openecomp.portalsdk.core.domain.FusionVo; +import org.openecomp.portalsdk.core.domain.support.NameValueId; + + + +public class Lookup extends FusionVo implements Serializable { + + private NameValueId nameValueId = new NameValueId(); + + public Lookup() {} + + public Lookup(String label, String value) { + this(); + setLabel(label); + setValue(value); + } + + public String getValue() { + return getNameValueId().getVal(); + } + + public String getLabel() { + return getNameValueId().getLab(); + } + + public void setValue(String value) { + getNameValueId().setVal(value); + } + + public void setLabel(String label) { + getNameValueId().setLab(label); + } + + public NameValueId getNameValueId() { + return nameValueId; + } + + public void setNameValueId(NameValueId nameValueId) { + this.nameValueId = nameValueId; + } + + // required by ZK for to set the selectedItems of Listboxes (used heavily for <select>-style drop-downs) + public int hashCode() { + int hash = getValue().hashCode(); + hash = hash + getLabel().hashCode(); + + return hash; + } + + public boolean equals( Object obj ) { + boolean equivalent = false; + + Lookup lookup = (Lookup)obj; + if( lookup.getValue().equals(getValue()) && lookup.getLabel().equals(getLabel())) { + equivalent = true; + } + + return equivalent; + } + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/RaptorAdapter.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/RaptorAdapter.java new file mode 100644 index 00000000..99cc0272 --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/RaptorAdapter.java @@ -0,0 +1,368 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.openecomp.portalsdk.analytics.system.AppUtils; +import org.openecomp.portalsdk.core.domain.Menu; +import org.openecomp.portalsdk.core.domain.MenuData; +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.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Service("raptorAdapter") +public class RaptorAdapter extends FusionAdapter { + + @Autowired + private static DataAccessService dataAccessService; + + static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorAdapter.class); + + + public static final int RAPTOR_USER_ID = 20000; // RAPTOR system user id (for auditing purposes) + public static final String RAPTOR_CONTROLLER_CLASSNAME = "org.openecomp.portalsdk.analytics.controller.Controller"; + public static final String KEY_USER_ROLES_CACHE = "userRoles"; + + public void initializeRaptor() { + org.openecomp.portalsdk.analytics.config.ConfigLoader.setConfigFilesPath(SystemProperties.getProperty(SystemProperties.RAPTOR_CONFIG_FILE_PATH)); + org.openecomp.portalsdk.analytics.system.Globals.initializeSystem(getServletContext()); + } + + + /** Returns ID of the user currently logged in */ + public static String getUserID(HttpServletRequest request) { + return String.valueOf(UserUtils.getUserId(request)); + //return null; + } + + public static String getUserID(String user_id) { + return user_id; + } + + + public static String getUserBackdoorLoginId(HttpServletRequest request) { + if(AppUtils.getRequestNvlValue(request, "login_id").length()>0) return AppUtils.getRequestNvlValue(request, "login_id"); + return String.valueOf(UserUtils.getUserSession(request).getLoginId()); + } + + public static String getUserBackdoorLoginId(String user_id) { + return getUserLoginId(user_id); + } + + /** Obtains user name by ID */ + public static String getUserName(String userId) { + Map<String, Long> params = new HashMap<String, Long>(); + params.put("user_id", new Long(userId)); + + List list = getDataAccessService().executeNamedQuery("getUserNameById", params, null); + + String firstName = ""; + String lastName = ""; + + if (list != null) { + if (!list.isEmpty()) { + Object[] user = (Object[]) list.get(0); + firstName = (String) user[0]; // firstName scalar + lastName = (String) user[1]; // lastName scalar + } + } + + return lastName + ", " + firstName; + } + + public static String getUserName(HttpServletRequest request) { + User user = UserUtils.getUserSession(request); + return user.getLastName() + ", " + user.getFirstName(); + } + + public static String getUserEmail(String userId) { + Map<String, Long> params = new HashMap<String, Long>(); + params.put("user_id", new Long(userId)); + List list = getDataAccessService().executeNamedQuery("getUserEmail", params, null); + String email = ""; + if (list != null && !list.isEmpty()) + email = (String) list.get(0); + return email; + } + + public static String getUserEmail(HttpServletRequest request) { + User user = UserUtils.getUserSession(request); + return user.getEmail(); + } + + public static String getUserLoginId(String userId) { + + String loginId = ""; + try{ + List list = getDataAccessService().getList(User.class, " where user_id = " + userId, null, null); + if (list != null) { + if (!list.isEmpty()) { + User user = (User)list.get(0); + loginId = user.getLoginId(); // firstName scalar + } + } + }catch(Exception e){ + logger.error(EELFLoggerDelegate.debugLogger, ("error while getting login id : Exception" + e.getMessage())); + } + return loginId; + } + + + public static String getUserLoginId(HttpServletRequest request) { + User user = UserUtils.getUserSession(request); + return user.getLoginId(); + } + + /** Obtains list of all users (in IdNameValue objects) */ + public static Map<Long, String> getAllUsers(String customizedQuery, String param, boolean isAdmin) { + List users = null; + Map<Long, String> map = new LinkedHashMap<Long, String>(); + + if(customizedQuery.length()>0 && !isAdmin) { + + users = getDataAccessService().executeSQLQuery(customizedQuery, IdName.class, null); + + if (users != null) { + Iterator i = users.iterator(); + while (i.hasNext()) { + IdName item = (IdName)i.next(); + map.put(item.getId(), item.getName()); + } + } + + } else { + users = getDataAccessService().executeNamedQuery("getAllUsers", null, null); + if (users != null) { + Iterator i = users.iterator(); + while (i.hasNext()) { + Object[] user = (Object[])i.next(); + Long id = (Long)user[0]; // id scalar + String firstName = (String)user[1]; // firstName scalar + String lastName = (String)user[2]; // lastName scalar + map.put(id, lastName + ", " + firstName); + } + } + } + return map; + } + + /** Obtains role name by ID */ + public static String getRoleName(String roleId) { + Map<String, Long> params = new HashMap<String, Long>(); + params.put("role_id", new Long(roleId)); + + List list = getDataAccessService().executeNamedQuery("getRoleNameById", params, null); + + String roleName = ""; + + if (list != null) { + if (!list.isEmpty()) { + roleName = (String) list.get(0); // name scalar + } + } + + return roleName; + } + + /** Obtains list of all roles (in IdNameValue objects) */ + public static Map<Long, String> getAllRolesUsingCustomizedQuery(String customizedQuery, String param, boolean isAdmin) { + List roles = null; + + Map<Long, String> map = new LinkedHashMap<Long, String>(); + + if(customizedQuery.length()>0 && !isAdmin) { + + roles = getDataAccessService().executeSQLQuery(customizedQuery, IdName.class, null); + + if (roles != null) { + Iterator i = roles.iterator(); + while (i.hasNext()) { + IdName item = (IdName)i.next(); + map.put(item.getId(), item.getName()); + } + } + } else { + + roles = getDataAccessService().executeNamedQuery("getAllRoles", null, null); + + if (roles != null) { + Iterator i = roles.iterator(); + while (i.hasNext()) { + Object[] role = (Object[])i.next(); + Long id = (Long)role[0]; // id scalar + String name = (String)role[1]; // firstName scalar + map.put(id, name); + } + } + } + + return map; + } + + public static Set getUserRoles(HttpServletRequest request) { + return UserUtils.getRoles(request).keySet(); + } + + public static Set getUserRoles(String userId) { + Set userRoles = new HashSet<Long>(); +// Map usersRolesMap = new LinkedHashMap<Long, Set>(); +// Map<String, Long> params = new HashMap<String, Long>(); +// +// params.put("user_id", new Long(userId)); +// +// List usersRolesList = getDataAccessService().executeNamedQuery("getAllUsersRoles", params, null); +// Iterator i = usersRolesList.iterator(); +// while (i.hasNext()) { +// Object[] userRole = (Object[]) i.next(); +// +// Long roleId = (Long) userRole[1]; // role id scalar +// userRoles.add(roleId); +// +// } + userRoles = getActiveUsersRoleIds(new Long(userId)); + + + return userRoles; + } + + /** this is used to get role for the current user. **/ + public static synchronized boolean isCurrentUserInRole(HttpServletRequest request, String roleId) { + HttpSession session = request.getSession(false); + if(session!=null && session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME))!=null) + return UserUtils.hasRole(request, roleId); + else + return false; + } + + // public static void processErrorNotification(HttpServletRequest request, Exception e) { + //org.openecomp.portalsdk.core.web.support.AppUtils.processError(e, logger, request); + //} + + /** Obtains menu label by ID */ + public static String getMenuLabel(String menuId) { + return ((Menu) getDataAccessService().getDomainObject(MenuData.class, new Long(menuId), null)).getLabel(); + } + + public static String formatUserDateForDBTimeZone(String dateValue,String inPattern, + Long userId, String outPattern)throws Exception{ + return DateUtils.formatUserDateForDBTimeZone(dateValue,inPattern,userId,outPattern); + } + + public static String getCurrentDBDateForUser(String inPattern,Long userId)throws Exception{ + return DateUtils.getCurrentDBDateForUser(inPattern, userId); + } + + public static Set<Long> getActiveUsersRoleIds(Long userId) { + Set<Role> allActiveUserRoles = getActiveUserRoles(userId); + Iterator<Role> allActiveUserRolesIterator = allActiveUserRoles.iterator(); + Set<Long> allActiveUserRoleIds = new TreeSet<Long>(); + while(allActiveUserRolesIterator.hasNext()){ + Role role = allActiveUserRolesIterator.next(); + allActiveUserRoleIds.add(role.getId()); + } + + return allActiveUserRoleIds; + } + + public static Set<Long> getActiveUserRoleIds(Long userId) { + Set<Role> allActiveUserRoles = getActiveUserRoles(userId); + Iterator<Role> allActiveUserRolesIterator = allActiveUserRoles.iterator(); + Set<Long> allActiveUserRoleIds = new TreeSet<Long>(); + while(allActiveUserRolesIterator.hasNext()){ + Role role = allActiveUserRolesIterator.next(); + allActiveUserRoleIds.add(role.getId()); + } + + return allActiveUserRoleIds; + } + + public static Set<RoleFunction> getActiveRoleFunctions(Long userId) { + Set<Role> allActiveUserRoles = getActiveUserRoles(userId); + Iterator<Role> allActiveUserRolesIterator = allActiveUserRoles.iterator(); + Set<RoleFunction> allActiveRoleFunctions = new TreeSet<RoleFunction>(); + while(allActiveUserRolesIterator.hasNext()){ + Role role = allActiveUserRolesIterator.next(); + allActiveRoleFunctions.addAll(role.getRoleFunctions()); + } + + return allActiveRoleFunctions; + } + + public static Set<Role> getActiveUserRoles(Long userId) { + User user = (User)getDataAccessService().getDomainObject(User.class,userId,null); + Set<Role> allActiveUserRoles = new TreeSet<Role>(); + allActiveUserRoles.addAll(user.getRoles()); + Iterator<Role> userRolesIterator = user.getRoles().iterator(); + while(userRolesIterator.hasNext()){ + getAllChildRoles( userRolesIterator.next(),allActiveUserRoles); + } + + Iterator<Role> allActiveUserRolesIterator = allActiveUserRoles.iterator(); + while(allActiveUserRolesIterator.hasNext()){ + Role role = allActiveUserRolesIterator.next(); + if(!role.getActive()){ + allActiveUserRolesIterator.remove(); + } + } + + return allActiveUserRoles; + } + + public static Set<Role> getAllChildRoles(Role role, Set<Role> allchildRoles) { + Set<Role> childRoles = role.getChildRoles(); + allchildRoles.addAll(childRoles); + Iterator<Role> childRolesIterator = childRoles.iterator(); + while (childRolesIterator.hasNext()) { + getAllChildRoles(childRolesIterator.next(),allchildRoles); + } + return allchildRoles; + } + + + public static DataAccessService getDataAccessService() { + return org.openecomp.portalsdk.core.web.support.AppUtils.getDataAccessService(); + } + + + public static void setDataAccessService(DataAccessService dataAccessService) { + dataAccessService = dataAccessService; + } + + + +} diff --git a/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/SpringContext.java b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/SpringContext.java new file mode 100644 index 00000000..1d46290a --- /dev/null +++ b/ecomp-sdk/sdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/SpringContext.java @@ -0,0 +1,37 @@ +/*- + * ================================================================================ + * 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.analytics.system.fusion.adapter; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component("springContext") +public class SpringContext implements ApplicationContextAware { + private static ApplicationContext context; + + public void setApplicationContext(ApplicationContext context) throws BeansException { + this.context = context; + } + public static ApplicationContext getApplicationContext() { + return context; + } +} |