Beispiel #1
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;
  }
  @RemoteMethod
  public String findLike(String firmName) throws IOException, ServletException {

    WebContext webContext = WebContextFactory.get();

    HttpSession httpSession = webContext.getHttpServletRequest().getSession(false);

    if ((httpSession == null) || (httpSession.getAttribute("userId") == null)) {

      return "";
    }

    String firmNameInLowerCase = firmName.toLowerCase();

    List<EntitySection> sections = EntityManager.listByName("sections.all", new Object[0]);

    List firms = new ArrayList();

    for (EntitySection section : sections) {

      for (EntityFirm firm : section.getFirms()) {

        if (firm.getName().toLowerCase().contains(firmNameInLowerCase)) {

          firms.add(firm);
        }
      }
    }

    webContext.getHttpServletRequest().setAttribute("firms", firms);

    return webContext.forwardToString("/security/likefirms.jsp");
  }
  public CityTrl[] getCityList(String value) {
    // System.out.println("bgn");
    if (!DwrPrivilegeFilter.isView(this.getClass().getName())) {
      return null;
    }
    if (value == null) value = "";
    Map param = new HashMap();
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    UserResource ur = (UserResource) request.getSession().getAttribute("resource");
    param.put(
        "accessString",
        "language='"
            + ur.getLocale().toString()
            + "' and name like '%"
            + value.trim()
            + "%'   and id in (SELECT  id FROM base_city where levelint>=3)");
    List<CityTrl> list = cityTrlService.selectByExample(param);
    if (list != null) {

      if (list.size() > 10) {
        list = list.subList(0, 10);
      }
      CityTrl[] cityTrlArray = new CityTrl[list.size()];
      list.toArray(cityTrlArray);
      // System.out.println("comp");
      return cityTrlArray;
    }
    return null;
  }
 /**
  * DWR函数--返回列表页面的字符串
  *
  * @param form
  * @return
  * @throws Exception
  */
 public String getSysParameterConfList(SysParameterConfActionForm form) throws Exception {
   SysParameterConfExample ex = new SysParameterConfExample();
   List list = this.sysParameterConfService.selectByExample(ex);
   WebContext wctx = WebContextFactory.get();
   HttpServletRequest request = wctx.getHttpServletRequest();
   request.setAttribute("parameterList", list);
   return wctx.forwardToString("/jsp/sys/par/sysParameterConfList.jsp");
 }
Beispiel #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;
  }
Beispiel #6
0
  private List<ViewComponentState> getViewPointData(User user, View view, boolean edit) {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    List<ViewComponentState> states = new ArrayList<ViewComponentState>();
    Map<String, Object> model = new HashMap<String, Object>();
    RuntimeManager rtm = Common.ctx.getRuntimeManager();

    for (ViewComponent viewComponent : view.getViewComponents()) {
      if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) {
        CompoundComponent compoundComponent = (CompoundComponent) viewComponent;

        boolean imageChart = compoundComponent instanceof ImageChartComponent;

        // Add states for each of the children
        for (CompoundChild child : compoundComponent.getChildComponents())
          addPointComponentState(
              child.getViewComponent(), rtm, model, request, view, user, states, edit, !imageChart);

        // Add a state for the compound component.
        ViewComponentState state = new ViewComponentState();
        state.setId(compoundComponent.getId());

        model.clear();
        model.put("compoundComponent", compoundComponent);

        List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>();
        for (CompoundChild child : compoundComponent.getChildComponents()) {
          if (child.getViewComponent().isPointComponent()) {
            DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint();
            if (point != null) {
              Map<String, Object> map = new HashMap<String, Object>();
              if (imageChart) map.put("name", point.getName());
              else map.put("name", getMessage(child.getDescription()));
              map.put("point", point);
              map.put("pointValue", point.lastValue());
              childData.add(map);
            }
          }
        }
        model.put("childData", childData);

        if (compoundComponent.hasInfo())
          state.setInfo(generateContent(request, "compoundInfoContent.jsp", model));

        if (imageChart)
          state.setContent(
              ((ImageChartComponent) compoundComponent).getImageChartData(getResourceBundle()));
        else if (!edit) state.setChart(compoundComponent.getImageChartData(getResourceBundle()));

        states.add(state);
      } else
        addPointComponentState(viewComponent, rtm, model, request, view, user, states, edit, true);
    }

    return states;
  }
 /** 添加在线用户 */
 public void addOnlineUser() {
   WebContext context = WebContextFactory.get();
   String userId = AppLoginUtils.getLoginUserId();
   String userName = AppLoginUtils.getLoginUserName();
   String departmentId = AppLoginUtils.getDepartmentId();
   ScriptSession scriptSession = context.getScriptSession();
   scriptSession.setAttribute(USER_ID, userId);
   scriptSession.setAttribute(USER_NAME, userName);
   scriptSession.setAttribute(DEPART_ID, departmentId);
 }
Beispiel #8
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;
  }
 @SuppressWarnings("unchecked")
 private static Collection<ScriptSession> loadScriptPages() {
   WebContext context = WebContextFactory.get();
   if (context == null) {
     context = wctx;
   }
   String currentPage = context.getServletContext().getContextPath() + SCRIPT_PAGE;
   // Loop over all the users on the current page
   Collection<ScriptSession> pages = context.getScriptSessionsByPage(currentPage);
   logger.info(currentPage + " ScriptSessions: " + pages.size());
   return pages;
 }
 /**
  * {@inheritDoc}
  *
  * @throws Exception sometimes things just don't work out
  */
 public String renderAsync() throws Exception {
   WebContext ctx = WebContextFactory.get();
   HttpServletRequest req = ctx.getHttpServletRequest();
   RequestContext rhnCtx = new RequestContext(req);
   User user = rhnCtx.getCurrentUser();
   PageControl pc = new PageControl();
   pc.setStart(1);
   pc.setPageSize(PAGE_SIZE);
   render(user, pc, req);
   HttpServletResponse resp = ctx.getHttpServletResponse();
   return RendererHelper.renderRequest(getPageUrl(), req, resp);
 }
