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-19 15:39:31
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21730 Modified Files: Tag: itrackerhibernate ScheduledTaskFactoryImpl.java Log Message: implement findByPrimaryKey add some comments Index: ScheduledTaskFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/ScheduledTaskFactoryImpl.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 *** ScheduledTaskFactoryImpl.java 11 Oct 2005 01:36:08 -0000 1.1.2.1 --- ScheduledTaskFactoryImpl.java 19 Nov 2005 15:39:23 -0000 1.1.2.2 *************** *** 5,8 **** --- 5,9 ---- import net.sf.hibernate.Criteria; import net.sf.hibernate.HibernateException; + import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.orm.hibernate.support.HibernateDaoSupport; *************** *** 12,20 **** public class ScheduledTaskFactoryImpl extends HibernateDaoSupport implements ScheduledTaskFactory { public ScheduledTaskBean findByPrimaryKey(Integer id) { ! // TODO Auto-generated method stub ! return null; } public Collection findAll() throws DataException { Criteria criteria = getSession().createCriteria(ScheduledTaskBean.class); --- 13,40 ---- public class ScheduledTaskFactoryImpl extends HibernateDaoSupport implements ScheduledTaskFactory { + /** + * Finds a <code>ScheduledTaskBean</code> by its id + * + * @param id the id of the <code>ScheduledTaskBean</code> + * @return a <code>ScheduledTaskBean</code> + */ public ScheduledTaskBean findByPrimaryKey(Integer id) { ! try { ! return (ScheduledTaskBean) this.getSession().load(ScheduledTaskBean.class, id); ! } catch (DataAccessResourceFailureException ex) { ! throw new DataException( ex ); ! } catch (HibernateException ex) { ! throw new DataException( ex ); ! } catch (IllegalStateException ex) { ! throw new DataException( ex ); ! } } + /** + * Finds all <code>ScheduledTaskBean</code> + * + * @returns a <code>Collection</code> of <code>ScheduledTaskBean</code>s + * @throws A <code>DataException</code> if searchg fails for any reason + */ public Collection findAll() throws DataException { Criteria criteria = getSession().createCriteria(ScheduledTaskBean.class); *************** *** 25,28 **** } } - } --- 45,47 ---- |
From: Marc B. <mb...@us...> - 2005-11-19 14:06:47
|
Update of /cvsroot/itracker/itracker/web/WEB-INF In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4036/web/WEB-INF Modified Files: Tag: itrackerhibernate applicationContext.xml Log Message: add bean elements for issueAttachmentFactoryTarget and issueAttachmentFactory Index: applicationContext.xml =================================================================== RCS file: /cvsroot/itracker/itracker/web/WEB-INF/Attic/applicationContext.xml,v retrieving revision 1.1.2.12 retrieving revision 1.1.2.13 diff -C2 -d -r1.1.2.12 -r1.1.2.13 *** applicationContext.xml 7 Nov 2005 23:04:22 -0000 1.1.2.12 --- applicationContext.xml 19 Nov 2005 14:06:39 -0000 1.1.2.13 *************** *** 137,140 **** --- 137,147 ---- <constructor-arg ref="issueFactory"/> </bean> + + <!-- The workflow script factory --> + <bean id="issueAttachmentFactoryTarget" class="cowsultants.itracker.ejb.beans.session.IssueAttachmentFactoryImpl"> + <property name="sessionFactory"> + <ref bean="sessionFactory"/> + </property> + </bean> <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> *************** *** 458,461 **** --- 465,488 ---- </bean> + <!-- A proxy to the entity factory, after the Hibernate interceptor is applied --> + <!-- Application code uses this object --> + <bean id="issueAttachmentFactory" 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="issueAttachmentFactoryTarget"/> + <property name="proxyInterfaces"> + <value>cowsultants.itracker.ejb.beans.session.IssueAttachmentFactory</value> + </property> + <property name="postInterceptors"> + <list> + <ref bean="myHibernateInterceptor"/> + </list> + </property> + </bean> + <!-- A proxy to the workflow script factory, after the Hibernate interceptor is applied --> <!-- Application code uses this object --> |
From: Marc B. <mb...@us...> - 2005-11-19 14:04:05
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3290 Modified Files: Tag: itrackerhibernate CreateIssueAction.java EditIssueAction.java Log Message: adjust to new method interface of AttachmentUtilities. As new parameter the itrackerServices are passed to the utilities as an temporary solution Index: CreateIssueAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/CreateIssueAction.java,v retrieving revision 1.15.4.6 retrieving revision 1.15.4.7 diff -C2 -d -r1.15.4.6 -r1.15.4.7 *** CreateIssueAction.java 29 Oct 2005 16:55:22 -0000 1.15.4.6 --- CreateIssueAction.java 19 Nov 2005 14:03:54 -0000 1.15.4.7 *************** *** 175,179 **** if(file != null && ! "".equals(file.getFileName())) { String origFileName = file.getFileName(); ! if(AttachmentUtilities.checkFile(file)) { int lastSlash = Math.max(origFileName.lastIndexOf('/'), origFileName.lastIndexOf('\\')); if(lastSlash > -1) { --- 175,179 ---- if(file != null && ! "".equals(file.getFileName())) { String origFileName = file.getFileName(); ! if(AttachmentUtilities.checkFile(file, this.getITrackerServices())) { int lastSlash = Math.max(origFileName.lastIndexOf('/'), origFileName.lastIndexOf('\\')); if(lastSlash > -1) { Index: EditIssueAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditIssueAction.java,v retrieving revision 1.21.4.5 retrieving revision 1.21.4.6 diff -C2 -d -r1.21.4.5 -r1.21.4.6 *** EditIssueAction.java 29 Oct 2005 00:26:52 -0000 1.21.4.5 --- EditIssueAction.java 19 Nov 2005 14:03:54 -0000 1.21.4.6 *************** *** 292,296 **** // int numAttachments = ih.getIssueAttachmentCount(issue.getId()) + 1; // String filename = "proj" + project.getId() + "_issue" + issue.getId() + "_attachment" + numAttachments; ! if(AttachmentUtilities.checkFile(file)) { int lastSlash = Math.max(origFileName.lastIndexOf('/'), origFileName.lastIndexOf('\\')); if(lastSlash > -1) { --- 292,296 ---- // int numAttachments = ih.getIssueAttachmentCount(issue.getId()) + 1; // String filename = "proj" + project.getId() + "_issue" + issue.getId() + "_attachment" + numAttachments; ! if(AttachmentUtilities.checkFile(file, this.getITrackerServices())) { int lastSlash = Math.max(origFileName.lastIndexOf('/'), origFileName.lastIndexOf('\\')); if(lastSlash > -1) { |
From: Marc B. <mb...@us...> - 2005-11-19 14:02:37
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2857 Modified Files: Tag: itrackerhibernate AttachmentUtilities.java Log Message: remove usage of static static methods on IssueAttachmentFactory with an intermediadte solution. Maybe the method checkfile should be moved to another class with access to itrackerServices Index: AttachmentUtilities.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/util/AttachmentUtilities.java,v retrieving revision 1.10.4.3 retrieving revision 1.10.4.4 diff -C2 -d -r1.10.4.3 -r1.10.4.4 *** AttachmentUtilities.java 26 Oct 2005 00:01:15 -0000 1.10.4.3 --- AttachmentUtilities.java 19 Nov 2005 14:02:26 -0000 1.10.4.4 *************** *** 18,21 **** --- 18,22 ---- package cowsultants.itracker.web.util; + import cowsultants.itracker.ejb.beans.session.ITrackerServices; import cowsultants.itracker.ejb.beans.session.IssueHandlerBean; *************** *** 37,43 **** private static long spaceLeft = 0; ! public static boolean checkFile(FormFile file) { if(! initialized) { ! if(! init()) { return false; } --- 38,44 ---- private static long spaceLeft = 0; ! public static boolean checkFile(FormFile file, ITrackerServices services) { if(! initialized) { ! if(! init(services)) { return false; } *************** *** 72,80 **** } ! private static boolean init() { if(! initialized) { try { ! SystemConfiguration sc = new SystemConfigurationBean(); ! IssueHandler ih = new IssueHandlerBean(); maxFileSize = sc.getLongProperty("max_attachment_size", MAX_FILE_SIZE_KB) * 1024L; --- 73,81 ---- } ! private static boolean init(ITrackerServices services) { if(! initialized) { try { ! SystemConfiguration sc = services.getSystemConfiguration(); ! IssueHandler ih = services.getIssueHandler(); maxFileSize = sc.getLongProperty("max_attachment_size", MAX_FILE_SIZE_KB) * 1024L; |
From: Marc B. <mb...@us...> - 2005-11-19 14:00:35
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2200 Modified Files: Tag: itrackerhibernate IssueHandlerBean.java Log Message: change from static mehtod calls of IssueAttachmentFactory to member variable Index: IssueHandlerBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/IssueHandlerBean.java,v retrieving revision 1.57.4.8 retrieving revision 1.57.4.9 diff -C2 -d -r1.57.4.8 -r1.57.4.9 *** IssueHandlerBean.java 9 Nov 2005 20:23:50 -0000 1.57.4.8 --- IssueHandlerBean.java 19 Nov 2005 14:00:22 -0000 1.57.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.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 customFieldFactory; private UserFactory userFactory; private ProjectFactory projectFactory; private IssueFactory issueFactory; private IssueHistoryFactory issueHistoryFactory; private NotificationFactory notificationFactory; private IssueRelationFactory issueRelationFactory; private ComponentFactory componentFactory; private IssueActivityFactory issueActivityFactory; private VersionFactory versionFactory; 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 = customFieldFactory.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 = issueHistoryFactory.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 = issueHistoryFactory.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; } public CustomFieldFactory getCustomFieldFactory() { return customFieldFactory; } public void setCustomFieldFactory(CustomFieldFactory customFieldFactory) { this.customFieldFactory = customFieldFactory; } public IssueHistoryFactory getIssueHistoryFactory() { return issueHistoryFactory; } public void setIssueHistoryFactory(IssueHistoryFactory issueHistoryFactory) { this.issueHistoryFactory = issueHistoryFactory; } public IssueRelationFactory getIssueRelationFactory() { return issueRelationFactory; } public void setIssueRelationFactory(IssueRelationFactory issueRelationFactory) { this.issueRelationFactory = issueRelationFactory; } } \ 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.... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-19 13:58:59
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1776 Added Files: Tag: itrackerhibernate IssueAttachmentFactoryImpl.java Log Message: add IssueAttachementFactory implementind IssueAttachmentFactory interface --- NEW FILE: IssueAttachmentFactoryImpl.java --- /* * IssueAttachmentFactoryImpl.java * * Created on 16. November 2005, 19:31 * * 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.IssueAttachmentBean; import java.util.Collection; import net.sf.hibernate.HibernateException; import net.sf.hibernate.expression.Expression; /** * * @author mbae */ public class IssueAttachmentFactoryImpl extends BaseHibernateFactoryImpl implements IssueAttachmentFactory { public IssueAttachmentBean findByPrimaryKey(Integer attachmentId) { try { return (IssueAttachmentBean) (getSession().load(IssueAttachmentBean.class, attachmentId)); } catch (HibernateException e) { throw new DataException(e); } } public IssueAttachmentBean findByFileName(String fileName) { try { return ((IssueAttachmentBean) getSession() .createCriteria(IssueAttachmentBean.class) .add(Expression.eq("fileName", fileName)).uniqueResult()); } catch (HibernateException e) { throw new DataException(e); } } public Collection findAll() { try { return getSession().createCriteria(IssueAttachmentBean.class).list(); } catch (HibernateException e) { throw new DataException(e); } } } |
From: Marc B. <mb...@us...> - 2005-11-19 13:58:08
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1617 Modified Files: Tag: itrackerhibernate IssueAttachmentFactory.java Log Message: make IssueAttachementFactory an interface extending the BaseFactory interface Index: IssueAttachmentFactory.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/IssueAttachmentFactory.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 *** IssueAttachmentFactory.java 11 Oct 2005 01:36:08 -0000 1.1.2.1 --- IssueAttachmentFactory.java 19 Nov 2005 13:57:53 -0000 1.1.2.2 *************** *** 6,29 **** import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; ! public class IssueAttachmentFactory { ! ! public static IssueAttachmentBean findByPrimaryKey(Integer attachmentId) { ! // TODO Auto-generated method stub ! return null; ! } ! ! public static IssueAttachmentBean findByFileName(String fileName) { ! // TODO Auto-generated method stub ! return null; ! } ! public static void remove(Integer attachmentId) { ! // TODO Auto-generated method stub ! ! } ! public static Collection findAll() { ! return new LinkedList(); ! } } --- 6,15 ---- import cowsultants.itracker.ejb.beans.entity.IssueAttachmentBean; ! public interface IssueAttachmentFactory extends BaseFactory { ! public IssueAttachmentBean findByPrimaryKey(Integer attachmentId) ; ! public IssueAttachmentBean findByFileName(String fileName); + public Collection findAll(); } |
From: Marc B. <mb...@us...> - 2005-11-19 13:55:55
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1243 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - set mandatory version attribute while creting a new configuration item Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.13 retrieving revision 1.31.4.14 diff -C2 -d -r1.31.4.13 -r1.31.4.14 *** SystemConfigurationBean.java 14 Nov 2005 22:03:18 -0000 1.31.4.13 --- SystemConfigurationBean.java 19 Nov 2005 13:55:38 -0000 1.31.4.14 *************** *** 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a workflow script. * * @param model The <code>WorkflowScriptModel</code> carring the data * @return The <code>WorkflowScriptModel</code> after inserting */ public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // create workflow script and populate data WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); workflowScript.setCreateDate( new Timestamp( System.currentTimeMillis())); // save entity this.workflowScriptFactory.saveOrUpdate( workflowScript ); model.setId(workflowScript.getId()); return workflowScript.getModel(); } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } /** * remove a workflow script by its id * * @todo get all ProjectScriptBeans with that script attached and delete the ProjectScriptBean * @param id the id of the workflow script to remove */ public void removeWorkflowScript( Integer id ) { if ( id != null ) { WorkflowScriptBean wfsBean = this.workflowScriptFactory.findByPrimaryKey(id); if ( wfsBean != null ) { this.workflowScriptFactory.delete(wfsBean); } } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); if ( customField != null ) { this.customFieldFactory.delete(customField); } } /** * Gets a <code>CustomFieldValueModel</code> by primary key * * @param id the primary key * @return The <code>CustomFieldValueModel</code> found or <code>null</code> */ public CustomFieldValueModel getCustomFieldValue(Integer id) { CustomFieldValueBean cfvBean = (CustomFieldValueBean) this.customFieldValueFactory.findByPrimaryKey(id); return cfvBean == null ? null : cfvBean.getModel(); } 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); customFieldValue.setCreateDate( new Timestamp(System.currentTimeMillis())); this.customFieldValueFactory.saveOrUpdate(customFieldValue); return customFieldValue.getModel(); } /** * Updates a <code>CustomFieldValueModel</code>. * * @param model The model to update * @return The <code>CustomFieldValueModel</code> after saving */ public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { if(model != null) { CustomFieldValueBean customFieldValue = this.customFieldValueFactory .findByPrimaryKey( model.getId() ); customFieldValue.setModel( model ); this.customFieldValueFactory.saveOrUpdate( customFieldValue ); 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; } /** * removes a custom field value by primary key * * @param customFieldValueId the id of the custoem field */ public void removeCustomFieldValue(Integer customFieldValueId) { // find custom field value by id CustomFieldValueBean customFieldValue = this.customFieldValueFactory.findByPrimaryKey(customFieldValueId); // remove from parent field customFieldValue.getCustomField().getValues().remove(customFieldValue); // delete it this.customFieldValueFactory.delete(customFieldValue); } /** * Removes all field values of a given custom field * * @param customFieldId The id of the customField */ public void removeCustomFieldValues(Integer customFieldId) { CustomFieldBean customFieldBean = this.customFieldFactory.findByPrimaryKey( customFieldId ); // get values of the field Collection values = customFieldBean.getValues(); for ( Iterator iter = values.iterator(); iter.hasNext();) { // get current CustomFieldValueBean customFieldValue = (CustomFieldValueBean)iter.next(); // remove from collection iter.remove(); // delete from datasource this.customFieldValueFactory.delete( customFieldValue ); } } 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 * @todo replace hardcoded version by a resource */ public ConfigurationModel createConfigurationItem(ConfigurationModel model) { ConfigurationBean configurationItem = new ConfigurationBean(); configurationItem.setModel(model); configurationItem.setCreateDate( new Timestamp( new Date().getTime())); configurationItem.setVersion( this.getProperty("version") ); 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a workflow script. * * @param model The <code>WorkflowScriptModel</code> carring the data * @return The <code>WorkflowScriptModel</code> after inserting */ public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // create workflow script and populate data WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); workflowScript.setCreateDate( new Timestamp( System.currentTimeMillis())); // save entity this.workflowScriptFactory.saveOrUpdate( workflowScript ); model.setId(workflowScript.getId()); return workflowScript.getModel(); } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } /** * remove a workflow script by its id * * @todo get all ProjectScriptBeans with that script attached and delete the ProjectScriptBean * @param id the id of the workflow script to remove */ public void removeWorkflowScript( Integer id ) { if ( id != null ) { WorkflowScriptBean wfsBean = this.workflowScriptFactory.findByPrimaryKey(id); if ( wfsBean != null ) { this.workflowScriptFactory.delete(wfsBean); } } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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 !=... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-19 13:49:25
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32405 Modified Files: Tag: itrackerhibernate EditLanguageAction.java Log Message: - fix validating user locale - catch NoSuchEntityException while deleting a languageBean Index: EditLanguageAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditLanguageAction.java,v retrieving revision 1.9.4.4 retrieving revision 1.9.4.5 diff -C2 -d -r1.9.4.4 -r1.9.4.5 *** EditLanguageAction.java 29 Oct 2005 16:58:55 -0000 1.9.4.4 --- EditLanguageAction.java 19 Nov 2005 13:49:15 -0000 1.9.4.5 *************** *** 43,46 **** --- 43,47 ---- import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.SystemConfigurationUtilities; + import cowsultants.itracker.ejb.beans.session.NoSuchEntityException; import cowsultants.itracker.web.util.Constants; *************** *** 81,85 **** errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidlocale")); } else if("create".equals(action)) { ! if(locale.length() != 2 || (locale.length() != 5 && locale.indexOf('_') == 2)) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidlocale")); } else { --- 82,86 ---- errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidlocale")); } else if("create".equals(action)) { ! if(locale.length() != 2 && (locale.length() != 5 || locale.indexOf('_') != 2)) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidlocale")); } else { *************** *** 111,116 **** String currValue = ITrackerResources.getCheckForKey(key.replace('/', '.'), updateLocale); if(value == null || value.trim().equals("")) { ! sc.removeLanguageItem(new LanguageModel(locale, key.replace('/', '.'))); ! ITrackerResources.clearKeyFromBundles(key.replace('/', '.'), true); } else if(! value.equals(currValue)) { sc.updateLanguageItem(new LanguageModel(locale, key.replace('/', '.'), value)); --- 112,122 ---- String currValue = ITrackerResources.getCheckForKey(key.replace('/', '.'), updateLocale); if(value == null || value.trim().equals("")) { ! try { ! sc.removeLanguageItem(new LanguageModel(locale, key.replace('/', '.'))); ! ITrackerResources.clearKeyFromBundles(key.replace('/', '.'), true); ! } catch ( NoSuchEntityException e ) { ! // do nothing; we want to delete it, so... ! } ! } else if(! value.equals(currValue)) { sc.updateLanguageItem(new LanguageModel(locale, key.replace('/', '.'), value)); |
From: Marc B. <mb...@us...> - 2005-11-19 13:39:49
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30438 Modified Files: Tag: itrackerhibernate EditLanguageFormAction.java Log Message: set parentLanguage if a country language is updated Index: EditLanguageFormAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditLanguageFormAction.java,v retrieving revision 1.7.4.4 retrieving revision 1.7.4.5 diff -C2 -d -r1.7.4.4 -r1.7.4.5 *** EditLanguageFormAction.java 29 Oct 2005 16:58:55 -0000 1.7.4.4 --- EditLanguageFormAction.java 19 Nov 2005 13:39:36 -0000 1.7.4.5 *************** *** 85,89 **** languageForm.set("locale", ""); } ! } String[] sortedKeys = sc.getSortedKeys(); --- 85,89 ---- languageForm.set("locale", ""); } ! } String[] sortedKeys = sc.getSortedKeys(); *************** *** 107,110 **** --- 107,111 ---- if(! locale.equalsIgnoreCase(ITrackerResources.BASE_LOCALE)) { String parentLocale = SystemConfigurationUtilities.getLocalePart(locale, SystemConfigurationUtilities.LOCALE_TYPE_LANGUAGE); + languageForm.set( "parentLocale" , parentLocale ); langItems = sc.getDefinedKeys(parentLocale); items = langItems; |
From: Marc B. <mb...@us...> - 2005-11-14 22:59:48
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23358 Modified Files: Tag: itrackerhibernate EditWorkflowScriptAction.java Log Message: fix syntax check of beanshell scripts Index: EditWorkflowScriptAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditWorkflowScriptAction.java,v retrieving revision 1.5.4.6 retrieving revision 1.5.4.7 diff -C2 -d -r1.5.4.6 -r1.5.4.7 *** EditWorkflowScriptAction.java 14 Nov 2005 22:06:37 -0000 1.5.4.6 --- EditWorkflowScriptAction.java 14 Nov 2005 22:59:40 -0000 1.5.4.7 *************** *** 74,80 **** Parser parser = new Parser(sbis); try { ! while(parser.Line()) { ! ! parser.getNextToken(); } } catch(Throwable t) { --- 74,80 ---- Parser parser = new Parser(sbis); try { ! while(!parser.Line()) { ! // do nothing, if script is syntactically correct ! // no exception is thrown } } catch(Throwable t) { |
From: Marc B. <mb...@us...> - 2005-11-14 22:08:06
|
Update of /cvsroot/itracker/itracker/web/WEB-INF/config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10873 Modified Files: Tag: itrackerhibernate struts-config.xml Log Message: add action removeworkflowscript Index: struts-config.xml =================================================================== RCS file: /cvsroot/itracker/itracker/web/WEB-INF/config/Attic/struts-config.xml,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** struts-config.xml 2 Nov 2005 15:15:54 -0000 1.1.2.2 --- struts-config.xml 14 Nov 2005 22:07:55 -0000 1.1.2.3 *************** *** 336,339 **** --- 336,341 ---- <action path="/editworkflowscriptform" type="cowsultants.itracker.web.actions.EditWorkflowScriptFormAction" name="workflowScriptForm" scope="request" input="/themes/standardtheme/admin/edit_workflowscript.jsp" validate="false"/> + <action path="/removeworkflowscript" type="cowsultants.itracker.web.actions.RemoveWorkflowScriptAction" + name="workflowScriptForm" scope="request" input="/themes/standardtheme/admin/list_workflowscript.jsp"/> <action path="/exportattachments" type="cowsultants.itracker.web.actions.ExportAttachmentsAction" name="adminActionForm" scope="request" input="/themes/standardtheme/admin/list_attachments.jsp"/> |
From: Marc B. <mb...@us...> - 2005-11-14 22:06:45
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10592 Modified Files: Tag: itrackerhibernate EditWorkflowScriptAction.java Log Message: Avoid looping forever while parsing beanshell script. However validating the script isn't really implemented as it currently checks the first expression only. Needs some investigation to find out how to correctly parse and validate the whole script (anybody?) Index: EditWorkflowScriptAction.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions/EditWorkflowScriptAction.java,v retrieving revision 1.5.4.5 retrieving revision 1.5.4.6 diff -C2 -d -r1.5.4.5 -r1.5.4.6 *** EditWorkflowScriptAction.java 1 Nov 2005 12:51:02 -0000 1.5.4.5 --- EditWorkflowScriptAction.java 14 Nov 2005 22:06:37 -0000 1.5.4.6 *************** *** 69,82 **** SystemConfiguration sc = getITrackerServices().getSystemConfiguration(); ! String scriptData = (String) PropertyUtils.getSimpleProperty(form, "script"); ! ByteArrayInputStream sbis = new ByteArrayInputStream(scriptData.getBytes()); ! Parser parser = new Parser(sbis); ! try { ! while(parser.Line()) { ! // SimpleNode node = parser.popNode(); ! } ! } catch(Throwable t) { ! throw new ParseException(t.getMessage()); ! } script = new WorkflowScriptModel(); --- 69,85 ---- SystemConfiguration sc = getITrackerServices().getSystemConfiguration(); ! String scriptData = (String) PropertyUtils.getSimpleProperty(form, "script"); ! if ( scriptData != null && scriptData.trim().length() > 0 ) { ! ByteArrayInputStream sbis = new ByteArrayInputStream(scriptData.getBytes()); ! Parser parser = new Parser(sbis); ! try { ! while(parser.Line()) { ! ! parser.getNextToken(); ! } ! } catch(Throwable t) { ! throw new ParseException(t.getMessage()); ! } ! } script = new WorkflowScriptModel(); *************** *** 93,99 **** } ! if(script == null) { ! throw new Exception("Error creating/updating workflow script."); ! } HttpSession session = request.getSession(true); --- 96,102 ---- } ! if (script == null) { ! throw new Exception("Error creating/updating workflow script."); ! } HttpSession session = request.getSession(true); *************** *** 105,109 **** saveErrors(request, errors); saveToken(request); ! return mapping.getInputForward(); } catch(Exception e) { Logger.logError("Exception processing form data", e); --- 108,112 ---- saveErrors(request, errors); saveToken(request); ! return mapping.getInputForward(); } catch(Exception e) { Logger.logError("Exception processing form data", e); |
From: Marc B. <mb...@us...> - 2005-11-14 22:03:26
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9832 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: fix and add methods to deal with workflow scripts Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.12 retrieving revision 1.31.4.13 diff -C2 -d -r1.31.4.12 -r1.31.4.13 *** SystemConfigurationBean.java 12 Nov 2005 18:01:06 -0000 1.31.4.12 --- SystemConfigurationBean.java 14 Nov 2005 22:03:18 -0000 1.31.4.13 *************** *** 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); if ( customField != null ) { this.customFieldFactory.delete(customField); } } /** * Gets a <code>CustomFieldValueModel</code> by primary key * * @param id the primary key * @return The <code>CustomFieldValueModel</code> found or <code>null</code> */ public CustomFieldValueModel getCustomFieldValue(Integer id) { CustomFieldValueBean cfvBean = (CustomFieldValueBean) this.customFieldValueFactory.findByPrimaryKey(id); return cfvBean == null ? null : cfvBean.getModel(); } 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); customFieldValue.setCreateDate( new Timestamp(System.currentTimeMillis())); this.customFieldValueFactory.saveOrUpdate(customFieldValue); return customFieldValue.getModel(); } /** * Updates a <code>CustomFieldValueModel</code>. * * @param model The model to update * @return The <code>CustomFieldValueModel</code> after saving */ public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { if(model != null) { CustomFieldValueBean customFieldValue = this.customFieldValueFactory .findByPrimaryKey( model.getId() ); customFieldValue.setModel( model ); this.customFieldValueFactory.saveOrUpdate( customFieldValue ); 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; } /** * removes a custom field value by primary key * * @param customFieldValueId the id of the custoem field */ public void removeCustomFieldValue(Integer customFieldValueId) { // find custom field value by id CustomFieldValueBean customFieldValue = this.customFieldValueFactory.findByPrimaryKey(customFieldValueId); // remove from parent field customFieldValue.getCustomField().getValues().remove(customFieldValue); // delete it this.customFieldValueFactory.delete(customFieldValue); } /** * Removes all field values of a given custom field * * @param customFieldId The id of the customField */ public void removeCustomFieldValues(Integer customFieldId) { CustomFieldBean customFieldBean = this.customFieldFactory.findByPrimaryKey( customFieldId ); // get values of the field Collection values = customFieldBean.getValues(); for ( Iterator iter = values.iterator(); iter.hasNext();) { // get current CustomFieldValueBean customFieldValue = (CustomFieldValueBean)iter.next(); // remove from collection iter.remove(); // delete from datasource this.customFieldValueFactory.delete( customFieldValue ); } } 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a workflow script. * * @param model The <code>WorkflowScriptModel</code> carring the data * @return The <code>WorkflowScriptModel</code> after inserting */ public WorkflowScriptModel createWorkflowScript(WorkflowScriptModel model) { // create workflow script and populate data WorkflowScriptBean workflowScript = new WorkflowScriptBean(); workflowScript.setModel(model); workflowScript.setCreateDate( new Timestamp( System.currentTimeMillis())); // save entity this.workflowScriptFactory.saveOrUpdate( workflowScript ); model.setId(workflowScript.getId()); return workflowScript.getModel(); } public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model) { if (model != null) { WorkflowScriptBean workflowScript = workflowScriptFactory.findByPrimaryKey(model.getId()); workflowScript.setModel(model); return workflowScript.getModel(); } return null; } /** * remove a workflow script by its id * * @todo get all ProjectScriptBeans with that script attached and delete the ProjectScriptBean * @param id the id of the workflow script to remove */ public void removeWorkflowScript( Integer id ) { if ( id != null ) { WorkflowScriptBean wfsBean = this.workflowScriptFactory.findByPrimaryKey(id); if ( wfsBean != null ) { this.workflowScriptFactory.delete(wfsBean); } } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public voi... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-14 22:02:19
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9613 Modified Files: Tag: itrackerhibernate WorkflowScriptFactoryImpl.java Log Message: - extend BaseHibernateFactoryImpl - implement derived methods findByPrimaryKey and findAll Index: WorkflowScriptFactoryImpl.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/WorkflowScriptFactoryImpl.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 *** WorkflowScriptFactoryImpl.java 17 Oct 2005 16:26:46 -0000 1.1.2.1 --- WorkflowScriptFactoryImpl.java 14 Nov 2005 22:02:09 -0000 1.1.2.2 *************** *** 4,19 **** import net.sf.hibernate.Criteria; import net.sf.hibernate.HibernateException; - import org.springframework.orm.hibernate.support.HibernateDaoSupport; - import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; ! public class WorkflowScriptFactoryImpl extends HibernateDaoSupport implements WorkflowScriptFactory { ! public WorkflowScriptBean findByPrimaryKey(Integer id) { ! return null; } public Collection findAll() { Criteria criteria = getSession().createCriteria(WorkflowScriptBean.class); --- 4,35 ---- import net.sf.hibernate.Criteria; + import net.sf.hibernate.expression.Expression; import net.sf.hibernate.HibernateException; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; ! public class WorkflowScriptFactoryImpl extends BaseHibernateFactoryImpl implements WorkflowScriptFactory { ! /** ! * Find a <code>WorkflowScriptBean</code> by its primary key ! * ! * @param id primary key of the <code>WorkflowScriptBean</code> ! * @return The <code>WorkflowScriptBean</code> found ! * @throws DataException thrown if finding fails ! */ ! public WorkflowScriptBean findByPrimaryKey(Integer id) throws DataException { ! ! try { ! return (WorkflowScriptBean)(getSession().load(WorkflowScriptBean.class, id)); ! } catch (HibernateException ex) { ! throw new DataException(ex); ! } } + /** + * Finds all <code>WorkflowScriptBean</code>s + * + * @return a <code>Collection</code> with all <code>WorkflowScriptBean</code>s + */ public Collection findAll() { Criteria criteria = getSession().createCriteria(WorkflowScriptBean.class); |
From: Marc B. <mb...@us...> - 2005-11-14 22:00:29
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9102 Modified Files: Tag: itrackerhibernate WorkflowScriptFactory.java Log Message: extend BaseFactory Index: WorkflowScriptFactory.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/Attic/WorkflowScriptFactory.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 *** WorkflowScriptFactory.java 13 Oct 2005 14:11:31 -0000 1.1.2.2 --- WorkflowScriptFactory.java 14 Nov 2005 22:00:20 -0000 1.1.2.3 *************** *** 5,12 **** import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; ! public interface WorkflowScriptFactory { ! public WorkflowScriptBean findByPrimaryKey(Integer id); ! public Collection findAll(); --- 5,28 ---- import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; ! /** ! * Interface to define basic operations to deal with the ! * <code>WorkflowScriptBean</code> entity ! */ ! public interface WorkflowScriptFactory extends BaseFactory { ! ! /** ! * Find a <code>WorkflowScriptBean</code> by its primary key ! * ! * @param id primary key of the <code>WorkflowScriptBean</code> ! * @return The <code>WorkflowScriptBean</code> found ! * @throws DataException thrown if finding fails ! */ public WorkflowScriptBean findByPrimaryKey(Integer id); ! ! /** ! * Finds all <code>WorkflowScriptBean</code>s ! * ! * @return a <code>Collection</code> with all <code>WorkflowScriptBean</code>s ! */ public Collection findAll(); |
From: Marc B. <mb...@us...> - 2005-11-14 21:59:21
|
Update of /cvsroot/itracker/itracker/web/themes/standardtheme/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8779 Modified Files: Tag: itrackerhibernate list_workflow.jsp Log Message: change name of the action to delete a workflowscript to fit naming convention (removeworkflowscript) Index: list_workflow.jsp =================================================================== RCS file: /cvsroot/itracker/itracker/web/themes/standardtheme/admin/Attic/list_workflow.jsp,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** list_workflow.jsp 31 Oct 2005 10:35:00 -0000 1.1.2.2 --- list_workflow.jsp 14 Nov 2005 21:59:13 -0000 1.1.2.3 *************** *** 61,66 **** <td> <it:formatImageAction action="editworkflowscriptform" paramName="id" paramValue="<%= workflowScripts[i].getId() %>" targetAction="update" src="/themes/standardtheme/images/edit.gif" altKey="itracker.web.image.edit.workflowscript.alt" arg0="<%= workflowScripts[i].getName() %>" textActionKey="itracker.web.image.edit.texttag"/> ! <it:formatImageAction action="removescript" paramName="id" paramValue="<%= workflowScripts[i].getId() %>" src="/themes/standardtheme/images/delete.gif" altKey="itracker.web.image.delete.workflowscript.alt" arg0="<%= workflowScripts[i].getName() %>" textActionKey="itracker.web.image.delete.texttag"/> ! </td> <td></td> <td><%= workflowScripts[i].getName() %></td> --- 61,66 ---- <td> <it:formatImageAction action="editworkflowscriptform" paramName="id" paramValue="<%= workflowScripts[i].getId() %>" targetAction="update" src="/themes/standardtheme/images/edit.gif" altKey="itracker.web.image.edit.workflowscript.alt" arg0="<%= workflowScripts[i].getName() %>" textActionKey="itracker.web.image.edit.texttag"/> ! <it:formatImageAction action="removeworkflowscript" paramName="id" paramValue="<%= workflowScripts[i].getId() %>" src="/themes/standardtheme/images/delete.gif" altKey="itracker.web.image.delete.workflowscript.alt" arg0="<%= workflowScripts[i].getName() %>" textActionKey="itracker.web.image.delete.texttag"/> ! </td> <td></td> <td><%= workflowScripts[i].getName() %></td> |
From: Marc B. <mb...@us...> - 2005-11-14 21:58:08
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/client/interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8428 Modified Files: Tag: itrackerhibernate SystemConfiguration.java Log Message: add method removeWorkflowScript to interface Index: SystemConfiguration.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/client/interfaces/SystemConfiguration.java,v retrieving revision 1.22.4.1 retrieving revision 1.22.4.2 diff -C2 -d -r1.22.4.1 -r1.22.4.2 *** SystemConfiguration.java 11 Oct 2005 01:21:04 -0000 1.22.4.1 --- SystemConfiguration.java 14 Nov 2005 21:57:56 -0000 1.22.4.2 *************** *** 132,135 **** --- 132,140 ---- */ public WorkflowScriptModel updateWorkflowScript(WorkflowScriptModel model); + /** + * This method removes a workflow script in the database. + * @param id The id of the workflow script + */ + public void removeWorkflowScript(Integer id); /** |
From: Marc B. <mb...@us...> - 2005-11-14 21:57:29
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/web/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8285 Added Files: Tag: itrackerhibernate RemoveWorkflowScriptAction.java Log Message: add Action to delete workflow scripts --- NEW FILE: RemoveWorkflowScriptAction.java --- /* * RemoveWorkflowScriptAction.java * * Created on 13. November 2005, 04:51 */ package cowsultants.itracker.web.actions; import cowsultants.itracker.ejb.beans.entity.WorkflowScriptBean; import cowsultants.itracker.ejb.beans.session.WorkflowScriptFactory; import cowsultants.itracker.ejb.client.util.Logger; import cowsultants.itracker.ejb.client.util.UserUtilities; import cowsultants.itracker.web.util.Constants; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.beanutils.PropertyUtils; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * Action to remove a workflow script * * <ol> * <li>get all project and remove the script to be deleted</li> * <li>delete the script</li> * </ol> * * @author mb...@bc... */ public class RemoveWorkflowScriptAction extends ITrackerAction { /** * executes the action which removes a workflow script * * @param form the form with user input * @param request the request triggering the action * @param response response to the client * @param mapping The action mapping * * @throws ServletException thrown if execution fails * @throws IOException thrown if io to client fails * * @return the <code>ActionForward</code> to forward to */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ActionErrors errors = new ActionErrors(); ActionForward fw = mapping.findForward("error"); if(! isLoggedIn(request, response)) { return mapping.findForward("login"); } // check permissions HttpSession session = request.getSession(true); HashMap userPermissions = (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY); if(! UserUtilities.hasPermission(userPermissions, UserUtilities.PERMISSION_USER_ADMIN)) { return mapping.findForward("unauthorized"); } try { // get the id from the form Integer scriptId = (Integer) PropertyUtils.getSimpleProperty(form, "id"); // remove the script this.getITrackerServices().getSystemConfiguration() .removeWorkflowScript(scriptId); // find the mapping for the list of all worksflows fw = mapping.findForward( "listworkflow" ); } catch (InvocationTargetException ex) { Logger.logError( ex.getMessage(), ex ); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidworkflowscript")); } catch (NoSuchMethodException ex) { Logger.logError( ex.getMessage(), ex ); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidworkflowscript")); } catch (IllegalAccessException ex) { Logger.logError( ex.getMessage(), ex ); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidworkflowscript")); } if(! errors.isEmpty()) { this.saveErrors(request, errors); } return fw; } } |
From: Marc B. <mb...@us...> - 2005-11-13 01:59:26
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/client/resources In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7303 Modified Files: Tag: itrackerhibernate ITrackerResources.java Log Message: be aware of NoSuchEntityException avoids pages which could not been displayed because of a single missing resource string Index: ITrackerResources.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/client/resources/ITrackerResources.java,v retrieving revision 1.33.4.2 retrieving revision 1.33.4.3 diff -C2 -d -r1.33.4.2 -r1.33.4.3 *** ITrackerResources.java 30 Oct 2005 16:45:21 -0000 1.33.4.2 --- ITrackerResources.java 13 Nov 2005 01:59:19 -0000 1.33.4.3 *************** *** 19,22 **** --- 19,23 ---- package cowsultants.itracker.ejb.client.resources; + import cowsultants.itracker.ejb.beans.session.NoSuchEntityException; import java.util.HashMap; import java.util.Iterator; *************** *** 242,246 **** + locale); return "MISSING KEY: " + key; ! } } --- 243,251 ---- + locale); return "MISSING KEY: " + key; ! } catch (NoSuchEntityException mre) { ! Logger.logInfo("NoSuchEntityException caught while retrieving translation key '" + key + "' for locale " ! + locale); ! return "MISSING KEY: " + key; ! } } |
From: Marc B. <mb...@us...> - 2005-11-12 18:01:14
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4615 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - implemented removeCustomFieldValue and removeCustomFieldValues Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.11 retrieving revision 1.31.4.12 diff -C2 -d -r1.31.4.11 -r1.31.4.12 *** SystemConfigurationBean.java 12 Nov 2005 15:51:47 -0000 1.31.4.11 --- SystemConfigurationBean.java 12 Nov 2005 18:01:06 -0000 1.31.4.12 *************** *** 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); if ( customField != null ) { this.customFieldFactory.delete(customField); } } /** * Gets a <code>CustomFieldValueModel</code> by primary key * * @param id the primary key * @return The <code>CustomFieldValueModel</code> found or <code>null</code> */ public CustomFieldValueModel getCustomFieldValue(Integer id) { CustomFieldValueBean cfvBean = (CustomFieldValueBean) this.customFieldValueFactory.findByPrimaryKey(id); return cfvBean == null ? null : cfvBean.getModel(); } 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); customFieldValue.setCreateDate( new Timestamp(System.currentTimeMillis())); this.customFieldValueFactory.saveOrUpdate(customFieldValue); return customFieldValue.getModel(); } /** * Updates a <code>CustomFieldValueModel</code>. * * @param model The model to update * @return The <code>CustomFieldValueModel</code> after saving */ public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { if(model != null) { CustomFieldValueBean customFieldValue = this.customFieldValueFactory .findByPrimaryKey( model.getId() ); customFieldValue.setModel( model ); this.customFieldValueFactory.saveOrUpdate( customFieldValue ); 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; } /** * removes a custom field value by primary key * * @param customFieldValueId the id of the custoem field */ public void removeCustomFieldValue(Integer customFieldValueId) { // find custom field value by id CustomFieldValueBean customFieldValue = this.customFieldValueFactory.findByPrimaryKey(customFieldValueId); // delete it this.customFieldValueFactory.delete(customFieldValue); } 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); if ( customField != null ) { this.customFieldFactory.delete(customField); } } /** * Gets a <code>CustomFieldValueModel</code> by primary key * * @param id the primary key * @return The <code>CustomFieldValueModel</code> found or <code>null</code> */ public CustomFieldValueModel getCustomFieldValue(Integer id) { CustomFieldValueBean cfvBean = (CustomFieldValueBean) this.customFieldValueFactory.findByPrimaryKey(id); return cfvBean == null ? null : cfvBean.getModel(); } 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); customFieldValue.setCreateDate( new Timestamp(System.currentTimeMillis())); ... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-12 15:51:55
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3786/src/cowsultants/itracker/ejb/beans/session Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - (re)implement some methods concerning CustomField and CustomeFieldValue Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.10 retrieving revision 1.31.4.11 diff -C2 -d -r1.31.4.10 -r1.31.4.11 *** SystemConfigurationBean.java 12 Nov 2005 01:48:04 -0000 1.31.4.10 --- SystemConfigurationBean.java 12 Nov 2005 15:51:47 -0000 1.31.4.11 *************** *** 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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; } /** * Creates a custom field * * @param model The <code>CustomFieldModel</code> carrying the data * @return the <code>CustomFieldModel</code> after saving * @exception DataException thrown if creation fails */ public CustomFieldModel createCustomField(CustomFieldModel model) throws DataException { CustomFieldBean customField = new CustomFieldBean(); customField.setModel(model); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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); customField.setCreateDate( new Timestamp( System.currentTimeMillis())); this.customFieldFactory.saveOrUpdate( customField ); 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; } /** * searches for a custom field by primary key and removes it * * @param customFieldId the primary key * @exception DataException thrown if removing fails */ public void removeCustomField(Integer customFieldId) throws DataException { CustomFieldBean customField = customFieldFactory.findByPrimaryKey(customFieldId); if ( customField != null ) { this.customFieldFactory.delete(customField); } } /** * Gets a <code>CustomFieldValueModel</code> by primary key * * @param id the primary key * @return The <code>CustomFieldValueModel</code> found or <code>null</code> */ public CustomFieldValueModel getCustomFieldValue(Integer id) { CustomFieldValueBean cfvBean = (CustomFieldValueBean) this.customFieldValueFactory.findByPrimaryKey(id); return cfvBean == null ? null : cfvBean.getModel(); } 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); customFieldValue.setCreateDate( new Timestamp(System.currentTimeMillis())); this.customFieldValueFactory.saveOrUpdate(customFieldValue); return customFieldValue.getModel(); } /** * Updates a <code>CustomFieldValueModel</code>. * * @param model The model to update * @return The <code>CustomFieldValueModel</code> after saving */ public CustomFieldValueModel updateCustomFieldValue(CustomFieldValueModel model) { if(model != null) { CustomFieldValueBean customFieldValue = this.customFieldValueFactory .findByPrimaryKey( model.getId() ); customFieldValue.setModel( model ); this.customFieldValueFactory.saveOrUpdate( customFieldValue ); 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 = (Cust... [truncated message content] |
From: Marc B. <mb...@us...> - 2005-11-12 02:25:13
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/entity In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10336 Modified Files: Tag: itrackerhibernate CustomFieldBean.java Log Message: initialize collection members to avoid nullPointer Index: CustomFieldBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/entity/CustomFieldBean.java,v retrieving revision 1.9.4.1 retrieving revision 1.9.4.2 diff -C2 -d -r1.9.4.1 -r1.9.4.2 *** CustomFieldBean.java 11 Oct 2005 01:21:04 -0000 1.9.4.1 --- CustomFieldBean.java 12 Nov 2005 02:25:03 -0000 1.9.4.2 *************** *** 27,30 **** --- 27,31 ---- import cowsultants.itracker.ejb.client.models.CustomFieldModel; import cowsultants.itracker.ejb.client.models.CustomFieldValueModel; + import java.util.ArrayList; public class CustomFieldBean extends GenericBean { *************** *** 34,40 **** public int required; public int sortOptionsByName; ! public Collection values; ! public Collection projects; ! public Collection fields; public String getDateFormat() { --- 35,41 ---- public int required; public int sortOptionsByName; ! public Collection values = new ArrayList(); ! public Collection projects = new ArrayList(); ! public Collection fields = new ArrayList(); public String getDateFormat() { |
From: Marc B. <mb...@us...> - 2005-11-12 02:22:02
|
Update of /cvsroot/itracker/itracker/web/themes/standardtheme/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9819 Modified Files: Tag: itrackerhibernate edit_customfield.jsp Log Message: - added trailing curly brace to end the code bloack and make jsp compile Index: edit_customfield.jsp =================================================================== RCS file: /cvsroot/itracker/itracker/web/themes/standardtheme/admin/Attic/edit_customfield.jsp,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** edit_customfield.jsp 2 Nov 2005 15:15:22 -0000 1.1.2.3 --- edit_customfield.jsp 12 Nov 2005 02:21:53 -0000 1.1.2.4 *************** *** 207,208 **** --- 207,209 ---- <%@ include file="/themes/standardtheme/includes/footer.jsp" %> + <% } %> \ No newline at end of file |
From: Marc B. <mb...@us...> - 2005-11-12 01:48:12
|
Update of /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3523 Modified Files: Tag: itrackerhibernate SystemConfigurationBean.java Log Message: - implemented updateCOnfigurationItems and removeConfigurationItems Index: SystemConfigurationBean.java =================================================================== RCS file: /cvsroot/itracker/itracker/src/cowsultants/itracker/ejb/beans/session/SystemConfigurationBean.java,v retrieving revision 1.31.4.9 retrieving revision 1.31.4.10 diff -C2 -d -r1.31.4.9 -r1.31.4.10 *** SystemConfigurationBean.java 12 Nov 2005 00:52:34 -0000 1.31.4.9 --- SystemConfigurationBean.java 12 Nov 2005 01:48:04 -0000 1.31.4.10 *************** *** 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() ); } } /** * 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); } /** * Updates the configuration items * * @param models the <code>ConfigurationModels</code> to update * @param type The type of the <code>ConfigurationItem</code>s to update * @return an array with the saved models * @exception DataException thrown if update fails */ public ConfigurationModel[] updateConfigurationItems(ConfigurationModel[] models, int type) throws DataException { // remove all items removeConfigurationItems(type); for (int i = 0; i < models.length; i++) { // create a new item ConfigurationBean configurationItem = new ConfigurationBean(); // populate the data configurationItem.setModel(models[i]); // set creation date configurationItem.setCreateDate( new Timestamp( System.currentTimeMillis() ) ); // save or update this.configurationFactory.saveOrUpdate( configurationItem ); // add saved model to array models[i] = configurationItem.getModel(); } // sort array Arrays.sort(models, new ConfigurationModel()); return models; } /** * 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 ); } } /** * Removes all <code>ConfigurationBean</code>s of the give <code>type</code> * * @param type the type of <code>ConfigurationBean</code> to remove * @exception DataException thrown if removing fails */ public void removeConfigurationItems(int type) throws DataException { // find the configuration beans by its type Collection currentItems = configurationFactory.findByType(type); for (Iterator iter = currentItems.iterator(); iter.hasNext();) { // get current config bean ConfigurationBean config = (ConfigurationBean) iter.next(); // delete it this.configurationFactory.delete( config ); } } 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()).g... [truncated message content] |