Exemplo n.º 1
0
  /**
   * Method that will verify if a given template title is already used by another template
   *
   * @param title template title to verify
   * @param templateInode template inode in case we are editing a template, null or empty in case of
   *     a new template
   * @param hostIdentifier current host identifier
   * @return
   * @throws DotDataException
   * @throws SystemException
   * @throws PortalException
   * @throws DotSecurityException
   */
  public boolean duplicatedTitle(String title, String templateInode, String hostIdentifier)
      throws DotDataException, SystemException, PortalException, DotSecurityException {

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);

    // Getting the current host
    Host host = hostAPI.find(hostIdentifier, user, respectFrontendRoles);

    // The template name must be unique
    Template foundTemplate =
        FactoryLocator.getTemplateFactory().findWorkingTemplateByName(title, host);
    boolean duplicatedTitle = false;
    if (foundTemplate != null && InodeUtils.isSet(foundTemplate.getInode())) {
      if (!UtilMethods.isSet(templateInode)) {
        duplicatedTitle = true;
      } else {
        if (!foundTemplate.getInode().equals(templateInode)) {
          duplicatedTitle = true;
        }
      }
    }

    return duplicatedTitle;
  }
Exemplo n.º 2
0
  public void init(Object obj) {
    if (!Config.getBooleanProperty("ENABLE_SCRIPTING", false)) {
      return;
    }
    ViewContext context = (ViewContext) obj;

    this.request = context.getRequest();
    ctx = context.getVelocityContext();
    try {
      host = WebAPILocator.getHostWebAPI().getCurrentHost(request);
    } catch (PortalException e1) {
      Logger.error(this, e1.getMessage(), e1);
    } catch (SystemException e1) {
      Logger.error(this, e1.getMessage(), e1);
    } catch (DotDataException e1) {
      Logger.error(this, e1.getMessage(), e1);
    } catch (DotSecurityException e1) {
      Logger.error(this, e1.getMessage(), e1);
    }
    userAPI = WebAPILocator.getUserWebAPI();
    try {
      user = userAPI.getLoggedInFrontendUser(request);
      backuser = userAPI.getLoggedInUser(request);
      respectFrontendRoles = true;
    } catch (Exception e) {
      Logger.error(this, "Error finding the logged in user", e);
    }
  }
Exemplo n.º 3
0
 public String checkDependencies(String templateInode)
     throws DotDataException, DotRuntimeException, DotSecurityException, PortalException,
         SystemException {
   HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
   User user = userWebAPI.getLoggedInUser(req);
   boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
   return templateAPI.checkDependencies(templateInode, user, respectFrontendRoles);
 }
