- Versuch der Problem mit der NPE beim ThreadPublishing zu beheben

- Verschiedene Kleinigkeiten


git-svn-id: https://svn.libreccm.org/ccm/trunk@1466 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-01-23 12:59:16 +00:00
parent ee9cf3e769
commit 93ab00c608
4 changed files with 294 additions and 211 deletions

View File

@ -14,8 +14,11 @@ import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.web.RedirectSignal;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import javax.servlet.ServletException;
/** /**
* Generates the extra XML output for a profile for the embedded view. * Generates the extra XML output for a profile for the embedded view.
@ -41,6 +44,20 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
final PublicPersonalProfile profile = (PublicPersonalProfile) item; final PublicPersonalProfile profile = (PublicPersonalProfile) item;
final String showItem = state.getRequest().getParameter(SHOW_ITEM_PARAM); final String showItem = state.getRequest().getParameter(SHOW_ITEM_PARAM);
if (!config.getEmbedded() && state.getRequestURI().contains(profile.getName())) {
/*try {
DispatcherHelper.forwardRequestByPath(getProfileUrl(profile),
state.getRequest(),
state.getResponse());
return;
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
} catch (ServletException ex) {
throw new UncheckedWrapperException(ex);
}*/
throw new RedirectSignal(getProfileUrl(profile), true);
}
if (config.getEmbedded()) { if (config.getEmbedded()) {
final Element navigation = element.newChildElement( final Element navigation = element.newChildElement(
"profileNavigation"); "profileNavigation");
@ -142,4 +159,32 @@ public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator
public void addGlobalStateParams(final Page p) { public void addGlobalStateParams(final Page p) {
//Nothing yet //Nothing yet
} }
private String getProfileUrl(final PublicPersonalProfile profile) {
final GenericPerson owner = profile.getOwner();
final GenericPersonContactCollection contacts = owner.getContacts();
String homepage = null;
while(contacts.next() && (homepage == null)) {
homepage = getHomepageContactEntry(contacts.getContact());
}
contacts.close();
return homepage;
}
private String getHomepageContactEntry(final GenericContact contact) {
final GenericContactEntryCollection entries = contact.getContactEntries();
String homepage = null;
while(entries.next()) {
if ("homepage".equals(entries.getKey())) {
homepage = entries.getValue();
break;
}
}
entries.close();
return homepage;
}
} }

View File

