[kune-commits] r1698 - in trunk/src: main/java/cc/kune/common/shared/res main/java/cc/kune/core/server main/java/cc/kune/core/server/rpc main/java/cc/kune/core/server/state main/java/cc/kune/core/shared/dto main/java/cc/kune/events/client/actions main/java/cc/kune/events/client/viewer main/java/cc/kune/events/server main/java/cc/kune/events/shared main/java/cc/kune/wave/server/kspecific main/resources test/java/cc/kune/core/server/mapper test/java/cc/kune/events/shared

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Thu Feb 23 00:49:01 CET 2012


Author: vjrj_
Date: 2012-02-23 00:48:59 +0100 (Thu, 23 Feb 2012)
New Revision: 1698

Added:
   trunk/src/main/java/cc/kune/core/server/state/StateEventContainer.java
   trunk/src/main/java/cc/kune/core/shared/dto/StateEventContainerDTO.java
   trunk/src/main/java/cc/kune/events/server/DateServerUtils.java
   trunk/src/main/java/cc/kune/events/server/EventsServerConversionUtil.java
   trunk/src/main/java/cc/kune/events/shared/EventsClientConversionUtil.java
   trunk/src/main/java/cc/kune/events/shared/EventsSharedConversionUtil.java
   trunk/src/test/java/cc/kune/events/shared/EventsServerConversionUtilTest.java
Removed:
   trunk/src/main/java/cc/kune/events/shared/EventsConversionUtil.java
   trunk/src/test/java/cc/kune/events/shared/EventsConversionUtilTest.java
Modified:
   trunk/src/main/java/cc/kune/common/shared/res/ICalConstants.java
   trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
   trunk/src/main/java/cc/kune/core/server/rpc/ContentRPC.java
   trunk/src/main/java/cc/kune/core/server/state/StateServiceDefault.java
   trunk/src/main/java/cc/kune/events/client/actions/EventAddMenuItem.java
   trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPanel.java
   trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java
   trunk/src/main/java/cc/kune/events/server/CalendarServerUtils.java
   trunk/src/main/java/cc/kune/events/shared/DateUtils.java
   trunk/src/main/java/cc/kune/wave/server/kspecific/KuneAgent.java
   trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveService.java
   trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveServiceDefault.java
   trunk/src/main/resources/dozerBeanMapping.xml
   trunk/src/test/java/cc/kune/core/server/mapper/MapperTest.java
Log:
NEW - # 158: Add a Calendar view to event tool 
http://kune.ourproject.org/issues/ticket/158

Modified: trunk/src/main/java/cc/kune/common/shared/res/ICalConstants.java
===================================================================
--- trunk/src/main/java/cc/kune/common/shared/res/ICalConstants.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/common/shared/res/ICalConstants.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -1,8 +1,10 @@
 package cc.kune.common.shared.res;
 
 public class ICalConstants {
+
   /* Note that all day events is not supported by ICalendar */
   public static final String _ALL_DAY = "ALLDAY";
+  public static final String _INTERNAL_ID = "INTERNALID";
   // VTIMEZONE ?? See: TimeZoneConstants in GWT for names and values
   public static final String DATE_TIME_END = "DTEND";
   public static final String DATE_TIME_START = "DTSTART";
@@ -10,4 +12,6 @@
   public static final String LOCATION = "LOCATION";
   public static final String ORGANIZER = "ORGANIZER";
   public static final String SUMMARY = "SUMMARY";
+  public static final String[] TOTAL_LIST = new String[] { DATE_TIME_START, DATE_TIME_END, DESCRIPTION,
+      LOCATION, ORGANIZER, SUMMARY, _ALL_DAY, _INTERNAL_ID };
 }
\ No newline at end of file

Modified: trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -59,6 +59,7 @@
 import cc.kune.core.server.rest.UserJSONService;
 import cc.kune.core.server.scheduler.CronServerTasksManager;
 import cc.kune.docs.server.DocumentServerModule;
+import cc.kune.events.server.CalendarServerUtils;
 import cc.kune.events.server.EventsServerModule;
 import cc.kune.hspace.client.ClientStatsService;
 import cc.kune.lists.client.rpc.ListsService;
@@ -121,7 +122,11 @@
         if (sessionScope != null) {
           bindScope(SessionScoped.class, sessionScope);
         }