Exemplo n.º 4
0
  public Map<String, Object> unpublishEvent(String identifier)
      throws PortalException, SystemException, DotDataException, DotSecurityException {
    Map<String, Object> callbackData = new HashMap<String, Object>(); // DOTCMS-5199
    List<String> eventUnpublishErrors = new ArrayList<String>();
    HibernateUtil.startTransaction();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

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

    Event ev = eventAPI.find(identifier, false, user, respectFrontendRoles);

    try {
      contAPI.unpublish(ev, user, respectFrontendRoles);
    } catch (DotSecurityException e) {
      eventUnpublishErrors.add(e.getLocalizedMessage());
    } catch (DotDataException e) {
      eventUnpublishErrors.add(e.getLocalizedMessage());
    } catch (DotContentletStateException e) {
      eventUnpublishErrors.add(e.getLocalizedMessage());
    } finally {
      if (eventUnpublishErrors.size() > 0) {
        callbackData.put("eventUnpublishErrors", eventUnpublishErrors);
      }
    }
    HibernateUtil.commitTransaction();
    if (!contAPI.isInodeIndexed(ev.getInode())) {
      Logger.error(this, "Timed out while waiting for index to return");
    }

    return callbackData;
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
0
  public Map<String, Object> getEvent(String id, boolean live)
      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;

    Event ev = eventAPI.find(id, live, user, respectFrontendRoles);

    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());
    }
    eventMap.put("categories", categoryMaps);
    eventMap.put("rating", RatingAPI.getAverageRating(ev.getIdentifier()));
    eventMap.put("votes", RatingAPI.getRatingVotesNumber(ev.getIdentifier()));
    eventMap.put(
        "hasReadPermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
    eventMap.put(
        "hasWritePermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
    eventMap.put(
        "hasPublishPermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
    eventMap.put(
        "readPermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles));
    eventMap.put(
        "writePermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles));
    eventMap.put(
        "publishPermission",
        perAPI.doesUserHavePermission(
            ev, PermissionAPI.PERMISSION_PUBLISH, user, respectFrontendRoles));
    eventMap.put("isDisconnected", UtilMethods.isSet(ev.getDisconnectedFrom()));
    CommentsWebAPI cAPI = new CommentsWebAPI();
    cAPI.setUser(user);
    cAPI.setRespectFrontendRoles(respectFrontendRoles);
    eventMap.put("commentsCount", cAPI.getCommentsCount(ev.getInode()));

    return eventMap;
  }
Exemplo n.º 7
0
 protected boolean canUserEvalute() throws DotDataException, DotSecurityException {
   if (!Config.getBooleanProperty("ENABLE_SCRIPTING", false)) {
     Logger.warn(this.getClass(), "Scripting called and ENABLE_SCRIPTING set to false");
     return false;
   }
   ica = new InternalContextAdapterImpl(ctx);
   String fieldResourceName = ica.getCurrentTemplateName();
   String conInode =
       fieldResourceName.substring(
           fieldResourceName.indexOf("/") + 1, fieldResourceName.indexOf("_"));
   Contentlet con =
       APILocator.getContentletAPI().find(conInode, APILocator.getUserAPI().getSystemUser(), true);
   User mu = userAPI.loadUserById(con.getModUser(), APILocator.getUserAPI().getSystemUser(), true);
   Role scripting = APILocator.getRoleAPI().loadRoleByKey("Scripting Developer");
   return APILocator.getRoleAPI().doesUserHaveRole(mu, scripting);
 }
Exemplo n.º 8
0
  public void unarchiveEvent(String identifier)
      throws PortalException, SystemException, DotDataException, DotSecurityException {
    HibernateUtil.startTransaction();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

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

    Event ev = eventAPI.find(identifier, false, user, respectFrontendRoles);
    try {

      if (UtilMethods.isSet(ev.getDisconnectedFrom())) {
        Event baseEvent = null;
        try {
          baseEvent = eventAPI.find(ev.getDisconnectedFrom(), false, user, respectFrontendRoles);
        } catch (Exception e) {
          Logger.error(this, "Base event not found");
        }
        if (baseEvent != null) {
          try {
            Date originalStartDate = ev.getOriginalStartDate();
            baseEvent.addDateToIgnore(originalStartDate);
            APILocator.getContentletAPI()
                .checkin(
                    baseEvent,
                    categoryAPI.getParents(baseEvent, user, true),
                    perAPI.getPermissions(baseEvent),
                    user,
                    false);
          } catch (Exception e) {
            Logger.error(this, "Could not delete event from recurrence");
          }
        }
      }
      contAPI.unarchive(ev, user, respectFrontendRoles);

    } catch (Exception e) {
      Logger.error(this, e.getMessage());
    }

    HibernateUtil.commitTransaction();
    if (!contAPI.isInodeIndexed(ev.getInode())) {
      Logger.error(this, "Timed out while waiting for index to return");
    }
  }
Exemplo n.º 9
0
  public List<Map<String, Object>> findLocations(String filter)
      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;

    // Searching for buildings
    Structure buildingStructure = eventAPI.getBuildingStructure();
    Field titleField = buildingStructure.getFieldVar("title");
    String luceneQuery = "+structureInode:" + buildingStructure.getInode();
    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    List<Contentlet> matches =
        contAPI.search(
            luceneQuery, -1, 0, titleField.getFieldContentlet(), user, respectFrontendRoles);
    List<Map<String, Object>> facilitiesList =
        findChildFacilities(matches, filter, user, respectFrontendRoles);

    for (Contentlet cont : matches) {
      List<Map<String, Object>> facilitiesListCont = new ArrayList<Map<String, Object>>();
      Map<String, Object> contMap = cont.getMap();
      if (!UtilMethods.isSet(filter)
          || facilitiesList.size() > 0
          || ((String) contMap.get("title")).contains(filter)) {
        for (Map<String, Object> facility : facilitiesList) {
          for (Contentlet building : (ArrayList<Contentlet>) facility.get("buildings")) {
            if (building.getIdentifier().equals(cont.getIdentifier())
                && !facilitiesListCont.contains(facility)) {
              Map<String, Object> facilityMap = new HashMap<String, Object>();
              facilityMap.putAll(facility);
              facilityMap.put("buildings", null);
              facilitiesListCont.add(facilityMap);
              break;
            }
          }
        }
        contMap.put("facilities", facilitiesListCont);
        results.add(contMap);
      }
    }
    return results;
  }
Exemplo n.º 10
0
  public List<Map<String, Object>> findRelatedEvents(
      String parentEvent, Date fromDate, Date toDate, boolean live)
      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>>();
    Event parentEv = eventAPI.find(parentEvent, live, user, respectFrontendRoles);
    List<Event> events =
        eventAPI.findRelatedEvents(parentEv, fromDate, toDate, live, user, respectFrontendRoles);
    for (Event ev : events) {
      retList.add(ev.getMap());
    }
    return retList;
  }
Exemplo n.º 11
0
  public void archiveEvent(String identifier)
      throws PortalException, SystemException, DotDataException, DotSecurityException {
    HibernateUtil.startTransaction();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();

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

    Event ev = eventAPI.find(identifier, false, user, respectFrontendRoles);
    try {
      contAPI.archive(ev, user, respectFrontendRoles);
    } catch (Exception e) {
      Logger.error(this, e.getMessage());
    }

    HibernateUtil.commitTransaction();
    if (!contAPI.isInodeIndexed(ev.getInode())) {
      Logger.error(this, "Timed out while waiting for index to return");
    }
  }
  @Override
  public void executeAction(
      WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params)
      throws WorkflowActionFailureException {
    if (LicenseUtil.getLevel() < 200) return; // the apis will do nothing anyway

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();
    User user = null;
    try {
      user = uWebAPI.getLoggedInUser(request);
    } catch (Exception exx) {
      throw new WorkflowActionFailureException(exx.getMessage());
    }
    Contentlet con = processor.getContentlet();

    List<InvalidLink> httpResponse = null;
    try {
      httpResponse = APILocator.getLinkCheckerAPI().findInvalidLinks(con);
    } catch (Exception e1) {
      Logger.error(this, e1.getMessage(), e1);
      throw new WorkflowActionFailureException(e1.getMessage());
    }

    // if there are unreachable URL...
    if (httpResponse.size() > 0) {
      String msg = "";
      try {
        msg = LanguageUtil.get(user, "checkURL.errorBrokenLinks");
      } catch (Exception e) {

      }
      throw new WorkflowActionFailureException(
          LinkCheckerUtil.buildPopupMsgWithLinksList(msg, httpResponse));
    }
  }
Exemplo n.º 13
0
  public Map<String, Object> fetchTemplates(
      Map<String, String> query,
      Map<String, String> queryOptions,
      int start,
      int count,
      List<String> sort)
      throws PortalException, SystemException, DotDataException, DotSecurityException {

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
    if (count <= 0) count = 10;

    List<Template> fullListTemplates = new ArrayList<Template>();
    List<Template> totalTemplates = new ArrayList<Template>();
    Host host = hostAPI.find(query.get("hostId"), user, respectFrontendRoles);

    try {
      String filter = query.get("fullTitle");
      if (UtilMethods.isSet(filter)) {
        filter = filter.replaceAll("\\*", "");
        filter = filter.replaceAll("\\?", "");
      }

      if (UtilMethods.isSet(query.get("hostId"))) {
        int startF = start;
        int countF = count;
        if (start == 0) {
          Template t = new Template();
          t.setOwner(user.getUserId());
          t.setModUser(user.getUserId());
          t.setInode("0");
          t.setTitle("--- " + LanguageUtil.get(user, "All-Hosts") + " ---");
          t.setIdentifier("0");
          fullListTemplates.add(t);
          totalTemplates.add(t);
          countF = count - 1;
        } else {
          startF = start - 1;
        }
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, host.getHostname(), filter, true, startF, countF));
        totalTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(user, host.getHostname(), filter, true, 0, 1000));
      }

      // doesn't currently respect archived
      if (fullListTemplates.size() == 0) {
        fullListTemplates.addAll(
            templateAPI.findTemplatesUserCanUse(
                user, "", filter, true, start, start > 0 ? count : count + 1));
        totalTemplates.addAll(templateAPI.findTemplatesUserCanUse(user, "", filter, true, 0, 1000));
      }

    } catch (DotDataException e) {
      Logger.error(this, e.getMessage(), e);
      throw new DotDataException(e.getMessage(), e);
    }
    // Collections.sort(fullListTemplates, new TemplateComparator(baseHostId));
    Map<String, Object> results = new HashMap<String, Object>();
    List<Map<String, Object>> list = new LinkedList<Map<String, Object>>();

    boolean shouldIncludeTemplate = true;
    String toInclude = queryOptions.get("includeTemplate");
    for (Template template : fullListTemplates) {
      Map<String, Object> contMap = buildTemplateMap(template);
      list.add(contMap);
    }
    if (toInclude != null && shouldIncludeTemplate) {
      Template template =
          templateAPI.findWorkingTemplate(
              toInclude, APILocator.getUserAPI().getSystemUser(), false);
      if (template != null) {
        list.add(buildTemplateMap(template));
      }
    }

    //		totalTemplates = templateAPI.findTemplatesAssignedTo(host);
    //		if(start >= list.size()) start =  list.size() - 1;
    //		if(start < 0)  start  = 0;
    //		if(start + count >= list.size()) count = list.size() - start;
    //		List<Map<String, Object>> templates = list.subList(start, start + count);

    results.put("totalResults", totalTemplates.size());

    results.put("list", list);

    return results;
  }
Exemplo n.º 14
0
 public Map<String, Object> fetchByIdentity(String id)
     throws DotDataException, DotSecurityException {
   return buildTemplateMap(templateAPI.findWorkingTemplate(id, userWebAPI.getSystemUser(), false));
 }
Exemplo n.º 15
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;
  }
Exemplo n.º 16
0
  public Map<String, Object> disconnectEvent(String inode, String startDateStr, String endDateStr)
      throws DotRuntimeException, PortalException, SystemException, DotDataException,
          DotSecurityException, java.text.ParseException {

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

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

    Map<String, Object> eventMap = new HashMap<String, Object>();
    List<String> disconnectEventErrors = new ArrayList<String>();

    String inodeStr = (InodeUtils.isSet(inode) ? inode : "");
    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 {
            if (disconnectEventErrors.size() > 0) {
              eventMap.put("disconnectEventErrors", disconnectEventErrors);
            }
          }
        }
      }
    }

    return eventMap;
  }