svn commit: r787927 [2/2] - in /ofbiz/trunk/applications/workeffort: data/ entitydef/ script/org/ofbiz/workeffort/permission/ script/org/ofbiz/workeffort/workeffort/ servicedef/ src/org/ofbiz/workeffort/workeffort/ webapp/ical/WEB-INF/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r787927 [2/2] - in /ofbiz/trunk/applications/workeffort: data/ entitydef/ script/org/ofbiz/workeffort/permission/ script/org/ofbiz/workeffort/workeffort/ servicedef/ src/org/ofbiz/workeffort/workeffort/ webapp/ical/WEB-INF/

adrianc
Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java?rev=787927&r1=787926&r2=787927&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java Wed Jun 24 06:58:54 2009
@@ -19,293 +19,236 @@
 
 package org.ofbiz.workeffort.workeffort;
 
-import java.net.URISyntaxException;
-import java.sql.Timestamp;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Date;
+import java.util.Enumeration;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
-import javolution.util.FastList;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
-import net.fortuna.ical4j.model.*;
-import net.fortuna.ical4j.model.component.*;
-import net.fortuna.ical4j.model.parameter.*;
-import net.fortuna.ical4j.model.property.*;
+import javolution.util.FastList;
+import javolution.util.FastMap;
 
-import org.ofbiz.base.util.DateRange;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.TimeDuration;
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilJ2eeCompat;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.condition.EntityExpr;
-import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.service.calendar.TemporalExpression;
-import org.ofbiz.service.calendar.TemporalExpressionWorker;
-
-/** iCalendar worker class. This class uses the <a href="http://ical4j.sourceforge.net/index.html">
- * iCal4J</a> library. */
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.webapp.stats.VisitHandler;
+import org.ofbiz.webapp.webdav.PropFindHelper;
+import org.ofbiz.webapp.webdav.ResponseHelper;
+import org.ofbiz.webapp.webdav.WebDavUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/** iCalendar worker class. This class handles the WebDAV requests and
+ * delegates the calendar tasks to <code>ICalConverter</code>.
+ */
 public class ICalWorker {
     public static final String module = ICalWorker.class.getName();
     
-    protected static final ProdId prodId = new ProdId("-//Apache Open For Business//Work Effort Calendar//EN");
-    protected static final Map<String, Status> statusMap = UtilMisc.toMap("CAL_TENTATIVE", Status.VEVENT_TENTATIVE,
-            "CAL_CONFIRMED", Status.VEVENT_CONFIRMED, "CAL_CANCELLED", Status.VEVENT_CANCELLED);
-    protected static final String uidPrefix = "org-apache-ofbiz-we-";
-
-    /** Returns a calendar derived from a Work Effort calendar publish point.
-     *
-     * @param delegator
-     * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
-     * <code>PUBLISH_PROPS</code>.
-     * @return A <code>net.fortuna.ical4j.model.Calendar</code> instance, or <code>null</code>
-     * if <code>workEffortId</code> is invalid.
-     * @throws GenericEntityException
-     */
-    public static net.fortuna.ical4j.model.Calendar getICalendar(GenericDelegator delegator, String workEffortId) throws GenericEntityException {
-        GenericValue publishProperties = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
-        if (publishProperties == null || !"PUBLISH_PROPS".equals(publishProperties.get("workEffortTypeId"))) {
-            return null;
-        }
-        net.fortuna.ical4j.model.Calendar calendar = makeCalendar(publishProperties);
-        ComponentList components = calendar.getComponents();
-        List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties);
-        for (GenericValue workEffort : workEfforts) {
-            components.add(makeCalendarComponent(workEffort));
-        }
-        if (Debug.verboseOn()) {
-            try {
-                calendar.validate(true);
-                Debug.logVerbose("iCalendar passes validation", module);
-            } catch (ValidationException e) {
-                Debug.logVerbose("iCalendar fails validation: " + e, module);
-            }
-        }
-        return calendar;
-    }
-
-    /** Returns a <code>List</code> of work efforts related to a work effort calendar
-     * publish point.<p>The <code>List</code> includes:<ul><li>All public work efforts of all
-     * parties related to the publish point work effort</li><li>All public work efforts
-     * of all fixed assets related to the publish point work effort</li><li>All
-     * child work efforts of the publish point work effort</li></ul></p>
-     *
-     * @param workEffort
-     * @return A <code>List</code> of related work efforts
-     * @throws GenericEntityException
-     */
-    public static List<GenericValue> getRelatedWorkEfforts(GenericValue workEffort) throws GenericEntityException {
-        GenericDelegator delegator = workEffort.getDelegator();
-        String workEffortId = workEffort.getString("workEffortId");
-        List<GenericValue> relatedParties = EntityUtil.filterByDate(delegator.findList("WorkEffortPartyAssignment", EntityCondition.makeCondition("workEffortId", EntityOperator.EQUALS, workEffortId), null, null, null, false));
-        List<GenericValue> relatedFixedAssets = EntityUtil.filterByDate(delegator.findList("WorkEffortFixedAssetAssign", EntityCondition.makeCondition("workEffortId", EntityOperator.EQUALS, workEffortId), null, null, null, false));
-        List<GenericValue> workEfforts = FastList.newInstance();
-        List<EntityCondition> conditionList = UtilMisc.<EntityCondition>toList(
-                EntityCondition.makeCondition("scopeEnumId", EntityOperator.EQUALS, "WES_PUBLIC"),
-                EntityCondition.makeCondition("workEffortTypeId", EntityOperator.NOT_EQUAL, "PUBLISH_PROPS"));
-        EntityExpr variableExpr = EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, "");
-        conditionList.add(variableExpr);
-        EntityCondition workEffortCond = EntityCondition.makeCondition(conditionList);
-        for (GenericValue partyValue : relatedParties) {
-            variableExpr.init("partyId", EntityOperator.EQUALS, partyValue.get("partyId"));
-            workEfforts.addAll(EntityUtil.filterByDate(delegator.findList("WorkEffortAndPartyAssign", workEffortCond, null, null, null, false)));
-        }
-        for (GenericValue fixedAssetValue : relatedFixedAssets) {
-            variableExpr.init("fixedAssetId", EntityOperator.EQUALS, fixedAssetValue.get("fixedAssetId"));
-            workEfforts.addAll(delegator.findList("WorkEffort", workEffortCond, null, null, null, false));
-            workEfforts.addAll(EntityUtil.filterByDate(delegator.findList("WorkEffortAndFixedAssetAssign", workEffortCond, null, null, null, false)));
-        }
-        workEfforts.addAll(EntityUtil.filterByDate(delegator.findList("WorkEffortAssocToView", EntityCondition.makeCondition("workEffortIdFrom", EntityOperator.EQUALS, workEffortId), null, null, null, false)));
-        return WorkEffortWorker.removeDuplicateWorkEfforts(workEfforts);
-    }
-
-    /** Returns a <code>Component</code> instance based on a work effort.
-     * If the work effort is a task, then a <code>VToDo</code> is returned,
-     * otherwise a <code>VEvent</code> is returned.
-     *
-     * @param workEffort
-     * @return A <code>VToDo</code> or <code>VEvent</code> instance
-     * @throws GenericEntityException
-     */
-    public static Component makeCalendarComponent(GenericValue workEffort) throws GenericEntityException {
-        GenericDelegator delegator = workEffort.getDelegator();
-        String workEffortId = workEffort.getString("workEffortId");
-        PropertyList eventProps = new PropertyList();
-        eventProps.add(new DtStamp()); // iCalendar object created date/time
-        if (workEffort.getTimestamp("createdDate") != null) {
-            eventProps.add(new Created(new DateTime(workEffort.getTimestamp("createdDate"))));
-        }
-        if (workEffort.getTimestamp("lastModifiedDate") != null) {
-            eventProps.add(new LastModified(new DateTime(workEffort.getTimestamp("lastModifiedDate"))));
-        }
-        eventProps.add(new Uid(uidPrefix.concat(workEffortId)));
-        eventProps.add(new Summary(workEffort.getString("workEffortName")));
-        Status eventStatus = statusMap.get(workEffort.getString("currentStatusId"));
-        if (eventStatus != null) {
-            eventProps.add(statusMap.get(workEffort.getString("currentStatusId")));
-        }
-        Double durationMillis = workEffort.getDouble("estimatedMilliSeconds");
-        if (durationMillis != null) {
-            TimeDuration duration = TimeDuration.fromLong(durationMillis.longValue());
-            eventProps.add(new Duration(new Dur(duration.days(), duration.hours(), duration.minutes(), duration.seconds())));
-        }
-        List<GenericValue> relatedParties = EntityUtil.filterByDate(delegator.findList("WorkEffortPartyAssignView", EntityCondition.makeCondition("workEffortId", EntityOperator.EQUALS, workEffortId), null, null, null, false));
-        for (GenericValue partyValue : relatedParties) {
-            ParameterList paramList = null;
-            String partyName = partyValue.getString("groupName");
-            if (UtilValidate.isEmpty(partyName)) {
-                partyName = partyValue.getString("firstName") + "_" + partyValue.getString("lastName");
-            }
-            partyName = partyName.replace(" ", "_");
-            try {
-                if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
-                    Organizer organizer = new Organizer("CN:".concat(partyName));
-                    paramList = organizer.getParameters();
-                    eventProps.add(organizer);
-                } else {
-                    Attendee attendee = new Attendee("CN:".concat(partyName));
-                    paramList = attendee.getParameters();
-                    eventProps.add(attendee);
-                }
-                paramList.add(new XParameter("X-ORG-APACHE-OFBIZ-PARTY-ID", partyValue.getString("partyId")));
-            } catch (Exception e) {
-                Debug.logError(e, "Error while processing related parties: ", module);
-            }
-        }
-        DateRange range = new DateRange(workEffort.getTimestamp("estimatedStartDate"), workEffort.getTimestamp("estimatedCompletionDate"));
-        eventProps.add(new DtStart(new DateTime(range.start())));
-        if (UtilValidate.isNotEmpty(workEffort.getString("tempExprId"))) {
-            TemporalExpression tempExpr = TemporalExpressionWorker.getTemporalExpression(delegator, workEffort.getString("tempExprId"));
-            if (tempExpr != null) {
-                try {
-                    ICalRecurConverter.convert(tempExpr, eventProps);
-                } catch (Exception e) {
-                    eventProps.add(new Description("Error while converting recurrence: " + e));
-                    eventProps.add(new DtStart());
-                    eventProps.add(new DtEnd());
-                    return new VEvent(eventProps);
-                }
-            }
+    @SuppressWarnings("unchecked")
+    protected static Map<String, Object> createConversionContext(HttpServletRequest request) {
+        Map<String, Object> context = FastMap.newInstance();
+        Enumeration<String> attributeEnum = request.getAttributeNames();
+        while (attributeEnum.hasMoreElements()) {
+            String attributeName = attributeEnum.nextElement();
+            context.put(attributeName, request.getAttribute(attributeName));
+        }
+        context.put("parameters", request.getParameterMap());
+        return context;
+    }
+
+    protected static Writer getWriter(HttpServletResponse response, ServletContext context) throws IOException {
+        Writer writer = null;
+        if (UtilJ2eeCompat.useOutputStreamNotWriter(context)) {
+            ServletOutputStream ros = response.getOutputStream();
+            writer = new OutputStreamWriter(ros, "UTF-8");
         } else {
-            eventProps.add(new DtEnd(new DateTime(range.end())));
+            writer = response.getWriter();
         }
-        if (workEffort.getString("description") != null) {
-            eventProps.add(new Description(workEffort.getString("description")));
-        }
-        ComponentList alarms = null;
-        Component result = null;
-        if ("TASK".equals(workEffort.get("workEffortTypeId"))) {
-            VToDo toDo = new VToDo(eventProps);
-            alarms = toDo.getAlarms();
-            result = toDo;
-        } else {
-            VEvent event = new VEvent(eventProps);
-            alarms = event.getAlarms();
-            result = event;
-        }
-        getAlarms(workEffort, alarms);
-        if (Debug.verboseOn()) {
-            try {
-                result.validate(true);
-                Debug.logVerbose("iCalendar component passes validation", module);
-            } catch (ValidationException e) {
-                Debug.logVerbose("iCalendar component fails validation: " + e, module);
-            }
-        }
-        return result;
+        return writer;
     }
 
-    /** Returns a new <code>net.fortuna.ical4j.model.Calendar</code> instance,
-     * based on a work effort calendar publish point.
-     *
-     * @param workEffort
-     * @return
-     * @throws GenericEntityException
-     */
-    public static net.fortuna.ical4j.model.Calendar makeCalendar(GenericValue workEffort) throws GenericEntityException {
-        net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
-        PropertyList propList = calendar.getProperties();
-        propList.add(prodId);
-        propList.add(Version.VERSION_2_0);
-        propList.add(CalScale.GREGORIAN);
-        // TODO: Get time zone from publish properties value
-        java.util.TimeZone tz = java.util.TimeZone.getDefault();
-        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
-        net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(tz.getID());
-        calendar.getComponents().add(timezone.getVTimeZone());
-        return calendar;
-    }
-
-    /** Converts <code>WorkEffortEventReminder</code> entities to <code>VAlarm</code>
-     * instances, and adds them to a <code>ComponentList</code>.
-     *
-     * @param workEffort The work effort to get the event reminders for
-     * @param alarms The <code>ComponentList</code> that will contain the
-     * <code>VAlarm</code> instances
-     * @throws GenericEntityException
-     */
-    public static void getAlarms(GenericValue workEffort, ComponentList alarms) throws GenericEntityException {
-        Description description = null;
-        if (workEffort.get("description") != null) {
-            description = new Description(workEffort.getString("description"));
-        } else {
-            description = new Description(workEffort.getString("workEffortName"));
-        }
-        Summary summary = new Summary(UtilProperties.getMessage("WorkEffortUiLabels", "WorkEffortEventReminder", Locale.getDefault()));
-        GenericDelegator delegator = workEffort.getDelegator();
-        List<GenericValue> reminderList = delegator.findList("WorkEffortEventReminder", EntityCondition.makeCondition("workEffortId", EntityOperator.EQUALS, workEffort.get("workEffortId")), null, null, null, false);
-        for (GenericValue reminder : reminderList) {
-            VAlarm alarm = createAlarm(reminder);
-            PropertyList alarmProps = alarm.getProperties();
-            GenericValue contactMech = reminder.getRelatedOne("ContactMech");
-            if (contactMech != null && "EMAIL_ADDRESS".equals(contactMech.get("contactMechTypeId"))) {
-                try {
-                    alarmProps.add(new Attendee(contactMech.getString("infoString")));
-                    alarmProps.add(Action.EMAIL);
-                    alarmProps.add(summary);
-                    alarmProps.add(description);
-                } catch (URISyntaxException e) {
-                    alarmProps.add(Action.DISPLAY);
-                    alarmProps.add(new Description("Error encountered while creating iCalendar: " + e));
+    public static void handleGetRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException {
+        setupRequest(request, response);
+        String workEffortId = (String) request.getAttribute("workEffortId");
+        if (workEffortId == null) {
+            Debug.logInfo("[sendCalendar] workEffortId missing", module);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            return;
+        }
+        Debug.logInfo("[sendCalendar] workEffortId = " + workEffortId, module);
+        try {
+            String calendar = ICalConverter.getICalendar(workEffortId, createConversionContext(request));
+            if (calendar == null) {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+            response.setContentType("text/calendar");
+            response.setStatus(HttpServletResponse.SC_OK);
+            Writer writer = getWriter(response, context);
+            writer.write(calendar);
+            writer.close();
+        } catch (Exception e) {
+            Debug.logError(e, "[sendCalendar] Error while sending calendar: ", module);
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+    }
+
+    public static void handlePropFindRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException {
+        setupRequest(request, response);
+        String workEffortId = (String) request.getAttribute("workEffortId");
+        if (workEffortId == null) {
+            Debug.logInfo("[sendProperties] workEffortId missing", module);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            return;
+        }
+        Debug.logInfo("[sendProperties] workEffortId = " + workEffortId, module);
+        try {
+            Document requestDocument = WebDavUtil.getDocumentFromRequest(request);
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            UtilXml.writeXmlDocument(os, requestDocument, "UTF-8", true, true);
+            Debug.logInfo("[sendProperties] PROPFIND body:\r\n" + os.toString(), module);
+            PropFindHelper helper = new PropFindHelper(requestDocument);
+            if (!helper.isAllProp() && !helper.isPropName()) {
+                Document responseDocument = helper.getResponseDocument();
+                List<Element> supportedProps = FastList.newInstance();
+                List<Element> unSupportedProps = FastList.newInstance();
+                List<Element> propElements = helper.getFindPropsList(ResponseHelper.DAV_NAMESPACE_URI);
+                for (Element propElement : propElements) {
+                    if ("getetag".equals(propElement.getLocalName())) {
+                        Element etagElement = helper.createElementSetValue("D:getetag", String.valueOf(System.currentTimeMillis()));
+                        supportedProps.add(etagElement);
+                        continue;
+                    }
+                    if ("getlastmodified".equals(propElement.getLocalName())) {
+                        Element lmElement = helper.createElementSetValue("D:getlastmodified", WebDavUtil.formatDate(WebDavUtil.RFC1123_DATE_FORMAT, new Date()));
+                        supportedProps.add(lmElement);
+                        continue;
+                    }
+                    unSupportedProps.add(responseDocument.createElementNS(propElement.getNamespaceURI(), propElement.getTagName()));
                 }
-            } else {
-                alarmProps.add(Action.DISPLAY);
-                alarmProps.add(description);
-            }
-            if (Debug.verboseOn()) {
-                try {
-                    alarm.validate(true);
-                    Debug.logVerbose("iCalendar alarm passes validation", module);
-                } catch (ValidationException e) {
-                    Debug.logVerbose("iCalendar alarm fails validation: " + e, module);
+                Element responseElement = helper.createResponseElement();
+                responseElement.appendChild(helper.createHrefElement("/" + workEffortId + "/"));
+                if (supportedProps.size() > 0) {
+                    Element propElement = helper.createPropElement(supportedProps);
+                    responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_200));
                 }
-            }
-            alarms.add(alarm);
-        }
-    }
-
-    /** Converts a <code>WorkEffortEventReminder</code> entity to a
-     * <code>VAlarm</code> instance.
-     *
-     * @param workEffortEventReminder
-     * @return A <code>VAlarm</code> instance
-     * @throws GenericEntityException
-     */
-    public static VAlarm createAlarm(GenericValue workEffortEventReminder) {
-        VAlarm alarm = null;
-        Timestamp reminderStamp = workEffortEventReminder.getTimestamp("reminderDateTime");
-        if (reminderStamp != null) {
-            alarm = new VAlarm(new DateTime(reminderStamp));
+                if (unSupportedProps.size() > 0) {
+                    Element propElement = helper.createPropElement(unSupportedProps);
+                    responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_404));
+                }
+                Element rootElement = helper.createMultiStatusElement();
+                rootElement.appendChild(responseElement);
+                responseDocument.appendChild(rootElement);
+                os = new ByteArrayOutputStream();
+                UtilXml.writeXmlDocument(os, responseDocument, "UTF-8", true, true);
+                Debug.logInfo("[sendProperties] PROPFIND response:\r\n" + os.toString(), module);
+                ResponseHelper.prepareResponse(response, 207, "Multi-Status");
+                Writer writer = getWriter(response, context);
+                helper.writeResponse(writer);
+                writer.close();
+                return;
+            }
+        } catch (Exception e) {
+            Debug.logError(e, "PROPFIND error: ", module);
+        }
+        response.setStatus(HttpServletResponse.SC_OK);
+        response.flushBuffer();
+        
+    }
+
+    public static void handlePutRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException {
+        String contentType = request.getContentType();
+        Debug.logInfo("[updateCalendar] content type = " + contentType, module);
+        if (contentType != null && !"text/calendar".equals(contentType)) {
+            Debug.logInfo("[updateCalendar] invalid content type", module);
+            response.sendError(HttpServletResponse.SC_CONFLICT);
+            return;
+        }
+        setupRequest(request, response);
+        String workEffortId = (String) request.getAttribute("workEffortId");
+        if (workEffortId == null) {
+            Debug.logInfo("[updateCalendar] workEffortId missing", module);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            return;
+        }
+        Debug.logInfo("[updateCalendar] workEffortId = " + workEffortId, module);
+        try {
+            ICalConverter.storeCalendar(request.getInputStream(), createConversionContext(request));
+        } catch (Exception e) {
+            Debug.logError(e, "[updateCalendar] Error while updating calendar: ", module);
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+        response.setStatus(HttpServletResponse.SC_OK);
+    }
+
+    protected static void logInUser(HttpServletRequest request, HttpServletResponse response) throws GenericServiceException, GenericEntityException {
+        GenericValue userLogin = null;
+        String username = request.getParameter("USERNAME");
+        String password = request.getParameter("PASSWORD");
+        if (UtilValidate.isEmpty(username) || UtilValidate.isEmpty(password)) {
+            return;
+        }
+        if ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "username.lowercase"))) {
+            username = username.toLowerCase();
+        }
+        if ("true".equalsIgnoreCase(UtilProperties.getPropertyValue("security.properties", "password.lowercase"))) {
+            password = password.toLowerCase();
+        }
+        HttpSession session = request.getSession();
+        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+        Map<String, Object> result = dispatcher.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password, "locale", UtilHttp.getLocale(request)));
+        if (ModelService.RESPOND_SUCCESS.equals(result.get(ModelService.RESPONSE_MESSAGE))) {
+            userLogin = (GenericValue) result.get("userLogin");
+            request.setAttribute("userLogin", userLogin);
+            session.setAttribute("userLogin", userLogin);
+            VisitHandler.getVisitor(request, response);
         } else {
-            long reminderOffset = workEffortEventReminder.get("reminderOffset") == null ? 0 : workEffortEventReminder.getLong("reminderOffset").longValue();
-            TimeDuration duration = TimeDuration.fromLong(reminderOffset);
-            alarm = new VAlarm(new Dur(duration.days(), duration.hours(), duration.minutes(), duration.seconds()));
+            return;
+        }
+        GenericValue person = userLogin.getRelatedOne("Person");
+        GenericValue partyGroup = userLogin.getRelatedOne("PartyGroup");
+        if (person != null) request.setAttribute("person", person);
+        if (partyGroup != null) request.setAttribute("partyGroup", partyGroup);
+    }
+
+    protected static void setupRequest(HttpServletRequest request, HttpServletResponse response) {
+        String path = request.getPathInfo();
+        if (UtilValidate.isEmpty(path)) {
+            path = "/";
+        }
+        String workEffortId = path.substring(1);
+        if (workEffortId.contains("/")) {
+            workEffortId = workEffortId.substring(0, workEffortId.indexOf("/"));
+        }
+        if (workEffortId.length() < 1) {
+            return;
+        }
+        request.setAttribute("workEffortId", workEffortId);
+        try {
+            logInUser(request, response);
+        } catch (Exception e) {
+            Debug.logError(e, "Error while logging in user: ", module);
         }
-        return alarm;
     }
 }

