From 6beb446925c967aca92f5513adf36c5db77c00d6 Mon Sep 17 00:00:00 2001 From: TATTAVARADA Date: Thu, 27 Apr 2017 07:53:18 -0400 Subject: [PORTAL-7] Rebase This rebasing includes common libraries and common overlays projects abstraction of components Change-Id: Ia1efa4deacdc5701e6205104ac021a6c80ed60ba Signed-off-by: st782s --- .../adapter/AdapterSessionFactoryContainer.java | 39 +++ .../analytics/system/fusion/adapter/DateUtils.java | 287 ++++++++++++++++ .../system/fusion/adapter/FusionAdapter.java | 121 +++++++ .../analytics/system/fusion/adapter/IdName.java | 67 ++++ .../analytics/system/fusion/adapter/Item.java | 55 +++ .../analytics/system/fusion/adapter/Lookup.java | 85 +++++ .../system/fusion/adapter/RaptorAdapter.java | 367 +++++++++++++++++++++ .../system/fusion/adapter/SpringContext.java | 37 +++ 8 files changed, 1058 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/DateUtils.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Item.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/RaptorAdapter.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/SpringContext.java (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter') diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/AdapterSessionFactoryContainer.java new file mode 100644 index 00000000..6a70d258 --- /dev/null +++ b/ecomp-sdk/epsdk-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.*; + +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/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/DateUtils.java b/ecomp-sdk/epsdk-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/epsdk-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/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java new file mode 100644 index 00000000..4b6c6d78 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/FusionAdapter.java @@ -0,0 +1,121 @@ +/*- + * ================================================================================ + * 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.*; +import java.util.*; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.servlet.*; + +import com.mchange.v2.c3p0.ComboPooledDataSource; + +import org.hibernate.SessionFactory; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SessionImplementor; +import org.openecomp.portalsdk.core.FusionObject; +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; + +public class FusionAdapter implements FusionObject { + + public static final String LOCAL_SESSION_FACTORY_KEY = "local"; + + + private ComboPooledDataSource dataSource; + private Map dataSourceMap; + + //private SessionFactory sessionFactory; + private ServletContext servletContext; + + public FusionAdapter() { + } + + + public ServletContext getServletContext() { + return servletContext; + } + + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + + /** Gets connection to the database **/ + public Connection getConnection() { + 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(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + + public ComboPooledDataSource getDataSource() { + return dataSource; + } + + + @Autowired + public void setDataSource(ComboPooledDataSource dataSource) { + this.dataSource = dataSource; + } + + public Map getDataSourceMap() { + if(dataSourceMap==null) + dataSourceMap = (Map)SpringContext.getApplicationContext().getBean("dataSourceMap"); + + return dataSourceMap; + } + + public void setdataSourceMap(Map dataSourceMap) { + this.dataSourceMap = dataSourceMap; + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java new file mode 100644 index 00000000..c46d6730 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/IdName.java @@ -0,0 +1,67 @@ +/*- + * ================================================================================ + * 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 javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.openecomp.portalsdk.core.domain.support.DomainVo; + +/** + *

IdName.java

+ *

Represents a id/name data object.

+*/ +@Entity +public class IdName extends DomainVo { + + private String name; + private Long id; + + public IdName() {} + + @Id + @GeneratedValue + @Column(name = "ID", unique = true, nullable = false) + 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); + } + +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Item.java b/ecomp-sdk/epsdk-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/epsdk-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/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/adapter/Lookup.java new file mode 100644 index 00000000..c77835ed --- /dev/null +++ b/ecomp-sdk/epsdk-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.*; + +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