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; }
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; }
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; }
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"); } }
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; }
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"); } }
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; }
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; }
/** * Retrieves the event object from storage * * @param mapping * @param form * @param config * @param req * @param res * @param user * @throws DotSecurityException * @throws DotDataException * @throws NumberFormatException */ private void editEvent( ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, ActionResponse res, User user) { EventForm eventForm = (EventForm) form; Event event = (Event) req.getAttribute(WebKeys.EVENT_EDIT); if (!UtilMethods.isSet(event.getInode())) return; if (event.getRecurs()) { eventForm.setRecurrenceStartsDate(event.getRecurrenceStart()); eventForm.setRecurrenceDayOfMonth(String.valueOf(event.getRecurrenceDayOfMonth())); eventForm.setRecurrenceDayOfWeek(event.getRecurrenceDayOfWeek()); if (UtilMethods.isSet(event.getRecurrenceEnd())) { eventForm.setRecurrenceEndsDate(event.getRecurrenceEnd()); eventForm.setNoEndDate(false); } else { eventForm.setNoEndDate(true); } String daysOfWeek = event.getRecurrenceDaysOfWeek(); if (daysOfWeek == null) daysOfWeek = ""; List<String> daysList = new ArrayList<String>(); for (String day : daysOfWeek.split(",")) { if (UtilMethods.isSet(day)) { daysList.add(day); } } String[] daysListArr = new String[daysList.size()]; for (int i = 0; i < daysList.size(); i++) daysListArr[i] = daysList.get(i); eventForm.setRecurrenceDaysOfWeek(daysListArr); eventForm.setRecurrenceInterval((int) event.getRecurrenceInterval()); if (event.getOccursEnum() == Event.Occurrency.DAILY) { eventForm.setRecurrenceOccurs("daily"); } else if (event.getOccursEnum() == Event.Occurrency.WEEKLY) { eventForm.setRecurrenceOccurs("weekly"); } else if (event.getOccursEnum() == Event.Occurrency.MONTHLY) { eventForm.setRecurrenceOccurs("monthly"); if (UtilMethods.isSet(event.getRecurrenceDayOfMonth()) && event.getRecurrenceDayOfMonth() > 0) { eventForm.setRecurrenceDayOfMonth(String.valueOf(event.getRecurrenceDayOfMonth())); eventForm.setSpecificDate(true); } else { eventForm.setSpecificDate(false); eventForm.setRecurrenceMonthOfYear(event.getRecurrenceMonthOfYear()); eventForm.setRecurrenceWeekOfMonth(event.getRecurrenceWeekOfMonth()); eventForm.setRecurrenceDayOfMonth(""); } } else if (event.getOccursEnum() == Event.Occurrency.ANNUALLY) { if (UtilMethods.isSet(event.getRecurrenceDayOfMonth()) && event.getRecurrenceDayOfMonth() > 0) { eventForm.setSpecificDayOfMonthRecY(String.valueOf(event.getRecurrenceDayOfMonth())); eventForm.setSpecificMonthOfYearRecY(String.valueOf(event.getRecurrenceMonthOfYear())); eventForm.setSpecificDate(true); } else { eventForm.setSpecificDate(false); eventForm.setSpecificDayOfMonthRecY(""); eventForm.setSpecificMonthOfYearRecY(""); eventForm.setRecurrenceMonthOfYear(event.getRecurrenceMonthOfYear()); eventForm.setRecurrenceWeekOfMonth(event.getRecurrenceWeekOfMonth()); } eventForm.setRecurrenceOccurs("annually"); } } else { eventForm.setRecurrenceStartsDate(new Date()); eventForm.setRecurrenceEndsDate(new Date()); eventForm.setNoEndDate(false); eventForm.setRecurrenceDayOfMonth(""); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date()); eventForm.setRecurrenceWeekOfMonth(cal.get(Calendar.WEEK_OF_MONTH)); eventForm.setRecurrenceDayOfWeek(cal.get(Calendar.DAY_OF_WEEK)); eventForm.setRecurrenceMonthOfYear(cal.get(Calendar.MONTH) + 1); String[] daysOfWeekRecurrence = { String.valueOf(Calendar.MONDAY), String.valueOf(Calendar.TUESDAY), String.valueOf(Calendar.WEDNESDAY), String.valueOf(Calendar.THURSDAY), String.valueOf(Calendar.FRIDAY), String.valueOf(Calendar.SATURDAY), String.valueOf(Calendar.SUNDAY) }; eventForm.setRecurrenceDaysOfWeek(daysOfWeekRecurrence); eventForm.setRecurrenceInterval(1); eventForm.setRecurrenceOccurs("never"); } }