Package org.jical

Examples of org.jical.ICalendarVEvent


   * @throws NullPointerException if sGuFellow or dtFrom or dtTo is <b>null</b>
   */
  public static ICalendar createICalendar(JDCConnection oConn, String sGuFellow,
                                          Date dtFrom, Date dtTo, String sLanguage)
    throws SQLException,IllegalArgumentException,NullPointerException {
    ICalendarVEvent oEvt;
    String sTpRoom, sOrganizerName, sOrganizerMail;
    Date dtNow = new Date();

    if (DebugFile.trace) {
      DebugFile.writeln("Begin ICalendarFactory([JDCConnection],"+sGuFellow+","+dtFrom.toString()+","+dtTo.toString()+","+sLanguage+")");
      DebugFile.incIdent();
    }

    if (sGuFellow==null) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new NullPointerException("ICalendarFactory.createICalendar() Fellow GUID parameter is required");
    }

    if (dtFrom==null || dtTo==null) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new NullPointerException("ICalendarFactory.createICalendar() Both start and end date are required");
    }

    if (dtFrom.compareTo(dtTo)>0) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new IllegalArgumentException("ICalendarFactory.createICalendar() End date cannot be prior to start date");
    }

    if (sLanguage==null) sLanguage=Locale.getDefault().getLanguage();

    Fellow oFlw = new Fellow();
    if (!oFlw.load(oConn, new Object[]{sGuFellow})) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new SQLException("Fellow "+sGuFellow+" not found at "+DB.k_fellows+" table");
    }
    DBSubset oMeetings = new DBSubset (DB.k_meetings+" m,"+DB.k_x_meeting_fellow+" f",
                                       "m."+DB.gu_meeting+",m."+DB.dt_start+",m."+DB.dt_end+","+
                                       "m."+DB.bo_private+",m."+DB.gu_writer+",m."+DB.df_before+","+
                                       "m."+DB.tp_meeting+",m."+DB.tx_meeting+",m."+DB.de_meeting+","+
                                       "m."+DB.tx_status,
                                       "f."+DB.gu_fellow+"=? AND m."+DB.gu_fellow+"=f."+DB.gu_fellow, 100);
    int iMeetings = oMeetings.load(oConn, new Object[]{sGuFellow});

    if (DebugFile.trace) DebugFile.writeln(String.valueOf(iMeetings)+" meetings found");

    DBSubset oRooms = new DBSubset(DB.k_x_meeting_room+" x,"+DB.k_rooms+" r",
                                   "r."+DB.gu_workarea+",r."+DB.tp_room+",r."+DB.nm_room+","+"r."+DB.tx_location,
                                   "x."+DB.gu_meeting+"=? AND "+"x."+DB.nm_room+"=r."+DB.nm_room,2);
    int iRooms;

    ICalendar oCal = new ICalendar();
    oCal.setProdId("JICAL");
    oCal.setVersion("2.0");
    for (int m=0; m<iMeetings; m++) {
      if (DebugFile.trace) DebugFile.writeln("Loading meeting "+oMeetings.getStringNull(7,m,""));
      oEvt = new ICalendarVEvent(oMeetings.getDate(1,m),oMeetings.getDate(2,m),
                                 oMeetings.getStringNull(8,m,""),
                                 duration(oMeetings.getDate(1,m),oMeetings.getDate(2,m)),
                                 oMeetings.getStringNull(7,m,""), null, null);
      oEvt.setSequence(0);
      oEvt.setDateStamp(dtNow);
      oEvt.setCreated(dtNow);
      oEvt.setLastModified(dtNow);
      oEvt.setEventClass(oMeetings.getShort(3,m)==0 ? "PUBLIC" : "PRIVATE");
      oEvt.setTransparency("OPAQUE");
      if (!oMeetings.isNull(6,m)) oEvt.setCategories(oMeetings.getString(6,m));
      if (oMeetings.isNull(4,m) || sGuFellow.equals(oMeetings.get(4,m))) {
        sOrganizerName = (oFlw.getStringNull(DB.tx_name,"")+" "+oFlw.getStringNull(DB.tx_surname,"")).trim();
        sOrganizerMail = oFlw.getStringNull(DB.tx_email,"");
      } else {
        ACLUser oWrt = new ACLUser();
        if (oWrt.load(oConn, new Object[]{oMeetings.get(4,m)})) {
          sOrganizerName = (oFlw.getStringNull(DB.nm_user,"")+" "+oFlw.getStringNull(DB.tx_surname1,"")+" "+oFlw.getStringNull(DB.tx_surname2,"")).trim();
          sOrganizerMail = oFlw.getStringNull(DB.tx_main_email,"");
        } else {
          sOrganizerName = (oFlw.getStringNull(DB.tx_name,"")+" "+oFlw.getStringNull(DB.tx_surname,"")).trim();
          sOrganizerMail = oFlw.getStringNull(DB.tx_email,"");
        }
      }
      if (DebugFile.trace) DebugFile.writeln("Organizer is \""+sOrganizerName+"\" <"+sOrganizerMail+">");
      oEvt.setOrganizer("CN=:\""+sOrganizerName.replace((char)34,(char)32)+"\":MAILTO:"+sOrganizerMail);
      oEvt.setUid("hipergate-"+oMeetings.getString(0,m));
      oEvt.setPriority(3);
      if (!oMeetings.isNull(9,m)) oEvt.setStatus(oMeetings.getString(9,m));
      iRooms = oRooms.load(oConn, new Object[]{oMeetings.getString(0,m)});
      if (iRooms>0) {
        if (DebugFile.trace) DebugFile.writeln(String.valueOf(iRooms)+" rooms found");
        if (sLanguage!=null)
          sTpRoom = DBLanguages.getLookUpTranslation(oConn, DB.k_rooms_lookup, oRooms.getString(1,0), DB.tp_room, sLanguage, oRooms.getString(2,0));
        else
          sTpRoom = null;
        if (null==sTpRoom) sTpRoom=""; else sTpRoom+=" ";
        oEvt.setLocation(sTpRoom+oRooms.getString(2,0)+(oRooms.isNull(3,0) ? "" : " "+oRooms.getStringNull(3,0,"")));
      }
      oCal.icalEventCollection.add(oEvt);
    } // next
    if (DebugFile.trace) {
      DebugFile.decIdent();
View Full Code Here


      throw new SQLException(ACL.getErrorMessage(ACL.USER_NOT_FOUND));
    }
    Room oRoom = new Room();
    oRoom.put(DB.gu_workarea, oFllw.getString(DB.gu_workarea));

    ICalendarVEvent oEvnt;
    ICalendarParser oPrsr = new ICalendarParser();
    ICalendar oCal = oPrsr.parse(oCalFile, sEncoding);
    Iterator oIter = oCal.icalEventCollection.iterator();
    while (oIter.hasNext()) {
      oEvnt = (ICalendarVEvent) oIter.next();
      // remove - from Mozilla UIDs
      sGuid = Gadgets.removeChar(oEvnt.getUid(),'-').trim();
      sCats = oEvnt.getCategories();
      if (sCats!=null) sCats = (Gadgets.split(sCats,','))[0];
      oMeet = new Meeting();
      if (oMeet.load(oConn, new Object[]{sGuid})) {
        // Current meeting is only modified if the one comming in the iCalendar file is newer
        if (oMeet.lastModified().compareTo(oEvnt.getLastModified()==null ? new Date() : oEvnt.getLastModified())<0) {
          oMeet.replace(DB.dt_start, oEvnt.getDateStart());
          oMeet.replace(DB.dt_end, oEvnt.getDateEnd());
          if (null==oEvnt.getEventClass())
            oMeet.replace(DB.bo_private, (short)1);
          else
            oMeet.replace(DB.bo_private, (short)(oEvnt.getEventClass().equals("PRIVATE") ? 1 : 0));
          oMeet.replace(DB.tx_status, oEvnt.getStatus());
          oMeet.replace(DB.tp_meeting, sCats);
          oMeet.replace(DB.tx_meeting, oEvnt.getSummary());
          oMeet.replace(DB.tx_meeting, oEvnt.getDescription());
          oMeet.store(oConn);
        }
      } else {
        oMeet.put(DB.gu_meeting, sGuid);
        oMeet.put(DB.gu_workarea, oFllw.getString(DB.gu_workarea));
        oMeet.put(DB.id_domain, oFllw.getInt(DB.id_domain));
        oMeet.put(DB.gu_fellow, sGuFellow);
        oMeet.put(DB.gu_writer, sGuFellow);
        oMeet.put(DB.dt_start, oEvnt.getDateStart());
        oMeet.put(DB.dt_end, oEvnt.getDateEnd());
        if (null==oEvnt.getEventClass())
          oMeet.put(DB.bo_private, (short)1);
        else
          oMeet.put(DB.bo_private, (short)(oEvnt.getEventClass().equals("PRIVATE") ? 1 : 0));
        oMeet.put(DB.tx_status, oEvnt.getStatus());
        oMeet.replace(DB.tp_meeting, sCats);
        oMeet.put(DB.tx_meeting, oEvnt.getSummary());
        oMeet.put(DB.tx_meeting, oEvnt.getDescription());
        oMeet.store(oConn);
        oMeet.setAttendant(oConn, sGuFellow);
      }
      if (oEvnt.getLocation()!=null) {
        oRoom.replace(DB.nm_room, oEvnt.getLocation());
        if (oRoom.exists(oConn))
          oMeet.setRoom(oConn, oEvnt.getLocation());
      } // fi (getLocation())
    } // wend
  } // loadCalendar
View Full Code Here

TOP

Related Classes of org.jical.ICalendarVEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.