/*
* This software and supporting documentation were developed by
*
* Siemens Corporate Technology
* Competence Center Knowledge Management and Business Transformation
* D-81730 Munich, Germany
*
* Authors (representing a really great team ;-) )
* Stefan B. Augustin, Thorbj�rn Hansen, Manfred Langen
*
* This software is Open Source under GNU General Public License (GPL).
* Read the text of this license in LICENSE.TXT
* or look at www.opensource.org/licenses/
*
* Once more we emphasize, that:
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, WITHOUT ANY WARRANTY
* REGARDING THE SOFTWARE, ITS PERFORMANCE OR
* FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
* ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
* PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
*/
// P_GadgetViewBroker
// ************ package ****************************************************
package appl.Portal.Personalize.DB;
// ************ imports ******************************************************
import KFM.Exceptions.KFM_SQLException;
import KFM.DB.*;
import KFM.DB.DbTagValueIterator; // Father class.
import KFM.Converter;
import KFM.Exceptions.KFM_NoSuchObjectException;
import java.util.*;
import java.io.*;
import KFM.log.*;
import KFM.DateTimeServices.*;
import KFM.Exceptions.ProgrammerException;
/** View on Gadgets. Connects P_GadgetView and P_RolesView (not a DB view but a DB table).
*
* Cut and paste file was `CompetenceView� and `PersonsTrainingsView� in KMS.
*
* @version 0.1 (27.08.99)
*/
public class P_GadgetViewBroker
{
private P_RolesView mRolesView;
private P_GadgetView mGadgetView;
private Properties mGadgetRoles = null;
public P_GadgetViewBroker(KFM_Database2 aDb)
{
mGadgetRoles = new Properties();
mRolesView = new P_RolesView(aDb);
mGadgetView = new P_GadgetView(aDb);
}
public Hashtable getOnlyNecessary()
throws KFM_SQLException
{
mGadgetView.loadOnlyNecessary();
return performLoad(false);
}
/**
* Gets all valid gadgets from db and their corresponding roles.
* @return a Hashtable consisting of the gadgetids as keys,
* a second hashtable as value consisting of the languages as keys
* and the gadgets as entries.
* @throws KFM_SQLException
*/
public Hashtable getAllValidGadgets()
throws KFM_SQLException
{
mGadgetView.loadAllValidGadgets();
return performLoad(false);
}
/**
* Gets all gadgets from db and their corresponding roles.
* @return a Hashtable consisting of the gadgetids as keys,
* a second hashtable as value consisting of the languages as keys
* and the gadgets as entries.
* @throws KFM_SQLException
*/
public Hashtable getAllGadgets()
throws KFM_SQLException
{
mGadgetView.loadAllGadgets();
return performLoad(false);
}
/**
* Gets all gadgets from db and their corresponding roles.
* @return a Hashtable structure.
*
* application hashtable with application id as key and gadget hashtables
* as value
* gadget hashtable has gadgetids as keys and language hashtables as values
* the language hashtable has language as key and gadgets as values
*
* @throws KFM_SQLException
*/
public Hashtable getAllGadgetsOrderedByApplications()
throws KFM_SQLException
{
mGadgetView.loadAllGadgets();
return performLoad(true);
}
private void initializeRoles()
throws KFM_SQLException
{
// Initialize mGadgetRoles
mRolesView.loadAllRoles();
mRolesView.reset();
while (mRolesView.next())
{
String tRole = mRolesView.getString("Role_Name");
String tId = mRolesView.getString("GadgetId");
// The value of the properties object is a vector of role_names
// because a gadget can have a number of roles.
Vector tCurrRoles = (Vector) mGadgetRoles.get(tId);
if (tCurrRoles == null)
tCurrRoles = new Vector();
tCurrRoles.addElement(tRole);
mGadgetRoles.put(tId, tCurrRoles);
}
}
/**
* This method delivers a hashtable containing all gadgets. If aOrderedByApplication
* is set to true the gadget hashtable will be embedded in an application
* hashtable.
* @param aOrderedByApplication
* @return
* @throws KFM_SQLException
*/
private Hashtable performLoad(boolean aOrderedByApplication)
throws KFM_SQLException
{
initializeRoles();
Hashtable tApplications = new Hashtable();
Hashtable tAllGadgets = new Hashtable();
mGadgetView.reset();
while (mGadgetView.next())
{
String tID = mGadgetView.getString("ID");
String tApp_ID = mGadgetView.getString("appl_id");
int tis_cas = getIntValue("is_cas");
String tGadgetID = mGadgetView.getString("GadgetID");
String tLanguage = mGadgetView.getString("Language");
String tGuiTitle = mGadgetView.getString("GUITitle");
String tQuickUrl = mGadgetView.getString("QuickUrl");
String tQuickPostParams = mGadgetView.getString("QuickPostParams");
String tQuickFormParams = mGadgetView.getString("QuickFormParams");
String tWorkUrl = mGadgetView.getString("WorkUrl");
String tWorkPostParams = mGadgetView.getString("WorkPostParams");
String tWorkFormParams = mGadgetView.getString("WorkFormParams");
String tAppl_Url = mGadgetView.getString("Appl_Url");
String tPrefs_Url = mGadgetView.getString("Prefs_Url");
String tHelp_Url = mGadgetView.getString("Help_Url");
String tDescription = mGadgetView.getString("Description");
String tPicDef_Path = mGadgetView.getString("PicDef_Path");
String tPicWork_Path = mGadgetView.getString("PicWork_Path");
String tValidUntil = mGadgetView.getString("validuntil");
int tExpandToWork = getIntValue("ExpandToWork");
int tExpandToDesktop = getIntValue("ExpandToDesktop");
int tQuickForceDump = getIntValue("QuickForceDump");
int tWorkForceDump = getIntValue("WorkForceDump");
String tAllowForSlot = mGadgetView.getString("AllowForSlot");
int tForceLock = getIntValue("forceLock");
String tForceLockText = mGadgetView.getString("forceLockText");
int tStatePreserving = getIntValue("statePreserving");
int tAdvancedSettings = getIntValue("advancedSettings");
int tServletStartWaitTime = getIntValue("servletStartWaitTime");
int tServletStartCycleTime = getIntValue("servletStartCycleTime");
int tServletStartMaxTime = getIntValue("servletStartMaxTime");
int tTransferSession = getIntValue("transfer_session");
int tTransferNick = getIntValue("transfer_nick");
int tTransferLastName = getIntValue("transfer_lastname");
int tTransferFirstName = getIntValue("transfer_firstname");
int tTransferGid = getIntValue("transfer_gid");
int tTransferDepartment = getIntValue("transfer_department");
int tTransferEmail = getIntValue("transfer_email");
int tTransferPhone = getIntValue("transfer_phone");
int tTransferOrganisation = getIntValue("transfer_organisation");
int tTransferOrgUnit = getIntValue("transfer_organisationunit");
int tTransferLocation = getIntValue("transfer_location");
int tTransferCountry = getIntValue("transfer_country");
int tTransferDN = getIntValue("transfer_dn");
int tTransferAPD = getIntValue("transfer_apd_persnr");
int tTransferMAIdent = getIntValue("transfer_ma_ident");
int tTransferAuthtype = getIntValue("transfer_authtype");
int tTransferSiemensOrg = getIntValue("transfer_siemensorganisation");
int tTransferSCDID = getIntValue("transfer_scdid");
int tTransferRole = getIntValue("transfer_role");
int tTransferLanguage = getIntValue("transfer_portal_language");
int tTransferModem = getIntValue("transfer_modem");
int tTransferStatId = getIntValue("transfer_statid");
int tIsNecessaryOnLoad = getIntValue("necessaryOnLoad");
// Now get the roles
Vector tRoles = (Vector)mGadgetRoles.get(tID);
if (tRoles == null)
throw new ProgrammerException ("Wrong configuration. Gadget with id "
+ tID + " has no roles assigned!");
String [] tRolesVector = new String[tRoles.size()];
tRoles.copyInto(tRolesVector);
// Build the gadget
Gadget tGadget = new Gadget(tGadgetID,
tID,
tis_cas,
tApp_ID,
tLanguage,
tGuiTitle,
tDescription,
tPicDef_Path,
tPicWork_Path,
tForceLock,
tForceLockText,
tStatePreserving,
tAdvancedSettings,
tValidUntil);
tGadget.setApplicationUrls(tQuickUrl,
tQuickPostParams,
tQuickFormParams,
tWorkUrl,
tWorkPostParams,
tWorkFormParams,
tAppl_Url,
tPrefs_Url,
tHelp_Url);
tGadget.setFlags(
tExpandToWork,
tExpandToDesktop,
tQuickForceDump,
tWorkForceDump,
tAllowForSlot);
tGadget.setServletWaitTimes(
tServletStartWaitTime, tServletStartCycleTime, tServletStartMaxTime);
tGadget.setTransferBits( tTransferSession,
tTransferNick,
tTransferLastName,
tTransferFirstName,
tTransferGid,
tTransferDepartment,
tTransferEmail,
tTransferPhone,
tTransferOrganisation,
tTransferOrgUnit,
tTransferLocation,
tTransferCountry,
tTransferDN,
tTransferAPD,
tTransferMAIdent,
tTransferAuthtype,
tTransferSiemensOrg,
tTransferSCDID,
tTransferRole,
tTransferLanguage,
tTransferModem,
tTransferStatId);
//Set the isNecessary flag to indicate if this gadget has to be transmitted on load
tGadget.setNecessaryOnLoad(tIsNecessaryOnLoad);
// set the roles
tGadget.setRoles(tRolesVector);
// Checks if there is already an entry for this application
Hashtable tGadgets = (Hashtable)tApplications.get(tApp_ID);
if (tGadgets == null)
tGadgets = new Hashtable();
// Checks if there is already an entry for this gadget
Hashtable tEntries = (Hashtable)tGadgets.get(tGadgetID);
if (tEntries == null)
tEntries = new Hashtable();
// puts the gadget by its language in the hashtable tEntries
tEntries.put(tLanguage, tGadget);
// puts the tEntries hashtable by the gadgetid in the hashtable
// tGadgets
tGadgets.put(tGadgetID, tEntries);
tAllGadgets.put(tGadgetID, tEntries);
// puts the tGadgets hashtable by the application id in the
// hashtable tApps
tApplications.put(tApp_ID, tGadgets);
}
if (aOrderedByApplication){
return tApplications;
} else {
return tAllGadgets;
}
}
/**
* Gets a valid integer value for a integer column
* @param aColumnName name of the db column
* @return the integer value. If the value is 'null' returns '0'
*/
private int getIntValue(String aColumnName)
{
int tRet = 0;
String tValue = mGadgetView.getString(aColumnName);
if (tValue != null && !tValue.equals(""))
tRet = Integer.parseInt(tValue);
return tRet;
}
public static void main (String [] args)
{
String sJDBCDRIVER = "JdbcDriver";
String sJDBCCONN = "JdbcConnectionURL";
String sDBUSER = "JdbcUser";
String sDBPWD = "JdbcPassword";
String sLOGFILENAME = "LogFileName";
String sLOGFILELEVEL = "LogFileLevel";
String sLOGFILEPREFIX = "LogFilePrefix";
String sLOGFILEORIGINATOR = "LogFileOriginator";
String tFilePath = "o:/kfm/config/dev/tanker/Personalize.properties";
System.out.println("Initialize DB");
// Initialization
Properties tProps = new Properties ();
KFM_Database2 tDB = null;
try{
tProps.load (new FileInputStream (tFilePath));
KFMLog tLog = KFMLog.getInstance((String)tProps.get (sLOGFILEORIGINATOR),
(String)tProps.get (sLOGFILENAME),
Integer.parseInt((String)tProps.get (sLOGFILELEVEL)),
null,
null);
tDB = new KFM_Database2( tLog,
(String)tProps.get (sJDBCDRIVER),
(String)tProps.get (sJDBCCONN),
(String)tProps.get (sDBUSER),
(String)tProps.get (sDBPWD));
// } End refactor.
// * Initialization - do everytime
tDB.establishConnection();
// Clear autocommit *after* opening the DB Adapter. Really!
System.out.println("Fetch Gadgets ");
P_GadgetViewBroker tBroker = new P_GadgetViewBroker (tDB);
//Get all Gadgets from db
Hashtable tGadgets = tBroker.getAllGadgets();
Enumeration tKeys = tGadgets.keys();
while (tKeys.hasMoreElements())
{
// Get the gadget id
String tID = (String )tKeys.nextElement();
System.out.println("id for gadget is "+tID);
//the gadgets for the languages
Hashtable tEntries = (Hashtable)tGadgets.get(tID);
//Step through the entries for languages
Enumeration tEntryKeys = tEntries.keys();
while (tEntryKeys.hasMoreElements())
{
String tLanguage = (String)tEntryKeys.nextElement();
Gadget tGadget = (Gadget)tEntries.get(tLanguage);
System.out.println(tGadget.toString());
}
}
}
catch (Exception e){
e.printStackTrace();
}
finally
{
if ((tDB!= null)&& (tDB.isConnected())){
try{
tDB.freeConnection();
}
catch (KFM_SQLException ex){
ex.printStackTrace();
}
}
}
}
}