/*
* $RCSfile: AppSettingsEJB.java,v $ $Revision: 1.3 $ $Date: 2005/07/25 13:05:22 $ - $Author: mcallist $
*
* The contents of this file are subject to the Open Software License
* Version 2.1 (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.centraview.com/opensource/license.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is: CentraView Open Source.
*
* The developer of the Original Code is CentraView. Portions of the
* Original Code created by CentraView are Copyright (c) 2004 CentraView,
* LLC; All Rights Reserved. The terms "CentraView" and the CentraView
* logos are trademarks and service marks of CentraView, LLC.
*/
package com.centraview.administration.applicationsettings;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import org.apache.log4j.Logger;
import com.centraview.common.CVDal;
import com.centraview.common.DDNameValue;
/**
* This is the EJB class for Administration module -- Preferences The Logic for
* methods defined in Remote interface is defined in this class
* @author CentraView, LLC.
*/
public class AppSettingsEJB implements SessionBean {
protected SessionContext ctx;
private String dataSource = "MySqlDS";
private static Logger logger = Logger.getLogger(AppSettingsEJB.class);
public void setSessionContext(SessionContext ctx)
{
this.ctx = ctx;
}
public void ejbCreate()
{}
public void ejbRemove()
{}
public void ejbActivate()
{}
public void ejbPassivate()
{}
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new <code>setting</code> type record
* will be created. If the ID is something other than <code>-1</code>, the
* existing <code>setting</code> type record will be found and updated.
* @param setting The setting type to update.
* @param sourceCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
public void addMasterDataSettings(String setting, Collection sourceCollection)
{
if (setting != null) {
if (setting.equalsIgnoreCase("Source")) {
updateSource(sourceCollection);
} else if (setting.equalsIgnoreCase("Type")) {
updateTypes(sourceCollection);
} else if (setting.equalsIgnoreCase("Stage")) {
updateStages(sourceCollection);
} else if (setting.equalsIgnoreCase("Term")) {
updateTerms(sourceCollection);
} else if (setting.equalsIgnoreCase("Literature")) {
;// does nothing
} else if (setting.equalsIgnoreCase("Status")) {
updateStatus(sourceCollection);
} else if (setting.trim().equalsIgnoreCase("ACTerms")) {
updateAccountingTerm(sourceCollection);
} else if ((setting.equalsIgnoreCase("OrderStatus")) || (setting.equalsIgnoreCase("InvoiceStatus"))) {
updateOrderStatus(sourceCollection);
} else if (setting.equalsIgnoreCase("Locations")) {
updateLocations(sourceCollection);
} else if (setting.equalsIgnoreCase("Resource")) {
updateResources(sourceCollection);
} else if (setting.equalsIgnoreCase("Suggestion Box")) {
;// does nothing
}
} // end of if statement (setting != null)
} // end of addMasterDataSettings method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Source record will be created. If
* the ID is something other than <code>-1</code>, the existing Source
* record will be found and updated.
* @param sourceCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateSource(Collection sourceCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (sourceCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = sourceCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO source (Name) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE source SET Name = ? WHERE SourceID = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM source WHERE SourceID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
} catch (Exception e) {
logger.error("[updateSource]: Exception", e);
} finally {
cvdl.destroy();
} // end of finally block
} // end of updateSource method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Type record will be created. If
* the ID is something other than <code>-1</code>, the existing Type record
* will be found and updated.
* @param typeCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateTypes(Collection typeCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (typeCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = typeCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO salestype (Name) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE salestype SET Name = ? WHERE SalesTypeID = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM salestype WHERE SalesTypeID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
} // end of try block
catch (Exception e) {
logger.error("[updateTypes]: Exception", e);
} finally {
cvdl.destroy();
} // end of finally block
} // end of updateTypes method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Stage record will be created. If
* the ID is something other than <code>-1</code>, the existing Stage
* record will be found and updated.
* @param stageCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateStages(Collection stageCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (stageCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = stageCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO salesstage (Name) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE salesstage SET Name = ? WHERE SalesStageID = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM salesstage WHERE SalesStageID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
} // end of try block
catch (Exception e) {
logger.error("[updateStages]: Exception", e);
} finally {
cvdl.destroy();
} // end of finally block
} // end of updateStages method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Term record will be created. If
* the ID is something other than <code>-1</code>, the existing Term record
* will be found and updated.
* @param termsCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateTerms(Collection termsCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (termsCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = termsCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO terms (TermName) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE terms SET TermName = ? WHERE TermID = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM terms WHERE TermID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateTerms]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateTerms method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Status record will be created. If
* the ID is something other than <code>-1</code>, the existing Status
* record will be found and updated.
* @param statusCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateStatus(Collection statusCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (statusCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = statusCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO projectstatus (Title) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE projectstatus SET Title = ? WHERE StatusID = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM projectstatus WHERE StatusID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateStatus]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateStatus method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Term record will be created. If
* the ID is something other than <code>-1</code>, the existing Term record
* will be found and updated.
* @param termCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateAccountingTerm(Collection termCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (termCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = termCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO accountingterms (title) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE accountingterms SET title = ? WHERE termsid = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM accountingterms WHERE termsid NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateAccountingTerm]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateAccountingTerm method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Order Status record will be
* created. If the ID is something other than <code>-1</code>, the existing
* Order Status record will be found and updated.
* @param statusCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateOrderStatus(Collection statusCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (statusCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = statusCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO accountingstatus (title) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE accountingstatus SET title = ? WHERE statusid = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM accountingstatus WHERE statusid NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateOrderStatus]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateOrderStatus method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Location record will be created.
* If the ID is something other than <code>-1</code>, the existing Location
* record will be found and updated.
* @param locationCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateLocations(Collection locationCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (locationCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = locationCollection.iterator();
while (it.hasNext()) {
DDNameValue sourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: sourceObject: " +
// sourceObject.toString());
if (sourceObject.getName() != null && sourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO location (title) VALUES (?)");
cvdl.setString(1, sourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (sourceObject.getName() != null ...
else if (sourceObject.getName() != null) {
// update the existing Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE location SET title = ? WHERE locationid = ?");
cvdl.setString(1, sourceObject.getName());
cvdl.setInt(2, sourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(sourceObject.getId());
} // end of else if statement (sourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM location WHERE locationid NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateLocations]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateLocations method
/**
* This method is expecting a Collection of DDNameValues. If the ID in the
* DDNameValue is <code>-1</code>, a new Resource record will be created.
* If the ID is something other than <code>-1</code>, the existing Resource
* record will be found and updated.
* @param resourceCollection A Collection of DDNameValues.
* @see com.centraview.common.DDNameValue
*/
private void updateResources(Collection resourceCollection)
{
CVDal cvdl = new CVDal(dataSource);
try {
if (resourceCollection != null) {
StringBuffer stringBuffer = new StringBuffer();
Iterator it = resourceCollection.iterator();
while (it.hasNext()) {
DDNameValue resourceObject = (DDNameValue) it.next();
// System.out.println("[DEBUG] [AppSettingsEJB]: resourceObject: " +
// resourceObject.toString());
if (resourceObject.getName() != null && resourceObject.getId() == -1) {
// create a new Source Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("INSERT INTO activityresources (Name) VALUES (?)");
cvdl.setString(1, resourceObject.getName());
cvdl.executeUpdate();
int newId = cvdl.getAutoGeneratedKey();
stringBuffer.append(newId);
} // end of if statement (resourceObject.getName() != null ...
else if (resourceObject.getName() != null) {
// update the existing Resource Record
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("UPDATE activityresources SET Name = ? WHERE ActivityResourceID = ?");
cvdl.setString(1, resourceObject.getName());
cvdl.setInt(2, resourceObject.getId());
cvdl.executeUpdate();
stringBuffer.append(resourceObject.getId());
} // end of else if statement (resourceObject.getName() != null)
if (stringBuffer.length() > 0 && it.hasNext()) {
stringBuffer.append(", ");
}
} // end of while loop (it.hasNext())
if (stringBuffer.length() > 0) {
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DELETE FROM activityresources WHERE ActivityResourceID NOT IN (" + stringBuffer + ")");
cvdl.executeUpdate();
} // end of if statement (stringBuffer.length() > 0)
} // end of if statement (sourceValues != null)
}catch (Exception e) {
logger.error("[updateResources]: Exception", e);
}finally {
cvdl.destroy();
} // end of finally block
} // end of updateResources method
public Vector viewMasterDataSettings(String setting)
{
CVDal dl = new CVDal(dataSource);
Vector valuelist = new Vector();
try {
dl.setSqlQuery("select name from ?");
dl.setString(1, setting);
java.util.Collection col = dl.executeQuery();
if (col != null) {
java.util.Iterator it = col.iterator();
int count = 1;
while (it.hasNext()) {
HashMap hm = (java.util.HashMap) it.next();
valuelist.addElement(hm.get("Name").toString());
count++;
}
}
} catch (Exception e) {
logger.error("[viewMasterDataSettings]: Exception", e);
} finally {
dl.destroy();
}
return valuelist;
}
/**
* get record types of module.
*/
public Vector getRecordType(String module)
{
CVDal dl = new CVDal(dataSource);
Vector valuelist = new Vector();
try {
dl.setSql("appsettings.getrecordtypes");
dl.setString(1, module);
java.util.Collection col = dl.executeQuery();
if (col != null) {
java.util.Iterator it = col.iterator();
int count = 1;
StringTokenizer sttk = null;
while (it.hasNext()) {
java.util.HashMap hm = (java.util.HashMap) it.next();
sttk = new StringTokenizer(hm.get("primarytable").toString(), " ");
valuelist.addElement(sttk.nextToken());
count++;
}
}
} catch (Exception e) {
logger.error("[getRecordType]: Exception", e);
} finally {
dl.destroy();
}
return valuelist;
}
public void addSupportMailId(Vector ids)
{
CVDal cvdl = null;
try {
cvdl = new CVDal(dataSource);
cvdl.setSqlQuery("delete from supportemailaccount");
cvdl.executeUpdate();
for (Enumeration e = ids.elements(); e.hasMoreElements();) {
cvdl.setSqlQueryToNull();
String val = e.nextElement().toString();
cvdl.setSqlQuery("insert into supportemailaccount(EmailAccountID) values(?)");
cvdl.setString(1, val);
cvdl.executeUpdate();
}
} catch (Exception e) {
logger.error("[addSupportMailId]: Exception", e);
} finally {
cvdl.destroy();
}
}
public Vector getSupportMailId()
{
CVDal dl = new CVDal(dataSource);
Vector ids = new Vector();
try {
dl.setSqlQuery("select EmailAccountID from supportemailaccount");
java.util.Collection col = dl.executeQuery();
if (col != null) {
java.util.Iterator it = col.iterator();
int count = 1;
while (it.hasNext()) {
java.util.HashMap hm = (java.util.HashMap) it.next();
ids.addElement(hm.get("EmailAccountID").toString());
count++;
}
}
} catch (Exception e) {
logger.error("[getSupportMailId]: Exception", e);
} finally {
dl.destroy();
}
return ids;
}
public void exportTable(String filePath, String tabname)
{
CVDal cvdl = new CVDal(dataSource);
try {
cvdl.setSqlQuery("Select * from " + tabname);
cvdl.writeToFile(filePath, tabname);
} catch (Exception e) {
logger.error("[exportTable]: Exception", e);
} finally {
cvdl.destroy();
}
}
/**
* Get emailids from suggestionbox table for support
* @return Vector
*/
public Vector getAllSupportEmailIds()
{
Vector vec = new Vector();
CVDal cvdl = new CVDal(dataSource);
try {
cvdl.setSqlQuery("Select emailid from suggestionbox");
Collection col = cvdl.executeQuery();
Iterator it = col.iterator();
if (col != null) {
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
vec.add(hm.get("emailid"));
}
}
} catch (Exception e) {
logger.error("[getAllSupportEmailIds]: Exception", e);
} finally {
cvdl.destroy();
}
return vec;
}
public String getApplicationSettings(String msname)
{
CVDal cvdal = new CVDal(dataSource);
String valuelist = "";
try {
cvdal.setSqlQuery("SELECT msname, msvalue FROM applicationsetting WHERE msname=?");
cvdal.setString(1, msname);
Collection results = cvdal.executeQuery();
if (results != null && results.size() > 0) {
Iterator iter = results.iterator();
while (iter.hasNext()) {
HashMap row = (HashMap) iter.next();
valuelist = (row.get("msvalue").toString());
}
}
} catch (Exception e) {
logger.error("[getApplicationSettings]: Exception", e);
} finally {
cvdal.destroy();
}
return valuelist;
} // end getApplicationSettings(String) method
public void updateApplicationSettings(String msname, String msvalue)
{
CVDal cvdl = new CVDal(dataSource);
try {
cvdl.setSqlQuery("update applicationsetting set msvalue=? where msname=?");
cvdl.setString(1, msvalue);
cvdl.setString(2, msname);
cvdl.executeUpdate();
cvdl = null;
} catch (Exception e) {
logger.error("[updateApplicationSettings]: Exception", e);
} finally {
cvdl.destroy();
}
}
/**
* @author Kevin McAllister <kevin@centraview.com> This simply sets the target
* datasource to be used for DB interaction
* @param ds A string that contains the cannonical JNDI name of the datasource
*/
public void setDataSource(String ds)
{
this.dataSource = ds;
}
/**
* Returns the Calendar Settings (read: work hours/days) for the Application.
* The Hashmap being returned includes three entries: workingdays, starttime,
* endtime. Null is never returned, if there are no current settings, an emtpy
* Hashmap is returned.
* @return A Hashmap with three entries. workingdays, starttime, endtime.
*/
public HashMap getCalendarSettings()
{
HashMap hm = new HashMap();
CVDal cvdl = new CVDal(dataSource);
try {
cvdl.setSqlQuery("select starttime,endtime,workingdays from applicationsetting where workingdays != ''");
java.util.Collection col = cvdl.executeQuery();
cvdl.setSqlQueryToNull();
if (col != null) {
java.util.Iterator it = col.iterator();
while (it.hasNext()) {
hm = (HashMap) it.next();
}
}
} catch (Exception e) {
logger.error("[getCalendarSettings]: Exception", e);
} finally {
cvdl.destroy();
}
return hm;
}
public void updateCalendarSettings(String start, String end, String workingdays)
{
CVDal cvdl = new CVDal(dataSource);
try {
workingdays = workingdays.substring(0, (workingdays.length() - 1));
cvdl.setSqlQuery("select workingdays from applicationsetting");
java.util.Collection col = cvdl.executeQuery();
cvdl.setSqlQueryToNull();
String workday = "";
if (col != null) {
java.util.Iterator it = col.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
workday = (String) hm.get("workingdays");
}
}
if (workday.length() != 0) {
cvdl.setSqlQuery("update applicationsetting set starttime=?, endtime =?, workingdays=? where workingdays !=''");
cvdl.setString(1, start);
cvdl.setString(2, end);
cvdl.setString(3, workingdays);
cvdl.executeUpdate();
} else {
cvdl.setSqlQuery("insert into applicationsetting(starttime,endtime,workingdays) values(?,?,?)");
cvdl.setString(1, start);
cvdl.setString(2, end);
cvdl.setString(3, workingdays);
cvdl.executeUpdate();
}
} catch (Exception e) {
logger.error("[updateCalendarSettings]: Exception", e);
} finally {
cvdl.destroy();
}
}
}