19 package org.turro.dossier.command;
21 import java.util.Date;
22 import javax.servlet.ServletContext;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.turro.string.ObjectString;
26 import org.turro.action.Actions;
27 import org.turro.action.Contacts;
28 import org.turro.auth.Authentication;
29 import org.turro.collections.KeyValueMap;
30 import org.turro.dossier.db.DossierPU;
31 import org.turro.dossier.entity.Issue;
32 import org.turro.dossier.entity.IssueComment;
33 import org.turro.dossier.entity.IssueParticipant;
34 import org.turro.dossier.entity.IssueParticipantRole;
35 import org.turro.dossier.issue.IssueMail;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.context.IConstructor;
38 import org.turro.elephant.direct.DirectContent;
39 import org.turro.elephant.direct.DirectContents;
40 import org.turro.elephant.direct.IDirectContent;
41 import org.turro.i18n.I_;
42 import org.turro.jpa.Dao;
43 import org.turro.plugin.contacts.IContact;
44 import org.turro.registry.ChangeCategory;
45 import org.turro.registry.Changes;
46 import org.turro.registry.UniqueString;
52 @DirectContent(identifier=
"issue-action")
60 public boolean itsMe(String
id) {
61 return getIdentifier().equals(
id);
65 public boolean myTurn(HttpServletRequest request) {
70 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
74 String type = map.get(
"type");
75 if(
"assist".equals(type)) {
76 processAssist(map, constructor);
77 }
else if(
"unassist".equals(type)) {
78 processUnassist(map, constructor);
87 private Dao getDao() {
96 private void processAssist(KeyValueMap map, IConstructor constructor) {
97 IContact contact = Contacts.getContactById(map.get(
"contact"));
98 if(contact !=
null && contact.isWebUser()) {
99 Long issueId = (Long) ObjectString.parseString(map.get(
"issue"), Long.class,
true);
100 Issue issue = getDao().find(Issue.class, issueId);
101 if(issue !=
null && !issue.getIssueParticipants().isParticipant(contact)) {
102 Changes changes =
new Changes();
103 ChangeCategory cc =
new ChangeCategory(4, I_.get(
"Participants"));
104 IssueParticipant ip = issue.addParticipant(contact, IssueParticipantRole.ISSUE_ASSISTANT);
105 changes.addChange(
new UniqueString(cc, I_.byKey(ip.getRole().toString()), ip.getName()));
106 IssueComment ic =
new IssueComment();
108 ic.setModification(
new Date());
109 ic.setIContact(Authentication.getIContact());
110 ic.setComment(changes.getChangesString());
114 ic.setProcessed(
true);
115 issue.getComments().add(ic);
116 issue = getDao().saveObject(issue);
117 new IssueMail(changes, issue, 0, 0, 0).sendMail();
122 private void processUnassist(KeyValueMap map, IConstructor constructor) {
123 IContact contact = Contacts.getContactById(map.get(
"contact"));
124 if(contact !=
null && contact.isWebUser()) {
125 Long issueId = (Long) ObjectString.parseString(map.get(
"issue"), Long.class,
true);
126 Issue issue = getDao().find(Issue.class, issueId);
128 IssueParticipant ip = issue.removeParticipant(contact, IssueParticipantRole.ISSUE_ASSISTANT);
130 Changes changes =
new Changes();
131 ChangeCategory cc =
new ChangeCategory(4, I_.get(
"Participants"));
132 changes.addChange(
new UniqueString(cc, I_.byKey(ip.getRole().toString()),
"-" + ip.getName()));
133 IssueComment ic =
new IssueComment();
135 ic.setModification(
new Date());
136 ic.setIContact(Authentication.getIContact());
137 ic.setComment(changes.getChangesString());
141 ic.setProcessed(
true);
142 issue.getComments().add(ic);
143 issue = getDao().saveObject(issue);
144 new IssueMail(changes, issue, 0, 0, 0).sendMail();
static KeyValueMap getRightNowAction(IConstructor constructor)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
boolean myTurn(HttpServletRequest request)
static String getIdentifier()
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static boolean isYourTurn(HttpServletRequest request, String path)