Beispiel #11
0
 @RemoteMethod
 public void showPerson(Long id) {
   WebContext wctx = WebContextFactory.get();
   ScriptSession session = wctx.getScriptSession();
   Util util = new Util(session);
   Person p = dao.read(id);
   util.setValue("firstName", p.getFirstName());
   util.setValue("lastName", p.getLastName());
   util.setValue("birthDate", p.getBirthDate().toString());
   util.setStyle("personData", "display", "block");
   Effect effect = new Effect(session);
   effect.highlight("personData");
 }
  /**
   * Renders Action Chain entries from an Action Chain having a certain sort order number.
   *
   * @param actionChainId Action Chain identifier
   * @param sortOrder sort order number
   * @return a response string
   * @throws ServletException if something goes wrong
   * @throws IOException if something goes wrong
   */
  public String renderAsync(Long actionChainId, Integer sortOrder)
      throws ServletException, IOException {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    User u = new RequestContext(request).getCurrentUser();

    ActionChain actionChain = ActionChainFactory.getActionChain(u, actionChainId);
    request.setAttribute("sortOrder", sortOrder);
    request.setAttribute(
        "entries", ActionChainFactory.getActionChainEntries(actionChain, sortOrder));

    HttpServletResponse response = webContext.getHttpServletResponse();
    return RendererHelper.renderRequest(
        "/WEB-INF/pages/common/fragments/schedule/actionchainentries.jsp", request, response);
  }
Beispiel #13
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");
    }
  }
Beispiel #14
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;
  }
  public CityTrl[] getCityCityList(String value, String countryId, String provinceId) {
    // System.out.println("bgn");
    if (!DwrPrivilegeFilter.isView(this.getClass().getName())) {
      return null;
    }
    if (value == null) value = "";
    Map param = new HashMap();
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    UserResource ur = (UserResource) request.getSession().getAttribute("resource");
    StringBuilder sb = new StringBuilder("");
    if (StringUtil.isNotEmpty(provinceId)) {
      sb.append("and parent_id=").append(provinceId);
    } else if (StringUtil.isNotEmpty(countryId)) {
      sb.append("and parent_id in (select id from base_city where parent_id=")
          .append(countryId)
          .append(")");
    }

    param.put(
        "accessString",
        "language='"
            + ur.getLocale().toString()
            + "' and  ((name like '%"
            + value.trim()
            + "%') or (remark like '%"
            + value.trim()
            + "%'))  and  city_id in( select id from base_city where levelint=3 "
            + sb.toString()
            + ")");
    List<CityTrl> list = cityTrlService.selectByExample(param);
    if (list != null) {

      if (list.size() > 10) {
        list = list.subList(0, 10);
      }
      CityTrl[] cityTrlArray = new CityTrl[list.size()];
      list.toArray(cityTrlArray);
      // System.out.println("comp");
      return cityTrlArray;
    }
    return null;
  }
Beispiel #16
0
 /**
  * 登录验证
  *
  * @param account 帐号,可以是帐号、email、手机号
  * @param password 密码
  * @return resultVO
  */
 public ResultVO login(String account, String password) {
   ResultVO resultVO = new ResultVO();
   UserVO userVO = userDAO.queryUserByCodeOrEmailOrPhone(account);
   if (userVO == null) {
     resultVO = new ResultVO("账号或密码错误");
   } else {
     if (!password.equals(userVO.getPassword())) {
       resultVO = new ResultVO("账号或密码错误");
     }
   }
   EnvironmentInfoVO objEnvironmentInfoVO = new EnvironmentInfoVO();
   objEnvironmentInfoVO.setUser(userVO);
   WebContext objWebContext = WebContextFactory.get();
   objWebContext.getSession().setAttribute("environmentInfo", objEnvironmentInfoVO);
   if (resultVO.isSuccess()) {
     objWebContext.getSession().setAttribute("current_user", userVO);
   }
   return resultVO;
 }
Beispiel #17
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;
  }
Beispiel #18
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");
    }
  }
Beispiel #19
0
  /**
   * Guarda el POST mediante Ajax
   *
   * @param data el objeto
   * @return 1 solo si se guardo
   */
  public int saveData(Data data) {
    WebContext wctx = WebContextFactory.get();
    HttpSession session = wctx.getSession(true);
    UserFB userFB = (UserFB) session.getAttribute("userFB");
    logger.info("userFB = " + userFB);
    if (userFB == null) {
      throw new SecurityException("Ingrese al Sistema");
    }
    data.setUserByIdUser(getUserFB(userFB));
    data.setFechaData(new Timestamp(System.currentTimeMillis()));
    data.setCategoriaByIdCategoria(getCategoria(data.getIdCategoria()));

    if (data.getTituloData().equals("")) {
      throw new SecurityException("titulo vacio");
    } else if (data.getTextoData().equals("")) {
      throw new SecurityException("detalle vacio");
    }

    getHibernateTemplate().save(data);

    return 1;
  }
Beispiel #20
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;
  }
Beispiel #21
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;
  }