示例#1
0
  public Map<String, Object> deleteEvent(String identifier)
      throws PortalException, SystemException, DotDataException, DotSecurityException {
    HibernateUtil.startTransaction();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();
    List<String> eventDeleteErrors = new ArrayList<String>();
    Map<String, Object> callbackData = new HashMap<String, Object>();

    // 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 {
      if (eventDeleteErrors.size() > 0) {
        callbackData.put("eventUnpublishErrors", eventDeleteErrors);
      }
    }
    if (eventDeleteErrors.size() <= 0) {
      HibernateUtil.commitTransaction();
    }

    // At this point we already deleted the content from the index on the delete call
    /*if(!contAPI.isInodeIndexed(ev.getInode())){
    	Logger.error(this, "Timed out while waiting for index to return");
    }*/

    return callbackData;
  }
示例#2
0
  public List<Map<String, Object>> findEventsByHostId(
      String hostId,
      Date fromDate,
      Date toDate,
      String[] tags,
      String[] keywords,
      String[] categoriesInodes,
      boolean live,
      boolean includeArchived,
      int offset,
      int limit)
      throws DotDataException, DotSecurityException, PortalException, SystemException {

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

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

    List<Map<String, Object>> retList = new ArrayList<Map<String, Object>>();
    List<Category> categories = new ArrayList<Category>();
    if (categoriesInodes != null) {
      for (String categoryInode : categoriesInodes) {
        Category cat = categoryAPI.find(categoryInode, user, respectFrontendRoles);
        if (cat != null) categories.add(cat);
      }
    }
    List<Event> events =
        eventAPI.find(
            hostId,
            fromDate,
            toDate,
            tags,
            keywords,
            categories,
            live,
            includeArchived,
            offset,
            limit,
            user,
            respectFrontendRoles);
    for (Event ev : events) {
      Map<String, Object> eventMap = ev.getMap();

      // Loading categories
      List<Map<String, Object>> categoryMaps = new ArrayList<Map<String, Object>>();
      List<Category> eventCategories = categoryAPI.getParents(ev, user, respectFrontendRoles);
      for (Category cat : eventCategories) {
        categoryMaps.add(cat.getMap());
      }

      // http://jira.dotmarketing.net/browse/DOTCMS-6904
      // we're missing [working, live, deleted] info

      // sometimes we mess with identifier adding recurrence info
      String origIdent = ev.getIdentifier();
      String realIdent = APILocator.getIdentifierAPI().findFromInode(ev.getInode()).getId();
      ev.setIdentifier(realIdent);
      eventMap.put("live", ev.isLive());
      eventMap.put("working", ev.isWorking());
      eventMap.put("archived", ev.isArchived());
      eventMap.put("deleted", ev.isArchived());
      eventMap.put("locked", ev.isLocked());
      ev.setIdentifier(origIdent);

      eventMap.put("categories", categoryMaps);
      eventMap.put("rating", RatingAPI.getAverageRating(ev.getIdentifier()));
      eventMap.put("votes", RatingAPI.getRatingVotesNumber(ev.getIdentifier()));
      CommentsWebAPI cAPI = new CommentsWebAPI();
      cAPI.setUser(user);
      cAPI.setRespectFrontendRoles(respectFrontendRoles);
      eventMap.put("commentsCount", cAPI.getCommentsCount(ev.getInode()));

      eventMap.put(
          "hasReadPermission",
          perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_READ, user));
      eventMap.put(
          "hasWritePermission",
          perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_WRITE, user));
      eventMap.put(
          "hasPublishPermission",
          perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_PUBLISH, user));
      eventMap.put(
          "readPermission", perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_READ, user));
      eventMap.put(
          "writePermission",
          perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_WRITE, user));
      eventMap.put(
          "publishPermission",
          perAPI.doesUserHavePermission(ev, PermissionAPI.PERMISSION_PUBLISH, user));
      eventMap.put("offSet", DateViewWebAPI.getOffSet(ev.getStartDate()));
      eventMap.put("isDisconnected", UtilMethods.isSet(ev.getDisconnectedFrom()));

      retList.add(eventMap);
    }
    return retList;
  }