@ -759,7 +759,7 @@ class ItemLifecycleSelectForm extends BaseForm {
static void finish(Workflow workflow, ContentItem item, User user) throws static void finish(Workflow workflow, ContentItem item, User user) throws
TaskException { TaskException {
if (workflow != null) { if ((workflow != null) && (user != null)) {
final Engine engine = Engine.getInstance(CMSEngine.CMS_ENGINE_TYPE); final Engine engine = Engine.getInstance(CMSEngine.CMS_ENGINE_TYPE);
// ; // ;

View File

@ -45,26 +45,28 @@ import java.util.Iterator;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* User task that is associated with an interface for * User task that is associated with an interface for performing some manual
* performing some manual operation. * operation.
* *
* @author Karl Goldstein * @author Karl Goldstein
* @author Uday Mathur * @author Uday Mathur
* @author Khy Huang * @author Khy Huang
* @author Stefan Deusch * @author Stefan Deusch
* @version $Id: UserTask.java 1564 2007-04-18 16:15:27Z apevec $ * @version $Id: UserTask.java 1564 2007-04-18 16:15:27Z apevec $
**/ *
*/
public class UserTask extends Task implements Assignable { public class UserTask extends Task implements Assignable {
/** Private logger instance for log4j. */ /**
* Private logger instance for log4j.
*/
private static final Logger s_log = Logger.getLogger(UserTask.class); private static final Logger s_log = Logger.getLogger(UserTask.class);
/**
/** Private configuration object, singleton design pattern */ * Private configuration object, singleton design pattern
*/
private static final WorkflowConfig s_conf = WorkflowConfig.getInstance(); private static final WorkflowConfig s_conf = WorkflowConfig.getInstance();
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.workflow.simple.UserTask"; "com.arsdigita.workflow.simple.UserTask";
public static final String ASSIGNED_USERS = "assignedUsers"; public static final String ASSIGNED_USERS = "assignedUsers";
public static final String ASSIGNED_GROUPS = "assignedGroups"; public static final String ASSIGNED_GROUPS = "assignedGroups";
public static final String LOCKING_USER_ID = "lockingUserId"; public static final String LOCKING_USER_ID = "lockingUserId";
@ -73,15 +75,12 @@ public class UserTask extends Task implements Assignable {
public static final String START_DATE = "startDate"; public static final String START_DATE = "startDate";
public static final String DURATION_MINUTES = "durationMinutes"; public static final String DURATION_MINUTES = "durationMinutes";
public static final String NOTIFICATION_SENDER_ID = "notificationSenderID"; public static final String NOTIFICATION_SENDER_ID = "notificationSenderID";
public static final int DEFAULT_DURATION = 1440; public static final int DEFAULT_DURATION = 1440;
private User m_userLock; // Used to lock process private User m_userLock; // Used to lock process
private HashSet m_assignedUsers; private HashSet m_assignedUsers;
private HashSet m_assignedGroups; private HashSet m_assignedGroups;
private User m_finished_user; private User m_finished_user;
private Party m_notificationSender; // email alerts are from this sender private Party m_notificationSender; // email alerts are from this sender
// identify the different operations a Task can undergo // identify the different operations a Task can undergo
public static final String ENABLE_OP = "enable"; public static final String ENABLE_OP = "enable";
public static final String DISABLE_OP = "disable"; public static final String DISABLE_OP = "disable";
@ -95,61 +94,61 @@ public class UserTask extends Task implements Assignable {
* @param description the task description * @param description the task description
* @param is_active whether the task is in use * @param is_active whether the task is in use
* @param duration_minutes the projected duration of the task in minutes * @param duration_minutes the projected duration of the task in minutes
**/ *
*/
public UserTask(String label, String description, public UserTask(String label, String description,
boolean is_active, int duration_minutes) { boolean is_active, int duration_minutes) {
this(label, description); this(label, description);
setDuration(new Duration(0, 0, duration_minutes)); setDuration(new Duration(0, 0, duration_minutes));
} }
/** /**
* Constructor for a user task without runtime information. * Constructor for a user task without runtime information.
* *
* @param label the task definition label * @param label the task definition label
* @param description the description * @param description the description
**/ *
*/
public UserTask(String label, String description) { public UserTask(String label, String description) {
this(BASE_DATA_OBJECT_TYPE); this(BASE_DATA_OBJECT_TYPE);
setDuration(new Duration(DEFAULT_DURATION)); setDuration(new Duration(DEFAULT_DURATION));
initAttributes(label, description); initAttributes(label, description);
} }
/** /**
* Creates a new task definition and sets the properties * Creates a new task definition and sets the properties
* <code>label</code> and <code>description</code> to null. * <code>label</code> and
* The properties of this * <code>description</code> to null. The properties of this object are not
* object are not made persistent until the <code>save</code> * made persistent until the
* method is called. If save() is called * <code>save</code> method is called. If save() is called without setting
* without setting these properties, an IllegalArgumentException * these properties, an IllegalArgumentException will be thrown.
* will be thrown.
* *
**/ *
*/
public UserTask() { public UserTask() {
this(BASE_DATA_OBJECT_TYPE); this(BASE_DATA_OBJECT_TYPE);
setDuration(new Duration(0)); setDuration(new Duration(0));
} }
/** /**
* Constructor for a user task that is * Constructor for a user task that is used for setting the object type.
* used for setting the object type.
* *
* @param type the object type * @param type the object type
* *
**/ *
*/
protected UserTask(ObjectType type) { protected UserTask(ObjectType type) {
super(type); super(type);
} }
/** /**
* Constructor for user task that is * Constructor for user task that is used for setting the object type by
* used for setting the object type by name. * name.
* *
* @param typeName the type name * @param typeName the type name
* *
**/ *
*/
protected UserTask(String typeName) { protected UserTask(String typeName) {
super(typeName); super(typeName);
setDuration(new Duration(0, 0, 0)); setDuration(new Duration(0, 0, 0));
@ -160,7 +159,8 @@ public class UserTask extends Task implements Assignable {
* *
* @param userTaskObject the data object * @param userTaskObject the data object
* *
**/ *
*/
public UserTask(DataObject userTaskObject) { public UserTask(DataObject userTaskObject) {
super(userTaskObject); super(userTaskObject);
} }
@ -170,7 +170,8 @@ public class UserTask extends Task implements Assignable {
* *
* @param oid the user task OID * @param oid the user task OID
* *
**/ *
*/
public UserTask(OID oid) throws DataObjectNotFoundException { public UserTask(OID oid) throws DataObjectNotFoundException {
super(oid); super(oid);
} }
@ -180,7 +181,8 @@ public class UserTask extends Task implements Assignable {
* *
* @param id the user task ID as BigDecimal * @param id the user task ID as BigDecimal
* *
**/ *
*/
public UserTask(BigDecimal id) throws DataObjectNotFoundException { public UserTask(BigDecimal id) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
@ -190,25 +192,30 @@ public class UserTask extends Task implements Assignable {
* *
* @return user task OID. * @return user task OID.
* @see com.arsdigita.persistence.OID * @see com.arsdigita.persistence.OID
**/ *
*/
public OID getUserTaskOID() { public OID getUserTaskOID() {
return new OID(getBaseDataObjectType(), getID()); return new OID(getBaseDataObjectType(), getID());
} }
/** /**
* Retrieves the start date of this user task. * Retrieves the start date of this user task.
*
* @return the start date of this user task. * @return the start date of this user task.
* *
**/ *
*/
public Date getStartDate() { public Date getStartDate() {
return (Date) get(START_DATE); return (Date) get(START_DATE);
} }
/** /**
* Retrieves the due date of this user task. * Retrieves the due date of this user task.
*
* @return the due date of this user task. * @return the due date of this user task.
* *
**/ *
*/
public Date getDueDate() { public Date getDueDate() {
return (Date) get(DUE_DATE); return (Date) get(DUE_DATE);
} }
@ -218,18 +225,20 @@ public class UserTask extends Task implements Assignable {
* *
* @param startDate the date the task is supposed to start * @param startDate the date the task is supposed to start
* *
**/ *
*/
public void setStartDate(Date startDate) { public void setStartDate(Date startDate) {
set(START_DATE, startDate); set(START_DATE, startDate);
} }
/** /**
* Sets the duration for this user task. * Sets the duration for this user task. Updates the start date and due date
* Updates the start date and due date accordingly. * accordingly.
*
* @param duration the duration for this task * @param duration the duration for this task
* *
**/ *
*/
private void setDuration(Duration duration) { private void setDuration(Duration duration) {
setStartDate(duration.getStartDate()); setStartDate(duration.getStartDate());
setDueDate(duration.getDueDate()); setDueDate(duration.getDueDate());
@ -238,8 +247,10 @@ public class UserTask extends Task implements Assignable {
/** /**
* Returns the duration attribute for this user task. * Returns the duration attribute for this user task.
*
* @return the duration for this user task. * @return the duration for this user task.
**/ *
*/
public Duration getDuration() { public Duration getDuration() {
BigDecimal minutes = (BigDecimal) get(DURATION_MINUTES); BigDecimal minutes = (BigDecimal) get(DURATION_MINUTES);
@ -255,28 +266,28 @@ public class UserTask extends Task implements Assignable {
* *
* @param dueDate the imposed due date of the user task * @param dueDate the imposed due date of the user task
* *
**/ *
*/
public void setDueDate(Date dueDate) { public void setDueDate(Date dueDate) {
set(DUE_DATE, dueDate); set(DUE_DATE, dueDate);
} }
/** /**
* Marks the task as finished. (persistent operation) * Marks the task as finished. (persistent operation) <P>This operation is
* <P>This operation is only valid if the * only valid if the task is enabled. Only the user who previously locked
* task is enabled. * the task can call this method.
* Only the user who previously locked the task can call this
* method.
* *
* @param user the user who checks off the task * @param user the user who checks off the task
* *
**/ *
*/
public void finish(User user) throws TaskException { public void finish(User user) throws TaskException {
if (isLocked()) { if (isLocked()) {
if (!getLockedUser().equals(user)) { if (!getLockedUser().equals(user)) {
// SF patch [ 1587168 ] Show locking user // SF patch [ 1587168 ] Show locking user
String currentUserName = (user == null ? "(unknown)" : user String currentUserName = (user == null ? "(unknown)" : user.
.getName()); getName());
String lockedUserName = (getLockedUser() == null ? "(unknown)" String lockedUserName = (getLockedUser() == null ? "(unknown)"
: getLockedUser().getName()); : getLockedUser().getName());
throw new TaskException(currentUserName throw new TaskException(currentUserName
@ -291,7 +302,8 @@ public class UserTask extends Task implements Assignable {
/** /**
* Set the startDate to the current date, carrying the duration over from * Set the startDate to the current date, carrying the duration over from
* the current value. * the current value.
**/ *
*/
public void enable() { public void enable() {
// Create a new Duration (whose start date is now) // Create a new Duration (whose start date is now)
// with the specified duration. // with the specified duration.
@ -302,7 +314,8 @@ public class UserTask extends Task implements Assignable {
/** /**
* Enables an event action. Sends out notification to assigned users. * Enables an event action. Sends out notification to assigned users.
* *
**/ *
*/
public void enableEvt() { public void enableEvt() {
Party sender = getNotificationSender(); Party sender = getNotificationSender();
@ -313,16 +326,20 @@ public class UserTask extends Task implements Assignable {
super.enableEvt(); super.enableEvt();
} }
/** /**
* Sends email to assignees with information about * Sends email to assignees with information about who completed the task
* who completed the task and when. * and when.
* *
**/ *
*/
protected void finishEvt() { protected void finishEvt() {
User current = null; User current = null;
Party party = Kernel.getContext().getParty(); Party party = Kernel.getContext().getParty();
if (party == null) {
return;
}
try { try {
current = User.retrieve(party.getOID()); current = User.retrieve(party.getOID());
} catch (DataObjectNotFoundException e) { } catch (DataObjectNotFoundException e) {
@ -335,20 +352,19 @@ public class UserTask extends Task implements Assignable {
if (sendAlerts(FINISH_OP) && sender != null) { if (sendAlerts(FINISH_OP) && sender != null) {
Message msg = generateMessage(FINISH_OP, sender); Message msg = generateMessage(FINISH_OP, sender);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Sending alert message with body " + s_log.debug("Sending alert message with body " + msg.getBody()
msg.getBody() + + " for finishEvt.");
" for finishEvt.");
} }
sendMessageToAssignees(msg); sendMessageToAssignees(msg);
} }
super.finishEvt(); super.finishEvt();
} }
/** /**
* Sends email to subscribed events that this task was rolled back. * Sends email to subscribed events that this task was rolled back.
* *
**/ *
*/
protected void rollbackEvt() { protected void rollbackEvt() {
Party sender = getNotificationSender(); Party sender = getNotificationSender();
if (sendAlerts(ROLLBACK_OP) && sender != null) { if (sendAlerts(ROLLBACK_OP) && sender != null) {
@ -358,11 +374,11 @@ public class UserTask extends Task implements Assignable {
super.rollbackEvt(); super.rollbackEvt();
} }
/** /**
* Sends email that this task has been disabled. * Sends email that this task has been disabled.
* *
**/ *
*/
protected void disableEvt() { protected void disableEvt() {
Party sender = getNotificationSender(); Party sender = getNotificationSender();
if (sendAlerts(DISABLE_OP) && sender != null) { if (sendAlerts(DISABLE_OP) && sender != null) {
@ -374,25 +390,33 @@ public class UserTask extends Task implements Assignable {
/** /**
* Generate the message to send if for the specified event * Generate the message to send if for the specified event
**/ *
*/
protected Message generateMessage(String operation, Party sender) { protected Message generateMessage(String operation, Party sender) {
String subject = null; String subject = null;
String body = null; String body = null;
if (ENABLE_OP.equals(operation)) { if (ENABLE_OP.equals(operation)) {
subject = getLabel() + "is in ready state."; subject = getLabel() + "is in ready state.";
body = getLabel() + " moved to ready state from disabled on "+(new Date()); body = getLabel() + " moved to ready state from disabled on "
+ (new Date());
} else if (DISABLE_OP.equals(operation)) { } else if (DISABLE_OP.equals(operation)) {
subject = getLabel() + " moved to disable state."; subject = getLabel() + " moved to disable state.";
body = getLabel() + " was moved to disable state from ready on "+(new Date()); body = getLabel() + " was moved to disable state from ready on "
+ (new Date());
} else if (ROLLBACK_OP.equals(operation)) { } else if (ROLLBACK_OP.equals(operation)) {
subject = getLabel() + " moved to disable state."; subject = getLabel() + " moved to disable state.";
body = getLabel() + " moved to disable state from finished on "+(new Date()); body = getLabel() + " moved to disable state from finished on "
+ (new Date());
} else if (FINISH_OP.equals(operation)) { } else if (FINISH_OP.equals(operation)) {
subject = getLabel() + "was finished."; subject = getLabel() + "was finished.";
body = getLabel() + " completed on "+(new Date()) + body = getLabel() + " completed on " + (new Date()) + (m_finished_user
(m_finished_user != null ? "by: " + m_finished_user.getName() : ""); != null ? "by: "
+ m_finished_user.
getName()
: "");
} else { } else {
throw new IllegalArgumentException("Invalid workflow operation: " + operation); throw new IllegalArgumentException("Invalid workflow operation: "
+ operation);
} }
body += "\nDescription: " + getDescription() + "\n"; body += "\nDescription: " + getDescription() + "\n";
@ -409,8 +433,8 @@ public class UserTask extends Task implements Assignable {
*/ */
protected void sendMessageToAssignees(Message msg) { protected void sendMessageToAssignees(Message msg) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Sending message: " + msg.getBody() + s_log.debug("Sending message: " + msg.getBody()
" to all assignees."); + " to all assignees.");
} }
Iterator itr = getAssignedUsers(); Iterator itr = getAssignedUsers();
@ -421,7 +445,8 @@ public class UserTask extends Task implements Assignable {
notification = new Notification(tempParty, msg); notification = new Notification(tempParty, msg);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Sending message to user " + tempParty.getDisplayName()); s_log.debug("Sending message to user " + tempParty.
getDisplayName());
} }
notification.save(); notification.save();
@ -431,7 +456,8 @@ public class UserTask extends Task implements Assignable {
tempParty = (Party) itr.next(); tempParty = (Party) itr.next();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Sending message to group " + tempParty.getDisplayName()); s_log.debug("Sending message to group " + tempParty.
getDisplayName());
} }
notification = new Notification(tempParty, msg); notification = new Notification(tempParty, msg);
@ -439,26 +465,26 @@ public class UserTask extends Task implements Assignable {
} }
} }
/** /**
* Marks the task as finished with an additional * Marks the task as finished with an additional comment. (persistent
* comment. (persistent operation) * operation)
* *
* @param user the user checking off the task as finished * @param user the user checking off the task as finished
* @param comment a comment * @param comment a comment
* *
**/ *
*/
public void finish(User user, String comment) throws TaskException { public void finish(User user, String comment) throws TaskException {
finish(); finish();
addComment(user, comment); addComment(user, comment);
} }
/** /**
* Locks the task for finishing by a specified user. (persistent * Locks the task for finishing by a specified user. (persistent operation)
* operation)
* *
* @param user the user who is locking the task * @param user the user who is locking the task
**/ *
*/
public void lock(User user) { public void lock(User user) {
m_userLock = user; m_userLock = user;
@ -466,35 +492,36 @@ public class UserTask extends Task implements Assignable {
set(IS_LOCKED, "t"); set(IS_LOCKED, "t");
} }
/** /**
* Releases the lock on the task if it is currently * Releases the lock on the task if it is currently locked. (persistent
* locked. (persistent operation) * operation)
* *
* @param user the user who is unlocking the task * @param user the user who is unlocking the task
* *
**/ *
*/
public void unlock(User user) { public void unlock(User user) {
m_userLock = null; m_userLock = null;
set(LOCKING_USER_ID, null); set(LOCKING_USER_ID, null);
set(IS_LOCKED, "f"); set(IS_LOCKED, "f");
} }
/** /**
* Checks whether the task is locked by a user. * Checks whether the task is locked by a user.
* @return <code>true</code> if the task is locked *
* by a user; <code>false</code> otherwise. * @return
* <code>true</code> if the task is locked by a user;
* <code>false</code> otherwise.
*
* *
*/ */
public boolean isLocked() { public boolean isLocked() {
return (getLockedUser() != null); return (getLockedUser() != null);
} }
/** /**
* Retrieves the user who locked the process. * Retrieves the user who locked the process.
*
* @return the user who locked the process. * @return the user who locked the process.
* *
*/ */
@ -513,13 +540,13 @@ public class UserTask extends Task implements Assignable {
return m_userLock; return m_userLock;
} }
/** /**
* Assigns a user to this task. You must use the * Assigns a user to this task. You must use the
* <code>save</code> method to make it persistant. * <code>save</code> method to make it persistant.
* *
* @param user an active user of the system * @param user an active user of the system
**/ *
*/
public void assignUser(User user) { public void assignUser(User user) {
Collection users = getInternalAssignedUsers(); Collection users = getInternalAssignedUsers();
if (!users.contains(user)) { if (!users.contains(user)) {
@ -529,13 +556,13 @@ public class UserTask extends Task implements Assignable {
} }
} }
/** /**
* Assigns a group of users to this task. Use the * Assigns a group of users to this task. Use the
* <code>save</code> method to make it persistent. * <code>save</code> method to make it persistent.
* *
* @param group the group to assign * @param group the group to assign
**/ *
*/
public void assignGroup(Group group) { public void assignGroup(Group group) {
add(ASSIGNED_GROUPS, group); add(ASSIGNED_GROUPS, group);
Collection groups = getInternalAssignedGroups(); Collection groups = getInternalAssignedGroups();
@ -543,31 +570,30 @@ public class UserTask extends Task implements Assignable {
//group.addToAssociation(getAssignedGroupAssociation()); //group.addToAssociation(getAssignedGroupAssociation());
} }
/** /**
* Removes a user from the assignment list. * Removes a user from the assignment list.
* *
* @param user the user to be removed * @param user the user to be removed
**/ *
*/
public void removeUser(User user) { public void removeUser(User user) {
Collection users = getInternalAssignedUsers(); Collection users = getInternalAssignedUsers();
users.remove(user); users.remove(user);
user.removeFromAssociation(getAssignedUserAssociation()); user.removeFromAssociation(getAssignedUserAssociation());
} }
/** /**
* Removes a group from assignment list. * Removes a group from assignment list.
* *
* @param group the group to be removed * @param group the group to be removed
**/ *
*/
public void removeGroup(Group group) { public void removeGroup(Group group) {
Collection groups = getInternalAssignedGroups(); Collection groups = getInternalAssignedGroups();
groups.remove(group); groups.remove(group);
group.removeFromAssociation(getAssignedGroupAssociation()); group.removeFromAssociation(getAssignedGroupAssociation());
} }
/** /**
* Removes all groups assigned to this task. * Removes all groups assigned to this task.
* *
@ -587,22 +613,25 @@ public class UserTask extends Task implements Assignable {
/** /**
* Tests whether any user or group is assigned to this task. * Tests whether any user or group is assigned to this task.
* *
* @return <code>true</code> if a user or a group is assigned; * @return
* <code>true</code> if a user or a group is assigned;
* <code>false</code> otherwise. * <code>false</code> otherwise.
* *
**/ *
*/
public boolean isAssigned() { public boolean isAssigned() {
return ((getAssignedUserCount() > 0) || (getAssignedGroupCount() > 0)); return ((getAssignedUserCount() > 0) || (getAssignedGroupCount() > 0));
} }
/** /**
* Tests whether a specificv user is assigned to this task. * Tests whether a specificv user is assigned to this task.
* *
* @param user a system user * @param user a system user
* @return <code>true</code> if the user is assigned to this task; * @return
* <code>true</code> if the user is assigned to this task;
* <code>false</code> otherwise. * <code>false</code> otherwise.
**/ *
*/
public boolean isAssigned(User user) { public boolean isAssigned(User user) {
Collection users = getInternalAssignedUsers(); Collection users = getInternalAssignedUsers();
Iterator userItr = users.iterator(); Iterator userItr = users.iterator();
@ -620,14 +649,15 @@ public class UserTask extends Task implements Assignable {
return false; return false;
} }
/** /**
* Tests whether a specific group is assigned to this task. * Tests whether a specific group is assigned to this task.
* *
* @param group a system group * @param group a system group
* @return <code>true</code> if the group is actually assigned * @return
* to this task; <code>false</code> otherwise. * <code>true</code> if the group is actually assigned to this task;
**/ * <code>false</code> otherwise.
*
*/
public boolean isAssigned(Group group) { public boolean isAssigned(Group group) {
Collection groups = getInternalAssignedGroups(); Collection groups = getInternalAssignedGroups();
Iterator groupItr = groups.iterator(); Iterator groupItr = groups.iterator();
@ -645,22 +675,22 @@ public class UserTask extends Task implements Assignable {
return false; return false;
} }
/** /**
* Gets the number of assigned users. * Gets the number of assigned users.
* *
* @return the number of assigned users. * @return the number of assigned users.
**/ *
*/
public int getAssignedUserCount() { public int getAssignedUserCount() {
return getInternalAssignedUsers().size(); return getInternalAssignedUsers().size();
} }
/** /**
* Gets number of assigned groups. * Gets number of assigned groups.
* *
* @return the number of assigned groups. * @return the number of assigned groups.
**/ *
*/
public int getAssignedGroupCount() { public int getAssignedGroupCount() {
return getInternalAssignedGroups().size(); return getInternalAssignedGroups().size();
} }
@ -669,23 +699,23 @@ public class UserTask extends Task implements Assignable {
* Returns all assigned users. * Returns all assigned users.
* *
* @return an iterator over all assigned users. * @return an iterator over all assigned users.
**/ *
*/
public Iterator getAssignedUsers() { public Iterator getAssignedUsers() {
return getInternalAssignedUsers().iterator(); return getInternalAssignedUsers().iterator();
} }
/** /**
* Return the internal Collection of users * Return the internal Collection of users assigned to this task.
* assigned to this task.
* *
* @return a Collection of all assigned users * @return a Collection of all assigned users
* @see java.util.Collection * @see java.util.Collection
**/ *
*/
private Collection getInternalAssignedUsers() { private Collection getInternalAssignedUsers() {
if (m_assignedUsers == null) { if (m_assignedUsers == null) {
UserCollection uc = new UserCollection UserCollection uc = new UserCollection(getAssignedUserAssociation().
(getAssignedUserAssociation().cursor()); cursor());
m_assignedUsers = new HashSet(); m_assignedUsers = new HashSet();
while (uc.next()) { while (uc.next()) {
@ -695,20 +725,21 @@ public class UserTask extends Task implements Assignable {
return m_assignedUsers; return m_assignedUsers;
} }
/** /**
* Return the internal Collection of groups * Return the internal Collection of groups assigned to this task.
* assigned to this task.
* *
* @return a Collection of all assigned groups * @return a Collection of all assigned groups
* @see java.util.Collection * @see java.util.Collection
**/ *
*/
private Collection getInternalAssignedGroups() { private Collection getInternalAssignedGroups() {
if (m_assignedGroups == null) { if (m_assignedGroups == null) {
m_assignedGroups = new HashSet(); m_assignedGroups = new HashSet();
GroupCollection gc = new GroupCollection GroupCollection gc =
(getAssignedGroupAssociation().cursor()) {}; new GroupCollection(getAssignedGroupAssociation().
cursor()) {
};
while (gc.next()) { while (gc.next()) {
m_assignedGroups.add(gc.getDomainObject()); m_assignedGroups.add(gc.getDomainObject());
} }
@ -716,22 +747,22 @@ public class UserTask extends Task implements Assignable {
return m_assignedGroups; return m_assignedGroups;
} }
/** /**
* Returns the assigned groups. * Returns the assigned groups.
* *
* @return an iterator over all assigned groups. * @return an iterator over all assigned groups.
**/ *
*/
public Iterator getAssignedGroups() { public Iterator getAssignedGroups() {
return getInternalAssignedGroups().iterator(); return getInternalAssignedGroups().iterator();
} }
/** /**
* Retrieve the assigned users datacollection. * Retrieve the assigned users datacollection.
* *
* @return the assigned user data collection * @return the assigned user data collection
**/ *
*/
protected DataAssociation getAssignedUserAssociation() { protected DataAssociation getAssignedUserAssociation() {
return (DataAssociation) get(ASSIGNED_USERS); return (DataAssociation) get(ASSIGNED_USERS);
} }
@ -744,7 +775,8 @@ public class UserTask extends Task implements Assignable {
* Retrieve the assigned group data collection. * Retrieve the assigned group data collection.
* *
* @return the assigned group data collection. * @return the assigned group data collection.
**/ *
*/
protected DataAssociation getAssignedGroupAssociation() { protected DataAssociation getAssignedGroupAssociation() {
return (DataAssociation) get(ASSIGNED_GROUPS); return (DataAssociation) get(ASSIGNED_GROUPS);
} }
@ -756,7 +788,8 @@ public class UserTask extends Task implements Assignable {
/** /**
* Removes all assigned users from this task. * Removes all assigned users from this task.
* *
**/ *
*/
private void clearUser() { private void clearUser() {
Collection users = getInternalAssignedUsers(); Collection users = getInternalAssignedUsers();
Collection users2 = new HashSet(); Collection users2 = new HashSet();
@ -775,7 +808,8 @@ public class UserTask extends Task implements Assignable {
/** /**
* Removes all assigned groups from this task. * Removes all assigned groups from this task.
* *
**/ *
*/
private void clearGroup() { private void clearGroup() {
Collection groups = getInternalAssignedGroups(); Collection groups = getInternalAssignedGroups();
HashSet groups2 = new HashSet(); HashSet groups2 = new HashSet();
@ -792,7 +826,6 @@ public class UserTask extends Task implements Assignable {
} }
/** /**
* Deletes this user task. (persistent operation). * Deletes this user task. (persistent operation).
*/ */
@ -806,14 +839,15 @@ public class UserTask extends Task implements Assignable {
super.delete(); super.delete();
} }
/** /**
* Tests whether the task is overdue. * Tests whether the task is overdue.
* *
* @return <code>true</code> if the task is overdue; * @return
* <code>true</code> if the task is overdue;
* <code>false</code> otherwise. * <code>false</code> otherwise.
* *
**/ *
*/
public boolean isOverdue() { public boolean isOverdue() {
Date now = new Date(); Date now = new Date();
Date dueDate = getDueDate(); Date dueDate = getDueDate();
@ -823,33 +857,34 @@ public class UserTask extends Task implements Assignable {
return (dueDate.getTime() < now.getTime()); return (dueDate.getTime() < now.getTime());
} }
/** /**
* Specifies who is sending out the notification. * Specifies who is sending out the notification.
* *
* @param party the sender in email messages * @param party the sender in email messages
* @return the previous sender if one exists otherwise null * @return the previous sender if one exists otherwise null
* *
**/ *
*/
public Party setNotificationSender(Party party) { public Party setNotificationSender(Party party) {
Party previousSender = getInternalNotificationSender(); Party previousSender = getInternalNotificationSender();
setInternalNotificationSender(party); setInternalNotificationSender(party);
return previousSender; return previousSender;
} }
/** /**
* Returns the notification sender. * Returns the notification sender.
*
* @return the notification sender. * @return the notification sender.
* *
**/ *
*/
public Party getNotificationSender() { public Party getNotificationSender() {
return getInternalNotificationSender(); return getInternalNotificationSender();
} }
/** /**
* Method used internally to set the notification sender in the persistence layer. * Method used internally to set the notification sender in the persistence
* layer.
* *
* @param party the party sending the notification * @param party the party sending the notification
*/ */
@ -862,9 +897,9 @@ public class UserTask extends Task implements Assignable {
} }
} }
/** /**
* Method used internally to get the notification sender in the persistence layer. * Method used internally to get the notification sender in the persistence
* layer.
* *
* @return party, party sending out the notification. * @return party, party sending out the notification.
* *
@ -879,13 +914,14 @@ public class UserTask extends Task implements Assignable {
} }
try { try {
m_notificationSender = (Party) DomainObjectFactory.newInstance m_notificationSender =
(new OID(Party.BASE_DATA_OBJECT_TYPE,senderID)); (Party) DomainObjectFactory.newInstance(new OID(
Party.BASE_DATA_OBJECT_TYPE, senderID));
Assert.exists Assert.exists(m_notificationSender, "Party m_notificationSender");
(m_notificationSender, "Party m_notificationSender");
} catch (DataObjectNotFoundException e) { } catch (DataObjectNotFoundException e) {
throw new UncheckedWrapperException("Error restoring notification sender", throw new UncheckedWrapperException(
"Error restoring notification sender",
e); e);
} }
} }
@ -893,15 +929,15 @@ public class UserTask extends Task implements Assignable {
return m_notificationSender; return m_notificationSender;
} }
/** /**
* Clones a user task. Deep cloning (except the primary * Clones a user task. Deep cloning (except the primary key). Clones class
* key). Clones class and db-row The cloned copy is saved to * and db-row The cloned copy is saved to persistent storage before
* persistent storage before returning. * returning.
* *
* @return a clone of the user task definition. * @return a clone of the user task definition.
* *
**/ *
*/
public Object clone() { public Object clone() {
UserTask taskClone = new UserTask(); UserTask taskClone = new UserTask();
copyAttributes(taskClone); copyAttributes(taskClone);
@ -911,13 +947,13 @@ public class UserTask extends Task implements Assignable {
/** /**
* Exports the attributes of this domain object. * Exports the attributes of this domain object.
* *
* @param task the domain object to which this method copies the * @param task the domain object to which this method copies the attributes
* attributes of this object * of this object
* */ *
*/
protected void copyAttributes(UserTask task) { protected void copyAttributes(UserTask task) {
super.copyAttributes(task); super.copyAttributes(task);
task.setDuration(new Duration task.setDuration(new Duration(0, 0, getDuration().getDuration()));
(0,0,getDuration().getDuration()));
Collection assignedUsers = getInternalAssignedUsers(); Collection assignedUsers = getInternalAssignedUsers();
User user; User user;
@ -945,7 +981,9 @@ public class UserTask extends Task implements Assignable {
public static Party getAlertsSender() { public static Party getAlertsSender() {
String email = s_conf.getAlertsSender(); String email = s_conf.getAlertsSender();
if (email == null) { return null; } if (email == null) {
return null;
}
PartyCollection parties = Party.retrieveAllParties(); PartyCollection parties = Party.retrieveAllParties();
parties.addEqualsFilter("primaryEmail", email.toLowerCase()); parties.addEqualsFilter("primaryEmail", email.toLowerCase());
try { try {
@ -960,11 +998,11 @@ public class UserTask extends Task implements Assignable {
} }
/** /**
* Whether or not to send alerts. * Whether or not to send alerts. Subclasses can override this to send
* Subclasses can override this to send alerts based on * alerts based on different criteria, but they should always check
* different criteria, but they should always check super.sendAlerts() * super.sendAlerts() as well.
* as well. *
**/ */
protected boolean sendAlerts(String operation) { protected boolean sendAlerts(String operation) {
return s_conf.isAlertsEnabled(); return s_conf.isAlertsEnabled();
} }