diff --git a/applications/workeffort/config/WorkEffortUiLabels.xml b/applications/workeffort/config/WorkEffortUiLabels.xml
index 9b12148c72..99d243c441 100644
--- a/applications/workeffort/config/WorkEffortUiLabels.xml
+++ b/applications/workeffort/config/WorkEffortUiLabels.xml
@@ -288,16 +288,16 @@
The workEffortTypeId equal to
+ * PUBLISH_PROPS.
+ * @return A net.fortuna.ical4j.model.Calendar instance, or null
+ * if workEffortId is invalid.
+ * @throws GenericEntityException
+ */
public static net.fortuna.ical4j.model.Calendar getICalendar(GenericDelegator delegator, String workEffortId) throws GenericEntityException {
- GenericValue calendarProperties = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
- if (calendarProperties == null || !"PUBLISH_PROPS".equals(calendarProperties.get("workEffortTypeId"))) {
+ 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(calendarProperties);
+ net.fortuna.ical4j.model.Calendar calendar = makeCalendar(publishProperties);
ComponentList components = calendar.getComponents();
- ListList of work efforts related to a work effort calendar
+ * publish point.List includes:
List of related work efforts
+ * @throws GenericEntityException
+ */
public static ListComponent instance based on a work effort.
+ * If the work effort is a task, then a VToDo is returned,
+ * otherwise a VEvent is returned.
+ *
+ * @param workEffort
+ * @return A VToDo or VEvent instance
+ * @throws GenericEntityException
+ */
+ public static Component makeCalendarComponent(GenericValue workEffort) throws GenericEntityException {
GenericDelegator delegator = workEffort.getDelegator();
String workEffortId = workEffort.getString("workEffortId");
PropertyList eventProps = new PropertyList();
@@ -104,7 +143,7 @@ public class ICalendarWorker {
if (workEffort.getTimestamp("lastModifiedDate") != null) {
eventProps.add(new LastModified(new DateTime(workEffort.getTimestamp("lastModifiedDate"))));
}
- eventProps.add(new XProperty(workEffortIdPropName, workEffort.getString("workEffortId")));
+ eventProps.add(new Uid(uidPrefix.concat(workEffortId)));
eventProps.add(new Summary(workEffort.getString("workEffortName")));
Status eventStatus = statusMap.get(workEffort.getString("currentStatusId"));
if (eventStatus != null) {
@@ -126,9 +165,9 @@ public class ICalendarWorker {
// paramList.add(new XParameter(partyIdPropName, partyValue.getString("partyId")));
try {
if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
- eventProps.add(new Organizer(paramList, ""));
+ eventProps.add(new Organizer("CN:".concat(partyName)));
} else {
- eventProps.add(new Attendee(paramList, ""));
+ eventProps.add(new Attendee("CN:".concat(partyName)));
}
} catch (Exception e) {}
}
@@ -152,20 +191,42 @@ public class ICalendarWorker {
if (workEffort.getString("description") != null) {
eventProps.add(new Description(workEffort.getString("description")));
}
- return new VEvent(eventProps);
+ 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;
}
+ /** Returns a new net.fortuna.ical4j.model.Calendar 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);
- if (workEffort.get("description") != null) {
- propList.add(new Description(workEffort.getString("description")));
- } else {
- propList.add(new Description(workEffort.getString("workEffortName")));
- }
// TODO: Get time zone from publish properties value
java.util.TimeZone tz = java.util.TimeZone.getDefault();
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
@@ -173,4 +234,72 @@ public class ICalendarWorker {
calendar.getComponents().add(timezone.getVTimeZone());
return calendar;
}
+
+ /** Converts WorkEffortEventReminder entities to VAlarm
+ * instances, and adds them to a ComponentList.
+ *
+ * @param workEffort The work effort to get the event reminders for
+ * @param alarms The ComponentList that will contain the
+ * VAlarm 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();
+ ListWorkEffortEventReminder entity to a
+ * VAlarm instance.
+ *
+ * @param workEffortEventReminder
+ * @return A VAlarm 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));
+ } 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 alarm;
+ }
}
diff --git a/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java b/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
index 35538a5121..a090d502ae 100644
--- a/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
+++ b/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
@@ -49,6 +49,8 @@ import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityJoinOperator;
import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelField;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.security.Security;
import org.ofbiz.service.DispatchContext;
@@ -747,6 +749,9 @@ public class WorkEffortServices {
return ServiceUtil.returnError("Error while retrieving work effort event reminders: " + e);
}
for (GenericValue reminder : eventReminders) {
+ if (UtilValidate.isEmpty(reminder.get("contactMechId"))) {
+ continue;
+ }
int repeatCount = reminder.get("repeatCount") == null ? 0 : reminder.getLong("repeatCount").intValue();
int currentCount = reminder.get("currentCount") == null ? 0 : reminder.getLong("currentCount").intValue();
GenericValue workEffort = null;
@@ -780,11 +785,11 @@ public class WorkEffortServices {
if (temporalExpression != null) {
eventDateTime = temporalExpression.first(cal).getTime();
Date reminderDateTime = null;
- long recurrenceOffset = reminder.get("recurrenceOffset") == null ? 0 : reminder.getLong("recurrenceOffset").longValue();
+ long reminderOffset = reminder.get("reminderOffset") == null ? 0 : reminder.getLong("reminderOffset").longValue();
if (reminderStamp == null) {
- if (recurrenceOffset != 0) {
+ if (reminderOffset != 0) {
cal.setTime(eventDateTime);
- TimeDuration duration = TimeDuration.fromLong(recurrenceOffset);
+ TimeDuration duration = TimeDuration.fromLong(reminderOffset);
duration.addToCalendar(cal);
reminderDateTime = cal.getTime();
} else {
@@ -802,11 +807,11 @@ public class WorkEffortServices {
} else {
cal.setTime(reminderDateTime);
Date newReminderDateTime = null;
- if (recurrenceOffset != 0) {
- TimeDuration duration = TimeDuration.fromLong(-recurrenceOffset);
+ if (reminderOffset != 0) {
+ TimeDuration duration = TimeDuration.fromLong(-reminderOffset);
duration.addToCalendar(cal);
cal.setTime(temporalExpression.next(cal).getTime());
- duration = TimeDuration.fromLong(recurrenceOffset);
+ duration = TimeDuration.fromLong(reminderOffset);
duration.addToCalendar(cal);
newReminderDateTime = cal.getTime();
} else {
@@ -876,4 +881,30 @@ public class WorkEffortServices {
// TODO: Other contact mechanism types
Debug.logWarning("Invalid event reminder contact mech, workEffortId = " + reminder.get("workEffortId") + ", contactMechId = " + reminder.get("contactMechId"), module);
}
+
+ /** Migrate work effort event reminders.
+ * @param ctx
+ * @param context
+ * @return
+ */
+ @SuppressWarnings("deprecation")
+ public static Map