Modified: ofbiz/trunk/applications/workeffort/webapp/ical/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/ical/WEB-INF/web.xml?rev=787927&r1=787926&r2=787927&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/ical/WEB-INF/web.xml (original)
+++ ofbiz/trunk/applications/workeffort/webapp/ical/WEB-INF/web.xml Wed Jun 24 06:58:54 2009
@@ -40,14 +40,8 @@
     <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description>
   </context-param>
   <context-param>
-    <param-name>serviceReaderUrls</param-name>
-    <param-value>/WEB-INF/services.xml</param-value>
-    <description>Configuration File(s) For The Service Dispatcher</description>
-  </context-param>
-  <context-param>
-    <param-name>scriptLocationPath</param-name>
-    <param-value>/WEB-INF/bsh</param-value>
-    <description>BeanShell Script Location</description>
+    <param-name>requestHandlerFactoryClass</param-name>
+    <param-value>org.ofbiz.workeffort.workeffort.ICalHandlerFactory</param-value>
   </context-param>
 
     <filter>
@@ -75,7 +69,6 @@
         <filter-name>ContextFilter</filter-name>
             <url-pattern>/*</url-pattern>
     </filter-mapping>
-
   <listener><listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class></listener>
   <listener><listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class></listener>
   <!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener interface -->
@@ -84,8 +77,8 @@
   <servlet>
     <servlet-name>iCalendarServlet</servlet-name>
     <display-name>iCalendarServlet</display-name>
-    <description>Main Control Servlet</description>
-    <servlet-class>org.ofbiz.workeffort.workeffort.ICalServlet</servlet-class>
+    <description>iCalendar WebDAV Servlet</description>
+    <servlet-class>org.ofbiz.webapp.webdav.WebDavServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>