001: package com.technoetic.xplanner.actions;
002:
003: import java.util.Iterator;
004: import java.util.Properties;
005: import javax.servlet.ServletException;
006: import javax.servlet.http.HttpServletRequest;
007: import javax.servlet.http.HttpServletResponse;
008:
009: import org.apache.struts.action.ActionForm;
010: import org.apache.struts.action.ActionForward;
011: import org.apache.struts.action.ActionMapping;
012:
013: import com.technoetic.xplanner.XPlannerProperties;
014: import com.technoetic.xplanner.DomainSpecificPropertiesFactory;
015: import com.technoetic.xplanner.db.hibernate.ThreadSession;
016: import com.technoetic.xplanner.domain.Attribute;
017: import com.technoetic.xplanner.domain.DomainObject;
018: import com.technoetic.xplanner.domain.Person;
019: import com.technoetic.xplanner.domain.Project;
020: import com.technoetic.xplanner.domain.repository.ObjectRepository;
021: import com.technoetic.xplanner.forms.AbstractEditorForm;
022: import com.technoetic.xplanner.forms.ProjectEditorForm;
023: import com.technoetic.xplanner.wiki.WikiFormat;
024:
025: /**
026: * Created by IntelliJ IDEA.
027: * User: sg897500
028: * Date: Dec 2, 2004
029: * Time: 3:26:08 PM
030: * To change this template use File | Settings | File Templates.
031: */
032: public class EditProjectAction extends EditObjectAction {
033:
034: DomainSpecificPropertiesFactory domainSpecificPropertiesFactory;
035:
036: public void setDomainSpecificPropertiesFactory(
037: DomainSpecificPropertiesFactory domainSpecificPropertiesFactory) {
038: this .domainSpecificPropertiesFactory = domainSpecificPropertiesFactory;
039: }
040:
041: protected ActionForward doExecute(ActionMapping actionMapping,
042: ActionForm actionForm, HttpServletRequest request,
043: HttpServletResponse reply) throws Exception {
044: ProjectEditorForm pef = (ProjectEditorForm) actionForm;
045: //DEBT Move the notification management actions to its own action: NotificationAction.add() & delete().
046: if (pef.getAction() != null
047: && (pef.getAction().equals(
048: UpdateTimeNotificationReceivers.ADD) || pef
049: .getAction().equals(
050: UpdateTimeNotificationReceivers.DELETE))) {
051:
052: //return actionMapping.findForward("project/notification");
053: return new ActionForward("/do/edit/project/notification",
054: false);
055: }
056: return super .doExecute(actionMapping, actionForm, request,
057: reply); //To change body of overridden methods use File | Settings | File Templates.
058: }
059:
060: protected void saveForm(AbstractEditorForm form,
061: ActionMapping actionMapping, HttpServletRequest request)
062: throws Exception {
063: String oid = form.getOid();
064: Class objectClass = getObjectType(actionMapping, request);
065: ObjectRepository objectRepository = getRepository(objectClass);
066: DomainObject object;
067: String action = form.getAction();
068: if (action.equals(UPDATE_ACTION)) {
069: object = (DomainObject) objectRepository.load(Integer
070: .parseInt(oid));
071: populateObject(request, object, form);
072: objectRepository.update(object);
073: } else if (action.equals(CREATE_ACTION)) {
074: object = createObject(objectClass, request, form,
075: objectRepository);
076: } else {
077: throw new ServletException("Unknown editor action: "
078: + action);
079: }
080: setTargetObject(request, object);
081: form.setAction(null);
082: saveOrUpdateAttribute(XPlannerProperties.WIKI_URL_KEY, object,
083: ((ProjectEditorForm) form).getWikiUrl());
084: saveOrUpdateAttribute(
085: XPlannerProperties.SEND_NOTIFICATION_KEY,
086: object,
087: (new Boolean(((ProjectEditorForm) form)
088: .isSendingMissingTimeEntryReminderToAcceptor()))
089: .toString());
090: saveOrUpdateAttribute(WikiFormat.ESCAPE_BRACKETS_KEY, object,
091: (new Boolean(((ProjectEditorForm) form)
092: .isOptEscapeBrackets())).toString());
093: }
094:
095: private void saveOrUpdateAttribute(String attributeName,
096: DomainObject object, String currentAttributeValue)
097: throws Exception {
098: String attr = object.getAttribute(attributeName);
099: if (attr != null) {
100: Attribute attribute = new Attribute(object.getId(),
101: attributeName, currentAttributeValue);
102: ThreadSession.get().update(attribute);
103: } else {
104: String existingAttributeValue = new XPlannerProperties()
105: .getProperty(attributeName);
106: if (existingAttributeValue != null
107: && !existingAttributeValue
108: .equals(currentAttributeValue)
109: && !currentAttributeValue.equals("")) {
110: Attribute attribute = new Attribute(object.getId(),
111: attributeName, currentAttributeValue);
112: ThreadSession.get().save(attribute);
113: }
114: if (existingAttributeValue == null
115: && !currentAttributeValue.equals("")) {
116: Attribute attribute = new Attribute(object.getId(),
117: attributeName, currentAttributeValue);
118: ThreadSession.get().save(attribute);
119: }
120: }
121: }
122:
123: protected void populateForm(AbstractEditorForm form,
124: DomainObject object) throws Exception {
125: super .populateForm(form, object);
126: ProjectEditorForm pef = (ProjectEditorForm) form;
127:
128: Properties properties = domainSpecificPropertiesFactory
129: .createPropertiesFor(object);
130: pef.setWikiUrl(properties.getProperty(
131: XPlannerProperties.WIKI_URL_KEY, "http://"));
132: pef.setSendemail(Boolean.valueOf(
133: properties.getProperty(
134: XPlannerProperties.SEND_NOTIFICATION_KEY,
135: "true")).booleanValue());
136: pef.setOptEscapeBrackets(Boolean.valueOf(
137: properties.getProperty(WikiFormat.ESCAPE_BRACKETS_KEY,
138: "true")).booleanValue());
139: Project project = (Project) object;
140: ProjectEditorForm projectEditorForm = (ProjectEditorForm) form;
141: Iterator itr = project.getNotificationReceivers().iterator();
142: while (itr.hasNext()) {
143: Person person = (Person) itr.next();
144: projectEditorForm.addPersonInfo("" + person.getId(), person
145: .getUserId(), person.getInitials(), person
146: .getName());
147: }
148:
149: }
150: }
|