19 package org.turro.vendor;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.servlet.ServletContext;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import org.amic.util.date.CheckDate;
29 import org.turro.contacts.Address;
30 import org.turro.crm.db.CrmPU;
31 import org.turro.crm.entity.SaleAction;
32 import org.turro.crm.entity.Vendor;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.direct.DirectContent;
35 import org.turro.elephant.direct.DirectContents;
36 import org.turro.elephant.direct.IDirectContent;
37 import org.turro.elephant.security.IUser;
38 import org.turro.ical.Calendar;
39 import org.turro.jpa.Dao;
40 import org.turro.plugin.contacts.IContact;
54 public boolean itsMe(String
id) {
55 return getIdentifier().equals(
id);
59 public boolean myTurn(HttpServletRequest request) {
64 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
65 String vendorId = request.getParameter(
"ses");
68 "select v from Vendor v where v.idContact = ?",
69 new Object[] { vendorId.substring(3) });
71 List<SaleAction> list = dao.getResultList(
72 "select sa from SaleAction sa " +
73 "where sa.vendorProspect.vendor = ? " +
74 "and sa.actionDate >= ?",
75 new Object[] { vendor,
new CheckDate().addYears(-1).getDate() });
76 for(SaleAction sa : list) {
77 cal.
addEvent(sa.getActionDate(), sa.getFinalDate(),
78 sa.getVendorProspect().getSaleProspect().getCustomer().getName(),
80 if(sa.getStatus() == SaleAction.SA_DONE) {
82 }
else if(sa.getStatus() == SaleAction.SA_CANCELLED) {
86 cal.
setOrganizer(vendor.getName(), vendor.getIContact().getConnector(IUser.CONNECTOR_EMAIL));
87 for(IContact c : sa.getIAttendees()) {
88 cal.
addAttendee(c.getName(), c.getConnector(IUser.CONNECTOR_EMAIL));
90 Address address = sa.getAddress();
91 if(address !=
null) cal.
addLocation(address.getAddressString());
94 response.setContentType(
"text/calendar");
95 response.setCharacterEncoding(
"UTF-8");
96 cal.
output(response.getOutputStream());
97 }
catch (IOException ex) {
98 Logger.getLogger(VendorCalendar.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
static boolean isYourTurn(HttpServletRequest request, String path)
void addEvent(Date start, Date end, String name, String description)
void addLocation(String address)
void output(OutputStream out)
void addAttendee(String name, String email)
void setOrganizer(String name, String email)
Object getSingleResult(WhereClause wc)
static String getIdentifier()
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
boolean myTurn(HttpServletRequest request)