You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(217) |
Nov
(180) |
Dec
(71) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(58) |
Feb
(370) |
Mar
(105) |
Apr
(165) |
May
(93) |
Jun
(37) |
Jul
|
Aug
(21) |
Sep
(131) |
Oct
(40) |
Nov
(113) |
Dec
(401) |
2007 |
Jan
(180) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2008 |
Jan
(163) |
Feb
(78) |
Mar
|
Apr
(4) |
May
(28) |
Jun
(2) |
Jul
|
Aug
|
Sep
(96) |
Oct
(189) |
Nov
(413) |
Dec
(121) |
2009 |
Jan
(34) |
Feb
(18) |
Mar
(24) |
Apr
(16) |
May
(3) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(13) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(3) |
Oct
(16) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
(35) |
Jun
|
Jul
(17) |
Aug
(7) |
Sep
|
Oct
(9) |
Nov
|
Dec
|
From: Marc B. <mb...@us...> - 2005-11-12 00:56:33
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27771 Modified Files: Tag: itrackerhibernate EditConfigurationAction.java Log Message: fixed updating status entities (COnfigurationBean of type status). Mainly this included deleting old language resources after changing the value of the status. This causes the resource key to change. Index: EditConfigurationAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditConfigurationAction.java,v retrieving revision 1.10.4.6 retrieving revision 1.10.4.7 diff -C2 -d -r1.10.4.6 -r1.10.4.7 *** EditConfigurationAction.java 9 Nov 2005 20:20:06 -0000 1.10.4.6 --- EditConfigurationAction.java 12 Nov 2005 00:56:25 -0000 1.10.4.7 *************** *** 72,75 **** --- 72,77 ---- String action = (String) PropertyUtils.getSimpleProperty(form, "action"); String formValue = (String) PropertyUtils.getSimpleProperty(form, "value"); + + String initialLanguageKey = null; HashMap translations = (HashMap) PropertyUtils.getSimpleProperty(form, "translations"); *************** *** 136,139 **** --- 138,144 ---- throw new SystemConfigurationException("Invalid configuration item id " + id); } + + initialLanguageKey = SystemConfigurationUtilities.getLanguageKey(configItem); + if(configItem.getType() == SystemConfigurationUtilities.TYPE_STATUS && formValue != null && ! formValue.equals("")) { if(! configItem.getValue().equalsIgnoreCase(formValue)) { *************** *** 208,212 **** --- 213,222 ---- String baseValue = (String) translations.get(ITrackerResources.BASE_LOCALE); sc.updateLanguageItem(new LanguageModel(ITrackerResources.BASE_LOCALE, key, baseValue)); + // remove old languageItems if resource key has changed + if ( initialLanguageKey != null && !initialLanguageKey.equals( key ) ) { + sc.removeLanguageKey( initialLanguageKey ); + } ITrackerResources.clearKeyFromBundles(key, true); + ITrackerResources.clearKeyFromBundles(initialLanguageKey, true); } |
From: Marc B. <mb...@us...> - 2005-11-12 00:52:44
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27069 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - implemented removeConfigurationItem Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.8 retrieving revision 1.31.4.9 diff -C2 -d -r1.31.4.8 -r1.31.4.9 *** SystemConfigurationBean.java 12 Nov 2005 00:20:30 -0000 1.31.4.8 --- SystemConfigurationBean.java 12 Nov 2005 00:52:34 -0000 1.31.4.9 *************** *** 1 **** ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; private ConfigurationFactory configurationFactory; private CustomFieldFactory customFieldFactory; private CustomFieldValueFactory customFieldValueFactory; private LanguageFactory languageFactory; private WorkflowScriptFactory workflowScriptFactory; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } /** * Creates a <code>ConfigurationModel</code>. * * @param model The <code>ConfigurationModel</code> to store * @return the <code>ConfigurationModel</code> after saving */ public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } /** * Updates a <code>ConfigurationItem</code> * * @param model The model containing the data * @return the <code>ConfigurationModel</code> after save */ public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { // find item by primary key ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); // set the model configurationItem.setModel(model); // update now configurationFactory.saveOrUpdate( configurationItem ); // get model from saved item return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } public void removeConfigurationItem(Integer id) { // cHome.remove(id); // Logger.logDebug("Unable to remove configuration item " + id + "."); } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = workflowScriptFactory.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = customFieldFactory.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } /** * Removes all <code>LanguageBean</code>s with the give key * * @param key The key to be removed * @exception thrown if deleting of at least one item fails */ public void removeLanguageKey(String key) throws DataException { // find all <code>LanguageBean</code>s for the given key Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { // delete current item this.languageFactory.delete( iter.next() ); } } /** * Removes the <code>LanguageModel</code> passed as parameter * * @param model The <code>LanguageModel</code> to remove * @excpetion DataException thrown if deletion fails */ public void removeLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); if ( languageItem != null ) { // delete item this.languageFactory.delete( languageItem ); } } public String[] getSortedKeys() throws DataException { String[] sortedKeys = new String[0]; int i = 0; Collection items = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); sortedKeys = new String[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); sortedKeys[i] = item.getResourceKey(); } // Now sort the list of keys in a logical manner Arrays.sort(sortedKeys); return sortedKeys; } public HashMap getDefinedKeys(String locale) throws DataException { HashMap keys = new HashMap(); if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } Collection items = languageFactory.findByLocale(locale); for (Iterator iter = items.iterator(); iter.hasNext();) { LanguageBean item = (LanguageBean) iter.next(); keys.put(item.getResourceKey(), item.getResourceValue()); } return keys; } public NameValuePairModel[] getDefinedKeysAsArray(String locale) throws DataException { NameValuePairModel[] keys = new NameValuePairModel[0]; if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } int i = 0; Collection items = languageFactory.findByLocale(locale); keys = new NameValuePairModel[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); keys[i] = new NameValuePairModel(item.getResourceKey(), item.getResourceValue()); } Arrays.sort(keys, new NameValuePairModel()); return keys; } public int getNumberDefinedKeys(String locale) throws DataException { return getDefinedKeys(locale).size(); } public LanguageModel[] getLanguage(Locale locale) throws DataException { LanguageModel[] languageArray = new LanguageModel[0]; HashMap language = new HashMap(); Collection baseItems = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); for (Iterator iterator = baseItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (locale != null && !"".equals(locale.getLanguage())) { Collection languageItems = languageFactory.findByLocale(locale.getLanguage()); for (Iterator iterator = languageItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (!"".equals(locale.getCountry())) { Collection countryItems = languageFactory.findByLocale(locale.toString()); for (Iterator iterator = countryItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } } } languageArray = new LanguageModel[language.size()]; int i = 0; String localeString = (locale == null ? ITrackerResources.BASE_LOCALE : locale.toString()); for (Iterator iterator = language.keySet().iterator(); iterator.hasNext(); i++) { String key = (String) iterator.next(); languageArray[i] = new LanguageModel(localeString, key, (String) language.get(key)); } return languageArray; } public HashMap getAvailableLanguages() throws DataException { HashMap languages = new HashMap(); ConfigurationModel[] locales = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_LOCALE); for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } if (locales[i].getValue().length() == 2) { languages.put(locales[i].getValue(), new Vector()); } } for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } String locale = locales[i].getValue(); if (locale.length() == 5 && locale.indexOf('_') == 2) { String baseLanguage = locale.substring(0, 2); Vector languageVector = (Vector) languages.get(baseLanguage); if (languageVector != null) { languageVector.addElement(locale); } } } return languages; } public int getNumberAvailableLanguages() throws DataException { int numLanguages = 0; HashMap availableLanguages = getAvailableLanguages(); for (Iterator iter = availableLanguages.keySet().iterator(); iter.hasNext();) { Vector language = (Vector) availableLanguages.get((String) iter.next()); if (language != null && language.size() > 0) { numLanguages += language.size(); } else { numLanguages += 1; } } return numLanguages; } public void updateLanguage(Locale locale, LanguageModel[] items) throws DataException { if (locale != null && items != null) { ConfigurationModel configItem = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale .toString(), props.getProperty("version")); updateLanguage(locale, items, configItem); } } public void updateLanguage(Locale locale, LanguageModel[] items, ConfigurationModel configItem) throws DataException { if (items == null || locale == null || configItem == null) { return; } for (int i = 0; i < items.length; i++) { if (items[i] != null) { if (items[i].getAction() == SystemConfigurationUtilities.ACTION_REMOVE) { removeLanguageItem(items[i]); } else { updateLanguageItem(items[i]); } } } removeConfigurationItems(configItem); createConfigurationItem(configItem); } public SystemConfigurationModel getSystemConfiguration(Locale locale) throws DataException { SystemConfigurationModel config = new SystemConfigurationModel(); // Load the basic system configuration ConfigurationModel[] resolutions = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < resolutions.length; i++) { resolutions[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(resolutions[i]), locale)); } config.setResolutions(resolutions); ConfigurationModel[] severities = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY); for (int i = 0; i < severities.length; i++) { severities[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(severities[i]), locale)); } config.setSeverities(severities); ConfigurationModel[] statuses = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS); for (int i = 0; i < statuses.length; i++) { statuses[i].setName(ITrackerResources.getString(SystemConfigurationUtilities.getLanguageKey(statuses[i]), locale)); } config.setStatuses(statuses); // Now load the CustomFields config.setCustomFields(IssueUtilities.getCustomFields(locale)); // Now set the system version config.setVersion(props.getProperty("version")); return config; } public boolean initializeLocale(String locale, boolean forceReload) throws DataException { boolean result = false; ConfigurationModel localeConfig = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale, props.getProperty("version")); if (!configurationItemUpToDate(localeConfig) || forceReload) { Logger.logDebug("Loading database with locale " + locale); PropertiesFileHandler localePropertiesHandler = new PropertiesFileHandler( "/cowsultants/itracker/ejb/client/resources/ITracker" + (ITrackerResources.BASE_LOCALE.equals(locale) ? "" : "_" + locale) + ".properties"); if (localePropertiesHandler.hasProperties()) { Properties localeProperties = localePropertiesHandler.getProperties(); Logger.logDebug("Locale " + locale + " contains " + localeProperties.size() + " properties."); for (Enumeration propertiesEnumeration = localeProperties.propertyNames(); propertiesEnumeration .hasMoreElements();) { String key = (String) propertiesEnumeration.nextElement(); String value = localeProperties.getProperty(key); updateLanguageItem(new LanguageModel(locale, key, value)); } removeConfigurationItems(localeConfig); createConfigurationItem(localeConfig); ITrackerResources.clearBundle(ITrackerResources.getLocale(locale)); result = true; } else { Logger.logInfo("Locale " + locale + " contained no properties."); } } return result; } public void initializeConfiguration() { // Need to eventually add in code that detects the current version of // the config and update // if necessary try { ConfigurationModel[] initialized = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_INITIALIZED); if (initialized == null || initialized.length != 1) { Logger.logDebug("System does not appear to be initialized, initializing system configuration."); LanguageModel[] baseLanguage = getLanguage(ITrackerResources.getLocale(ITrackerResources.BASE_LOCALE)); if (baseLanguage == null || baseLanguage.length == 0) { throw new SystemConfigurationException( "Languages must be initialized before the system configuration can be loaded."); } // Remove any previous configuration information, possibly left // over from previous failed initialization Logger.logDebug("Removing previous incomplete initialization information."); removeConfigurationItems(SystemConfigurationUtilities.TYPE_STATUS); removeConfigurationItems(SystemConfigurationUtilities.TYPE_SEVERITY); removeConfigurationItems(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < baseLanguage.length; i++) { if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_RESOLUTION)) { try { String resolutionString = baseLanguage[i].getResourceKey().substring(20); Logger.logDebug("Adding new configuration resolution value: " + resolutionString); int resolutionNumber = Integer.parseInt(resolutionString); createConfigurationItem(new ConfigurationModel( SystemConfigurationUtilities.TYPE_RESOLUTION, resolutionString, props .getProperty("version"), resolutionNumber)); } catch (Exception e) { Logger.logError("Unable to load resolution value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_SEVERITY)) { try { String severityString = baseLanguage[i].getResourceKey().substring(18); Logger.logDebug("Adding new configuration severity value: " + severityString); int severityNumber = Integer.parseInt(severityString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_SEVERITY, severityString, props.getProperty("version"), severityNumber)); } catch (Exception e) { Logger.logError("Unable to load severity value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_STATUS)) { try { String statusString = baseLanguage[i].getResourceKey().substring(16); Logger.logDebug("Adding new configuration status value: " + statusString); int statusNumber = Integer.parseInt(statusString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_STATUS, statusString, props.getProperty("version"), statusNumber)); } catch (Exception e) { Logger.logError("Unable to load status value: " + baseLanguage[i].getResourceKey(), e); } } } createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_INITIALIZED, "1", props.getProperty("version"))); } } catch (Exception e) { Logger.logError("Unable to initialize system configuration.", e); } } public LanguageFactory getLanguageFactory() { return languageFactory; } public void setLanguageFactory(LanguageFactory home) { languageFactory = home; } public ConfigurationFactory getConfigurationFactory() { return configurationFactory; } public void setConfigurationFactory(ConfigurationFactory configurationFactory) { this.configurationFactory = configurationFactory; } public CustomFieldFactory getCustomFieldFactory() { return customFieldFactory; } public void setCustomFieldFactory(CustomFieldFactory customFieldFactory) { this.customFieldFactory = customFieldFactory; } public CustomFieldValueFactory getCustomFieldValueFactory() { return customFieldValueFactory; } public void setCustomFieldValueFactory(CustomFieldValueFactory customFieldValueFactory) { this.customFieldValueFactory = customFieldValueFactory; } public WorkflowScriptFactory getWorkflowScriptFactory() { return workflowScriptFactory; } public void setWorkflowScriptFactory(WorkflowScriptFactory workflowScriptFactory) { this.workflowScriptFactory = workflowScriptFactory; } } \ No newline at end of file --- 1 ---- ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; private ConfigurationFactory configurationFactory; private CustomFieldFactory customFieldFactory; private CustomFieldValueFactory customFieldValueFactory; private LanguageFactory languageFactory; private WorkflowScriptFactory workflowScriptFactory; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } /** * Creates a <code>ConfigurationModel</code>. * * @param model The <code>ConfigurationModel</code> to store * @return the <code>ConfigurationModel</code> after saving */ public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } /** * Updates a <code>ConfigurationItem</code> * * @param model The model containing the data * @return the <code>ConfigurationModel</code> after save */ public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { // find item by primary key ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); // set the model configurationItem.setModel(model); // update now configurationFactory.saveOrUpdate( configurationItem ); // get model from saved item return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } /** * Finds the <code>ConfigurationBean</code> by primary key <code>id<code> * and deletes it. * * @param id The id of the <code>COnfigurationBean</code> to remove */ public void removeConfigurationItem(Integer id) { ConfigurationBean configBean = this.configurationFactory.findByPrimaryKey(id); if ( configBean != null ) { this.configurationFactory.delete( configBean ); } } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = workflowScriptFactory.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = customFieldFactory.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } /** * Removes all <code>LanguageBean</code>s with the give key * * @param key The key to be removed * @exception thrown if deleting of at least one item fails */ public void removeLanguageKey(String key) throws DataException { // find all <code>LanguageBean</code>s for the given key Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { // delete current item this.languageFactory.delete( iter.next() ); } } /** * R... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-12 00:20:38
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22534 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - implemented deltion of LanguageBean by LanguageMdel and by resourceKey - implemented updating ConfigurationBeans Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.7 retrieving revision 1.31.4.8 diff -C2 -d -r1.31.4.7 -r1.31.4.8 *** SystemConfigurationBean.java 7 Nov 2005 23:01:11 -0000 1.31.4.7 --- SystemConfigurationBean.java 12 Nov 2005 00:20:30 -0000 1.31.4.8 *************** *** 1 **** ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; private ConfigurationFactory configurationFactory; private CustomFieldFactory customFieldFactory; private CustomFieldValueFactory customFieldValueFactory; private LanguageFactory languageFactory; private WorkflowScriptFactory workflowScriptFactory; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); configurationItem.setModel(model); return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } public void removeConfigurationItem(Integer id) { // cHome.remove(id); // Logger.logDebug("Unable to remove configuration item " + id + "."); } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = workflowScriptFactory.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = customFieldFactory.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } public void removeLanguageKey(String key) throws DataException { Vector currentIds = new Vector(); Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { currentIds.add(((LanguageBean) iter.next()).getId()); } for (int i = 0; i < currentIds.size(); i++) { // lHome.remove((Integer) currentIds.elementAt(i)); } // } catch(FinderException ce) { // Logger.logDebug("Unable to find any language items with key" + key + // " for removal."); // } } public void removeLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); // lHome.remove(languageItem.getId()); // Logger.logDebug("Unable to remove language item " + model.toString() // + "."); } public String[] getSortedKeys() throws DataException { String[] sortedKeys = new String[0]; int i = 0; Collection items = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); sortedKeys = new String[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); sortedKeys[i] = item.getResourceKey(); } // Now sort the list of keys in a logical manner Arrays.sort(sortedKeys); return sortedKeys; } public HashMap getDefinedKeys(String locale) throws DataException { HashMap keys = new HashMap(); if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } Collection items = languageFactory.findByLocale(locale); for (Iterator iter = items.iterator(); iter.hasNext();) { LanguageBean item = (LanguageBean) iter.next(); keys.put(item.getResourceKey(), item.getResourceValue()); } return keys; } public NameValuePairModel[] getDefinedKeysAsArray(String locale) throws DataException { NameValuePairModel[] keys = new NameValuePairModel[0]; if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } int i = 0; Collection items = languageFactory.findByLocale(locale); keys = new NameValuePairModel[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); keys[i] = new NameValuePairModel(item.getResourceKey(), item.getResourceValue()); } Arrays.sort(keys, new NameValuePairModel()); return keys; } public int getNumberDefinedKeys(String locale) throws DataException { return getDefinedKeys(locale).size(); } public LanguageModel[] getLanguage(Locale locale) throws DataException { LanguageModel[] languageArray = new LanguageModel[0]; HashMap language = new HashMap(); Collection baseItems = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); for (Iterator iterator = baseItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (locale != null && !"".equals(locale.getLanguage())) { Collection languageItems = languageFactory.findByLocale(locale.getLanguage()); for (Iterator iterator = languageItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (!"".equals(locale.getCountry())) { Collection countryItems = languageFactory.findByLocale(locale.toString()); for (Iterator iterator = countryItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } } } languageArray = new LanguageModel[language.size()]; int i = 0; String localeString = (locale == null ? ITrackerResources.BASE_LOCALE : locale.toString()); for (Iterator iterator = language.keySet().iterator(); iterator.hasNext(); i++) { String key = (String) iterator.next(); languageArray[i] = new LanguageModel(localeString, key, (String) language.get(key)); } return languageArray; } public HashMap getAvailableLanguages() throws DataException { HashMap languages = new HashMap(); ConfigurationModel[] locales = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_LOCALE); for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } if (locales[i].getValue().length() == 2) { languages.put(locales[i].getValue(), new Vector()); } } for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } String locale = locales[i].getValue(); if (locale.length() == 5 && locale.indexOf('_') == 2) { String baseLanguage = locale.substring(0, 2); Vector languageVector = (Vector) languages.get(baseLanguage); if (languageVector != null) { languageVector.addElement(locale); } } } return languages; } public int getNumberAvailableLanguages() throws DataException { int numLanguages = 0; HashMap availableLanguages = getAvailableLanguages(); for (Iterator iter = availableLanguages.keySet().iterator(); iter.hasNext();) { Vector language = (Vector) availableLanguages.get((String) iter.next()); if (language != null && language.size() > 0) { numLanguages += language.size(); } else { numLanguages += 1; } } return numLanguages; } public void updateLanguage(Locale locale, LanguageModel[] items) throws DataException { if (locale != null && items != null) { ConfigurationModel configItem = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale .toString(), props.getProperty("version")); updateLanguage(locale, items, configItem); } } public void updateLanguage(Locale locale, LanguageModel[] items, ConfigurationModel configItem) throws DataException { if (items == null || locale == null || configItem == null) { return; } for (int i = 0; i < items.length; i++) { if (items[i] != null) { if (items[i].getAction() == SystemConfigurationUtilities.ACTION_REMOVE) { removeLanguageItem(items[i]); } else { updateLanguageItem(items[i]); } } } removeConfigurationItems(configItem); createConfigurationItem(configItem); } public SystemConfigurationModel getSystemConfiguration(Locale locale) throws DataException { SystemConfigurationModel config = new SystemConfigurationModel(); // Load the basic system configuration ConfigurationModel[] resolutions = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < resolutions.length; i++) { resolutions[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(resolutions[i]), locale)); } config.setResolutions(resolutions); ConfigurationModel[] severities = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY); for (int i = 0; i < severities.length; i++) { severities[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(severities[i]), locale)); } config.setSeverities(severities); ConfigurationModel[] statuses = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS); for (int i = 0; i < statuses.length; i++) { statuses[i].setName(ITrackerResources.getString(SystemConfigurationUtilities.getLanguageKey(statuses[i]), locale)); } config.setStatuses(statuses); // Now load the CustomFields config.setCustomFields(IssueUtilities.getCustomFields(locale)); // Now set the system version config.setVersion(props.getProperty("version")); return config; } public boolean initializeLocale(String locale, boolean forceReload) throws DataException { boolean result = false; ConfigurationModel localeConfig = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale, props.getProperty("version")); if (!configurationItemUpToDate(localeConfig) || forceReload) { Logger.logDebug("Loading database with locale " + locale); PropertiesFileHandler localePropertiesHandler = new PropertiesFileHandler( "/cowsultants/itracker/ejb/client/resources/ITracker" + (ITrackerResources.BASE_LOCALE.equals(locale) ? "" : "_" + locale) + ".properties"); if (localePropertiesHandler.hasProperties()) { Properties localeProperties = localePropertiesHandler.getProperties(); Logger.logDebug("Locale " + locale + " contains " + localeProperties.size() + " properties."); for (Enumeration propertiesEnumeration = localeProperties.propertyNames(); propertiesEnumeration .hasMoreElements();) { String key = (String) propertiesEnumeration.nextElement(); String value = localeProperties.getProperty(key); updateLanguageItem(new LanguageModel(locale, key, value)); } removeConfigurationItems(localeConfig); createConfigurationItem(localeConfig); ITrackerResources.clearBundle(ITrackerResources.getLocale(locale)); result = true; } else { Logger.logInfo("Locale " + locale + " contained no properties."); } } return result; } public void initializeConfiguration() { // Need to eventually add in code that detects the current version of // the config and update // if necessary try { ConfigurationModel[] initialized = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_INITIALIZED); if (initialized == null || initialized.length != 1) { Logger.logDebug("System does not appear to be initialized, initializing system configuration."); LanguageModel[] baseLanguage = getLanguage(ITrackerResources.getLocale(ITrackerResources.BASE_LOCALE)); if (baseLanguage == null || baseLanguage.length == 0) { throw new SystemConfigurationException( "Languages must be initialized before the system configuration can be loaded."); } // Remove any previous configuration information, possibly left // over from previous failed initialization Logger.logDebug("Removing previous incomplete initialization information."); removeConfigurationItems(SystemConfigurationUtilities.TYPE_STATUS); removeConfigurationItems(SystemConfigurationUtilities.TYPE_SEVERITY); removeConfigurationItems(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < baseLanguage.length; i++) { if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_RESOLUTION)) { try { String resolutionString = baseLanguage[i].getResourceKey().substring(20); Logger.logDebug("Adding new configuration resolution value: " + resolutionString); int resolutionNumber = Integer.parseInt(resolutionString); createConfigurationItem(new ConfigurationModel( SystemConfigurationUtilities.TYPE_RESOLUTION, resolutionString, props .getProperty("version"), resolutionNumber)); } catch (Exception e) { Logger.logError("Unable to load resolution value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_SEVERITY)) { try { String severityString = baseLanguage[i].getResourceKey().substring(18); Logger.logDebug("Adding new configuration severity value: " + severityString); int severityNumber = Integer.parseInt(severityString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_SEVERITY, severityString, props.getProperty("version"), severityNumber)); } catch (Exception e) { Logger.logError("Unable to load severity value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_STATUS)) { try { String statusString = baseLanguage[i].getResourceKey().substring(16); Logger.logDebug("Adding new configuration status value: " + statusString); int statusNumber = Integer.parseInt(statusString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_STATUS, statusString, props.getProperty("version"), statusNumber)); } catch (Exception e) { Logger.logError("Unable to load status value: " + baseLanguage[i].getResourceKey(), e); } } } createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_INITIALIZED, "1", props.getProperty("version"))); } } catch (Exception e) { Logger.logError("Unable to initialize system configuration.", e); } } public LanguageFactory getLanguageFactory() { return languageFactory; } public void setLanguageFactory(LanguageFactory home) { languageFactory = home; } public ConfigurationFactory getConfigurationFactory() { return configurationFactory; } public void setConfigurationFactory(ConfigurationFactory configurationFactory) { this.configurationFactory = configurationFactory; } public CustomFieldFactory getCustomFieldFactory() { return customFieldFactory; } public void setCustomFieldFactory(CustomFieldFactory customFieldFactory) { this.customFieldFactory = customFieldFactory; } public CustomFieldValueFactory getCustomFieldValueFactory() { return customFieldValueFactory; } public void setCustomFieldValueFactory(CustomFieldValueFactory customFieldValueFactory) { this.customFieldValueFactory = customFieldValueFactory; } public WorkflowScriptFactory getWorkflowScriptFactory() { return workflowScriptFactory; } public void setWorkflowScriptFactory(WorkflowScriptFactory workflowScriptFactory) { this.workflowScriptFactory = workflowScriptFactory; } } \ No newline at end of file --- 1 ---- ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; private ConfigurationFactory configurationFactory; private CustomFieldFactory customFieldFactory; private CustomFieldValueFactory customFieldValueFactory; private LanguageFactory languageFactory; private WorkflowScriptFactory workflowScriptFactory; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } /** * Creates a <code>ConfigurationModel</code>. * * @param model The <code>ConfigurationModel</code> to store * @return the <code>ConfigurationModel</code> after saving */ public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } /** * Updates a <code>ConfigurationItem</code> * * @param model The model containing the data * @return the <code>ConfigurationModel</code> after save */ public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { // find item by primary key ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); // set the model configurationItem.setModel(model); // update now configurationFactory.saveOrUpdate( configurationItem ); // get model from saved item return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } public void removeConfigurationItem(Integer id) { // cHome.remove(id); // Logger.logDebug("Unable to remove configuration item " + id + "."); } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = workflowScriptFactory.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = customFieldFactory.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } /** * Removes all <code>LanguageBean</code>s with the give key * * @param key The key to be removed * @exception thrown if deleting of at least one item fails */ public void removeLanguageKey(String key) throws DataException { // find all <code>LanguageBean</code>s for the given key Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { // delete current item this.languageFactory.delete( iter.next() ); } } /** * Removes the <code>LanguageModel</code> passed as parameter * * @param model The <code>LanguageModel</code> to remove * @excpetion DataException thrown if deletion fails */ public void removeLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); if ( languageItem != null ) { // delete item this.languageFactory.delete( languageItem ); } } public String[] getSortedKeys() throws DataException { String[] sortedKeys = new String[0]; int i = 0; Collection items = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); sortedKeys = new String[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next();... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-09 20:23:59
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1198 Modified Files: Tag: itrackerhibernate IssueHandlerBean.java Log Message: - rename member variable to fit depend. inj. naming convention - provided last setters and getters for member variables Index: IssueHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/IssueHandlerBean.java,v retrieving revision 1.57.4.7 retrieving revision 1.57.4.8 diff -C2 -d -r1.57.4.7 -r1.57.4.8 *** IssueHandlerBean.java 3 Nov 2005 20:12:47 -0000 1.57.4.7 --- IssueHandlerBean.java 9 Nov 2005 20:23:50 -0000 1.57.4.8 *************** *** 1 **** ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ComponentBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueActivityBean; import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; import cowsultants.itracker.ejb.beans.entity.IssueBean; import cowsultants.itracker.ejb.beans.entity.IssueFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueHistoryBean; import cowsultants.itracker.ejb.beans.entity.IssueRelationBean; import cowsultants.itracker.ejb.beans.entity.NotificationBean; import cowsultants.itracker.ejb.beans.entity.ProjectBean; import cowsultants.itracker.ejb.beans.entity.UserBean; import cowsultants.itracker.ejb.beans.entity.VersionBean; import cowsultants.itracker.ejb.beans.message.NotificationMessageBean; import cowsultants.itracker.ejb.client.exceptions.IssueException; import cowsultants.itracker.ejb.client.interfaces.IssueHandler; import cowsultants.itracker.ejb.client.models.ComponentModel; import cowsultants.itracker.ejb.client.models.IssueAttachmentModel; import cowsultants.itracker.ejb.client.models.IssueFieldModel; import cowsultants.itracker.ejb.client.models.IssueHistoryModel; import cowsultants.itracker.ejb.client.models.IssueModel; import cowsultants.itracker.ejb.client.models.IssueRelationModel; import cowsultants.itracker.ejb.client.models.NotificationModel; import cowsultants.itracker.ejb.client.models.ProjectModel; import cowsultants.itracker.ejb.client.models.UserModel; import cowsultants.itracker.ejb.client.models.VersionModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.AuthenticationConstants; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.NotificationUtilities; import cowsultants.itracker.ejb.client.util.ProjectUtilities; import cowsultants.itracker.ejb.client.util.UserUtilities; /** * Issue related service layer. A bit "fat" at this time, because of being a direct EJB porting. * Going go get thinner over time * * @author ricardo * */ public class IssueHandlerBean implements IssueHandler { private static String notificationFactoryName = NotificationMessageBean.DEFAULT_CONNECTION_FACTORY; private static String notificationQueueName = NotificationMessageBean.DEFAULT_QUEUE_NAME; private static String systemBaseURL = ""; private CustomFieldFactory cfHome = null; private UserFactory userFactory = null; private ProjectFactory projectFactory; private IssueFactory issueFactory; private IssueHistoryFactory ihfHome = null; private NotificationFactory notificationFactory; private IssueRelationFactory issuerelationfactory = null; private ComponentFactory componentFactory = null; private IssueActivityFactory issueActivityFactory; private VersionFactory versionFactory; public IssueHandlerBean() { ihfHome = SpringFactories.getIssueHistoryFactory(); issuerelationfactory = SpringFactories.getIssueRelationFactory(); componentFactory = SpringFactories.getComponentFactory(); cfHome = SpringFactories.getCustomFieldFactory(); } public IssueModel getIssue(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); return issue.getModel(); } public IssueModel[] getAllIssues() throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findAll(); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public int getNumberIssues() throws DataException { Collection issues = issueFactory.findAll(); return issues.size(); } public IssueModel[] getIssuesCreatedByUser(Integer userId) throws DataException { return getIssuesCreatedByUser(userId, true); } public IssueModel[] getIssuesCreatedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByCreatorInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) : issueFactory.findByCreator(userId, IssueUtilities.STATUS_CLOSED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesOwnedByUser(Integer userId) throws DataException { return getIssuesOwnedByUser(userId, true); } public IssueModel[] getIssuesOwnedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByOwnerInAvailableProjects(userId, IssueUtilities.STATUS_RESOLVED) : issueFactory.findByOwner(userId, IssueUtilities.STATUS_RESOLVED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesWatchedByUser(Integer userId) throws DataException { return getIssuesWatchedByUser(userId, true); } public IssueModel[] getIssuesWatchedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByNotificationInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) : issueFactory.findByNotification(userId, IssueUtilities.STATUS_CLOSED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getUnassignedIssues() throws DataException { return getUnassignedIssues(true); } public IssueModel[] getUnassignedIssues(boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory .findByStatusLessThanEqualToInAvailableProjects(IssueUtilities.STATUS_UNASSIGNED) : issueFactory .findByStatusLessThanEqualTo(IssueUtilities.STATUS_UNASSIGNED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a status equal to the given status number * * * * @param status * * the status to compare * * @return an array of IssueModels that match the criteria * */ public IssueModel[] getIssuesWithStatus(int status) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByStatus(status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a status less than the given status number * * * * @param status * * the status to compare * * @return an array of IssueModels that match the criteria * * @throws DataException * */ public IssueModel[] getIssuesWithStatusLessThan(int status) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByStatusLessThan(status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a severity equal to the given severity number * * * * @param severity * * the severity to compare * * @return an array of IssueModels that match the criteria * */ public IssueModel[] getIssuesWithSeverity(int severity) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findBySeverity(severity); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesByProjectId(Integer projectId) { return getIssuesByProjectId(projectId, IssueUtilities.STATUS_END); } public IssueModel[] getIssuesByProjectId(Integer projectId, int status) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByProjectIdAndLowerStatus(projectId, status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public UserModel getIssueCreator(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = issue.getCreator(); return (user != null ? user.getModel() : null); } public UserModel getIssueOwner(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = issue.getOwner(); return (user != null ? user.getModel() : null); } public ComponentModel[] getIssueComponents(Integer issueId) throws DataException { int i = 0; ComponentModel[] componentArray = new ComponentModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); componentArray = new ComponentModel[components.size()]; for (Iterator iterator = components.iterator(); iterator.hasNext(); i++) { componentArray[i] = ((ComponentBean) iterator.next()).getModel(); } return componentArray; } public VersionModel[] getIssueVersions(Integer issueId) throws DataException { int i = 0; VersionModel[] versionArray = new VersionModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); versionArray = new VersionModel[versions.size()]; for (Iterator iterator = versions.iterator(); iterator.hasNext(); i++) { versionArray[i] = ((VersionBean) iterator.next()).getModel(); } return versionArray; } public IssueAttachmentModel[] getIssueAttachments(Integer issueId) throws DataException { int i = 0; IssueAttachmentModel[] attachmentsArray = new IssueAttachmentModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection attachments = issue.getAttachments(); attachmentsArray = new IssueAttachmentModel[attachments.size()]; for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { attachmentsArray[i] = ((IssueAttachmentBean) iterator.next()).getModel(); } return attachmentsArray; } /** * Old implementation is left here, commented, because it checked for * history entry status. This feature was not finished, I think (RJST) */ public IssueHistoryModel[] getIssueHistory(Integer issueId) { return (issueFactory.findByPrimaryKey(issueId).getModel().getHistory()); /* * int i = 0; * * IssueHistoryModel[] historyArray = new IssueHistoryModel[0]; * * Vector results = new Vector(); * * new IssueBean().getModel().getHistory() * * Collection history = ifHome.findByIssueId(issueId); * * historyArray = new IssueHistoryModel[history.size()]; * * for (Iterator iterator = history.iterator(); iterator.hasNext(); i++) { * * IssueHistoryBean entry = (IssueHistoryBean) iterator.next(); * * if (entry.getStatus() == IssueUtilities.HISTORY_STATUS_AVAILABLE) { * * results.addElement(entry.getModel()); } } * * historyArray = new IssueHistoryModel[results.size()]; * * results.copyInto(historyArray); * * * * return historyArray; */ } public IssueModel createIssue(IssueModel model, Integer projectId, Integer userId, Integer createdById) throws DataException { try { ProjectBean project = projectFactory.findByPrimaryKey(projectId); UserBean creator = userFactory.findByPrimaryKey(userId); if (project.getStatus() != ProjectUtilities.STATUS_ACTIVE) { throw new IssueException("Project is not active."); } IssueBean issue = new IssueBean(); if (issue != null) { if (createdById == null || createdById.equals(userId)) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_ISSUE_CREATED); activity.setUser(creator); activity.setIssue(issue); } else { UserBean createdBy = userFactory.findByPrimaryKey(createdById); IssueActivityBean activity = new IssueActivityBean(); activity.setDescription(ITrackerResources.getString("itracker.activity.system.createdfor") + " " + creator.getFirstName() + " " + creator.getLastName()); activity.setUser(createdBy); activity.setIssue(issue); NotificationModel watchModel = new NotificationModel(); watchModel.setUserId(createdById); watchModel.setIssueId(issue.getId()); watchModel.setNotificationRole(NotificationUtilities.ROLE_IP); addIssueNotification(watchModel); } issue.setModel(model); issue.setProject(project); issue.setCreator(creator); // save issue.setCreateDate(new Timestamp(new Date().getTime())); issueFactory.save(issue); return issue.getModel(); } } catch (IssueException ie) { Logger.logInfo("Error while creating new issue: " + ie.getMessage()); } return null; } public IssueModel updateIssue(IssueModel model, Integer userId) throws DataException { try { String existingTargetVersion = null; IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); UserBean user = userFactory.findByPrimaryKey(userId); if (issue.getProject().getStatus() != ProjectUtilities.STATUS_ACTIVE) { throw new IssueException("Project is not active."); } if (issue.getDescription() != null && model.getDescription() != null && !issue.getDescription().equalsIgnoreCase(model.getDescription())) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_DESCRIPTION_CHANGE); activity.setDescription(ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getDescription()); activity.setUser(user); activity.setIssue(issue); } if (issue.getResolution() != null && model.getResolution() != null && !issue.getResolution().equalsIgnoreCase(model.getResolution())) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RESOLUTION_CHANGE); activity.setDescription(ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getResolution()); activity.setIssue(issue); activity.setUser(user); } if (issue.getStatus() != model.getStatus() && model.getStatus() != -1) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_STATUS_CHANGE); activity.setDescription(IssueUtilities.getStatusName(issue.getStatus()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + IssueUtilities.getStatusName(model.getStatus())); activity.setIssue(issue); activity.setUser(user); } if (issue.getSeverity() != model.getSeverity() && model.getSeverity() != -1) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_SEVERITY_CHANGE); activity.setDescription(IssueUtilities.getSeverityName(issue.getSeverity()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + IssueUtilities.getSeverityName(model.getSeverity())); activity.setIssue(issue); activity.setUser(user); } if (issue.getTargetVersion() != null && model.getTargetVersion() != null && !issue.getTargetVersion().getId().equals(model.getTargetVersionId())) { existingTargetVersion = issue.getTargetVersion().getNumber(); } issue.setModel(model); if (model.getTargetVersion() != null) { VersionBean version = this.versionFactory.findByPrimaryKey(model.getTargetVersionId()); issue.setTargetVersion(version); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_TARGETVERSION_CHANGE); String description = existingTargetVersion + " " + ITrackerResources.getString("itracker.web.generic.to") + " "; description += version.getNumber(); activity.setDescription(description); activity.setUser(user); activity.setIssue(issue); } else { issue.setTargetVersion(null); } // save issueFactory.saveOrUpdate(issue); return issue.getModel(); } catch (IssueException ie) { Logger.logInfo("Error while updating new issue: " + ie.getMessage()); } return null; } /** * * Moves an issues from its current project to a new project. * * * * @param issue * * an IssueModel of the issue to move * * @param projectId * * the id of the target project * * @param userId * * the id of the user that is moving the issue * * @return an IssueModel of the issue after it has been moved * * @throws DataException * */ public IssueModel moveIssue(IssueModel model, Integer projectId, Integer userId) throws DataException { if (model == null) { return null; } IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); ProjectBean project = projectFactory.findByPrimaryKey(projectId); UserBean user = userFactory.findByPrimaryKey(userId); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_ISSUE_MOVE); activity.setDescription(model.getProjectName() + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + project.getName()); activity.setUser(user); activity.setIssue(issue); issue.setProject(project); // The versions and components are per project so we need to delete // these setIssueComponents(issue.getId(), new HashSet(), userId); setIssueVersions(issue.getId(), new HashSet(), userId); return issue.getModel(); } public boolean deleteIssue(IssueModel model) throws DataException { if (model != null) { IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); issueFactory.delete(issue); return true; } return false; } /** * this should not exist. adding an history entry should be adding the history entry * to the domain object and saving the object... */ public boolean addIssueHistory(IssueHistoryModel model) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueHistoryBean history = new IssueHistoryBean(); history.setModel(model); history.setIssue(issue); history.setUser(user); history.setCreateDate(new Timestamp(new Date().getTime())); issueFactory.saveOrUpdate(history); return true; } public boolean setIssueFields(Integer issueId, IssueFieldModel[] fields) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection issueFields = issue.getFields(); for (Iterator iter = issueFields.iterator(); iter.hasNext();) { // try { IssueFieldBean field = (IssueFieldBean) iter.next(); // iter.remove(); // field.remove(); // } catch(RemoveException re) { // Logger.logInfo("Unable to remove issue field value. Manual // database cleanup may be necessary."); // } } if (fields.length > 0) { for (int i = 0; i < fields.length; i++) { IssueFieldBean field = new IssueFieldBean(); CustomFieldBean customField = cfHome.findByPrimaryKey(fields[i].getCustomFieldId()); field.setModel(fields[i]); field.setCustomField(customField); field.setIssue(issue); field.setDateValue(new Timestamp(new Date().getTime())); issueFields.add(field); } } return true; } public boolean setIssueComponents(Integer issueId, HashSet componentIds, Integer userId) throws DataException { boolean wasChanged = false; StringBuffer changesBuf = new StringBuffer(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); if (componentIds.isEmpty() && components != null && !components.isEmpty()) { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed")); components.clear(); } else { for (Iterator iterator = components.iterator(); iterator.hasNext();) { ComponentBean component = (ComponentBean) iterator.next(); if (componentIds.contains(component.getId())) { componentIds.remove(component.getId()); } else { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + component.getName() + "; "); iterator.remove(); } } for (Iterator iterator = componentIds.iterator(); iterator.hasNext();) { Integer componentId = (Integer) iterator.next(); ComponentBean component = componentFactory.findByPrimaryKey(componentId); wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + component.getName() + "; "); components.add(component); } } if (wasChanged) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_COMPONENTS_MODIFIED); activity.setDescription(changesBuf.toString()); activity.setIssue(issue); // activity.setUser(); // userId); -> I think we need to set user here } return true; } public boolean setIssueVersions(Integer issueId, HashSet versionIds, Integer userId) throws DataException { boolean wasChanged = false; StringBuffer changesBuf = new StringBuffer(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); if (versionIds.isEmpty() && versions != null && !versions.isEmpty()) { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed")); versions.clear(); } else { for (Iterator iterator = versions.iterator(); iterator.hasNext();) { VersionBean version = (VersionBean) iterator.next(); if (versionIds.contains(version.getId())) { versionIds.remove(version.getId()); } else { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + version.getNumber() + "; "); iterator.remove(); } } for (Iterator iterator = versionIds.iterator(); iterator.hasNext();) { Integer versionId = (Integer) iterator.next(); VersionBean version = versionFactory.findByPrimaryKey(versionId); wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + version.getNumber() + "; "); versions.add(version); } } if (wasChanged) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_VERSIONS_MODIFIED); activity.setDescription(changesBuf.toString()); activity.setIssue(issue); // need to set user here // userId); } return true; } public IssueRelationModel getIssueRelation(Integer relationId) throws DataException { IssueRelationBean issueRelation = issuerelationfactory.findByPrimaryKey(relationId); return issueRelation.getModel(); } public boolean addIssueRelation(Integer issueId, Integer relatedIssueId, int relationType, Integer userId) throws DataException { if (issueId != null && relatedIssueId != null) { int matchingRelationType = IssueUtilities.getMatchingRelationType(relationType); // if(matchingRelationType < 0) { // throw new CreateException("Unable to find matching relation type // for type: " + relationType); // } IssueBean issue = issueFactory.findByPrimaryKey(issueId); IssueBean relatedIssue = issueFactory.findByPrimaryKey(relatedIssueId); IssueRelationBean relationA = new IssueRelationBean(); relationA.setRelationType(relationType); // relationA.setMatchingRelationId(relationBId); relationA.setIssue(issue); relationA.setRelatedIssue(relatedIssue); relationA.setLastModifiedDate(new java.sql.Timestamp(new java.util.Date().getTime())); IssueRelationBean relationB = new IssueRelationBean(); relationB.setRelationType(matchingRelationType); // relationB.setMatchingRelationId(relationAId); relationB.setIssue(relatedIssue); relationB.setRelatedIssue(issue); relationB.setLastModifiedDate(new java.sql.Timestamp(new java.util.Date().getTime())); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_ADDED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.add")); // probably add this to description // new Object[] {IssueUtilities.getRelationName(relationType), // relatedIssueId }; activity.setIssue(issue); // need to set user here... userId); // need to save here activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_ADDED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.add", new Object[] { IssueUtilities.getRelationName(matchingRelationType) })); activity.setIssue(relatedIssue); // net to save and set user here.. userId); return true; } return false; } public Integer removeIssueRelation(Integer relationId, Integer userId) { Integer issueId = new Integer(-1); try { IssueRelationBean issueRelation = issuerelationfactory.findByPrimaryKey(relationId); issueId = issueRelation.getIssue().getId(); Integer relatedIssueId = issueRelation.getRelatedIssue().getId(); Integer matchingRelationId = issueRelation.getMatchingRelationId(); if (matchingRelationId != null) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_REMOVED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.removed", issueId .toString())); // need to fix the commented code and save // activity.setIssue(relatedIssueId); // activity.setUser(userId); // IssueRelationFactory.remove(matchingRelationId); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_REMOVED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.removed", relatedIssueId .toString())); // activity.setIssue(issueId); // activity.setUser(userId); // irHome.remove(relationId); // need to save } catch (Exception e) { Logger.logDebug("Exception while removing issue relation.", e); } return issueId; } public boolean assignIssue(Integer issueId, Integer userId) throws DataException { return assignIssue(issueId, userId, userId); } public boolean assignIssue(Integer issueId, Integer userId, Integer assignedByUserId) throws DataException { if (userId.intValue() == -1) { return unassignIssue(issueId, assignedByUserId); } UserBean assignedByUser; IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = userFactory.findByPrimaryKey(userId); if (assignedByUserId.equals(userId)) { assignedByUser = user; } else { assignedByUser = userFactory.findByPrimaryKey(assignedByUserId); } UserBean currOwner = issue.getOwner(); if (currOwner == null || !currOwner.getId().equals(user.getId())) { if (currOwner != null && !hasIssueNotification(issueId, currOwner.getId(), NotificationUtilities.ROLE_CONTRIBUTER)) { NotificationBean notification = new NotificationBean(); NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER); notification.setModel(model); notification.setIssue(issue); notification.setUser(currOwner); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_OWNER_CHANGE); activity.setDescription((currOwner == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : currOwner.getLogin()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + user.getLogin()); activity.setUser(assignedByUser); activity.setIssue(issue); issue.setOwner(user); if (issue.getStatus() < IssueUtilities.STATUS_ASSIGNED) { issue.setStatus(IssueUtilities.STATUS_ASSIGNED); } } return true; } public boolean unassignIssue(Integer issueId, Integer assignedByUserId) throws DataException { UserBean assignedByUser = userFactory.findByPrimaryKey(assignedByUserId); IssueBean issue = issueFactory.findByPrimaryKey(issueId); if (issue.getOwner() != null) { if (!hasIssueNotification(issueId, issue.getOwner().getId(), NotificationUtilities.ROLE_CONTRIBUTER)) { NotificationBean notification = new NotificationBean(); NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER); notification.setModel(model); notification.setIssue(issue); notification.setUser(issue.getOwner()); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_OWNER_CHANGE); activity.setDescription((issue.getOwner() == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : issue.getOwner() .getLogin()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " [" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]"); activity.setUser(assignedByUser); activity.setIssue(issue); issue.setOwner(null); if (issue.getStatus() >= IssueUtilities.STATUS_ASSIGNED) { issue.setStatus(IssueUtilities.STATUS_UNASSIGNED); } } return true; } /* * public boolean addIssueActivity(IssueActivityModel model) throws * DataException { * * IssueBean issue = ifHome.findByPrimaryKey(model.getIssueId()); * * UserBean user = ufHome.findByPrimaryKey(model.getUserId()); * * //return addIssueActivity(model, issue, user); return * addIssueActivity(null, issue, user); } */ /* * public boolean addIssueActivity(IssueActivityModel model, IssueBean * issue) throws DataException { * * UserBean user = ufHome.findByPrimaryKey(model.getUserId()); * * return true;//addIssueActivity(model, issue, user); } */ /** * I think this entire method is useless - RJST * * @param model * @param issue * @param user * @return */ /* * public boolean addIssueActivity(IssueActivityBean model, IssueBean issue, * UserBean user) { * * IssueActivityBean activity = new IssueActivityBean(); * * //activity.setModel(model); * * activity.setIssue(issue); * * activity.setUser(user); * * return true; } */ public void updateIssueActivityNotification(Integer issueId, boolean notificationSent) { if (issueId == null) { return; } Collection activity = issueActivityFactory.findByIssueId(issueId); for (Iterator iter = activity.iterator(); iter.hasNext();) { ((IssueActivityBean) iter.next()).setNotificationSent((notificationSent ? 1 : 0)); } } public boolean addIssueAttachment(IssueAttachmentModel model, byte[] data) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueAttachmentBean attachment = new IssueAttachmentBean(); model.setFileName("attachment" + attachment.getId()); attachment.setModel(model); attachment.setFileData((data == null ? new byte[0] : data)); attachment.setIssue(issue); attachment.setUser(user); return true; } public boolean setIssueAttachmentData(Integer attachmentId, byte[] data) { if (attachmentId != null && data != null) { IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); attachment.setFileData(data); return true; } return false; } public boolean setIssueAttachmentData(String fileName, byte[] data) { if (fileName != null && data != null) { IssueAttachmentBean attachment = IssueAttachmentFactory.findByFileName(fileName); attachment.setFileData(data); return true; } return false; } public boolean removeIssueAttachment(Integer attachmentId) { IssueAttachmentFactory.remove(attachmentId); return true; } public Integer removeIssueHistoryEntry(Integer entryId, Integer userId) throws DataException { IssueHistoryBean history = ihfHome.findByPrimaryKey(entryId); if (history != null) { history.setStatus(IssueUtilities.HISTORY_STATUS_REMOVED); history.setLastModifiedDate(new Timestamp(new Date().getTime())); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_REMOVE_HISTORY); activity.setDescription(ITrackerResources.getString("itracker.web.generic.entry") + " " + entryId + " " + ITrackerResources.getString("itracker.web.generic.removed") + "."); // need to fix this - RJST // activity.setIssue(history.getIssue().getId()); // activity.setUser(userId); return history.getIssue().getId(); } return new Integer(-1); } public ProjectModel getIssueProject(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); ProjectBean project = issue.getProject(); return (project != null ? project.getModel() : null); } public HashSet getIssueComponentIds(Integer issueId) throws DataException { HashSet componentIds = new HashSet(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); for (Iterator iterator = components.iterator(); iterator.hasNext();) { componentIds.add(((ComponentBean) iterator.next()).getId()); } return componentIds; } public HashSet getIssueVersionIds(Integer issueId) throws DataException { HashSet versionIds = new HashSet(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); for (Iterator iterator = versions.iterator(); iterator.hasNext();) { versionIds.add(((VersionBean) iterator.next()).getId()); } return versionIds; } public IssueActivityBean[] getIssueActivity(Integer issueId) { int i = 0; IssueActivityBean[] activityArray = new IssueActivityBean[0]; Collection activity = issueActivityFactory.findByIssueId(issueId); activityArray = new IssueActivityBean[activity.size()]; for (Iterator iterator = activity.iterator(); iterator.hasNext(); i++) { activityArray[i] = ((IssueActivityBean) iterator.next());// .getModel(); } return activityArray; } public IssueActivityBean[] getIssueActivity(Integer issueId, boolean notificationSent) { int i = 0; IssueActivityBean[] activityArray = new IssueActivityBean[0]; Collection activity = issueActivityFactory.findByIssueIdAndNotification(issueId, (notificationSent ? 1 : 0)); activityArray = new IssueActivityBean[activity.size()]; for (Iterator iterator = activity.iterator(); iterator.hasNext(); i++) { activityArray[i] = ((IssueActivityBean) iterator.next());// .getModel(); } return activityArray; } public IssueAttachmentModel[] getAllIssueAttachments() { int i = 0; IssueAttachmentModel[] attachmentArray = new IssueAttachmentModel[0]; Collection attachments = IssueAttachmentFactory.findAll(); attachmentArray = new IssueAttachmentModel[attachments.size()]; for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { attachmentArray[i] = ((IssueAttachmentBean) iterator.next()).getModel(); } return attachmentArray; } public long[] getAllIssueAttachmentsSizeAndCount() { long[] sizeAndCount = new long[2]; int i = 0; Collection attachments = IssueAttachmentFactory.findAll(); sizeAndCount[1] = attachments.size(); for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { sizeAndCount[0] += ((IssueAttachmentBean) iterator.next()).getSize(); } return sizeAndCount; } public IssueAttachmentModel getIssueAttachment(Integer attachmentId) { IssueAttachmentModel attachmentModel = null; IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); attachmentModel = attachment.getModel(); return attachmentModel; } public byte[] getIssueAttachmentData(Integer attachmentId) { byte[] data = new byte[0]; IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); data = attachment.getFileData(); return data; } public int getIssueAttachmentCount(Integer issueId) throws DataException { int i = 0; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection attachments = issue.getAttachments(); i = attachments.size(); return i; } /** * * Returns the latest issue history entry for a particular issue. * * * * @param issueId * * the id of the issue to return the history entry for. * * @return the latest IssueHistoryModel, or null if no entries could be * * found * * @throws DataException * */ public IssueHistoryModel getLastIssueHistory(Integer issueId) throws DataException { IssueHistoryModel model = null; IssueHistoryBean lastEntry = null; Collection history = ihfHome.findByIssueId(issueId); Iterator iterator = history.iterator(); while (iterator.hasNext()) { IssueHistoryBean nextEntry = (IssueHistoryBean) iterator.next(); if (nextEntry != null) { if (lastEntry == null && nextEntry.getLastModifiedDate() != null) { lastEntry = nextEntry; } else if (nextEntry.getLastModifiedDate() != null && nextEntry.getLastModifiedDate().equals(lastEntry.getLastModifiedDate()) && nextEntry.getId().compareTo(lastEntry.getId()) > 0) { lastEntry = nextEntry; } else if (nextEntry.getLastModifiedDate() != null && nextEntry.getLastModifiedDate().after(lastEntry.getLastModifiedDate())) { lastEntry = nextEntry; } } } if (lastEntry != null) { model = lastEntry.getModel(); } return model; } /** * * Retrieves the primary issue notifications. Primary notifications are * * defined as the issue owner (or creator if not assigned), and any project * * owners. This should encompass the list of people that should be notified * * so that action can be taken on an issue that needs immediate attention. * * * * @param issueId * * the id of the issue to find notifications for * * @throws DataException * * @returns an array of NotificationModels * */ public NotificationModel[] getPrimaryIssueNotifications(Integer issueId) throws DataException { return getIssueNotifications(issueId, true, false); } /** * * Retrieves all notifications for an issue where the notification's user is * * also active. * * * * @param issueId * * the id of the issue to find notifications for * * @throws DataException * * @returns an array of NotificationModels * */ public NotificationModel[] getIssueNotifications(Integer issueId) throws DataException { return getIssueNotifications(issueId, false, true); } /** * * Retrieves an array of issue notifications. The notifications by default * * is the creator and owner of the issue, all project admins for the issue's * * project, and anyone else that has a notfication on file. * * * * @param issueId * * the id of the issue to find notifications for * * @param pimaryOnly * * only include the primary notifications * * @param activeOnly * * only include the notification if the user is currently active * * (not locked or deleted) * * @throws DataException * * @returns an array of NotificationModels * * @see IssueHandlerBean#getPrimaryIssueNotifications * */ public NotificationModel[] getIssueNotifications(Integer issueId, boolean primaryOnly, boolean activeOnly) throws DataException { NotificationModel[] notificationArray = new NotificationModel[0]; Vector notificationVector = new Vector(); IssueBean issue = null; if (!primaryOnly) { Collection notifications = notificationFactory.findByIssueId(issueId); for (Iterator iterator = notifications.iterator(); iterator.hasNext();) { NotificationBean notification = (NotificationBean) iterator.next(); UserBean notificationUser = notification.getUser(); if (!activeOnly || notificationUser.getStatus() == UserUtilities.STATUS_ACTIVE) { notificationVector.add(notification.getModel()); } } } // Now add in other notifications like owner, creator, project owners, // etc... boolean hasOwner = false; issue = issueFactory.findByPrimaryKey(issueId); if (issue.getOwner() != null) { UserModel ownerModel = issue.getOwner().getModel(); if (ownerModel != null && (!activeOnly || ownerModel.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector.add(new NotificationModel(ownerModel, issueId, NotificationUtilities.ROLE_OWNER)); hasOwner = true; } } if (!primaryOnly || !hasOwner) { UserModel creatorModel = issue.getCreator().getModel(); if (creatorModel != null && (!activeOnly || creatorModel.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector .add(new NotificationModel(creatorModel, issueId, NotificationUtilities.ROLE_CREATOR)); } } if (issue != null) { ProjectBean project = projectFactory.findByPrimaryKey(issue.getProject().getId()); Collection projectOwners = project.getOwners(); for (Iterator iterator = projectOwners.iterator(); iterator.hasNext();) { UserBean projectOwner = (UserBean) iterator.next(); if (projectOwner != null && (!activeOnly || projectOwner.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector.add(new NotificationModel(projectOwner.getModel(), issueId, NotificationUtilities.ROLE_PO)); } } } notificationArray = new NotificationModel[notificationVector.size()]; notificationVector.copyInto(notificationArray); return notificationArray; } public boolean addIssueNotification(NotificationModel model) throws DataException { if (model != null) { UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); NotificationBean notification = new NotificationBean(); notification.setModel(model); notification.setIssue(issue); notification.setUser(user); return true; } return false; } public boolean hasIssueNotification(Integer issueId, Integer userId) throws DataException { return hasIssueNotification(issueId, userId, NotificationUtilities.ROLE_ANY); } public boolean hasIssueNotification(Integer issueId, Integer userId, int role) throws DataException { if (issueId != null && userId != null) { NotificationModel[] notifications = getIssueNotifications(issueId, false, false); for (int i = 0; i < notifications.length; i++) { if (role == NotificationUtilities.ROLE_ANY || notifications[i].getNotificationRole() == role) { if (notifications[i].getUserId().equals(userId)) { return true; } } } } return false; } public int getOpenIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectIdAndLowerStatus(projectId, IssueUtilities.STATUS_RESOLVED); return issues.size(); } public int getResolvedIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectIdAndHigherStatus(projectId, IssueUtilities.STATUS_RESOLVED); return issues.size(); } public int getTotalIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectId(projectId); return issues.size(); } public Date getLatestIssueDateByProjectId(Integer projectId) { return issueFactory.latestModificationDate(projectId); } public void sendNotification(Integer issueId, int type, String baseURL) { sendNotification(issueId, type, baseURL, null, null); } public void sendNotification(Integer issueId, int type, String baseURL, HashSet addresses, Integer lastModifiedDays) { // notifications are disabled for now /* * try { * * QueueConnectionFactory factory = (QueueConnectionFactory) * ic.lookup("java:comp/env/" + notificationFactoryName); * * Queue notificationQueue = (Queue) ic.lookup("java:comp/env/" + * notificationQueueName); QueueConnection connect = * factory.createQueueConnection(); QueueSession session = * connect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); * QueueSender sender = session.createSender(notificationQueue); * MapMessage message = session.createMapMessage(); * message.setInt("issueId", issueId.intValue()); message.setInt("type", * type); message.setObject("lastModifiedDays", (lastModifiedDays == * null ? new Integer(-1) : lastModifiedDays)); * * if (systemBaseURL != null && !systemBaseURL.equals("")) { * * message.setString("baseURL", systemBaseURL); } else if (baseURL != * null) { * * message.setString("baseURL", baseURL); } * * if (addresses != null) { * * try { * * ByteArrayOutputStream baos = new ByteArrayOutputStream(); * * ObjectOutputStream oos = new ObjectOutputStream(baos); * * oos.writeObject(addresses); * * message.setObject("addresses", baos.toByteArray()); } catch * (Exception e) { * * Logger.logDebug("Unable to write address list for notification: " + * e.getMessage()); } } * * sender.send(message); } catch (NamingException ne) { * * Logger.logError("Error looking up ConnectionFactory/Queue " + * notificationFactoryName + "/" + notificationQueueName + ".", ne); } * catch (JMSException jmse) { * * Logger.logWarn("Error sending notification message", jmse); } */ } public boolean canViewIssue(Integer issueId, UserModel user) throws DataException { IssueModel issue = getIssue(issueId); HashMap permissions = userFactory.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB); return IssueUtilities.canViewIssue(issue, user.getId(), permissions); } public boolean canViewIssue(IssueModel issue, UserModel user) { HashMap permissions = userFactory.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB); return IssueUtilities.canViewIssue(issue, user.getId(), permissions); } public UserFactory getUserFactory() { return userFactory; } public void setUserFactory(UserFactory userFactory) { this.userFactory = userFactory; } public IssueFactory getIssueFactory() { return issueFactory; } public void setIssueFactory(IssueFactory ifHome) { this.issueFactory = ifHome; } public NotificationFactory getNotificationFactory() { return notificationFactory; } public void setNotificationFactory(NotificationFactory nfHome) { this.notificationFactory = nfHome; } public ProjectFactory getProjectFactory() { return projectFactory; } public void setProjectFactory(ProjectFactory projectFactory) { this.projectFactory = projectFactory; } public IssueActivityFactory getIssueActivityFactory() { return issueActivityFactory; } public void setIssueActivityFactory(IssueActivityFactory issueActivityFactory) { this.issueActivityFactory = issueActivityFactory; } public VersionFactory getVersionFactory() { return this.versionFactory; } public void setVersionFactory(VersionFactory versionFactory) { this.versionFactory = versionFactory; } public ComponentFactory getComponentFactory() { return this.componentFactory; } public void setComponentFactory(ComponentFactory componentFactory) { this.componentFactory = componentFactory; } } \ No newline at end of file --- 1 ---- ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ComponentBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueActivityBean; import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; import cowsultants.itracker.ejb.beans.entity.IssueBean; import cowsultants.itracker.ejb.beans.entity.IssueFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueHistoryBean; import cowsultants.itracker.ejb.beans.entity.IssueRelationBean; import cowsultants.itracker.ejb.beans.entity.NotificationBean; import cowsultants.itracker.ejb.beans.entity.ProjectBean; import cowsultants.itracker.ejb.beans.entity.UserBean; import cowsultants.itracker.ejb.beans.entity.VersionBean; import cowsultants.itracker.ejb.beans.message.NotificationMessageBean; import cowsultants.itracker.ejb.client.exceptions.IssueException; import cowsultants.itracker.ejb.client.interfaces.IssueHandler; import cowsultants.itracker.ejb.client.models.ComponentModel; import cowsultants.itracker.ejb.client.models.IssueAttachmentModel; import cowsultants.itracker.ejb.client.models.IssueFieldModel; import cowsultants.itracker.ejb.client.models.Is... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-09 20:20:17
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32696 Modified Files: Tag: itrackerhibernate EditConfigurationAction.java Log Message: set the configItems value to make desired change persistent Index: EditConfigurationAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditConfigurationAction.java,v retrieving revision 1.10.4.5 retrieving revision 1.10.4.6 diff -C2 -d -r1.10.4.5 -r1.10.4.6 *** EditConfigurationAction.java 29 Oct 2005 16:58:55 -0000 1.10.4.5 --- EditConfigurationAction.java 9 Nov 2005 20:20:06 -0000 1.10.4.6 *************** *** 148,152 **** } } ! Logger.logDebug("Changing issue status values from " + configItem.getValue() + " to " + formValue); --- 148,154 ---- } } ! // set new value ! configItem.setValue( formValue.trim() ); ! Logger.logDebug("Changing issue status values from " + configItem.getValue() + " to " + formValue); |
From: Marc B. <mb...@us...> - 2005-11-09 20:16:08
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31826 Modified Files: Tag: itrackerhibernate UserHandlerBean.java Log Message: remove former solution which has been commented out (sorry about whitespace commit) Index: UserHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/UserHandlerBean.java,v retrieving revision 1.44.4.9 retrieving revision 1.44.4.10 diff -C2 -d -r1.44.4.9 -r1.44.4.10 *** UserHandlerBean.java 9 Nov 2005 20:13:07 -0000 1.44.4.9 --- UserHandlerBean.java 9 Nov 2005 20:16:00 -0000 1.44.4.10 *************** *** 328,340 **** } - // try { userPrefs = userPreferencesFactory.findByUserId(model.getUserId()); ! /* ! * } catch (ObjectNotFoundException onfe) { if (userPrefs == null || ! * userPrefs.getUser().getId().intValue() != ! * model.getUserId().intValue()) { userPrefs = new ! * UserPreferencesBean(); } } ! */ ! if ( userPrefs == null ) { userPrefs = new UserPreferencesBean(); --- 328,333 ---- } userPrefs = userPreferencesFactory.findByUserId(model.getUserId()); ! if ( userPrefs == null ) { userPrefs = new UserPreferencesBean(); |
From: Marc B. <mb...@us...> - 2005-11-09 20:13:20
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30907 Modified Files: Tag: itrackerhibernate UserHandlerBean.java Log Message: UserPreferenceBean must be created if it is null Index: UserHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/UserHandlerBean.java,v retrieving revision 1.44.4.8 retrieving revision 1.44.4.9 diff -C2 -d -r1.44.4.8 -r1.44.4.9 *** UserHandlerBean.java 5 Nov 2005 00:20:00 -0000 1.44.4.8 --- UserHandlerBean.java 9 Nov 2005 20:13:07 -0000 1.44.4.9 *************** *** 337,343 **** --- 337,352 ---- */ + if ( userPrefs == null ) { + userPrefs = new UserPreferencesBean(); + } userPrefs.setUser(user); userPrefs.setModel(model); // return userPrefs.getModel(); + + if ( userPrefs.getId() == null ) { + userPrefs.setCreateDate( new Timestamp(System.currentTimeMillis())); + this.userPreferencesFactory.saveOrUpdate( userPrefs ); + } + model.setUserId(user.getId()); model.setUserLogin(user.getLogin()); |
From: Marc B. <mb...@us...> - 2005-11-09 20:09:46
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30028 Modified Files: Tag: itrackerhibernate UserPreferencesFactory.java Log Message: extends BaseFactory now Index: UserPreferencesFactory.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/UserPreferencesFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** UserPreferencesFactory.java 11 Oct 2005 01:36:08 -0000 1.1.2.1 --- UserPreferencesFactory.java 9 Nov 2005 20:09:38 -0000 1.1.2.2 *************** *** 3,7 **** import cowsultants.itracker.ejb.beans.entity.UserPreferencesBean; ! public interface UserPreferencesFactory { public UserPreferencesBean findByUserId(Integer userId) throws DataException; } --- 3,7 ---- import cowsultants.itracker.ejb.beans.entity.UserPreferencesBean; ! public interface UserPreferencesFactory extends BaseFactory { public UserPreferencesBean findByUserId(Integer userId) throws DataException; } |
From: Marc B. <mb...@us...> - 2005-11-09 20:08:59
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29816 Modified Files: Tag: itrackerhibernate UserPreferencesFactoryImpl.java Log Message: extends BaseHibernateFactoryImpl now Index: UserPreferencesFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/UserPreferencesFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** UserPreferencesFactoryImpl.java 30 Oct 2005 16:52:13 -0000 1.1.2.2 --- UserPreferencesFactoryImpl.java 9 Nov 2005 20:08:46 -0000 1.1.2.3 *************** *** 1,4 **** --- 1,5 ---- package cowsultants.itracker.ejb.beans.session; + import java.sql.Connection; import net.sf.hibernate.Criteria; import net.sf.hibernate.HibernateException; *************** *** 10,14 **** import cowsultants.itracker.ejb.beans.entity.UserPreferencesBean; ! public class UserPreferencesFactoryImpl extends HibernateDaoSupport implements UserPreferencesFactory { private UserFactory userFactory; --- 11,15 ---- import cowsultants.itracker.ejb.beans.entity.UserPreferencesBean; ! public class UserPreferencesFactoryImpl extends BaseHibernateFactoryImpl implements UserPreferencesFactory { private UserFactory userFactory; |
From: Marc B. <mb...@us...> - 2005-11-07 23:22:13
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11070 Modified Files: Tag: itrackerhibernate IssueFactoryImpl.java Log Message: added implementation of IssueFactory.findByStatus( int status ) Index: IssueFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/IssueFactoryImpl.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** IssueFactoryImpl.java 30 Oct 2005 16:52:10 -0000 1.1.2.3 --- IssueFactoryImpl.java 7 Nov 2005 23:22:05 -0000 1.1.2.4 *************** *** 104,109 **** public Collection findByStatus(int status) { ! // TODO Auto-generated method stub ! return null; } --- 104,113 ---- public Collection findByStatus(int status) { ! try { ! return (getSession().createCriteria(IssueBean.class).add( ! Expression.le("status", new Integer(status))).list()); ! } catch (HibernateException e) { ! throw new DataException(e); ! } } |
From: Marc B. <mb...@us...> - 2005-11-07 23:04:34
|
Update of /cvsroot/itracker/itracker/web/WEB-INF In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4727/web/WEB-INF Modified Files: Tag: itrackerhibernate applicationContext.xml Log Message: added factoryTarget and Factory for customFieldValue entity Index: applicationContext.xml =================================================================== RCS file: /cvsroot/itracker/itracker/web/WEB-INF/Attic/applicationContext.xml,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -C2 -d -r1.1.2.11 -r1.1.2.12 *** applicationContext.xml 3 Nov 2005 20:15:02 -0000 1.1.2.11 --- applicationContext.xml 7 Nov 2005 23:04:22 -0000 1.1.2.12 *************** *** 36,39 **** --- 36,46 ---- </property> </bean> + + <!-- The custom field value factory --> + <bean id="customFieldValueFactoryTarget" class="cowsultants.itracker.ejb.beans.session.CustomFieldValueFactoryImpl"> + <property name="sessionFactory"> + <ref bean="sessionFactory"/> + </property> + </bean> <!-- The user factory --> *************** *** 213,216 **** --- 220,243 ---- <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> <!-- Application code uses this object --> + <bean id="customFieldValueFactory" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> + <property name="transactionManager" ref="transactionManager"/> + <property name="transactionAttributes"> + <props> + <prop key="*">PROPAGATION_REQUIRED</prop> + </props> + </property> + <property name="target" ref="customFieldValueFactoryTarget"/> + <property name="proxyInterfaces"> + <value>cowsultants.itracker.ejb.beans.session.CustomFieldValueFactory</value> + </property> + <property name="postInterceptors"> + <list> + <ref bean="myHibernateInterceptor"/> + </list> + </property> + </bean> + + <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> + <!-- Application code uses this object --> <bean id="userFactory" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> |
From: Marc B. <mb...@us...> - 2005-11-07 23:01:23
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3340 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - renamed member variables to match autowiring naming convention - encapsulate workflowScriptFactory, customFieldFactory and customFieldValueFactory with getters/setters Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.6 retrieving revision 1.31.4.7 diff -C2 -d -r1.31.4.6 -r1.31.4.7 *** SystemConfigurationBean.java 30 Oct 2005 16:52:11 -0000 1.31.4.6 --- SystemConfigurationBean.java 7 Nov 2005 23:01:11 -0000 1.31.4.7 *************** *** 1 **** ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; ConfigurationFactory configurationFactory; private CustomFieldFactory cfHome; CustomFieldValueFactory cfvHome = null; LanguageFactory languageFactory; WorkflowScriptFactory wsHome = null; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } // initialize Factories... cfHome = SpringFactories.getCustomFieldFactory(); wsHome = SpringFactories.getWorkflowScriptFactory(); } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); configurationItem.setModel(model); return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } public void removeConfigurationItem(Integer id) { // cHome.remove(id); // Logger.logDebug("Unable to remove configuration item " + id + "."); } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = wsHome.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = wsHome.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = wsHome.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = cfHome.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = cfHome.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = cfHome.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = cfHome.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = cfHome.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = cfHome.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } public void removeLanguageKey(String key) throws DataException { Vector currentIds = new Vector(); Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { currentIds.add(((LanguageBean) iter.next()).getId()); } for (int i = 0; i < currentIds.size(); i++) { // lHome.remove((Integer) currentIds.elementAt(i)); } // } catch(FinderException ce) { // Logger.logDebug("Unable to find any language items with key" + key + // " for removal."); // } } public void removeLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); // lHome.remove(languageItem.getId()); // Logger.logDebug("Unable to remove language item " + model.toString() // + "."); } public String[] getSortedKeys() throws DataException { String[] sortedKeys = new String[0]; int i = 0; Collection items = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); sortedKeys = new String[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); sortedKeys[i] = item.getResourceKey(); } // Now sort the list of keys in a logical manner Arrays.sort(sortedKeys); return sortedKeys; } public HashMap getDefinedKeys(String locale) throws DataException { HashMap keys = new HashMap(); if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } Collection items = languageFactory.findByLocale(locale); for (Iterator iter = items.iterator(); iter.hasNext();) { LanguageBean item = (LanguageBean) iter.next(); keys.put(item.getResourceKey(), item.getResourceValue()); } return keys; } public NameValuePairModel[] getDefinedKeysAsArray(String locale) throws DataException { NameValuePairModel[] keys = new NameValuePairModel[0]; if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } int i = 0; Collection items = languageFactory.findByLocale(locale); keys = new NameValuePairModel[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); keys[i] = new NameValuePairModel(item.getResourceKey(), item.getResourceValue()); } Arrays.sort(keys, new NameValuePairModel()); return keys; } public int getNumberDefinedKeys(String locale) throws DataException { return getDefinedKeys(locale).size(); } public LanguageModel[] getLanguage(Locale locale) throws DataException { LanguageModel[] languageArray = new LanguageModel[0]; HashMap language = new HashMap(); Collection baseItems = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); for (Iterator iterator = baseItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (locale != null && !"".equals(locale.getLanguage())) { Collection languageItems = languageFactory.findByLocale(locale.getLanguage()); for (Iterator iterator = languageItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } if (!"".equals(locale.getCountry())) { Collection countryItems = languageFactory.findByLocale(locale.toString()); for (Iterator iterator = countryItems.iterator(); iterator.hasNext();) { LanguageBean item = (LanguageBean) iterator.next(); language.put(item.getResourceKey(), item.getResourceValue()); } } } languageArray = new LanguageModel[language.size()]; int i = 0; String localeString = (locale == null ? ITrackerResources.BASE_LOCALE : locale.toString()); for (Iterator iterator = language.keySet().iterator(); iterator.hasNext(); i++) { String key = (String) iterator.next(); languageArray[i] = new LanguageModel(localeString, key, (String) language.get(key)); } return languageArray; } public HashMap getAvailableLanguages() throws DataException { HashMap languages = new HashMap(); ConfigurationModel[] locales = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_LOCALE); for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } if (locales[i].getValue().length() == 2) { languages.put(locales[i].getValue(), new Vector()); } } for (int i = 0; i < locales.length; i++) { if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locales[i].getValue())) { continue; } String locale = locales[i].getValue(); if (locale.length() == 5 && locale.indexOf('_') == 2) { String baseLanguage = locale.substring(0, 2); Vector languageVector = (Vector) languages.get(baseLanguage); if (languageVector != null) { languageVector.addElement(locale); } } } return languages; } public int getNumberAvailableLanguages() throws DataException { int numLanguages = 0; HashMap availableLanguages = getAvailableLanguages(); for (Iterator iter = availableLanguages.keySet().iterator(); iter.hasNext();) { Vector language = (Vector) availableLanguages.get((String) iter.next()); if (language != null && language.size() > 0) { numLanguages += language.size(); } else { numLanguages += 1; } } return numLanguages; } public void updateLanguage(Locale locale, LanguageModel[] items) throws DataException { if (locale != null && items != null) { ConfigurationModel configItem = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale .toString(), props.getProperty("version")); updateLanguage(locale, items, configItem); } } public void updateLanguage(Locale locale, LanguageModel[] items, ConfigurationModel configItem) throws DataException { if (items == null || locale == null || configItem == null) { return; } for (int i = 0; i < items.length; i++) { if (items[i] != null) { if (items[i].getAction() == SystemConfigurationUtilities.ACTION_REMOVE) { removeLanguageItem(items[i]); } else { updateLanguageItem(items[i]); } } } removeConfigurationItems(configItem); createConfigurationItem(configItem); } public SystemConfigurationModel getSystemConfiguration(Locale locale) throws DataException { SystemConfigurationModel config = new SystemConfigurationModel(); // Load the basic system configuration ConfigurationModel[] resolutions = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < resolutions.length; i++) { resolutions[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(resolutions[i]), locale)); } config.setResolutions(resolutions); ConfigurationModel[] severities = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY); for (int i = 0; i < severities.length; i++) { severities[i].setName(ITrackerResources.getString(SystemConfigurationUtilities .getLanguageKey(severities[i]), locale)); } config.setSeverities(severities); ConfigurationModel[] statuses = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS); for (int i = 0; i < statuses.length; i++) { statuses[i].setName(ITrackerResources.getString(SystemConfigurationUtilities.getLanguageKey(statuses[i]), locale)); } config.setStatuses(statuses); // Now load the CustomFields config.setCustomFields(IssueUtilities.getCustomFields(locale)); // Now set the system version config.setVersion(props.getProperty("version")); return config; } public boolean initializeLocale(String locale, boolean forceReload) throws DataException { boolean result = false; ConfigurationModel localeConfig = new ConfigurationModel(SystemConfigurationUtilities.TYPE_LOCALE, locale, props.getProperty("version")); if (!configurationItemUpToDate(localeConfig) || forceReload) { Logger.logDebug("Loading database with locale " + locale); PropertiesFileHandler localePropertiesHandler = new PropertiesFileHandler( "/cowsultants/itracker/ejb/client/resources/ITracker" + (ITrackerResources.BASE_LOCALE.equals(locale) ? "" : "_" + locale) + ".properties"); if (localePropertiesHandler.hasProperties()) { Properties localeProperties = localePropertiesHandler.getProperties(); Logger.logDebug("Locale " + locale + " contains " + localeProperties.size() + " properties."); for (Enumeration propertiesEnumeration = localeProperties.propertyNames(); propertiesEnumeration .hasMoreElements();) { String key = (String) propertiesEnumeration.nextElement(); String value = localeProperties.getProperty(key); updateLanguageItem(new LanguageModel(locale, key, value)); } removeConfigurationItems(localeConfig); createConfigurationItem(localeConfig); ITrackerResources.clearBundle(ITrackerResources.getLocale(locale)); result = true; } else { Logger.logInfo("Locale " + locale + " contained no properties."); } } return result; } public void initializeConfiguration() { // Need to eventually add in code that detects the current version of // the config and update // if necessary try { ConfigurationModel[] initialized = getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_INITIALIZED); if (initialized == null || initialized.length != 1) { Logger.logDebug("System does not appear to be initialized, initializing system configuration."); LanguageModel[] baseLanguage = getLanguage(ITrackerResources.getLocale(ITrackerResources.BASE_LOCALE)); if (baseLanguage == null || baseLanguage.length == 0) { throw new SystemConfigurationException( "Languages must be initialized before the system configuration can be loaded."); } // Remove any previous configuration information, possibly left // over from previous failed initialization Logger.logDebug("Removing previous incomplete initialization information."); removeConfigurationItems(SystemConfigurationUtilities.TYPE_STATUS); removeConfigurationItems(SystemConfigurationUtilities.TYPE_SEVERITY); removeConfigurationItems(SystemConfigurationUtilities.TYPE_RESOLUTION); for (int i = 0; i < baseLanguage.length; i++) { if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_RESOLUTION)) { try { String resolutionString = baseLanguage[i].getResourceKey().substring(20); Logger.logDebug("Adding new configuration resolution value: " + resolutionString); int resolutionNumber = Integer.parseInt(resolutionString); createConfigurationItem(new ConfigurationModel( SystemConfigurationUtilities.TYPE_RESOLUTION, resolutionString, props .getProperty("version"), resolutionNumber)); } catch (Exception e) { Logger.logError("Unable to load resolution value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_SEVERITY)) { try { String severityString = baseLanguage[i].getResourceKey().substring(18); Logger.logDebug("Adding new configuration severity value: " + severityString); int severityNumber = Integer.parseInt(severityString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_SEVERITY, severityString, props.getProperty("version"), severityNumber)); } catch (Exception e) { Logger.logError("Unable to load severity value: " + baseLanguage[i].getResourceKey(), e); } } if (baseLanguage[i].getResourceKey().startsWith(ITrackerResources.KEY_BASE_STATUS)) { try { String statusString = baseLanguage[i].getResourceKey().substring(16); Logger.logDebug("Adding new configuration status value: " + statusString); int statusNumber = Integer.parseInt(statusString); createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_STATUS, statusString, props.getProperty("version"), statusNumber)); } catch (Exception e) { Logger.logError("Unable to load status value: " + baseLanguage[i].getResourceKey(), e); } } } createConfigurationItem(new ConfigurationModel(SystemConfigurationUtilities.TYPE_INITIALIZED, "1", props.getProperty("version"))); } } catch (Exception e) { Logger.logError("Unable to initialize system configuration.", e); } } public LanguageFactory getLanguageFactory() { return languageFactory; } public void setLanguageFactory(LanguageFactory home) { languageFactory = home; } public ConfigurationFactory getConfigurationFactory() { return configurationFactory; } public void setConfigurationFactory(ConfigurationFactory configurationFactory) { this.configurationFactory = configurationFactory; } } \ No newline at end of file --- 1 ---- ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ConfigurationBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import cowsultants.itracker.ejb.beans.entity.LanguageBean; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.client.exceptions.SystemConfigurationException; import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; import cowsultants.itracker.ejb.client.models.ConfigurationModel; import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; import cowsultants.itracker.ejb.client.models.LanguageModel; import cowsultants.itracker.ejb.client.models.NameValuePairModel; import cowsultants.itracker.ejb.client.models.SystemConfigurationModel; import cowsultants.itracker.ejb.client.models.WorkflowScriptModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; import cowsultants.itracker.ejb.util.PropertiesFileHandler; /** * * Implimetation of the SystemConfiguration Interface. * * @see SystemConfiguration * */ public class SystemConfigurationBean implements SystemConfiguration { private static Properties props = null; private ConfigurationFactory configurationFactory; private CustomFieldFactory customFieldFactory; private CustomFieldValueFactory customFieldValueFactory; private LanguageFactory languageFactory; private WorkflowScriptFactory workflowScriptFactory; public SystemConfigurationBean() { if (props == null) { props = new Properties(); PropertiesFileHandler filePropertiesHandler = new PropertiesFileHandler(); filePropertiesHandler.addProperties("/itrackerApplication.properties"); filePropertiesHandler.addProperties("/itrackerVersion.properties"); Properties fileProps = filePropertiesHandler.getProperties(); for (Enumeration e = fileProps.propertyNames(); e.hasMoreElements();) { String propName = (String) e.nextElement(); Logger.logDebug("Setting property " + propName + " from file to value '" + fileProps.getProperty(propName) + "'"); props.setProperty(propName, fileProps.getProperty(propName)); } props.setProperty("start_time_millis", Long.toString(new java.util.Date().getTime())); } } public String getProperty(String name) { return props.getProperty(name); } public String getProperty(String name, String defaultValue) { return props.getProperty(name, defaultValue); } public boolean getBooleanProperty(String name, boolean defaultValue) { String value = props.getProperty(name); return (value == null ? defaultValue : new Boolean(value).booleanValue()); } public int getIntegerProperty(String name, int defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Integer.parseInt(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public long getLongProperty(String name, long defaultValue) { String value = props.getProperty(name); try { return (value == null ? defaultValue : Long.parseLong(value)); } catch (NumberFormatException nfe) { return defaultValue; } } public Properties getProperties() { return props; } public ConfigurationModel getConfigurationItem(Integer id) { ConfigurationBean configItem = configurationFactory.findByPrimaryKey(id); return configItem.getModel(); } public ConfigurationModel[] getConfigurationItemsByType(int type) throws DataException { ConfigurationModel[] items = new ConfigurationModel[0]; Collection configItems = configurationFactory.findByType(type); items = new ConfigurationModel[configItems.size()]; int i = 0; for (Iterator iter = configItems.iterator(); iter.hasNext(); i++) { items[i] = ((ConfigurationBean) iter.next()).getModel(); } Arrays.sort(items, new ConfigurationModel()); return items; } public ConfigurationModel[] getConfigurationItemsByType(int type, Locale locale) throws DataException { ConfigurationModel[] items = getConfigurationItemsByType(type); for (int i = 0; i < items.length; i++) { if (items[i].getType() == SystemConfigurationUtilities.TYPE_STATUS) { items[i].setName(IssueUtilities.getStatusName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { items[i].setName(IssueUtilities.getSeverityName(items[i].getValue(), locale)); } else if (items[i].getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { items[i].setName(IssueUtilities.getResolutionName(items[i].getValue(), locale)); } } return items; } public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationFactory.saveOrUpdate(configurationItem); return configurationItem.getModel(); } public ConfigurationModel updateConfigurationItem(ConfigurationModel model) { if (model != null) { ConfigurationBean configurationItem = configurationFactory.findByPrimaryKey(model.getId()); configurationItem.setModel(model); return configurationItem.getModel(); } return (null); } public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(models[i]); models[i] = configurationItem.getModel(); } Arrays.sort(models, new ConfigurationModel()); return models; // Logger.logDebug("Unable to create new language item."); // return new ConfigurationModel[0]; } public void removeConfigurationItem(Integer id) { // cHome.remove(id); // Logger.logDebug("Unable to remove configuration item " + id + "."); } public void removeConfigurationItems(int type) throws DataException { Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean config = (ConfigurationBean) iter.next(); // config.remove(); } } public void removeConfigurationItems(ConfigurationModel model) throws DataException { Vector currentIds = new Vector(); Collection currentItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); configurationFactory.delete(configItem); } } public boolean configurationItemExists(ConfigurationModel model) throws DataException { if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); if (configItems != null && configItems.size() > 0) { return true; } } return false; } public boolean configurationItemUpToDate(ConfigurationModel model) throws DataException { long currentVersion = 0; if (model != null && model.getVersion() != null) { Collection configItems = configurationFactory.findByTypeAndValue(model.getType(), model.getValue()); for (Iterator iter = configItems.iterator(); iter.hasNext();) { ConfigurationBean configItem = (ConfigurationBean) iter.next(); if (configItem != null) { currentVersion = Math.max(SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(model.getVersion())) { return true; } } return false; } public void resetConfigurationCache() throws DataException { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); IssueUtilities.setCustomFields(getCustomFields()); } public void resetConfigurationCache(int type) throws DataException { if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { IssueUtilities.setResolutions(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_RESOLUTION)); } else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { IssueUtilities.setSeverities(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY)); } else if (type == SystemConfigurationUtilities.TYPE_STATUS) { IssueUtilities.setStatuses(getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS)); } else if (type == SystemConfigurationUtilities.TYPE_CUSTOMFIELD) { IssueUtilities.setCustomFields(getCustomFields()); } } public WorkflowScriptModel getWorkflowScript(Integer id) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(id); return workflowScript.getModel(); } public WorkflowScriptModel[] getWorkflowScripts() { WorkflowScriptModel[] scripts = new WorkflowScriptModel[0]; Collection workflowScripts = workflowScriptFactory.findAll(); scripts = new WorkflowScriptModel[workflowScripts.size()]; int i = 0; for (Iterator iter = workflowScripts.iterator(); iter.hasNext(); i++) { scripts[i] = ((WorkflowScriptBean) iter.next()).getModel(); } return scripts; } public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // try { WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); model.setId(workflowScript.getId()); return workflowScript.getModel(); // } catch(CreateException ce) { // Logger.logDebug("Unable to create new workflow script.", ce); // } // return null; } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } public CustomFieldModel getCustomField(Integer id) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(id); return customField.getModel(); } public CustomFieldModel[] getCustomFields() throws DataException { CustomFieldModel[] fields = new CustomFieldModel[0]; Collection customFields = customFieldFactory.findAll(); fields = new CustomFieldModel[customFields.size()]; int i = 0; for (Iterator iter = customFields.iterator(); iter.hasNext(); i++) { fields[i] = ((CustomFieldBean) iter.next()).getModel(); } return fields; } public CustomFieldModel[] getCustomFields(Locale locale) throws DataException { CustomFieldModel[] fields = getCustomFields(); for (int i = 0; i < fields.length; i++) { fields[i].setLabels(locale); } return fields; } public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); model.setId(customField.getId()); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { newOptions[i].setCustomFieldId(customField.getId()); createCustomFieldValue(newOptions[i]); } } return customField.getModel(); // Logger.logDebug("Unable to create new custom field.", ce); } public CustomFieldModel updateCustomField(CustomFieldModel model) throws DataException { if (model != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getId()); customField.setModel(model); if (model.getOptions().length > 0) { removeCustomFieldValues(customField.getId()); CustomFieldValueModel[] newOptions = model.getOptions(); for (int i = 0; i < newOptions.length; i++) { createCustomFieldValue(newOptions[i]); } } return customField.getModel(); } return null; } public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); // customField.remove(); } public CustomFieldValueModel getCustomFieldValue(Integer id) { // CustomFieldValueBean customFieldValue = cfvHome.findByPrimaryKey(id); // return customFieldValue.getModel(); return (null); } public CustomFieldValueModel createCustomFieldValue(CustomFieldValueModel model) throws DataException { if (model == null || model.getCustomFieldId() == null) { return null; } CustomFieldBean customField = customFieldFactory.findByPrimaryKey(model.getCustomFieldId()); CustomFieldValueBean customFieldValue = new CustomFieldValueBean(); customFieldValue.setModel(model); customFieldValue.setCustomField(customField); return customFieldValue.getModel(); // Logger.logDebug("Unable to create new custom field value: " + // ce.getMessage()); // Logger.logDebug("Unable to create new custom field value, custom // field not found: " + fe.getMessage()); } public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { // if(model != null) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(model.getId()); // customFieldValue.setModel(model); // return customFieldValue.getModel(); // } return null; } public CustomFieldValueModel[] updateCustomFieldValues(Integer customFieldId, CustomFieldValueModel[] models) throws DataException { CustomFieldValueModel[] values = new CustomFieldValueModel[0]; if (customFieldId != null) { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); Collection currValues = customField.getValues(); for (Iterator iter = currValues.iterator(); iter.hasNext();) { if (models == null || models.length == 0) { // ((CustomFieldValueBean) iter.next()).remove(); } else { CustomFieldValueBean value = (CustomFieldValueBean) iter.next(); for (int i = 0; i < models.length; i++) { if (value.getId().equals(models[i].getId())) { value.setModel(models[i]); models[i] = value.getModel(); break; } } } } } Arrays.sort(models, new CustomFieldValueModel()); return models; } public void removeCustomFieldValue(Integer customFieldValueId) { // CustomFieldValueBean customFieldValue = // cfvHome.findByPrimaryKey(customFieldValueId); // customFieldValue.remove(); } public void removeCustomFieldValues(Integer customFieldId) { // Collection currentValues = cfvHome.findByCustomField(customFieldId); // for(Iterator iter = currentValues.iterator(); iter.hasNext(); ) { // // //((CustomFieldValueBean) iter.next()).remove(); // } } public LanguageModel getLanguageItemByKey(String key, Locale locale) throws DataException { LanguageModel model = null; if (key != null) { LanguageBean languageItem = languageFactory.findByKeyAndLocale(key, ITrackerResources.BASE_LOCALE); model = languageItem.getModel(); if (locale != null && !"".equals(locale.getLanguage())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.getLanguage()); model = languageItem.getModel(); if (!"".equals(locale.getCountry())) { languageItem = languageFactory.findByKeyAndLocale(key, locale.toString()); model = languageItem.getModel(); } } } return model; } public LanguageModel[] getLanguageItemsByKey(String key) throws DataException { LanguageModel[] items = new LanguageModel[0]; Collection languageItems = languageFactory.findByKey(key); items = new LanguageModel[languageItems.size()]; int i = 0; for (Iterator iter = languageItems.iterator(); iter.hasNext(); i++) { items[i] = ((LanguageBean) iter.next()).getModel(); } return items; } public LanguageModel updateLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem; try { languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); languageItem.setModel(model); } catch (NoSuchEntityException fe) { languageItem = new LanguageBean(); languageItem.setCreateDate(new Timestamp(new Date().getTime())); languageItem.setModel(model); languageFactory.saveOrUpdate(languageItem); } return languageItem.getModel(); } public void removeLanguageKey(String key) throws DataException { Vector currentIds = new Vector(); Collection languageItems = languageFactory.findByKey(key); for (Iterator iter = languageItems.iterator(); iter.hasNext();) { currentIds.add(((LanguageBean) iter.next()).getId()); } for (int i = 0; i < currentIds.size(); i++) { // lHome.remove((Integer) currentIds.elementAt(i)); } // } catch(FinderException ce) { // Logger.logDebug("Unable to find any language items with key" + key + // " for removal."); // } } public void removeLanguageItem(LanguageModel model) throws DataException { LanguageBean languageItem = languageFactory.findByKeyAndLocale(model.getResourceKey(), model.getLocale()); // lHome.remove(languageItem.getId()); // Logger.logDebug("Unable to remove language item " + model.toString() // + "."); } public String[] getSortedKeys() throws DataException { String[] sortedKeys = new String[0]; int i = 0; Collection items = languageFactory.findByLocale(ITrackerResources.BASE_LOCALE); sortedKeys = new String[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); sortedKeys[i] = item.getResourceKey(); } // Now sort the list of keys in a logical manner Arrays.sort(sortedKeys); return sortedKeys; } public HashMap getDefinedKeys(String locale) throws DataException { HashMap keys = new HashMap(); if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } Collection items = languageFactory.findByLocale(locale); for (Iterator iter = items.iterator(); iter.hasNext();) { LanguageBean item = (LanguageBean) iter.next(); keys.put(item.getResourceKey(), item.getResourceValue()); } return keys; } public NameValuePairModel[] getDefinedKeysAsArray(String locale) throws DataException { NameValuePairModel[] keys = new NameValuePairModel[0]; if (locale == null || locale.equals("")) { locale = ITrackerResources.BASE_LOCALE; } int i = 0; Collection items = languageFactory.findByLocale(locale); keys = new NameValuePairModel[items.size()]; for (Iterator iter = items.iterator(); iter.hasNext(); i++) { LanguageBean item = (LanguageBean) iter.next(); keys[i] = new NameValuePairModel(item.getResourceKey(), item.getResourceValue()); } Arrays.sort(keys, new NameValuePairModel()); return keys;... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-07 22:57:41
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2176 Modified Files: Tag: itrackerhibernate LanguageFactoryImpl.java Log Message: corrected typo Index: LanguageFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/LanguageFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** LanguageFactoryImpl.java 18 Oct 2005 20:47:56 -0000 1.1.2.2 --- LanguageFactoryImpl.java 7 Nov 2005 22:57:33 -0000 1.1.2.3 *************** *** 26,30 **** public Collection findByKey(String key) throws DataException { Criteria criteria = getSession().createCriteria(LanguageBean.class); ! criteria.add(Expression.eq("resource_key", key)); try { return (criteria.list()); --- 26,30 ---- public Collection findByKey(String key) throws DataException { Criteria criteria = getSession().createCriteria(LanguageBean.class); ! criteria.add(Expression.eq("resourceKey", key)); try { return (criteria.list()); |
From: Marc B. <mb...@us...> - 2005-11-07 22:47:47
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32563 Modified Files: Tag: itrackerhibernate ConfigurationFactoryImpl.java Log Message: added implementation of method findByPrimaryKey Index: ConfigurationFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/ConfigurationFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** ConfigurationFactoryImpl.java 24 Oct 2005 23:25:50 -0000 1.1.2.2 --- ConfigurationFactoryImpl.java 7 Nov 2005 22:47:37 -0000 1.1.2.3 *************** *** 13,19 **** * @see cowsultants.itracker.ejb.beans.session.ConfigurationFactoryI#findByPrimaryKey(java.lang.Integer) */ ! public ConfigurationBean findByPrimaryKey(Integer id) { ! // TODO Auto-generated method stub ! return null; } --- 13,22 ---- * @see cowsultants.itracker.ejb.beans.session.ConfigurationFactoryI#findByPrimaryKey(java.lang.Integer) */ ! public ConfigurationBean findByPrimaryKey(Integer configId) { ! try { ! return (ConfigurationBean) (getSession().load(ConfigurationBean.class, configId)); ! } catch (HibernateException e) { ! throw new DataException(e); ! } } |
From: Marc B. <mb...@us...> - 2005-11-07 22:11:48
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24605 Added Files: Tag: itrackerhibernate CustomFieldValueFactoryImpl.java Log Message: added implementation of CustomFieldValueFactory interface --- NEW FILE: CustomFieldValueFactoryImpl.java --- /* * CustomFieldValueFactoryImpl.java * * Created on 7. November 2005, 23:24 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package cowsultants.itracker.ejb.beans.session; import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import java.util.Collection; import net.sf.hibernate.HibernateException; /** * * @author mbae */ public class CustomFieldValueFactoryImpl extends BaseHibernateFactoryImpl implements CustomFieldValueFactory { public CustomFieldValueBean findByPrimaryKey(Integer customFieldId) throws DataException { try { return (CustomFieldValueBean) (getSession().load(CustomFieldValueBean.class, customFieldId)); } catch (HibernateException e) { throw new DataException(e); } } public Collection findAll() throws DataException { try { return (getSession().createCriteria(CustomFieldValueBean.class).list()); } catch (HibernateException e) { throw new DataException(e); } } } |
From: Marc B. <mb...@us...> - 2005-11-07 22:11:15
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24396 Modified Files: Tag: itrackerhibernate CustomFieldValueFactory.java Log Message: extend BaseFactory interface Index: CustomFieldValueFactory.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/CustomFieldValueFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** CustomFieldValueFactory.java 11 Oct 2005 01:36:08 -0000 1.1.2.1 --- CustomFieldValueFactory.java 7 Nov 2005 22:11:01 -0000 1.1.2.2 *************** *** 1,11 **** package cowsultants.itracker.ejb.beans.session; import java.util.Collection; ! import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; ! ! public interface CustomFieldValueFactory { ! public CustomFieldBean findByPrimaryKey(Integer customFieldId) throws DataException; public Collection findAll() throws DataException; --- 1,10 ---- package cowsultants.itracker.ejb.beans.session; + import cowsultants.itracker.ejb.beans.entity.CustomFieldValueBean; import java.util.Collection; ! public interface CustomFieldValueFactory extends BaseFactory { ! public CustomFieldValueBean findByPrimaryKey(Integer customFieldId) throws DataException; public Collection findAll() throws DataException; |
From: Marc B. <mb...@us...> - 2005-11-07 22:10:20
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24219 Modified Files: Tag: itrackerhibernate CustomFieldFactoryImpl.java Log Message: implement findByPrimaryKey with hibernate criteria Index: CustomFieldFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/CustomFieldFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** CustomFieldFactoryImpl.java 22 Oct 2005 16:37:28 -0000 1.1.2.2 --- CustomFieldFactoryImpl.java 7 Nov 2005 22:10:11 -0000 1.1.2.3 *************** *** 10,15 **** public CustomFieldBean findByPrimaryKey(Integer customFieldId) { ! // TODO Auto-generated method stub ! return null; } --- 10,18 ---- public CustomFieldBean findByPrimaryKey(Integer customFieldId) { ! try { ! return (CustomFieldBean) (getSession().load(CustomFieldBean.class, customFieldId)); ! } catch (HibernateException e) { ! throw new DataException(e); ! } } |
From: Ricardo T. <ric...@em...> - 2005-11-05 15:20:02
|
Hi, Regarding the JSP refactoring issue we've been discussing, about removing java code from JSP : 1) removing most of the Java code from list_issues.jsp was easy. I moved it to an action. This has cause the reduction of the JSP size to half, and I think was a very good thing. 2) I'm unsure how to proceed. What's left is stuff like this : <% if(project.getStatus() == ProjectUtilities.STATUS_ACTIVE && UserUtilities.hasPermission(currPermissions, project.getId(), UserUtilities.PERMISSION_EDIT)) { %> <it:formatImageAction forward="createissue" paramName="pid" paramValue="<%= project.getId() %>" src="/themes/standardtheme/images/create.gif" altKey="itracker.web.image.create.issue.alt" arg0="<%= project.getName() %>" textActionKey="itracker.web.image.create.texttag"/> <% } %> Some of the issues here will go away by themselves in the future. Changes like turning project.getStatus() == ProjectUtilities.STATUS_ACTIVE into project.isActive() will make code like this more readable. (this is just a simple example, I don't want to have hard coded project statuses, like the example implies) But still, if we want to do full templating, we'll need to go a step further. We need to remove java code associated with view. That means conditionals, iterations, formatting, etc... How best can I remove this java code ? I've examined some options : 1) Using JSTL (standard tag libraries). Latest version of JSP seems to have something called EL, that gives decent syntax inside JSPs. 2) Using a templating language like velocity, or freeemarker 3) Using java inside JSP, to code view logic 4) Using something else ? What should I do in prototype refactoring I'm doing ? I've worked with the all the technologies above (velocity, freemarker, JSPs, etc..), but I don't consider myself and expert in them, because there has been a while since I've been on or managed the front end layer of a web project. So I don't think I'm equipped to do the best choice. What I can tell is that having the power of a real programming language inside templates is good, but we have to take care to don't put business logic in. Unfortunately java is very verbose, so I'm not sure. My past experience and current small tests lead me to believe actually all of these aproaches, if well applied, are good. So my personal favorite at this point for pass one of the refactoring is 3). I'm sure it's not the best approach. If any of you have experience in this area, please help this discussion. Ricardo |
From: Marky G. <mar...@us...> - 2005-11-05 12:51:43
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5836/src/cowsultants/itracker/ejb/beans/session Modified Files: Tag: itrackerhibernate ProjectFactoryImpl.java Log Message: remove used import Index: ProjectFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/ProjectFactoryImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** ProjectFactoryImpl.java 25 Oct 2005 21:41:58 -0000 1.1.2.2 --- ProjectFactoryImpl.java 5 Nov 2005 12:51:29 -0000 1.1.2.3 *************** *** 6,11 **** import net.sf.hibernate.HibernateException; - import org.springframework.orm.hibernate.support.HibernateDaoSupport; - import cowsultants.itracker.ejb.beans.entity.ProjectBean; --- 6,9 ---- |
From: Marc B. <mb...@us...> - 2005-11-05 00:20:09
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3888 Modified Files: Tag: itrackerhibernate UserHandlerBean.java Log Message: check userTest must be null to deny changing loginname. Has this changing loginname been disabled by intention? If so the form should not allow to change the login (both html and strutsForm) Index: UserHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/UserHandlerBean.java,v retrieving revision 1.44.4.7 retrieving revision 1.44.4.8 diff -C2 -d -r1.44.4.7 -r1.44.4.8 *** UserHandlerBean.java 4 Nov 2005 23:06:35 -0000 1.44.4.7 --- UserHandlerBean.java 5 Nov 2005 00:20:00 -0000 1.44.4.8 *************** *** 248,252 **** if (!user.getLogin().equals(model.getLogin())) { UserBean userTest = userFactory.findByLogin(model.getLogin()); ! throw new UserException("User already exists with login: " + model.getLogin()); } --- 248,254 ---- if (!user.getLogin().equals(model.getLogin())) { UserBean userTest = userFactory.findByLogin(model.getLogin()); ! if ( userTest != null ) { ! throw new UserException("User already exists with login: " + model.getLogin()); ! } } |
From: Marc B. <mb...@us...> - 2005-11-04 23:06:43
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10074 Modified Files: Tag: itrackerhibernate UserHandlerBean.java Log Message: fixed removing off permissions in two cases: if some but not all permissions should be removed and remove all permissions at once Index: UserHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/UserHandlerBean.java,v retrieving revision 1.44.4.6 retrieving revision 1.44.4.7 diff -C2 -d -r1.44.4.6 -r1.44.4.7 *** UserHandlerBean.java 1 Nov 2005 22:59:12 -0000 1.44.4.6 --- UserHandlerBean.java 4 Nov 2005 23:06:35 -0000 1.44.4.7 *************** *** 535,544 **** if (newPermissions == null || newPermissions.length == 0) { for (Iterator iterator = permissions.iterator(); iterator.hasNext();) { ! PermissionBean permission = (PermissionBean) iterator.next(); ! permissionFactory.delete(permission); } } else { HashMap newPermissionsMap = new HashMap(); for (int i = 0; i < newPermissions.length; i++) { if (newPermissions[i] != null) { --- 535,547 ---- if (newPermissions == null || newPermissions.length == 0) { + // delete all existing permissions if no permissions + // have been submitted by http params for (Iterator iterator = permissions.iterator(); iterator.hasNext();) { ! iterator.next(); ! iterator.remove(); } } else { HashMap newPermissionsMap = new HashMap(); + // put all permissions into map for later lookup for (int i = 0; i < newPermissions.length; i++) { if (newPermissions[i] != null) { *************** *** 547,551 **** } } ! for (Iterator iterator = permissions.iterator(); iterator.hasNext();) { PermissionBean permission = (PermissionBean) iterator.next(); --- 550,556 ---- } } ! ! // - peek out permissions already granted ! // - delete permissioin not granted anymore for (Iterator iterator = permissions.iterator(); iterator.hasNext();) { PermissionBean permission = (PermissionBean) iterator.next(); *************** *** 555,573 **** newPermissionsMap.remove("Perm" + model.getPermissionType() + "Proj" + model.getProjectId()); } else { ! /* ! * try { iterator.remove(); //permission.remove(); } ! * catch(RemoveException re) { Logger.logWarn("Error ! * removing user (" + userId + ") permission (Proj: " + ! * model.getProjectId() + " Perm: " + ! * model.getPermissionType() + ").", re); successful = ! * false; } ! */ } } if (newPermissionsMap.values() != null) { for (Iterator iterator = newPermissionsMap.values().iterator(); iterator.hasNext();) { PermissionModel model = (PermissionModel) iterator.next(); if (model.getProjectId() != null) { - // try { ProjectBean project = projectFactory.findByPrimaryKey(model.getProjectId()); --- 560,572 ---- newPermissionsMap.remove("Perm" + model.getPermissionType() + "Proj" + model.getProjectId()); } else { ! // delete permission ! iterator.remove(); } } + // finally create all newPermissions which do not exist yet if (newPermissionsMap.values() != null) { for (Iterator iterator = newPermissionsMap.values().iterator(); iterator.hasNext();) { PermissionModel model = (PermissionModel) iterator.next(); if (model.getProjectId() != null) { ProjectBean project = projectFactory.findByPrimaryKey(model.getProjectId()); *************** *** 578,594 **** permission.setUser(user); permissions.add(permission); - // } /*catch(CreateException ce) { - // Logger.logWarn("Error adding user (" + userId + - // ") permission (Proj: " + model.getProjectId() + " - // Perm: " + model.getPermissionType() + "). Could - // not create permission.", ce); - // successful = false; - /* - * } catch(FinderException fe) { - * Logger.logWarn("Error adding user (" + userId + ") - * permission (Proj: " + model.getProjectId() + " - * Perm: " + model.getPermissionType() + "). Could - * not find project.", fe); successful = false; } - */ } } --- 577,580 ---- |
From: Marc B. <mb...@us...> - 2005-11-03 20:15:12
|
Update of /cvsroot/itracker/itracker/web/WEB-INF In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9953/web/WEB-INF Modified Files: Tag: itrackerhibernate applicationContext.xml Log Message: added versionFactoryTarget and versionFactory Index: applicationContext.xml =================================================================== RCS file: /cvsroot/itracker/itracker/web/WEB-INF/Attic/applicationContext.xml,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -C2 -d -r1.1.2.10 -r1.1.2.11 *** applicationContext.xml 2 Nov 2005 20:53:46 -0000 1.1.2.10 --- applicationContext.xml 3 Nov 2005 20:15:02 -0000 1.1.2.11 *************** *** 64,67 **** --- 64,74 ---- </property> </bean> + + <!-- The version factory --> + <bean id="versionFactoryTarget" class="cowsultants.itracker.ejb.beans.session.VersionFactoryImpl"> + <property name="sessionFactory"> + <ref bean="sessionFactory"/> + </property> + </bean> <!-- The userpreferences factory --> *************** *** 286,289 **** --- 293,316 ---- <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> <!-- Application code uses this object --> + <bean id="versionFactory" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> + <property name="transactionManager" ref="transactionManager"/> + <property name="transactionAttributes"> + <props> + <prop key="*">PROPAGATION_REQUIRED</prop> + </props> + </property> + <property name="target" ref="versionFactoryTarget"/> + <property name="proxyInterfaces"> + <value>cowsultants.itracker.ejb.beans.session.VersionFactory</value> + </property> + <property name="postInterceptors"> + <list> + <ref bean="myHibernateInterceptor"/> + </list> + </property> + </bean> + + <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> + <!-- Application code uses this object --> <bean id="userPreferencesFactory" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> |
From: Marc B. <mb...@us...> - 2005-11-03 20:12:59
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9571 Modified Files: Tag: itrackerhibernate IssueHandlerBean.java Log Message: add versionFactory for dependency inj. Index: IssueHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/IssueHandlerBean.java,v retrieving revision 1.57.4.6 retrieving revision 1.57.4.7 diff -C2 -d -r1.57.4.6 -r1.57.4.7 *** IssueHandlerBean.java 1 Nov 2005 14:46:46 -0000 1.57.4.6 --- IssueHandlerBean.java 3 Nov 2005 20:12:47 -0000 1.57.4.7 *************** *** 1 **** ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ComponentBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueActivityBean; import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; import cowsultants.itracker.ejb.beans.entity.IssueBean; import cowsultants.itracker.ejb.beans.entity.IssueFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueHistoryBean; import cowsultants.itracker.ejb.beans.entity.IssueRelationBean; import cowsultants.itracker.ejb.beans.entity.NotificationBean; import cowsultants.itracker.ejb.beans.entity.ProjectBean; import cowsultants.itracker.ejb.beans.entity.UserBean; import cowsultants.itracker.ejb.beans.entity.VersionBean; import cowsultants.itracker.ejb.beans.message.NotificationMessageBean; import cowsultants.itracker.ejb.client.exceptions.IssueException; import cowsultants.itracker.ejb.client.interfaces.IssueHandler; import cowsultants.itracker.ejb.client.models.ComponentModel; import cowsultants.itracker.ejb.client.models.IssueAttachmentModel; import cowsultants.itracker.ejb.client.models.IssueFieldModel; import cowsultants.itracker.ejb.client.models.IssueHistoryModel; import cowsultants.itracker.ejb.client.models.IssueModel; import cowsultants.itracker.ejb.client.models.IssueRelationModel; import cowsultants.itracker.ejb.client.models.NotificationModel; import cowsultants.itracker.ejb.client.models.ProjectModel; import cowsultants.itracker.ejb.client.models.UserModel; import cowsultants.itracker.ejb.client.models.VersionModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.AuthenticationConstants; import cowsultants.itracker.ejb.client.util.IssueUtilities; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.NotificationUtilities; import cowsultants.itracker.ejb.client.util.ProjectUtilities; import cowsultants.itracker.ejb.client.util.UserUtilities; /** * Issue related service layer. A bit "fat" at this time, because of being a direct EJB porting. * Going go get thinner over time * * @author ricardo * */ public class IssueHandlerBean implements IssueHandler { private static String notificationFactoryName = NotificationMessageBean.DEFAULT_CONNECTION_FACTORY; private static String notificationQueueName = NotificationMessageBean.DEFAULT_QUEUE_NAME; private static String systemBaseURL = ""; private CustomFieldFactory cfHome = null; private UserFactory userFactory = null; private ProjectFactory projectFactory; private IssueFactory issueFactory; private IssueHistoryFactory ihfHome = null; private NotificationFactory notificationFactory; private IssueRelationFactory issuerelationfactory = null; private ComponentFactory componentFactory = null; private IssueActivityFactory issueActivityFactory; public IssueHandlerBean() { ihfHome = SpringFactories.getIssueHistoryFactory(); issuerelationfactory = SpringFactories.getIssueRelationFactory(); componentFactory = SpringFactories.getComponentFactory(); cfHome = SpringFactories.getCustomFieldFactory(); } public IssueModel getIssue(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); return issue.getModel(); } public IssueModel[] getAllIssues() throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findAll(); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public int getNumberIssues() throws DataException { Collection issues = issueFactory.findAll(); return issues.size(); } public IssueModel[] getIssuesCreatedByUser(Integer userId) throws DataException { return getIssuesCreatedByUser(userId, true); } public IssueModel[] getIssuesCreatedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByCreatorInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) : issueFactory.findByCreator(userId, IssueUtilities.STATUS_CLOSED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesOwnedByUser(Integer userId) throws DataException { return getIssuesOwnedByUser(userId, true); } public IssueModel[] getIssuesOwnedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByOwnerInAvailableProjects(userId, IssueUtilities.STATUS_RESOLVED) : issueFactory.findByOwner(userId, IssueUtilities.STATUS_RESOLVED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesWatchedByUser(Integer userId) throws DataException { return getIssuesWatchedByUser(userId, true); } public IssueModel[] getIssuesWatchedByUser(Integer userId, boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory.findByNotificationInAvailableProjects(userId, IssueUtilities.STATUS_CLOSED) : issueFactory.findByNotification(userId, IssueUtilities.STATUS_CLOSED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getUnassignedIssues() throws DataException { return getUnassignedIssues(true); } public IssueModel[] getUnassignedIssues(boolean availableProjectsOnly) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = (availableProjectsOnly ? issueFactory .findByStatusLessThanEqualToInAvailableProjects(IssueUtilities.STATUS_UNASSIGNED) : issueFactory .findByStatusLessThanEqualTo(IssueUtilities.STATUS_UNASSIGNED)); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a status equal to the given status number * * * * @param status * * the status to compare * * @return an array of IssueModels that match the criteria * */ public IssueModel[] getIssuesWithStatus(int status) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByStatus(status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a status less than the given status number * * * * @param status * * the status to compare * * @return an array of IssueModels that match the criteria * * @throws DataException * */ public IssueModel[] getIssuesWithStatusLessThan(int status) throws DataException { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByStatusLessThan(status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } /** * * Returns all issues with a severity equal to the given severity number * * * * @param severity * * the severity to compare * * @return an array of IssueModels that match the criteria * */ public IssueModel[] getIssuesWithSeverity(int severity) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findBySeverity(severity); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public IssueModel[] getIssuesByProjectId(Integer projectId) { return getIssuesByProjectId(projectId, IssueUtilities.STATUS_END); } public IssueModel[] getIssuesByProjectId(Integer projectId, int status) { int i = 0; IssueModel[] issueArray = new IssueModel[0]; Collection issues = issueFactory.findByProjectIdAndLowerStatus(projectId, status); issueArray = new IssueModel[issues.size()]; for (Iterator iterator = issues.iterator(); iterator.hasNext(); i++) { issueArray[i] = ((IssueBean) iterator.next()).getModel(); } return issueArray; } public UserModel getIssueCreator(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = issue.getCreator(); return (user != null ? user.getModel() : null); } public UserModel getIssueOwner(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = issue.getOwner(); return (user != null ? user.getModel() : null); } public ComponentModel[] getIssueComponents(Integer issueId) throws DataException { int i = 0; ComponentModel[] componentArray = new ComponentModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); componentArray = new ComponentModel[components.size()]; for (Iterator iterator = components.iterator(); iterator.hasNext(); i++) { componentArray[i] = ((ComponentBean) iterator.next()).getModel(); } return componentArray; } public VersionModel[] getIssueVersions(Integer issueId) throws DataException { int i = 0; VersionModel[] versionArray = new VersionModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); versionArray = new VersionModel[versions.size()]; for (Iterator iterator = versions.iterator(); iterator.hasNext(); i++) { versionArray[i] = ((VersionBean) iterator.next()).getModel(); } return versionArray; } public IssueAttachmentModel[] getIssueAttachments(Integer issueId) throws DataException { int i = 0; IssueAttachmentModel[] attachmentsArray = new IssueAttachmentModel[0]; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection attachments = issue.getAttachments(); attachmentsArray = new IssueAttachmentModel[attachments.size()]; for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { attachmentsArray[i] = ((IssueAttachmentBean) iterator.next()).getModel(); } return attachmentsArray; } /** * Old implementation is left here, commented, because it checked for * history entry status. This feature was not finished, I think (RJST) */ public IssueHistoryModel[] getIssueHistory(Integer issueId) { return (issueFactory.findByPrimaryKey(issueId).getModel().getHistory()); /* * int i = 0; * * IssueHistoryModel[] historyArray = new IssueHistoryModel[0]; * * Vector results = new Vector(); * * new IssueBean().getModel().getHistory() * * Collection history = ifHome.findByIssueId(issueId); * * historyArray = new IssueHistoryModel[history.size()]; * * for (Iterator iterator = history.iterator(); iterator.hasNext(); i++) { * * IssueHistoryBean entry = (IssueHistoryBean) iterator.next(); * * if (entry.getStatus() == IssueUtilities.HISTORY_STATUS_AVAILABLE) { * * results.addElement(entry.getModel()); } } * * historyArray = new IssueHistoryModel[results.size()]; * * results.copyInto(historyArray); * * * * return historyArray; */ } public IssueModel createIssue(IssueModel model, Integer projectId, Integer userId, Integer createdById) throws DataException { try { ProjectBean project = projectFactory.findByPrimaryKey(projectId); UserBean creator = userFactory.findByPrimaryKey(userId); if (project.getStatus() != ProjectUtilities.STATUS_ACTIVE) { throw new IssueException("Project is not active."); } IssueBean issue = new IssueBean(); if (issue != null) { if (createdById == null || createdById.equals(userId)) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_ISSUE_CREATED); activity.setUser(creator); activity.setIssue(issue); } else { UserBean createdBy = userFactory.findByPrimaryKey(createdById); IssueActivityBean activity = new IssueActivityBean(); activity.setDescription(ITrackerResources.getString("itracker.activity.system.createdfor") + " " + creator.getFirstName() + " " + creator.getLastName()); activity.setUser(createdBy); activity.setIssue(issue); NotificationModel watchModel = new NotificationModel(); watchModel.setUserId(createdById); watchModel.setIssueId(issue.getId()); watchModel.setNotificationRole(NotificationUtilities.ROLE_IP); addIssueNotification(watchModel); } issue.setModel(model); issue.setProject(project); issue.setCreator(creator); // save issue.setCreateDate(new Timestamp(new Date().getTime())); issueFactory.save(issue); return issue.getModel(); } } catch (IssueException ie) { Logger.logInfo("Error while creating new issue: " + ie.getMessage()); } return null; } public IssueModel updateIssue(IssueModel model, Integer userId) throws DataException { try { String existingTargetVersion = null; IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); UserBean user = userFactory.findByPrimaryKey(userId); if (issue.getProject().getStatus() != ProjectUtilities.STATUS_ACTIVE) { throw new IssueException("Project is not active."); } if (issue.getDescription() != null && model.getDescription() != null && !issue.getDescription().equalsIgnoreCase(model.getDescription())) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_DESCRIPTION_CHANGE); activity.setDescription(ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getDescription()); activity.setUser(user); activity.setIssue(issue); } if (issue.getResolution() != null && model.getResolution() != null && !issue.getResolution().equalsIgnoreCase(model.getResolution())) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RESOLUTION_CHANGE); activity.setDescription(ITrackerResources.getString("itracker.web.generic.from") + ": " + issue.getResolution()); activity.setIssue(issue); activity.setUser(user); } if (issue.getStatus() != model.getStatus() && model.getStatus() != -1) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_STATUS_CHANGE); activity.setDescription(IssueUtilities.getStatusName(issue.getStatus()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + IssueUtilities.getStatusName(model.getStatus())); activity.setIssue(issue); activity.setUser(user); } if (issue.getSeverity() != model.getSeverity() && model.getSeverity() != -1) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_SEVERITY_CHANGE); activity.setDescription(IssueUtilities.getSeverityName(issue.getSeverity()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + IssueUtilities.getSeverityName(model.getSeverity())); activity.setIssue(issue); activity.setUser(user); } if (issue.getTargetVersion() != null && model.getTargetVersion() != null && !issue.getTargetVersion().getId().equals(model.getTargetVersionId())) { existingTargetVersion = issue.getTargetVersion().getNumber(); } issue.setModel(model); if (model.getTargetVersion() != null) { VersionBean version = VersionFactory.findByPrimaryKey(model.getTargetVersionId()); issue.setTargetVersion(version); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_TARGETVERSION_CHANGE); String description = existingTargetVersion + " " + ITrackerResources.getString("itracker.web.generic.to") + " "; description += version.getNumber(); activity.setDescription(description); activity.setUser(user); activity.setIssue(issue); } else { issue.setTargetVersion(null); } // save issueFactory.saveOrUpdate(issue); return issue.getModel(); } catch (IssueException ie) { Logger.logInfo("Error while updating new issue: " + ie.getMessage()); } return null; } /** * * Moves an issues from its current project to a new project. * * * * @param issue * * an IssueModel of the issue to move * * @param projectId * * the id of the target project * * @param userId * * the id of the user that is moving the issue * * @return an IssueModel of the issue after it has been moved * * @throws DataException * */ public IssueModel moveIssue(IssueModel model, Integer projectId, Integer userId) throws DataException { if (model == null) { return null; } IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); ProjectBean project = projectFactory.findByPrimaryKey(projectId); UserBean user = userFactory.findByPrimaryKey(userId); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_ISSUE_MOVE); activity.setDescription(model.getProjectName() + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + project.getName()); activity.setUser(user); activity.setIssue(issue); issue.setProject(project); // The versions and components are per project so we need to delete // these setIssueComponents(issue.getId(), new HashSet(), userId); setIssueVersions(issue.getId(), new HashSet(), userId); return issue.getModel(); } public boolean deleteIssue(IssueModel model) throws DataException { if (model != null) { IssueBean issue = issueFactory.findByPrimaryKey(model.getId()); issueFactory.delete(issue); return true; } return false; } /** * this should not exist. adding an history entry should be adding the history entry * to the domain object and saving the object... */ public boolean addIssueHistory(IssueHistoryModel model) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueHistoryBean history = new IssueHistoryBean(); history.setModel(model); history.setIssue(issue); history.setUser(user); history.setCreateDate(new Timestamp(new Date().getTime())); issueFactory.saveOrUpdate(history); return true; } public boolean setIssueFields(Integer issueId, IssueFieldModel[] fields) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection issueFields = issue.getFields(); for (Iterator iter = issueFields.iterator(); iter.hasNext();) { // try { IssueFieldBean field = (IssueFieldBean) iter.next(); // iter.remove(); // field.remove(); // } catch(RemoveException re) { // Logger.logInfo("Unable to remove issue field value. Manual // database cleanup may be necessary."); // } } if (fields.length > 0) { for (int i = 0; i < fields.length; i++) { IssueFieldBean field = new IssueFieldBean(); CustomFieldBean customField = cfHome.findByPrimaryKey(fields[i].getCustomFieldId()); field.setModel(fields[i]); field.setCustomField(customField); field.setIssue(issue); field.setDateValue(new Timestamp(new Date().getTime())); issueFields.add(field); } } return true; } public boolean setIssueComponents(Integer issueId, HashSet componentIds, Integer userId) throws DataException { boolean wasChanged = false; StringBuffer changesBuf = new StringBuffer(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); if (componentIds.isEmpty() && components != null && !components.isEmpty()) { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed")); components.clear(); } else { for (Iterator iterator = components.iterator(); iterator.hasNext();) { ComponentBean component = (ComponentBean) iterator.next(); if (componentIds.contains(component.getId())) { componentIds.remove(component.getId()); } else { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + component.getName() + "; "); iterator.remove(); } } for (Iterator iterator = componentIds.iterator(); iterator.hasNext();) { Integer componentId = (Integer) iterator.next(); ComponentBean component = componentFactory.findByPrimaryKey(componentId); wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + component.getName() + "; "); components.add(component); } } if (wasChanged) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_COMPONENTS_MODIFIED); activity.setDescription(changesBuf.toString()); activity.setIssue(issue); // activity.setUser(); // userId); -> I think we need to set user here } return true; } public boolean setIssueVersions(Integer issueId, HashSet versionIds, Integer userId) throws DataException { boolean wasChanged = false; StringBuffer changesBuf = new StringBuffer(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); if (versionIds.isEmpty() && versions != null && !versions.isEmpty()) { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.all") + " " + ITrackerResources.getString("itracker.web.generic.removed")); versions.clear(); } else { for (Iterator iterator = versions.iterator(); iterator.hasNext();) { VersionBean version = (VersionBean) iterator.next(); if (versionIds.contains(version.getId())) { versionIds.remove(version.getId()); } else { wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.removed") + ": " + version.getNumber() + "; "); iterator.remove(); } } for (Iterator iterator = versionIds.iterator(); iterator.hasNext();) { Integer versionId = (Integer) iterator.next(); VersionBean version = VersionFactory.findByPrimaryKey(versionId); wasChanged = true; changesBuf.append(ITrackerResources.getString("itracker.web.generic.added") + ": " + version.getNumber() + "; "); versions.add(version); } } if (wasChanged) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_VERSIONS_MODIFIED); activity.setDescription(changesBuf.toString()); activity.setIssue(issue); // need to set user here // userId); } return true; } public IssueRelationModel getIssueRelation(Integer relationId) throws DataException { IssueRelationBean issueRelation = issuerelationfactory.findByPrimaryKey(relationId); return issueRelation.getModel(); } public boolean addIssueRelation(Integer issueId, Integer relatedIssueId, int relationType, Integer userId) throws DataException { if (issueId != null && relatedIssueId != null) { int matchingRelationType = IssueUtilities.getMatchingRelationType(relationType); // if(matchingRelationType < 0) { // throw new CreateException("Unable to find matching relation type // for type: " + relationType); // } IssueBean issue = issueFactory.findByPrimaryKey(issueId); IssueBean relatedIssue = issueFactory.findByPrimaryKey(relatedIssueId); IssueRelationBean relationA = new IssueRelationBean(); relationA.setRelationType(relationType); // relationA.setMatchingRelationId(relationBId); relationA.setIssue(issue); relationA.setRelatedIssue(relatedIssue); relationA.setLastModifiedDate(new java.sql.Timestamp(new java.util.Date().getTime())); IssueRelationBean relationB = new IssueRelationBean(); relationB.setRelationType(matchingRelationType); // relationB.setMatchingRelationId(relationAId); relationB.setIssue(relatedIssue); relationB.setRelatedIssue(issue); relationB.setLastModifiedDate(new java.sql.Timestamp(new java.util.Date().getTime())); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_ADDED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.add")); // probably add this to description // new Object[] {IssueUtilities.getRelationName(relationType), // relatedIssueId }; activity.setIssue(issue); // need to set user here... userId); // need to save here activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_ADDED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.add", new Object[] { IssueUtilities.getRelationName(matchingRelationType) })); activity.setIssue(relatedIssue); // net to save and set user here.. userId); return true; } return false; } public Integer removeIssueRelation(Integer relationId, Integer userId) { Integer issueId = new Integer(-1); try { IssueRelationBean issueRelation = issuerelationfactory.findByPrimaryKey(relationId); issueId = issueRelation.getIssue().getId(); Integer relatedIssueId = issueRelation.getRelatedIssue().getId(); Integer matchingRelationId = issueRelation.getMatchingRelationId(); if (matchingRelationId != null) { IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_REMOVED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.removed", issueId .toString())); // need to fix the commented code and save // activity.setIssue(relatedIssueId); // activity.setUser(userId); // IssueRelationFactory.remove(matchingRelationId); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_RELATION_REMOVED); activity.setDescription(ITrackerResources.getString("itracker.activity.relation.removed", relatedIssueId .toString())); // activity.setIssue(issueId); // activity.setUser(userId); // irHome.remove(relationId); // need to save } catch (Exception e) { Logger.logDebug("Exception while removing issue relation.", e); } return issueId; } public boolean assignIssue(Integer issueId, Integer userId) throws DataException { return assignIssue(issueId, userId, userId); } public boolean assignIssue(Integer issueId, Integer userId, Integer assignedByUserId) throws DataException { if (userId.intValue() == -1) { return unassignIssue(issueId, assignedByUserId); } UserBean assignedByUser; IssueBean issue = issueFactory.findByPrimaryKey(issueId); UserBean user = userFactory.findByPrimaryKey(userId); if (assignedByUserId.equals(userId)) { assignedByUser = user; } else { assignedByUser = userFactory.findByPrimaryKey(assignedByUserId); } UserBean currOwner = issue.getOwner(); if (currOwner == null || !currOwner.getId().equals(user.getId())) { if (currOwner != null && !hasIssueNotification(issueId, currOwner.getId(), NotificationUtilities.ROLE_CONTRIBUTER)) { NotificationBean notification = new NotificationBean(); NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER); notification.setModel(model); notification.setIssue(issue); notification.setUser(currOwner); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_OWNER_CHANGE); activity.setDescription((currOwner == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : currOwner.getLogin()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " " + user.getLogin()); activity.setUser(assignedByUser); activity.setIssue(issue); issue.setOwner(user); if (issue.getStatus() < IssueUtilities.STATUS_ASSIGNED) { issue.setStatus(IssueUtilities.STATUS_ASSIGNED); } } return true; } public boolean unassignIssue(Integer issueId, Integer assignedByUserId) throws DataException { UserBean assignedByUser = userFactory.findByPrimaryKey(assignedByUserId); IssueBean issue = issueFactory.findByPrimaryKey(issueId); if (issue.getOwner() != null) { if (!hasIssueNotification(issueId, issue.getOwner().getId(), NotificationUtilities.ROLE_CONTRIBUTER)) { NotificationBean notification = new NotificationBean(); NotificationModel model = new NotificationModel(NotificationUtilities.ROLE_CONTRIBUTER); notification.setModel(model); notification.setIssue(issue); notification.setUser(issue.getOwner()); } IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_OWNER_CHANGE); activity.setDescription((issue.getOwner() == null ? "[" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]" : issue.getOwner() .getLogin()) + " " + ITrackerResources.getString("itracker.web.generic.to") + " [" + ITrackerResources.getString("itracker.web.generic.unassigned") + "]"); activity.setUser(assignedByUser); activity.setIssue(issue); issue.setOwner(null); if (issue.getStatus() >= IssueUtilities.STATUS_ASSIGNED) { issue.setStatus(IssueUtilities.STATUS_UNASSIGNED); } } return true; } /* * public boolean addIssueActivity(IssueActivityModel model) throws * DataException { * * IssueBean issue = ifHome.findByPrimaryKey(model.getIssueId()); * * UserBean user = ufHome.findByPrimaryKey(model.getUserId()); * * //return addIssueActivity(model, issue, user); return * addIssueActivity(null, issue, user); } */ /* * public boolean addIssueActivity(IssueActivityModel model, IssueBean * issue) throws DataException { * * UserBean user = ufHome.findByPrimaryKey(model.getUserId()); * * return true;//addIssueActivity(model, issue, user); } */ /** * I think this entire method is useless - RJST * * @param model * @param issue * @param user * @return */ /* * public boolean addIssueActivity(IssueActivityBean model, IssueBean issue, * UserBean user) { * * IssueActivityBean activity = new IssueActivityBean(); * * //activity.setModel(model); * * activity.setIssue(issue); * * activity.setUser(user); * * return true; } */ public void updateIssueActivityNotification(Integer issueId, boolean notificationSent) { if (issueId == null) { return; } Collection activity = issueActivityFactory.findByIssueId(issueId); for (Iterator iter = activity.iterator(); iter.hasNext();) { ((IssueActivityBean) iter.next()).setNotificationSent((notificationSent ? 1 : 0)); } } public boolean addIssueAttachment(IssueAttachmentModel model, byte[] data) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueAttachmentBean attachment = new IssueAttachmentBean(); model.setFileName("attachment" + attachment.getId()); attachment.setModel(model); attachment.setFileData((data == null ? new byte[0] : data)); attachment.setIssue(issue); attachment.setUser(user); return true; } public boolean setIssueAttachmentData(Integer attachmentId, byte[] data) { if (attachmentId != null && data != null) { IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); attachment.setFileData(data); return true; } return false; } public boolean setIssueAttachmentData(String fileName, byte[] data) { if (fileName != null && data != null) { IssueAttachmentBean attachment = IssueAttachmentFactory.findByFileName(fileName); attachment.setFileData(data); return true; } return false; } public boolean removeIssueAttachment(Integer attachmentId) { IssueAttachmentFactory.remove(attachmentId); return true; } public Integer removeIssueHistoryEntry(Integer entryId, Integer userId) throws DataException { IssueHistoryBean history = ihfHome.findByPrimaryKey(entryId); if (history != null) { history.setStatus(IssueUtilities.HISTORY_STATUS_REMOVED); history.setLastModifiedDate(new Timestamp(new Date().getTime())); IssueActivityBean activity = new IssueActivityBean(); activity.setType(IssueUtilities.ACTIVITY_REMOVE_HISTORY); activity.setDescription(ITrackerResources.getString("itracker.web.generic.entry") + " " + entryId + " " + ITrackerResources.getString("itracker.web.generic.removed") + "."); // need to fix this - RJST // activity.setIssue(history.getIssue().getId()); // activity.setUser(userId); return history.getIssue().getId(); } return new Integer(-1); } public ProjectModel getIssueProject(Integer issueId) throws DataException { IssueBean issue = issueFactory.findByPrimaryKey(issueId); ProjectBean project = issue.getProject(); return (project != null ? project.getModel() : null); } public HashSet getIssueComponentIds(Integer issueId) throws DataException { HashSet componentIds = new HashSet(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection components = issue.getComponents(); for (Iterator iterator = components.iterator(); iterator.hasNext();) { componentIds.add(((ComponentBean) iterator.next()).getId()); } return componentIds; } public HashSet getIssueVersionIds(Integer issueId) throws DataException { HashSet versionIds = new HashSet(); IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection versions = issue.getVersions(); for (Iterator iterator = versions.iterator(); iterator.hasNext();) { versionIds.add(((VersionBean) iterator.next()).getId()); } return versionIds; } public IssueActivityBean[] getIssueActivity(Integer issueId) { int i = 0; IssueActivityBean[] activityArray = new IssueActivityBean[0]; Collection activity = issueActivityFactory.findByIssueId(issueId); activityArray = new IssueActivityBean[activity.size()]; for (Iterator iterator = activity.iterator(); iterator.hasNext(); i++) { activityArray[i] = ((IssueActivityBean) iterator.next());// .getModel(); } return activityArray; } public IssueActivityBean[] getIssueActivity(Integer issueId, boolean notificationSent) { int i = 0; IssueActivityBean[] activityArray = new IssueActivityBean[0]; Collection activity = issueActivityFactory.findByIssueIdAndNotification(issueId, (notificationSent ? 1 : 0)); activityArray = new IssueActivityBean[activity.size()]; for (Iterator iterator = activity.iterator(); iterator.hasNext(); i++) { activityArray[i] = ((IssueActivityBean) iterator.next());// .getModel(); } return activityArray; } public IssueAttachmentModel[] getAllIssueAttachments() { int i = 0; IssueAttachmentModel[] attachmentArray = new IssueAttachmentModel[0]; Collection attachments = IssueAttachmentFactory.findAll(); attachmentArray = new IssueAttachmentModel[attachments.size()]; for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { attachmentArray[i] = ((IssueAttachmentBean) iterator.next()).getModel(); } return attachmentArray; } public long[] getAllIssueAttachmentsSizeAndCount() { long[] sizeAndCount = new long[2]; int i = 0; Collection attachments = IssueAttachmentFactory.findAll(); sizeAndCount[1] = attachments.size(); for (Iterator iterator = attachments.iterator(); iterator.hasNext(); i++) { sizeAndCount[0] += ((IssueAttachmentBean) iterator.next()).getSize(); } return sizeAndCount; } public IssueAttachmentModel getIssueAttachment(Integer attachmentId) { IssueAttachmentModel attachmentModel = null; IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); attachmentModel = attachment.getModel(); return attachmentModel; } public byte[] getIssueAttachmentData(Integer attachmentId) { byte[] data = new byte[0]; IssueAttachmentBean attachment = IssueAttachmentFactory.findByPrimaryKey(attachmentId); data = attachment.getFileData(); return data; } public int getIssueAttachmentCount(Integer issueId) throws DataException { int i = 0; IssueBean issue = issueFactory.findByPrimaryKey(issueId); Collection attachments = issue.getAttachments(); i = attachments.size(); return i; } /** * * Returns the latest issue history entry for a particular issue. * * * * @param issueId * * the id of the issue to return the history entry for. * * @return the latest IssueHistoryModel, or null if no entries could be * * found * * @throws DataException * */ public IssueHistoryModel getLastIssueHistory(Integer issueId) throws DataException { IssueHistoryModel model = null; IssueHistoryBean lastEntry = null; Collection history = ihfHome.findByIssueId(issueId); Iterator iterator = history.iterator(); while (iterator.hasNext()) { IssueHistoryBean nextEntry = (IssueHistoryBean) iterator.next(); if (nextEntry != null) { if (lastEntry == null && nextEntry.getLastModifiedDate() != null) { lastEntry = nextEntry; } else if (nextEntry.getLastModifiedDate() != null && nextEntry.getLastModifiedDate().equals(lastEntry.getLastModifiedDate()) && nextEntry.getId().compareTo(lastEntry.getId()) > 0) { lastEntry = nextEntry; } else if (nextEntry.getLastModifiedDate() != null && nextEntry.getLastModifiedDate().after(lastEntry.getLastModifiedDate())) { lastEntry = nextEntry; } } } if (lastEntry != null) { model = lastEntry.getModel(); } return model; } /** * * Retrieves the primary issue notifications. Primary notifications are * * defined as the issue owner (or creator if not assigned), and any project * * owners. This should encompass the list of people that should be notified * * so that action can be taken on an issue that needs immediate attention. * * * * @param issueId * * the id of the issue to find notifications for * * @throws DataException * * @returns an array of NotificationModels * */ public NotificationModel[] getPrimaryIssueNotifications(Integer issueId) throws DataException { return getIssueNotifications(issueId, true, false); } /** * * Retrieves all notifications for an issue where the notification's user is * * also active. * * * * @param issueId * * the id of the issue to find notifications for * * @throws DataException * * @returns an array of NotificationModels * */ public NotificationModel[] getIssueNotifications(Integer issueId) throws DataException { return getIssueNotifications(issueId, false, true); } /** * * Retrieves an array of issue notifications. The notifications by default * * is the creator and owner of the issue, all project admins for the issue's * * project, and anyone else that has a notfication on file. * * * * @param issueId * * the id of the issue to find notifications for * * @param pimaryOnly * * only include the primary notifications * * @param activeOnly * * only include the notification if the user is currently active * * (not locked or deleted) * * @throws DataException * * @returns an array of NotificationModels * * @see IssueHandlerBean#getPrimaryIssueNotifications * */ public NotificationModel[] getIssueNotifications(Integer issueId, boolean primaryOnly, boolean activeOnly) throws DataException { NotificationModel[] notificationArray = new NotificationModel[0]; Vector notificationVector = new Vector(); IssueBean issue = null; if (!primaryOnly) { Collection notifications = notificationFactory.findByIssueId(issueId); for (Iterator iterator = notifications.iterator(); iterator.hasNext();) { NotificationBean notification = (NotificationBean) iterator.next(); UserBean notificationUser = notification.getUser(); if (!activeOnly || notificationUser.getStatus() == UserUtilities.STATUS_ACTIVE) { notificationVector.add(notification.getModel()); } } } // Now add in other notifications like owner, creator, project owners, // etc... boolean hasOwner = false; issue = issueFactory.findByPrimaryKey(issueId); if (issue.getOwner() != null) { UserModel ownerModel = issue.getOwner().getModel(); if (ownerModel != null && (!activeOnly || ownerModel.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector.add(new NotificationModel(ownerModel, issueId, NotificationUtilities.ROLE_OWNER)); hasOwner = true; } } if (!primaryOnly || !hasOwner) { UserModel creatorModel = issue.getCreator().getModel(); if (creatorModel != null && (!activeOnly || creatorModel.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector .add(new NotificationModel(creatorModel, issueId, NotificationUtilities.ROLE_CREATOR)); } } if (issue != null) { ProjectBean project = projectFactory.findByPrimaryKey(issue.getProject().getId()); Collection projectOwners = project.getOwners(); for (Iterator iterator = projectOwners.iterator(); iterator.hasNext();) { UserBean projectOwner = (UserBean) iterator.next(); if (projectOwner != null && (!activeOnly || projectOwner.getStatus() == UserUtilities.STATUS_ACTIVE)) { notificationVector.add(new NotificationModel(projectOwner.getModel(), issueId, NotificationUtilities.ROLE_PO)); } } } notificationArray = new NotificationModel[notificationVector.size()]; notificationVector.copyInto(notificationArray); return notificationArray; } public boolean addIssueNotification(NotificationModel model) throws DataException { if (model != null) { UserBean user = userFactory.findByPrimaryKey(model.getUserId()); IssueBean issue = issueFactory.findByPrimaryKey(model.getIssueId()); NotificationBean notification = new NotificationBean(); notification.setModel(model); notification.setIssue(issue); notification.setUser(user); return true; } return false; } public boolean hasIssueNotification(Integer issueId, Integer userId) throws DataException { return hasIssueNotification(issueId, userId, NotificationUtilities.ROLE_ANY); } public boolean hasIssueNotification(Integer issueId, Integer userId, int role) throws DataException { if (issueId != null && userId != null) { NotificationModel[] notifications = getIssueNotifications(issueId, false, false); for (int i = 0; i < notifications.length; i++) { if (role == NotificationUtilities.ROLE_ANY || notifications[i].getNotificationRole() == role) { if (notifications[i].getUserId().equals(userId)) { return true; } } } } return false; } public int getOpenIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectIdAndLowerStatus(projectId, IssueUtilities.STATUS_RESOLVED); return issues.size(); } public int getResolvedIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectIdAndHigherStatus(projectId, IssueUtilities.STATUS_RESOLVED); return issues.size(); } public int getTotalIssueCountByProjectId(Integer projectId) { Collection issues = issueFactory.findByProjectId(projectId); return issues.size(); } public Date getLatestIssueDateByProjectId(Integer projectId) { return issueFactory.latestModificationDate(projectId); } public void sendNotification(Integer issueId, int type, String baseURL) { sendNotification(issueId, type, baseURL, null, null); } public void sendNotification(Integer issueId, int type, String baseURL, HashSet addresses, Integer lastModifiedDays) { // notifications are disabled for now /* * try { * * QueueConnectionFactory factory = (QueueConnectionFactory) * ic.lookup("java:comp/env/" + notificationFactoryName); * * Queue notificationQueue = (Queue) ic.lookup("java:comp/env/" + * notificationQueueName); QueueConnection connect = * factory.createQueueConnection(); QueueSession session = * connect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); * QueueSender sender = session.createSender(notificationQueue); * MapMessage message = session.createMapMessage(); * message.setInt("issueId", issueId.intValue()); message.setInt("type", * type); message.setObject("lastModifiedDays", (lastModifiedDays == * null ? new Integer(-1) : lastModifiedDays)); * * if (systemBaseURL != null && !systemBaseURL.equals("")) { * * message.setString("baseURL", systemBaseURL); } else if (baseURL != * null) { * * message.setString("baseURL", baseURL); } * * if (addresses != null) { * * try { * * ByteArrayOutputStream baos = new ByteArrayOutputStream(); * * ObjectOutputStream oos = new ObjectOutputStream(baos); * * oos.writeObject(addresses); * * message.setObject("addresses", baos.toByteArray()); } catch * (Exception e) { * * Logger.logDebug("Unable to write address list for notification: " + * e.getMessage()); } } * * sender.send(message); } catch (NamingException ne) { * * Logger.logError("Error looking up ConnectionFactory/Queue " + * notificationFactoryName + "/" + notificationQueueName + ".", ne); } * catch (JMSException jmse) { * * Logger.logWarn("Error sending notification message", jmse); } */ } public boolean canViewIssue(Integer issueId, UserModel user) throws DataException { IssueModel issue = getIssue(issueId); HashMap permissions = userFactory.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB); return IssueUtilities.canViewIssue(issue, user.getId(), permissions); } public boolean canViewIssue(IssueModel issue, UserModel user) { HashMap permissions = userFactory.getUserPermissions(user, AuthenticationConstants.REQ_SOURCE_WEB); return IssueUtilities.canViewIssue(issue, user.getId(), permissions); } public UserFactory getUserFactory() { return userFactory; } public void setUserFactory(UserFactory userFactory) { this.userFactory = userFactory; } public IssueFactory getIssueFactory() { return issueFactory; } public void setIssueFactory(IssueFactory ifHome) { this.issueFactory = ifHome; } public NotificationFactory getNotificationFactory() { return notificationFactory; } public void setNotificationFactory(NotificationFactory nfHome) { this.notificationFactory = nfHome; } public ProjectFactory getProjectFactory() { return projectFactory; } public void setProjectFactory(ProjectFactory projectFactory) { this.projectFactory = projectFactory; } public IssueActivityFactory getIssueActivityFactory() { return issueActivityFactory; } public void setIssueActivityFactory(IssueActivityFactory issueActivityFactory) { this.issueActivityFactory = issueActivityFactory; } } \ No newline at end of file --- 1 ---- ! /* * This software was designed and created by Jason Carroll. * Copyright (c) 2002, 2003, 2004 Jason Carroll. * The author can be reached at jca...@co... * ITracker website: http://www.cowsultants.com * ITracker forums: http://www.cowsultants.com/phpBB/index.php * * This program is free software; you can redistribute it and/or modify * it only under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ package cowsultants.itracker.ejb.beans.session; import java.sql.Timestamp; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Vector; import cowsultants.itracker.ejb.beans.entity.ComponentBean; import cowsultants.itracker.ejb.beans.entity.CustomFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueActivityBean; import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; import cowsultants.itracker.ejb.beans.entity.IssueBean; import cowsultants.itracker.ejb.beans.entity.IssueFieldBean; import cowsultants.itracker.ejb.beans.entity.IssueHistoryBean; import cowsultants.itracker.ejb.beans.entity.IssueRelationBean; import cowsultants.itracker.ejb.beans.entity.NotificationBean; import cowsultants.itracker.ejb.beans.entity.ProjectBean; import cowsultants.itracker.ejb.beans.entity.UserBean; import cowsultants.itracker.ejb.beans.entity.VersionBean; import cowsultants.itracker.ejb.beans.message.NotificationMessageBean; import cowsultants.itracker.ejb.client.exceptions.IssueException; import cowsultants.itracker.ejb.client.interfaces.IssueHandler; import cowsultants.itracker.ejb.client.models.ComponentModel; import cowsultants.itracker.ejb.client.models.IssueAttachmentModel; import cowsultants.itracker.ejb.client.models.IssueFieldModel; import cowsultants.itracker.ejb.client.models.IssueHistoryModel; import cowsultants.itracker.ejb.client.models.IssueModel; import cowsultants.itracker.ejb.client.models.IssueRelationModel; import cowsultants.itracker.ejb.client.models.NotificationModel; import cowsultants.itracker.ejb.client.models.ProjectModel; import cowsultants.itracker.ejb.client.models.UserModel; import cowsultants.itracker.ejb.client.models.VersionModel; import cowsultants.itracker.ejb.client.resources.ITrackerResources; import cowsultants.itracker.ejb.client.util.AuthenticationConstants; import cowsultants.itracker.ejb.client.util.IssueUti... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-03 20:10:30
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9028 Modified Files: Tag: itrackerhibernate VersionFactory.java Added Files: Tag: itrackerhibernate VersionFactoryImpl.java Log Message: VersionFactory is an interface now which is implemented by VersionFactoryImpl --- NEW FILE: VersionFactoryImpl.java --- /* * VersionFactoryImpl.java */ package cowsultants.itracker.ejb.beans.session; import cowsultants.itracker.ejb.beans.entity.ComponentBean; import cowsultants.itracker.ejb.beans.entity.ProjectBean; import cowsultants.itracker.ejb.beans.entity.VersionBean; import java.util.Collection; import net.sf.hibernate.HibernateException; import net.sf.hibernate.expression.Expression; /** * Hibernate implementation of <code>VersionFactory</code> interface */ public class VersionFactoryImpl extends BaseHibernateFactoryImpl implements VersionFactory { /** * find <code>VersionBean</code> by id * * @param targetVersionId id of the <code>VersionBean</code> to find * @return <code>VersionBean</code> found */ public VersionBean findByPrimaryKey(Integer versionId) { try { return (VersionBean) (getSession().load(VersionBean.class, versionId)); } catch (HibernateException e) { throw new DataException(e); } } /** * Finds <code>VersionBean</code>s by a project id and returns them as * a <code>Collection</code>. * * @param projectId id of the parent <code>ProjectBean</code> * @return a <code>Collection</code> containing the <code>VersionBean</code>s found */ public Collection findByProjectId(Integer projectId) { try { ProjectBean project = (ProjectBean) getSession().load(ProjectBean.class,projectId); return (getSession().createCriteria(ComponentBean.class). add(Expression.eq("project", project)).list()); } catch (HibernateException e) { throw new DataException(e); } } } Index: VersionFactory.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/VersionFactory.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** VersionFactory.java 11 Oct 2005 01:36:08 -0000 1.1.2.1 --- VersionFactory.java 3 Nov 2005 20:10:17 -0000 1.1.2.2 *************** *** 5,19 **** import cowsultants.itracker.ejb.beans.entity.VersionBean; ! public class VersionFactory { ! public static VersionBean findByPrimaryKey(Integer targetVersionId) { ! // TODO Auto-generated method stub ! return null; ! } ! public Collection findByProjectId(Integer projectId) { ! // TODO Auto-generated method stub ! return null; ! } } --- 5,13 ---- import cowsultants.itracker.ejb.beans.entity.VersionBean; ! public interface VersionFactory extends BaseFactory { ! public VersionBean findByPrimaryKey(Integer targetVersionId) ; ! public Collection findByProjectId(Integer projectId) ; } |
From: Marc B. <mb...@us...> - 2005-11-03 20:09:02
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/entity In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8378 Modified Files: Tag: itrackerhibernate VersionBean.java Log Message: initialize Collection to avoid NullPointer Index: VersionBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/entity/VersionBean.java,v retrieving revision 1.7.4.1 retrieving revision 1.7.4.2 diff -C2 -d -r1.7.4.1 -r1.7.4.2 *** VersionBean.java 11 Oct 2005 01:21:04 -0000 1.7.4.1 --- VersionBean.java 3 Nov 2005 20:08:52 -0000 1.7.4.2 *************** *** 20,23 **** --- 20,24 ---- import java.sql.Timestamp; + import java.util.ArrayList; import java.util.Collection; import java.util.Date; *************** *** 37,41 **** private ProjectBean project; ! private Collection issues; public String getDescription() { --- 38,42 ---- private ProjectBean project; ! private Collection issues = new ArrayList(); public String getDescription() { |