CalendarEvent.java

  1. /**
  2.  * Copyright (C) 2003-2007 eXo Platform SAS.
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Affero General Public License
  6.  * as published by the Free Software Foundation; either version 3
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, see<http://www.gnu.org/licenses/>.
  16.  **/
  17. package org.exoplatform.calendar.service;

  18. import org.exoplatform.calendar.model.Event;
  19. import org.exoplatform.container.ExoContainer;
  20. import org.exoplatform.container.ExoContainerContext;
  21. import org.exoplatform.services.security.ConversationState;

  22. import java.util.Arrays;
  23. import java.util.Collection;
  24. import java.util.Date;
  25. import java.util.Objects;

  26. /**
  27.  * Created by The eXo Platform SARL Author : Hung Nguyen Quang
  28.  * hung.nguyen@exoplatform.com Jul 11, 2007
  29.  *
  30.  * @deprecated This is only used in old Calendar Service API methods.
  31.  */
  32. @Deprecated
  33. public class CalendarEvent extends Event {
  34.  
  35.   private String               calType         = "0";

  36.   public static final CalendarEvent NULL_OBJECT = new CalendarEvent();


  37.   public CalendarEvent() {
  38.     super();
  39.   }

  40.   public CalendarEvent(CalendarEvent evt) {
  41.     super(evt);
  42.     this.calType = evt.calType;
  43.   }

  44.   public void setCalType(String calType) {
  45.     this.calType = calType;
  46.   }

  47.   public String getCalType() {
  48.     return calType;
  49.   }

  50.   /**
  51.    * use getLastModified instead
  52.    */
  53.   @Deprecated
  54.   public Date getLastUpdatedTime() {
  55.     return new Date(getLastModified());    
  56.   }

  57.   /**
  58.    * use setLastModified instead
  59.    */
  60.   @Deprecated
  61.   public void setLastUpdatedTime(Date lastUpdatedTime) {
  62.     long last = 0;
  63.     if (lastUpdatedTime != null) {
  64.       last = lastUpdatedTime.getTime();      
  65.     }
  66.     setLastModified(last);
  67.   }

  68.   /**
  69.    * @deprecated
  70.    * @see #setExceptionIds(Collection)
  71.    * @param excludeId the excludeId to set
  72.    */
  73.   public void setExcludeId(String[] excludeId) {
  74.     if (excludeId != null) {
  75.       setExclusions(Arrays.asList(excludeId));
  76.     } else {
  77.       setExclusions(null);
  78.     }
  79.   }

  80.   /**
  81.    * @deprecated
  82.    * @see #getExceptionIds()
  83.    * @return the excludeId
  84.    */
  85.   public String[] getExcludeId() {
  86.     Collection<String> collection = getExclusions();
  87.     if (collection != null) {
  88.       return collection.toArray(new String[collection.size()]);
  89.     }
  90.     return null;
  91.   }

  92.   /**
  93.    * This method will set the collection of excluded event's id to the collection
  94.    * @param ids a collection of id with string type
  95.    */
  96.   public void setExceptionIds(Collection<String> ids){
  97.     setExclusions(ids);
  98.   }

  99.   /**
  100.    * This method will return all id excluded event id
  101.    * @return collection of excluded event's id
  102.    */
  103.   public Collection<String> getExceptionIds(){
  104.     return getExclusions();
  105.   }
  106.  
  107.   /**
  108.    * This method will add more excluded id to existed collection
  109.    * @param id a single id want to add to exited excluded collection
  110.    */
  111.   public void addExceptionId(String id){
  112.     addExclusion(id);
  113.   }

  114.   public void removeExceptionId(String id){
  115.     removeExclusion(id);
  116.   }

  117.   public static CalendarEvent build(Event evt) {
  118.     CalendarEvent calEvent = new CalendarEvent();

  119.     calEvent.setId(evt.getId());
  120.     calEvent.setCalendarId(evt.getCalendarId());
  121.     calEvent.setSummary(evt.getSummary());
  122.     calEvent.setEventCategoryId(evt.getEventCategoryId());
  123.     calEvent.setEventCategoryName(evt.getEventCategoryName());
  124.     calEvent.setLocation(evt.getLocation());
  125.     calEvent.setTaskDelegator(evt.getTaskDelegator());
  126.     calEvent.setRepeatType(evt.getRepeatType());
  127.     calEvent.setDescription(evt.getDescription());
  128.     calEvent.setFromDateTime(evt.getFromDateTime());
  129.     calEvent.setToDateTime(evt.getToDateTime());
  130.     calEvent.setEventType(evt.getEventType());
  131.     calEvent.setPriority(evt.getPriority());
  132.     calEvent.setPrivate(evt.isPrivate());
  133.     calEvent.setEventState(evt.getEventState());
  134.     calEvent.setSendOption(evt.getSendOption());
  135.     calEvent.setMessage(evt.getMessage());
  136.     calEvent.setLastModified(evt.getLastModified());
  137.     calEvent.setInvitation(evt.getInvitation());
  138.     calEvent.setParticipant(evt.getParticipant());
  139.     calEvent.setParticipantStatus(evt.getParticipantStatus());
  140.     calEvent.setReminders(evt.getReminders());
  141.     calEvent.setAttachment(evt.getAttachment());

  142.     calEvent.setRecurrenceId(evt.getRecurrenceId());
  143.     calEvent.setIsExceptionOccurrence(evt.getIsExceptionOccurrence());
  144.     calEvent.setRepeatUntilDate(evt.getRepeatUntilDate());
  145.     calEvent.setRepeatCount(evt.getRepeatCount());
  146.     calEvent.setOriginalReference(evt.getOriginalReference());
  147.     calEvent.setRepeatInterval(evt.getRepeatInterval());
  148.     calEvent.setExceptionIds(evt.getExclusions());
  149.     calEvent.setRepeatByDay(evt.getRepeatByDay());
  150.     calEvent.setRepeatByMonthDay(evt.getRepeatByMonthDay());
  151.     calEvent.setActivityId(evt.getActivityId());
  152.    
  153.     ExoContainer container = ExoContainerContext.getCurrentContainer();
  154.     if (container != null) {
  155.       String username = ConversationState.getCurrent().getIdentity().getUserId();
  156.       CalendarService service = container.getComponentInstanceOfType(CalendarService.class);
  157.       try {
  158.         calEvent.setCalType(String.valueOf(service.getTypeOfCalendar(username, calEvent.getCalendarId())));
  159.       } catch (Exception e) {        
  160.       }      
  161.     }
  162.     return calEvent;
  163.   }

  164.   @Override
  165.   public boolean equals(Object o) {
  166.     if (this == o) return true;
  167.     if (o == null || getClass() != o.getClass()) return false;
  168.     if (!super.equals(o)) return false;
  169.     CalendarEvent event = (CalendarEvent) o;
  170.     return Objects.equals(calType, event.calType);
  171.   }

  172.   @Override
  173.   public int hashCode() {
  174.     return Objects.hash(super.hashCode(), calType);
  175.   }
  176. }