Package com.dotmarketing.portlets.calendar.model

Examples of com.dotmarketing.portlets.calendar.model.Event


    //Retrieving the current user
    User user = userAPI.getLoggedInUser(request);
    boolean respectFrontendRoles = true;

    Event ev = eventAPI.find(identifier, false, user, respectFrontendRoles);
    if(ev.isLive()){
      try
        contAPI.unpublish(ev, user, respectFrontendRoles)
      } catch (DotSecurityException e) {
        eventDeleteErrors.add(e.getLocalizedMessage());
      } catch (DotDataException e) {
        eventDeleteErrors.add(e.getLocalizedMessage());
      } catch (DotContentletStateException e) {
        eventDeleteErrors.add(e.getLocalizedMessage());
      }
      try{
        contAPI.archive(ev, user, respectFrontendRoles);
      }catch(Exception e){
        eventDeleteErrors.add(e.getLocalizedMessage());
      }
    }else if(!ev.isArchived()){
      try{
        contAPI.archive(ev, user, respectFrontendRoles);
      }catch(Exception e){
        eventDeleteErrors.add(e.getLocalizedMessage());
      }
    }
   
    try{
      if(ev.isArchived()){
        contAPI.delete(ev, user, respectFrontendRoles);
      }
    }catch(Exception e){ 
      eventDeleteErrors.add(e.getLocalizedMessage());
    }finally{
View Full Code Here


    Contentlet contentlet = new Contentlet();
    if(InodeUtils.isSet(inodeStr)){     
      contentlet = contAPI.find(inodeStr, user, false);
    }
    if(InodeUtils.isSet(contentlet.getInode())) {
      Event ev = null;
      try{
        ev = eventAPI.find(contentlet.getIdentifier(), false, user, respectFrontendRoles);
      }catch(Exception e){
        disconnectEventErrors.add(e.getLocalizedMessage());
      }finally{
        if(disconnectEventErrors.size() > 0){
          eventMap.put("disconnectEventErrors", disconnectEventErrors);               
        }       
      }

      if(ev!=null){
        Date startDate = null;
        Date endDate = null;

        try{
          if(UtilMethods.isSet(startDateStr)){
            String date = dateFormat.format(dateFormat2.parse(startDateStr));
            startDate =  dateFormat.parse(date);
          }
          if(UtilMethods.isSet(endDateStr)){
            String date = dateFormat.format(dateFormat2.parse(endDateStr));
            endDate = dateFormat.parse(date);
          }

        }catch(java.text.ParseException pe){
          disconnectEventErrors.add(pe.getLocalizedMessage());
        }finally{
          if(disconnectEventErrors.size() > 0){
            eventMap.put("disconnectEventErrors", disconnectEventErrors);               
          }       
        }

        if(startDate!=null && endDate!=null){
          Calendar originalStartDate = Calendar.getInstance();
          Calendar originalEndDate = Calendar.getInstance();
          Calendar newStartDate = Calendar.getInstance();
          Calendar newEndDate = Calendar.getInstance();
          originalStartDate.setTime(ev.getStartDate());
          originalEndDate.setTime(ev.getEndDate());
          newStartDate.setTime(startDate);
          newEndDate.setTime(endDate);

          originalStartDate.set(Calendar.YEAR, newStartDate.get(Calendar.YEAR));
          originalStartDate.set(Calendar.MONTH, newStartDate.get(Calendar.MONTH));
          originalStartDate.set(Calendar.DAY_OF_MONTH, newStartDate.get(Calendar.DAY_OF_MONTH));

          originalEndDate.set(Calendar.YEAR, newEndDate.get(Calendar.YEAR));
          originalEndDate.set(Calendar.MONTH, newEndDate.get(Calendar.MONTH));
          originalEndDate.set(Calendar.DAY_OF_MONTH, newEndDate.get(Calendar.DAY_OF_MONTH));

          Event newEvent = null;

          try{
            boolean autoCom = false;
            try{
              autoCom =   DbConnectionFactory.getConnection().getAutoCommit();
            }
            catch(Exception e){
              throw new DotDataException(e.getMessage());
            }
            if(autoCom){
              HibernateUtil.startTransaction();
            }
            newEvent = eventAPI.disconnectEvent(ev, user, originalStartDate.getTime(), originalEndDate.getTime());
            eventMap = newEvent.getMap();
            //Loading categories
            List<Map<String, Object>> categoryMaps = new ArrayList<Map<String,Object>>();
            List<Category> eventCategories =  categoryAPI.getParents(newEvent, user, respectFrontendRoles);
            for(Category cat : eventCategories) {
              categoryMaps.add(cat.getMap());
            }
            eventMap.put("categories", categoryMaps);
            eventMap.put("rating", RatingAPI.getAverageRating(newEvent.getIdentifier()));
            eventMap.put("votes", RatingAPI.getRatingVotesNumber(newEvent.getIdentifier()));
            eventMap.put("hasReadPermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
            eventMap.put("hasWritePermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
            eventMap.put("hasPublishPermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
            eventMap.put("readPermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
            eventMap.put("writePermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
            eventMap.put("publishPermission", perAPI.doesUserHavePermission(newEvent, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
            eventMap.put("isDisconnected", UtilMethods.isSet(newEvent.getDisconnectedFrom()));
            CommentsWebAPI cAPI = new CommentsWebAPI();
            cAPI.setUser(user);
            cAPI.setRespectFrontendRoles(respectFrontendRoles);
            eventMap.put("commentsCount", cAPI.getCommentsCount(newEvent.getInode()));
            HibernateUtil.commitTransaction();
          }catch(Exception e){
            HibernateUtil.rollbackTransaction();
            disconnectEventErrors.add(e.getLocalizedMessage());
          }finally{
View Full Code Here

 
 
  @Override
  protected Event find(String identifier, boolean live, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
   
    Event ev = null;
   
    Language lang = languageAPI.getDefaultLanguage();
    Contentlet cont = conAPI.findContentletByIdentifier(identifier, live, lang.getId(), user, respectFrontendRoles);
    if(cont == null)
      return null;
View Full Code Here

  }
 
  @Override
  protected Event findbyInode(String inode, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
   
    Event ev = null;
   
    Contentlet cont = conAPI.find(inode, user, respectFrontendRoles);
    if(cont == null)
      return null;
    ev = convertToEvent(cont);
View Full Code Here

    }
  }

  protected Event convertToEvent (Contentlet cont) throws DotDataException, DotContentletStateException, DotSecurityException {
   
    Event ev = new Event();
    ev.setStructureInode(getEventStructure().getInode());
    Map<String, Object> contentletMap = cont.getMap();
    conAPI.copyProperties(ev, contentletMap);   
    return ev;
  }
View Full Code Here

        for(Contentlet con: hits) { 
          recurrentInodes.add(con.getInode());
        }
        List<Contentlet> recurrentConts = conAPI.findContentlets(recurrentInodes);
        for(Contentlet con : recurrentConts) {
          Event event = convertToEvent(con);

          if(UtilMethods.isSet(event.getDisconnectedFrom())){
            String disconnectedId = event.getDisconnectedFrom();
            Event baseEvent = null;
            try{
              baseEvent = find(disconnectedId, false, APILocator.getUserAPI().getSystemUser(), false);
            }catch(Exception e){}
            if(baseEvent==null){
              event.setDisconnectedFrom("");
View Full Code Here

      }
           
      int count = 0;
      while (!startDate.getTime().after(end.getTime())) {
     
        Event recurrentEvent = copyEvent(baseEvent);
          recurrentEvent.setRecurrenceDatesToIgnore("");

        if(count>0 && UtilMethods.isSet(baseEvent.getDisconnectedFrom())){
          recurrentEvent.setDisconnectedFrom("");
          }
        switch(baseEvent.getOccursEnum()) {
        case DAILY:
         
          //build the start time/date
          GregorianCalendar cal = new GregorianCalendar();
          cal.setTime(startDate.getTime());
          cal.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
          cal.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
          cal.set(Calendar.SECOND, startTime.get(Calendar.SECOND));
          recurrentEvent.setStartDate(cal.getTime());
 
          //build end date/time
          cal = new GregorianCalendar();
          cal.setTime(startDate.getTime());
          cal.set(Calendar.HOUR_OF_DAY, endTime.get(Calendar.HOUR_OF_DAY));
          cal.set(Calendar.MINUTE, endTime.get(Calendar.MINUTE));
          cal.set(Calendar.SECOND, endTime.get(Calendar.SECOND));
          recurrentEvent.setEndDate(cal.getTime());
         
       
          //if this event is after, die
          if (cal.getTime().after(end.getTime()))
            break;
         
          GregorianCalendar calToIgnore = new GregorianCalendar();
          calToIgnore.setTime(recurrentEvent.getStartDate());
          calToIgnore.set(Calendar.SECOND, 0);
          calToIgnore.set(Calendar.MILLISECOND, 0);
         
          if(!datesToIgnore.contains(String.valueOf(calToIgnore.getTime().getTime()))){
            GregorianCalendar firstOccurence = new GregorianCalendar();
            firstOccurence.setTime(baseEvent.getStartDate());
            long numberOfDays = (long)( (calToIgnore.getTime().getTime() - firstOccurence.getTime().getTime()) / (1000 * 60 * 60 * 24));
            if(numberOfDays%interval==0){
              recurrentEvent.setStartDate(calToIgnore.getTime());
              //http://jira.dotmarketing.net/browse/DOTCMS-6303
              recurrentEvent.setIdentifier(RecurrenceUtil.getRecurrentEventIdentifier(recurrentEvent));
              events.add(recurrentEvent);
              count++;   
            }
          }
         
          //add to start date
          startDate.add(Calendar.DAY_OF_MONTH, 1);
       
          break;
  
        case WEEKLY:
         
          if (baseEvent.getRecurrenceDaysOfWeek() == null) {
            break;
          }
          for (int j = 1; j < 8; j++) {
            int x = startDate.get(Calendar.DAY_OF_WEEK);
            if (baseEvent.getRecurrenceDaysOfWeek().contains(String.valueOf(x))) {
             
              recurrentEvent = copyEvent(baseEvent);
              recurrentEvent.setRecurrenceDatesToIgnore("");
              if(count>0 && UtilMethods.isSet(baseEvent.getDisconnectedFrom())){
                recurrentEvent.setDisconnectedFrom("");
                }
             
              //build the start time/date
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime());
              cal.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
              recurrentEvent.setStartDate(cal.getTime());
 
              //build end date/time
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime());
              cal.set(Calendar.HOUR_OF_DAY, endTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, endTime.get(Calendar.MINUTE));
              recurrentEvent.setEndDate(cal.getTime());
 
           
              //if this event is after, die
              if (cal.getTime().after(end.getTime()))
                break;
             
              calToIgnore = new GregorianCalendar();
              calToIgnore.setTime(recurrentEvent.getStartDate());
              calToIgnore.set(Calendar.SECOND, 0);
              calToIgnore.set(Calendar.MILLISECOND, 0);
                         
              if(!datesToIgnore.contains(String.valueOf(calToIgnore.getTime().getTime()))){
               
                GregorianCalendar baseCal = new GregorianCalendar();
                baseCal.setTime(baseEvent.getStartDate());   
                GregorianCalendar firstOccurence = calculateFirstOccurence(baseEvent);
                GregorianCalendar c1 = baseCal;
                GregorianCalendar c2 = new GregorianCalendar();
                c2.setTime(recurrentEvent.getStartDate());
                long numberOfWeeks = 0;
                for( long i=1; ; i++ ) {          
                  c1.add( Calendar.WEEK_OF_YEAR, 1 );    
                  if( c1.after(c2) ) {
                    numberOfWeeks =  i-1;
                    break;
                  }
                }
                if(baseCal.get(Calendar.WEEK_OF_YEAR)<firstOccurence.get(Calendar.WEEK_OF_YEAR)){
                  c1 = firstOccurence;
                  c2 = new GregorianCalendar();
                  c2.setTime(recurrentEvent.getStartDate());;
                  for( long i=1; ; i++ ) {          
                    c1.add( Calendar.WEEK_OF_YEAR, 1 );  
                    if( c1.after(c2) )  {
                      numberOfWeeks =  i-1;
                      break;
                    }
                  }
                }
                if((numberOfWeeks%(interval)==0)){
                  recurrentEvent.setStartDate(calToIgnore.getTime());
                  //http://jira.dotmarketing.net/browse/DOTCMS-6303
                  recurrentEvent.setIdentifier(RecurrenceUtil.getRecurrentEventIdentifier(recurrentEvent));
                  events.add(recurrentEvent);
                  count++;   
                }
              }
             
             
             
            }
            startDate.add(Calendar.DAY_OF_MONTH, 1);
          }
          break;
         
        case MONTHLY:

            while (true) {

              recurrentEvent = copyEvent(baseEvent);
              recurrentEvent.setRecurrenceDatesToIgnore("");
              if(count>0 && UtilMethods.isSet(baseEvent.getDisconnectedFrom())){
                recurrentEvent.setDisconnectedFrom("");
              }

              boolean isInRange = false;
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime())
              cal.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));

              int weekOfMonth = baseEvent.getRecurrenceWeekOfMonth();
              int dayOfWeek = baseEvent.getRecurrenceDayOfWeek();
              if(UtilMethods.isSet(baseEvent.getRecurrenceDayOfMonth()) && (baseEvent.getRecurrenceDayOfMonth() > 0)){
                GregorianCalendar baseCal = new GregorianCalendar();
                baseCal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
                baseCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
                GregorianCalendar baseCal2 = new GregorianCalendar();
                baseCal2.set(Calendar.MONTH, cal.get(Calendar.MONTH));
                baseCal2.set(Calendar.YEAR, cal.get(Calendar.YEAR));

                int dayOfMonth = baseEvent.getRecurrenceDayOfMonth();
                baseCal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                while(baseCal.get(Calendar.MONTH) != baseCal2.get(Calendar.MONTH)){
                  baseCal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                  dayOfMonth--;
                }

                weekOfMonth = baseCal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
                dayOfWeek = baseCal.get(Calendar.DAY_OF_WEEK);
              }
             
              GregorianCalendar auxCal = new GregorianCalendar();
              auxCal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
              auxCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
              auxCal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
              if(weekOfMonth==1){
                auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);     
              }else{
                if(weekOfMonth<=4){
                  auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekOfMonth);
                }else{
                  auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);                        
                }
              }
              recurrentEvent.setStartDate(cal.getTime());
              if((cal.get(Calendar.WEEK_OF_MONTH)==auxCal.get(Calendar.WEEK_OF_MONTH)) && (cal.get(Calendar.DAY_OF_WEEK)==auxCal.get(Calendar.DAY_OF_WEEK))){
             
                GregorianCalendar baseCal = new GregorianCalendar();
                baseCal.setTime(baseEvent.getStartDate());   
                GregorianCalendar firstOccurence = calculateFirstOccurence(baseEvent);
                      int numberOfMonths =((baseCal.get(Calendar.YEAR) - auxCal.get(Calendar.YEAR)) * 12) + (baseCal.get(Calendar.MONTH) - auxCal.get(Calendar.MONTH));
                  if(baseCal.get(Calendar.MONTH)<firstOccurence.get(Calendar.MONTH)){
                    numberOfMonths =((firstOccurence.get(Calendar.YEAR) - auxCal.get(Calendar.YEAR)) * 12) + (firstOccurence.get(Calendar.MONTH) - auxCal.get(Calendar.MONTH));      
                }
                  if(numberOfMonths==0 || (numberOfMonths%interval==0)){
                   isInRange = true;
                }
             
              }
             
           

              //build end date/time
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime());
              cal.set(Calendar.HOUR_OF_DAY, endTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, endTime.get(Calendar.MINUTE));
              recurrentEvent.setEndDate(cal.getTime());

              //if this event is after, die
              if (cal.getTime().after(end.getTime()))
                break;


              if(isInRange){
                calToIgnore = new GregorianCalendar();
                calToIgnore.setTime(recurrentEvent.getStartDate());
                calToIgnore.set(Calendar.SECOND, 0);
                calToIgnore.set(Calendar.MILLISECOND, 0);
                if(!datesToIgnore.contains(String.valueOf(calToIgnore.getTime().getTime()))){
                  recurrentEvent.setStartDate(calToIgnore.getTime());
                  //http://jira.dotmarketing.net/browse/DOTCMS-6303
                  recurrentEvent.setIdentifier(RecurrenceUtil.getRecurrentEventIdentifier(recurrentEvent));
                  events.add(recurrentEvent);
                  count++;
                }
              }
              startDate.add(Calendar.DAY_OF_MONTH, 1);
            }


            //add to start date

            startDate.add(Calendar.MONTH, interval);
         
         
            break;
        case ANNUALLY:
         
           while (true) {
              recurrentEvent = copyEvent(baseEvent);
              recurrentEvent.setRecurrenceDatesToIgnore("");
              if(count>0 && UtilMethods.isSet(baseEvent.getDisconnectedFrom())){
                recurrentEvent.setDisconnectedFrom("");
                }
             
              boolean isInRange = false;
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime())
              cal.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));

              int weekOfMonth = baseEvent.getRecurrenceWeekOfMonth();
              int dayOfWeek = baseEvent.getRecurrenceDayOfWeek();
              int monthOfYear = baseEvent.getRecurrenceMonthOfYear()>0?baseEvent.getRecurrenceMonthOfYear()-1:0;
              if(UtilMethods.isSet(baseEvent.getRecurrenceDayOfMonth()) && (baseEvent.getRecurrenceDayOfMonth() > 0)){
                GregorianCalendar baseCal = new GregorianCalendar();
                baseCal.set(Calendar.MONTH, monthOfYear);
                baseCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
                GregorianCalendar baseCal2 = new GregorianCalendar();
                baseCal2.set(Calendar.MONTH, monthOfYear);
                baseCal2.set(Calendar.YEAR, cal.get(Calendar.YEAR));

                int dayOfMonth = baseEvent.getRecurrenceDayOfMonth();
                baseCal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                while(baseCal.get(Calendar.MONTH) != baseCal2.get(Calendar.MONTH)){
                  baseCal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                  dayOfMonth--;
                }

                weekOfMonth = baseCal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
                dayOfWeek = baseCal.get(Calendar.DAY_OF_WEEK);
              }
              GregorianCalendar auxCal = new GregorianCalendar();
                        auxCal.set(Calendar.MONTH, monthOfYear);
                        auxCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
                        auxCal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
                        if(weekOfMonth==1){
                          auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);     
                        }else{
                          if(weekOfMonth<=4){
                            auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekOfMonth);
                          }else{
                            auxCal.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);                        
                          }
                        }
              recurrentEvent.setStartDate(cal.getTime());
              if((cal.get(Calendar.MONTH)==auxCal.get(Calendar.MONTH)) && (cal.get(Calendar.WEEK_OF_MONTH)==auxCal.get(Calendar.WEEK_OF_MONTH)) && (cal.get(Calendar.DAY_OF_WEEK)==auxCal.get(Calendar.DAY_OF_WEEK))){
               
                GregorianCalendar baseCal = new GregorianCalendar();
                baseCal.setTime(baseEvent.getStartDate());   
                GregorianCalendar firstOccurence = calculateFirstOccurence(baseEvent);
                      int numberOfYears =(baseCal.get(Calendar.YEAR) - auxCal.get(Calendar.YEAR));
                  if(baseCal.get(Calendar.YEAR)<firstOccurence.get(Calendar.YEAR)){
                    numberOfYears =(firstOccurence.get(Calendar.YEAR) - auxCal.get(Calendar.YEAR));
                }
                  if(numberOfYears==0 || (numberOfYears%interval==0)){
                   isInRange = true;
                }
                 
              }

              //build end date/time
              cal = new GregorianCalendar();
              cal.setTime(startDate.getTime());
              cal.set(Calendar.HOUR_OF_DAY, endTime.get(Calendar.HOUR_OF_DAY));
              cal.set(Calendar.MINUTE, endTime.get(Calendar.MINUTE));
              recurrentEvent.setEndDate(cal.getTime());

              //if this event is after, die
              if (cal.getTime().after(end.getTime()))
                break;


              if(isInRange){
                calToIgnore = new GregorianCalendar();
                calToIgnore.setTime(recurrentEvent.getStartDate());
                calToIgnore.set(Calendar.SECOND, 0);
                calToIgnore.set(Calendar.MILLISECOND, 0);
                if(!datesToIgnore.contains(String.valueOf(calToIgnore.getTime().getTime()))){
                  recurrentEvent.setStartDate(calToIgnore.getTime());
                  //http://jira.dotmarketing.net/browse/DOTCMS-6303
                  recurrentEvent.setIdentifier(RecurrenceUtil.getRecurrentEventIdentifier(recurrentEvent));
                  events.add(recurrentEvent);
                  count++;
                }
              }
              startDate.add(Calendar.DAY_OF_MONTH, 1);
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.calendar.model.Event

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.