+
+        // This can be used also in Gin:
+        // http://code.google.com/p/google-gin/issues/detail?id=60
         requestStaticInjection(KuneWaveServerUtils.class);
+        requestStaticInjection(CalendarServerUtils.class);
       }
     };
   }

Modified: trunk/src/main/java/cc/kune/core/server/rpc/ContentRPC.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/rpc/ContentRPC.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/core/server/rpc/ContentRPC.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -50,6 +50,7 @@
 import cc.kune.core.server.mapper.Mapper;
 import cc.kune.core.server.state.StateContainer;
 import cc.kune.core.server.state.StateContent;
+import cc.kune.core.server.state.StateEventContainer;
 import cc.kune.core.server.state.StateService;
 import cc.kune.core.shared.domain.AccessRol;
 import cc.kune.core.shared.domain.ContentStatus;
@@ -62,6 +63,7 @@
 import cc.kune.core.shared.dto.StateAbstractDTO;
 import cc.kune.core.shared.dto.StateContainerDTO;
 import cc.kune.core.shared.dto.StateContentDTO;
+import cc.kune.core.shared.dto.StateEventContainerDTO;
 import cc.kune.core.shared.dto.StateNoContentDTO;
 import cc.kune.domain.AccessLists;
 import cc.kune.domain.Container;
@@ -322,7 +324,9 @@
   }
 
   private StateContainerDTO mapState(final StateContainer state, final User user) {
-    final StateContainerDTO stateDTO = mapper.map(state, StateContainerDTO.class);
+    final StateContainerDTO stateDTO = state instanceof StateEventContainer ? mapper.map(state,
+        StateEventContainerDTO.class) : mapper.map(state, StateContainerDTO.class);
+
     final AccessLists groupAccessList = state.getGroup().getSocialNetwork().getAccessLists();
     for (final ContentSimpleDTO siblingDTO : stateDTO.getRootContainer().getContents()) {
       mapContentRightsInstate(user, groupAccessList, siblingDTO);

Added: trunk/src/main/java/cc/kune/core/server/state/StateEventContainer.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/state/StateEventContainer.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/state/StateEventContainer.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,21 @@
+package cc.kune.core.server.state;
+
+import java.util.List;
+import java.util.Map;
+
+public class StateEventContainer extends StateContainer {
+
+  private List<Map<String, String>> appointments;
+
+  public StateEventContainer() {
+  }
+
+  public List<Map<String, String>> getAppointments() {
+    return appointments;
+  }
+
+  public void setAppointments(final List<Map<String, String>> appointments) {
+    this.appointments = appointments;
+  }
+
+}

Modified: trunk/src/main/java/cc/kune/core/server/state/StateServiceDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/state/StateServiceDefault.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/core/server/state/StateServiceDefault.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -35,6 +35,8 @@
 import cc.kune.domain.License;
 import cc.kune.domain.Revision;
 import cc.kune.domain.User;
+import cc.kune.events.server.CalendarServerUtils;
+import cc.kune.events.shared.EventsConstants;
 import cc.kune.wave.server.kspecific.KuneWaveService;
 
 import com.google.inject.Inject;
@@ -72,7 +74,8 @@
 
   @Override
   public StateContainer create(final User userLogged, final Container container) {
-    final StateContainer state = new StateContainer();
+    final boolean isCalendar = container.getTypeId().equals(EventsConstants.TYPE_ROOT);
+    final StateContainer state = isCalendar ? new StateEventContainer() : new StateContainer();
     state.setTitle(container.getName());
     state.setTypeId(container.getTypeId());
     state.setLanguage(container.getLanguage());
@@ -82,6 +85,9 @@
     state.setAccessLists(container.getAccessLists());
     final Group group = container.getOwner();
     setCommon(state, userLogged, group, container);
+    if (isCalendar) {
+      ((StateEventContainer) state).setAppointments(CalendarServerUtils.getAppointments(container));
+    }
     return state;
   }
 

Added: trunk/src/main/java/cc/kune/core/shared/dto/StateEventContainerDTO.java
===================================================================
--- trunk/src/main/java/cc/kune/core/shared/dto/StateEventContainerDTO.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/shared/dto/StateEventContainerDTO.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,21 @@
+package cc.kune.core.shared.dto;
+
+import java.util.List;
+import java.util.Map;
+
+public class StateEventContainerDTO extends StateContainerDTO {
+
+  private List<Map<String, String>> appointments;
+
+  public StateEventContainerDTO() {
+  }
+
+  public List<Map<String, String>> getAppointments() {
+    return appointments;
+  }
+
+  public void setAppointments(final List<Map<String, String>> appointments) {
+    this.appointments = appointments;
+  }
+
+}

Modified: trunk/src/main/java/cc/kune/events/client/actions/EventAddMenuItem.java
===================================================================
--- trunk/src/main/java/cc/kune/events/client/actions/EventAddMenuItem.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/client/actions/EventAddMenuItem.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -17,7 +17,7 @@
 import cc.kune.core.shared.dto.StateContentDTO;
 import cc.kune.events.client.viewer.CalendarViewer;
 import cc.kune.events.shared.EventsConstants;
-import cc.kune.events.shared.EventsConversionUtil;
+import cc.kune.events.shared.EventsClientConversionUtil;
 
 import com.bradrydzewski.gwt.calendar.client.Appointment;
 import com.bradrydzewski.gwt.calendar.client.AppointmentStyle;
@@ -75,7 +75,7 @@
               contService.get().addNewContentWithGadgetAndState(session.getUserHash(),
                   session.getContainerState().getStateToken(),
                   EventsConstants.TYPE_MEETING_DEF_GADGETNAME, EventsConstants.TYPE_MEETING, title,
-                  title, EventsConversionUtil.toMap(appt), new AsyncCallbackSimple<StateContentDTO>() {
+                  title, EventsClientConversionUtil.toMap(appt), new AsyncCallbackSimple<StateContentDTO>() {
                     @Override
                     public void onFailure(final Throwable caught) {
                       super.onFailure(caught);

Modified: trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPanel.java
===================================================================
--- trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPanel.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPanel.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -262,8 +262,8 @@
     final String dateFormatted = fmt.format(currentDate);
     final ForIsWidget docHeader = gsArmor.getDocHeader();
     UiUtils.clear(docHeader);
-    contentTitle.setTitle(i18n.tWithNT("Events in [%s]", dateFormatted), EventsConstants.TYPE_ROOT,
-        null, false);
+    contentTitle.setTitle(i18n.t("Events in [%s]", dateFormatted), EventsConstants.TYPE_ROOT, null,
+        false);
     docHeader.add(contentTitle);
   }
 

Modified: trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -1,20 +1,26 @@
 package cc.kune.events.client.viewer;
 
 import java.util.Date;
+import java.util.Map;
 
 import javax.annotation.Nonnull;
 
 import cc.kune.common.client.actions.ui.descrip.Position;
+import cc.kune.common.client.log.Log;
 import cc.kune.common.client.notify.NotifyUser;
 import cc.kune.common.shared.i18n.I18nTranslationService;
+import cc.kune.common.shared.res.ICalConstants;
 import cc.kune.core.client.state.Session;
 import cc.kune.core.client.state.StateManager;
 import cc.kune.core.shared.dto.HasContent;
+import cc.kune.core.shared.dto.StateEventContainerDTO;
 import cc.kune.events.client.actions.CalendarOnOverMenu;
+import cc.kune.events.shared.EventsClientConversionUtil;
 import cc.kune.gspace.client.viewers.AbstractFolderViewerView;
 import cc.kune.gspace.client.viewers.FolderViewerUtils;
 
 import com.bradrydzewski.gwt.calendar.client.Appointment;
+import com.bradrydzewski.gwt.calendar.client.AppointmentStyle;
 import com.bradrydzewski.gwt.calendar.client.CalendarViews;
 import com.bradrydzewski.gwt.calendar.client.HasAppointments;
 import com.bradrydzewski.gwt.calendar.client.HasLayout;
@@ -233,6 +239,10 @@
     updateTitle();
   }
 
+  private boolean isValid(final Appointment app) {
+    return app.getStart() != null && app.getEnd() != null;
+  }
+
   @Override
   public void removeAppointment(final Appointment app) {
     getView().removeAppointment(app);
@@ -246,7 +256,22 @@
   @Override
   public void setContent(@Nonnull final HasContent state) {
     folderViewerUtils.setContent(getView(), state);
+    final StateEventContainerDTO eventState = (StateEventContainerDTO) state;
     updateMenuItems();
+    getView().clearAppointments();
+    getView().suspendLayout();
+    for (final Map<String, String> map : eventState.getAppointments()) {
+      final Appointment app = EventsClientConversionUtil.toApp(map);
+      app.setId(map.get(ICalConstants._INTERNAL_ID));
+      app.setStyle(AppointmentStyle.GREEN);
+      if (isValid(app)) {
+        getView().addAppointment(app);
+
+      } else {
+        Log.error("Appointment is not valid: " + app);
+      }
+    }
+    getView().resumeLayout();
   }
 
   @Override

Modified: trunk/src/main/java/cc/kune/events/server/CalendarServerUtils.java
===================================================================
--- trunk/src/main/java/cc/kune/events/server/CalendarServerUtils.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/server/CalendarServerUtils.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -1,5 +1,12 @@
 package cc.kune.events.server;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import net.fortuna.ical4j.model.Date;
 import net.fortuna.ical4j.model.DateTime;
 import net.fortuna.ical4j.model.Property;
@@ -12,10 +19,27 @@
 import net.fortuna.ical4j.model.property.Location;
 import net.fortuna.ical4j.model.property.Summary;
 
+import org.waveprotocol.wave.model.waveref.InvalidWaveRefException;
+import org.waveprotocol.wave.util.escapers.jvm.JavaWaverefEncoder;
+
+import cc.kune.common.shared.res.ICalConstants;
+import cc.kune.domain.Container;
+import cc.kune.domain.Content;
+import cc.kune.wave.server.kspecific.KuneWaveService;
+
 import com.bradrydzewski.gwt.calendar.client.Appointment;
+import com.google.inject.Inject;
+import com.google.wave.api.Gadget;
 
 public class CalendarServerUtils {
 
+  @Inject
+  private static EventsServerTool eventTool;
+
+  @Inject
+  private static KuneWaveService kuneWaveService;
+  private static final Logger LOG = Logger.getLogger(CalendarServerUtils.class.getName());
+
   public static VEvent from(final Appointment app) {
     // final TimeZoneRegistry registry =
     // TimeZoneRegistryFactory.getInstance().createRegistry();
@@ -52,6 +76,31 @@
     return event;
   }
 
+  public static List<Map<String, String>> getAppointments(final Container container) {
+    final List<Map<String, String>> list = new ArrayList<Map<String, String>>();
+    for (final Content content : container.getContents()) {
+      final String waveId = content.getWaveId();
+      try {
+        final Gadget gadget = kuneWaveService.getGadget(
+            JavaWaverefEncoder.decodeWaveRefFromPath(waveId),
+            content.getAuthors().get(0).getShortName(), eventTool.getGadgetUrl());
+        final Map<String, String> gadgetProps = gadget.getProperties();
+        final HashMap<String, String> map = new HashMap<String, String>();
+        for (final String var : ICalConstants.TOTAL_LIST) {
+          final String value = gadgetProps.get(var);
+          if (value != null) {
+            map.put(var, value);
+          }
+        }
+        map.put(ICalConstants._INTERNAL_ID, content.getStateToken().toString());
+        list.add(map);
+      } catch (final InvalidWaveRefException e) {
+        LOG.log(Level.SEVERE, "Invalid Waveref", e);
+      }
+    }
+    return list;
+  }
+
   public static Appointment to(final VEvent event) {
     final Appointment app = new Appointment();
 

Added: trunk/src/main/java/cc/kune/events/server/DateServerUtils.java
===================================================================
--- trunk/src/main/java/cc/kune/events/server/DateServerUtils.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/events/server/DateServerUtils.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,26 @@
+package cc.kune.events.server;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * The Class DateUtils try to follow RFC 2445 date-time formats.
+ * 
+ * DTSTART;TZID=US-Eastern:19970714T133000 ;Local time and time ; zone reference
+ */
+public class DateServerUtils {
+
+  private static String RFC_DATE_TIME_FORMAT = "'DTSTART':yyyyMMdd'T'hhmmss";
+  // This is not tested: better use some class conversion util...
+  private static String RFC_DATE_TIME_FORMAT_TZ = "'DTSTART;TZID='z:yyyyMMdd'T'hhmmss";
+  private static SimpleDateFormat rfcDateFormat = new SimpleDateFormat(RFC_DATE_TIME_FORMAT);
+
+  public static Date toDate(final String date) throws ParseException {
+    return rfcDateFormat.parse(date);
+  }
+
+  public static String toString(final Date date) {
+    return rfcDateFormat.format(date);
+  }
+}

Added: trunk/src/main/java/cc/kune/events/server/EventsServerConversionUtil.java
===================================================================
--- trunk/src/main/java/cc/kune/events/server/EventsServerConversionUtil.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/events/server/EventsServerConversionUtil.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,44 @@
+package cc.kune.events.server;
+
+import java.text.ParseException;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import cc.kune.common.shared.res.ICalConstants;
+import cc.kune.events.shared.EventsSharedConversionUtil;
+
+import com.bradrydzewski.gwt.calendar.client.Appointment;
+
+/**
+ * The Class EventsConversionUtil is used to convert Appointments to Gadgets
+ * properties and viceversa
+ */
+public class EventsServerConversionUtil extends EventsSharedConversionUtil {
+  private static final Logger LOG = Logger.getLogger(EventsServerConversionUtil.class.getName());
+
+  public static Appointment toApp(final Map<String, String> properties) {
+    final Appointment app = EventsSharedConversionUtil.toApp(properties);
+    try {
+      final String start = properties.get(ICalConstants.DATE_TIME_START);
+      if (start != null) {
+        app.setStart(DateServerUtils.toDate(start));
+      }
+      final String end = properties.get(ICalConstants.DATE_TIME_END);
+      if (end != null) {
+        app.setEnd(DateServerUtils.toDate(end));
+      }
+    } catch (final ParseException e) {
+      LOG.log(Level.SEVERE, "Error parsing event", e);
+    }
+    return app;
+  }
+
+  public static Map<String, String> toMap(final Appointment app) {
+    final Map<String, String> properties = EventsSharedConversionUtil.toMap(app);
+    properties.put(ICalConstants.DATE_TIME_START, DateServerUtils.toString(app.getStart()));
+    properties.put(ICalConstants.DATE_TIME_END, DateServerUtils.toString(app.getEnd()));
+    return properties;
+  }
+
+}

Modified: trunk/src/main/java/cc/kune/events/shared/DateUtils.java
===================================================================
--- trunk/src/main/java/cc/kune/events/shared/DateUtils.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/shared/DateUtils.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -12,9 +12,9 @@
 public class DateUtils {
 
   private static String RFC_DATE_TIME_FORMAT = "'DTSTART':yyyyMMdd'T'hhmmss";
+  // This is not tested
   private static String RFC_DATE_TIME_FORMAT_TZ = "'DTSTART;TZID='v:yyyyMMdd'T'hhmmss";
   private static DateTimeFormat rfcDateFormat = DateTimeFormat.getFormat(RFC_DATE_TIME_FORMAT);
-  private static DateTimeFormat rfcDateFormatTz = DateTimeFormat.getFormat(RFC_DATE_TIME_FORMAT_TZ);
 
   public static Date toDate(final String date) {
     return rfcDateFormat.parse(date);

Copied: trunk/src/main/java/cc/kune/events/shared/EventsClientConversionUtil.java (from rev 1691, trunk/src/main/java/cc/kune/events/shared/EventsConversionUtil.java)
===================================================================
--- trunk/src/main/java/cc/kune/events/shared/EventsClientConversionUtil.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/events/shared/EventsClientConversionUtil.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,35 @@
+package cc.kune.events.shared;
+
+import java.util.Map;
+
+import cc.kune.common.shared.res.ICalConstants;
+
+import com.bradrydzewski.gwt.calendar.client.Appointment;
+
+/**
+ * The Class EventsConversionUtil is used to convert Appointments to Gadgets
+ * properties and viceversa
+ */
+public class EventsClientConversionUtil extends EventsSharedConversionUtil {
+
+  public static Appointment toApp(final Map<String, String> properties) {
+    final Appointment app = EventsSharedConversionUtil.toApp(properties);
+    final String start = properties.get(ICalConstants.DATE_TIME_START);
+    if (start != null) {
+      app.setStart(DateUtils.toDate(start));
+    }
+    final String end = properties.get(ICalConstants.DATE_TIME_END);
+    if (end != null) {
+      app.setEnd(DateUtils.toDate(end));
+    }
+    return app;
+  }
+
+  public static Map<String, String> toMap(final Appointment app) {
+    final Map<String, String> properties = EventsSharedConversionUtil.toMap(app);
+    properties.put(ICalConstants.DATE_TIME_START, DateUtils.toString(app.getStart()));
+    properties.put(ICalConstants.DATE_TIME_END, DateUtils.toString(app.getEnd()));
+    return properties;
+  }
+
+}

Deleted: trunk/src/main/java/cc/kune/events/shared/EventsConversionUtil.java
===================================================================
--- trunk/src/main/java/cc/kune/events/shared/EventsConversionUtil.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/events/shared/EventsConversionUtil.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -1,38 +0,0 @@
-package cc.kune.events.shared;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import cc.kune.common.shared.res.ICalConstants;
-
-import com.bradrydzewski.gwt.calendar.client.Appointment;
-
-/**
- * The Class EventsConversionUtil is used to convert Appointments to Gadgets
- * properties and viceversa
- */
-public class EventsConversionUtil {
-
-  public static Appointment toApp(final Map<String, String> properties) {
-    final Appointment app = new Appointment();
-    app.setStart(DateUtils.toDate(properties.get(ICalConstants.DATE_TIME_START)));
-    app.setEnd(DateUtils.toDate(properties.get(ICalConstants.DATE_TIME_END)));
-    app.setDescription(properties.get(ICalConstants.DESCRIPTION));
-    app.setTitle(properties.get(ICalConstants.SUMMARY));
-    app.setLocation(properties.get(ICalConstants.LOCATION));
-    app.setCreatedBy(properties.get(ICalConstants.ORGANIZER));
-    return app;
-  }
-
-  public static Map<String, String> toMap(final Appointment app) {
-    final Map<String, String> properties = new HashMap<String, String>();
-    properties.put(ICalConstants.DATE_TIME_START, DateUtils.toString(app.getStart()));
-    properties.put(ICalConstants.DATE_TIME_END, DateUtils.toString(app.getEnd()));
-    properties.put(ICalConstants.SUMMARY, app.getTitle());
-    properties.put(ICalConstants.DESCRIPTION, app.getDescription());
-    properties.put(ICalConstants.LOCATION, app.getLocation());
-    properties.put(ICalConstants.ORGANIZER, app.getCreatedBy());
-    return properties;
-  }
-
-}

Added: trunk/src/main/java/cc/kune/events/shared/EventsSharedConversionUtil.java
===================================================================
--- trunk/src/main/java/cc/kune/events/shared/EventsSharedConversionUtil.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/events/shared/EventsSharedConversionUtil.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,34 @@
+package cc.kune.events.shared;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import cc.kune.common.shared.res.ICalConstants;
+
+import com.bradrydzewski.gwt.calendar.client.Appointment;
+
+/**
+ * The Class EventsSharedConversionUtil is used to convert Appointments to
+ * Gadgets properties and viceversa
+ */
+public abstract class EventsSharedConversionUtil {
+
+  public static Appointment toApp(final Map<String, String> properties) {
+    final Appointment app = new Appointment();
+    app.setDescription(properties.get(ICalConstants.DESCRIPTION));
+    app.setTitle(properties.get(ICalConstants.SUMMARY));
+    app.setLocation(properties.get(ICalConstants.LOCATION));
+    app.setCreatedBy(properties.get(ICalConstants.ORGANIZER));
+    return app;
+  }
+
+  public static Map<String, String> toMap(final Appointment app) {
+    final Map<String, String> properties = new HashMap<String, String>();
+    properties.put(ICalConstants.SUMMARY, app.getTitle());
+    properties.put(ICalConstants.DESCRIPTION, app.getDescription());
+    properties.put(ICalConstants.LOCATION, app.getLocation());
+    properties.put(ICalConstants.ORGANIZER, app.getCreatedBy());
+    return properties;
+  }
+
+}

Modified: trunk/src/main/java/cc/kune/wave/server/kspecific/KuneAgent.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/kspecific/KuneAgent.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/wave/server/kspecific/KuneAgent.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -37,6 +37,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Singleton;
+import com.google.wave.api.Gadget;
 import com.google.wave.api.Participants;
 import com.google.wave.api.Wavelet;
 
@@ -168,6 +169,12 @@
   }
 
   @Override
+  public Gadget getGadget(final WaveRef waveletName, final String author, final URL gadgetUrl) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
   public Participants getParticipants(final WaveRef waveref, final String author) {
     // TODO Auto-generated method stub
     return null;

Modified: trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveService.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveService.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveService.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -29,6 +29,7 @@
 
 import cc.kune.common.shared.utils.SimpleArgCallback;
 
+import com.google.wave.api.Gadget;
 import com.google.wave.api.Participants;
 import com.google.wave.api.Wavelet;
 
@@ -74,6 +75,8 @@
 
   Wavelet fetchWave(WaveRef waveRef, String author);
 
+  Gadget getGadget(WaveRef waveletName, String author, URL gadgetUrl);
+
   Participants getParticipants(WaveRef waveref, String author);
 
   String getTitle(WaveRef waveName, String author);

Modified: trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveServiceDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveServiceDefault.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/java/cc/kune/wave/server/kspecific/KuneWaveServiceDefault.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -452,6 +452,21 @@
   }
 
   @Override
+  public Gadget getGadget(final WaveRef waveletName, final String author, final URL gadgetUrl) {
+    final Wavelet wavelet = fetchWave(waveletName, author);
+    final Blip rootBlip = wavelet.getRootBlip();
+    for (final Element elem : rootBlip.getElements().values()) {
+      if (elem.isGadget()) {
+        final Map<String, String> properties = elem.getProperties();
+        if (properties.get(Gadget.URL).equals(gadgetUrl.toString())) {
+          return (Gadget) elem;
+        }
+      }
+    }
+    return null;
+  }
+
+  @Override
   public Participants getParticipants(final WaveRef waveref, final String author) {
     return fetchWave(waveref, author).getParticipants();
   }

Modified: trunk/src/main/resources/dozerBeanMapping.xml
===================================================================
--- trunk/src/main/resources/dozerBeanMapping.xml	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/main/resources/dozerBeanMapping.xml	2012-02-22 23:48:59 UTC (rev 1698)
@@ -94,6 +94,16 @@
     <class-b>cc.kune.core.server.state.StateContainer</class-b>
   </mapping>
   <mapping>
+    <class-a>cc.kune.core.shared.dto.StateEventContainerDTO</class-a>
+    <class-b>cc.kune.core.server.state.StateEventContainer</class-b>
+    <field>
+      <a>appointments</a>
+      <b>appointments</b>
+      <a-hint>java.util.HashMap</a-hint>
+      <b-hint>java.util.HashMap</b-hint>
+    </field>
+  </mapping>
+  <mapping>
     <class-a>cc.kune.core.shared.dto.StateAbstractDTO</class-a>
     <class-b>cc.kune.core.server.state.StateAbstract</class-b>
   </mapping>
@@ -237,7 +247,7 @@
     <class-a> cc.kune.core.shared.dto.SocialNetworkDataDTO </class-a>
     <class-b> cc.kune.domain.SocialNetworkData </class-b>
   </mapping>
-    <mapping>
+  <mapping>
     <class-a> cc.kune.core.shared.dto.HomeStatsDTO </class-a>
     <class-b> cc.kune.core.server.stats.HomeStats </class-b>
     <field>
@@ -252,5 +262,5 @@
       <a-hint> cc.kune.core.shared.dto.ContentSimpleDTO </a-hint>
       <b-hint> cc.kune.domain.Content </b-hint>
     </field>
-    </mapping>
+  </mapping>
 </mappings>
\ No newline at end of file

Modified: trunk/src/test/java/cc/kune/core/server/mapper/MapperTest.java
===================================================================
--- trunk/src/test/java/cc/kune/core/server/mapper/MapperTest.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/test/java/cc/kune/core/server/mapper/MapperTest.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -28,6 +28,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.junit.Before;
@@ -39,6 +40,7 @@
 import cc.kune.core.server.TestHelper;
 import cc.kune.core.server.manager.GroupManager;
 import cc.kune.core.server.state.StateContent;
+import cc.kune.core.server.state.StateEventContainer;
 import cc.kune.core.shared.domain.GroupListMode;
 import cc.kune.core.shared.domain.SocialNetworkVisibility;
 import cc.kune.core.shared.domain.UserSNetVisibility;
@@ -55,6 +57,7 @@
 import cc.kune.core.shared.dto.LinkDTO;
 import cc.kune.core.shared.dto.SocialNetworkDataDTO;
 import cc.kune.core.shared.dto.StateContentDTO;
+import cc.kune.core.shared.dto.StateEventContainerDTO;
 import cc.kune.domain.BasicMimeType;
 import cc.kune.domain.Container;
 import cc.kune.domain.Content;
@@ -172,6 +175,20 @@
   }
 
   @Test
+  public void mapEventContainer() {
+    final StateEventContainer c = new StateEventContainer();
+    final HashMap<String, String> map = new HashMap<String, String>();
+    map.put("prop", "value");
+    map.put("prop2", "value2");
+    final List<Map<String, String>> list = new ArrayList<Map<String, String>>();
+    list.add(map);
+    c.setAppointments(list);
+    final StateEventContainerDTO dto = mapper.map(c, StateEventContainerDTO.class);
+    assertEquals(dto.getAppointments().get(0).get("prop"), "value");
+    assertEquals(dto.getAppointments().get(0).get("prop2"), "value2");
+  }
+
+  @Test
   public void testContentDescriptorMapping() {
     final Content d = createDefContent();
     final StateToken expectedToken = new StateToken(TESTGROUPSHORTNAME, TESTTOOL, "1", "1");

Deleted: trunk/src/test/java/cc/kune/events/shared/EventsConversionUtilTest.java
===================================================================
--- trunk/src/test/java/cc/kune/events/shared/EventsConversionUtilTest.java	2012-02-22 20:45:30 UTC (rev 1697)
+++ trunk/src/test/java/cc/kune/events/shared/EventsConversionUtilTest.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -1,28 +0,0 @@
-package cc.kune.events.shared;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Map;
-
-import org.junit.Test;
-
-import com.bradrydzewski.gwt.calendar.client.Appointment;
-import com.google.gwt.editor.client.Editor.Ignore;
-
-public class EventsConversionUtilTest extends BasicCalendarTest {
-
-  @Test
-  @Ignore
-  public void testToMap() {
-    final Appointment app = createAppointment(false);
-    final Map<String, String> map = EventsConversionUtil.toMap(app);
-    final Appointment appReConverted = EventsConversionUtil.toApp(map);
-    assertEquals(app.getStart(), appReConverted.getStart());
-    assertEquals(app.getEnd(), appReConverted.getEnd());
-    assertEquals(app.getDescription(), appReConverted.getDescription());
-    assertEquals(app.getTitle(), appReConverted.getTitle());
-    assertEquals(app.getLocation(), appReConverted.getLocation());
-    assertEquals(app.getCreatedBy(), appReConverted.getCreatedBy());
-  }
-
-}

Copied: trunk/src/test/java/cc/kune/events/shared/EventsServerConversionUtilTest.java (from rev 1691, trunk/src/test/java/cc/kune/events/shared/EventsConversionUtilTest.java)
===================================================================
--- trunk/src/test/java/cc/kune/events/shared/EventsServerConversionUtilTest.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/events/shared/EventsServerConversionUtilTest.java	2012-02-22 23:48:59 UTC (rev 1698)
@@ -0,0 +1,28 @@
+package cc.kune.events.shared;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.bradrydzewski.gwt.calendar.client.Appointment;
+import com.google.gwt.editor.client.Editor.Ignore;
+
+public class EventsServerConversionUtilTest extends BasicCalendarTest {
+
+  @Test
+  @Ignore
+  public void testToMap() {
+    final Appointment app = createAppointment(false);
+    final Map<String, String> map = EventsClientConversionUtil.toMap(app);
+    final Appointment appReConverted = EventsClientConversionUtil.toApp(map);
+    assertEquals(app.getStart(), appReConverted.getStart());
+    assertEquals(app.getEnd(), appReConverted.getEnd());
+    assertEquals(app.getDescription(), appReConverted.getDescription());
+    assertEquals(app.getTitle(), appReConverted.getTitle());
+    assertEquals(app.getLocation(), appReConverted.getLocation());
+    assertEquals(app.getCreatedBy(), appReConverted.getCreatedBy());
+  }
+
+}




More information about the kune-commits mailing list