@Override public PortletURL getURLAdd( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse, long classTypeId) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY); CalendarResource calendarResource = CalendarResourceUtil.getScopeGroupCalendarResource( liferayPortletRequest, themeDisplay.getScopeGroupId()); if (calendarResource == null) { return null; } PortletURL portletURL = PortalUtil.getControlPanelPortletURL( liferayPortletRequest, CalendarPortletKeys.CALENDAR, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcPath", "/edit_calendar_booking.jsp"); Calendar calendar = calendarResource.getDefaultCalendar(); portletURL.setParameter("calendarId", String.valueOf(calendar.getCalendarId())); return portletURL; }
protected void updateCalendars( PortletDataContext portletDataContext, CalendarResource calendarResource, CalendarResource importedCalendarResource) throws SystemException { Map<Long, Long> calendarIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class); List<Element> referenceElements = portletDataContext.getReferenceElements(calendarResource, Calendar.class); for (Element referenceElement : referenceElements) { long calendarId = GetterUtil.getLong(referenceElement.attributeValue("class-pk")); Calendar calendar = CalendarLocalServiceUtil.fetchCalendar(MapUtil.getLong(calendarIds, calendarId)); if (calendar != null) { calendar.setCalendarResourceId(importedCalendarResource.getCalendarResourceId()); CalendarLocalServiceUtil.updateCalendar(calendar); } } }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { Calendar newCalendar = addCalendar(); Calendar existingCalendar = _persistence.fetchByPrimaryKey(newCalendar.getPrimaryKey()); Assert.assertEquals(existingCalendar, newCalendar); }
@Override protected void doReindex(Object obj) throws Exception { Calendar calendar = (Calendar) obj; Document document = getDocument(calendar); SearchEngineUtil.updateDocument( getSearchEngineId(), calendar.getCompanyId(), document, isCommitImmediately()); }
@Test public void testCreate() throws Exception { long pk = RandomTestUtil.nextLong(); Calendar calendar = _persistence.create(pk); Assert.assertNotNull(calendar); Assert.assertEquals(calendar.getPrimaryKey(), pk); }
@Test public void testRemove() throws Exception { Calendar newCalendar = addCalendar(); _persistence.remove(newCalendar); Calendar existingCalendar = _persistence.fetchByPrimaryKey(newCalendar.getPrimaryKey()); Assert.assertNull(existingCalendar); }
@Test public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception { Calendar newCalendar = addCalendar(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newCalendar.getPrimaryKey()); Map<Serializable, Calendar> calendars = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, calendars.size()); Assert.assertEquals(newCalendar, calendars.get(newCalendar.getPrimaryKey())); }
@Test public void testResetOriginalValues() throws Exception { Calendar newCalendar = addCalendar(); _persistence.clearCache(); Calendar existingCalendar = _persistence.findByPrimaryKey(newCalendar.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingCalendar.getUuid(), ReflectionTestUtil.invoke(existingCalendar, "getOriginalUuid", new Class<?>[0]))); Assert.assertEquals( Long.valueOf(existingCalendar.getGroupId()), ReflectionTestUtil.<Long>invoke(existingCalendar, "getOriginalGroupId", new Class<?>[0])); }
/** * Adds the calendar to the database. Also notifies the appropriate model listeners. * * @param calendar the calendar * @return the calendar that was added */ @Indexable(type = IndexableType.REINDEX) @Override public Calendar addCalendar(Calendar calendar) { calendar.setNew(true); return calendarPersistence.update(calendar); }
@Override protected void doImportMissingReference( PortletDataContext portletDataContext, String uuid, long groupId, long calendarId) throws Exception { Calendar existingCalendar = fetchMissingReference(uuid, groupId); if (existingCalendar == null) { return; } Map<Long, Long> calendarIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class); calendarIds.put(calendarId, existingCalendar.getCalendarId()); }
public static List<CalendarBooking> getCalendarBookings( PermissionChecker permissionChecker, Calendar calendar, Date startDate, Date endDate) throws PortalException, SystemException { ClassLoader classLoader = ClassLoaderPool.getClassLoader("calendar-portlet"); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalendarBooking.class, classLoader); dynamicQuery.add(RestrictionsFactoryUtil.eq("calendarId", calendar.getCalendarId())); List<Integer> calendarStatus = new ArrayList<Integer>(); calendarStatus.add(WorkflowConstants.STATUS_APPROVED); calendarStatus.add(WorkflowConstants.STATUS_PENDING); calendarStatus.add(WorkflowConstants.STATUS_DRAFT_FROM_APPROVED); dynamicQuery.add(RestrictionsFactoryUtil.in("status", calendarStatus)); if (startDate != null) { dynamicQuery.add(RestrictionsFactoryUtil.ge("startTime", new Long(startDate.getTime()))); } if (endDate != null) { dynamicQuery.add(RestrictionsFactoryUtil.le("endTime", new Long(endDate.getTime()))); } List<CalendarBooking> allCalendarBookings = CalendarBookingLocalServiceUtil.dynamicQuery(dynamicQuery); return filterCalendarBookings(allCalendarBookings, permissionChecker, ActionKeys.VIEW); }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { Calendar newCalendar = addCalendar(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Calendar.class, _dynamicQueryClassLoader); dynamicQuery.add(RestrictionsFactoryUtil.eq("calendarId", newCalendar.getCalendarId())); List<Calendar> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Calendar existingCalendar = result.get(0); Assert.assertEquals(existingCalendar, newCalendar); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception { Calendar newCalendar = addCalendar(); long pk = RandomTestUtil.nextLong(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newCalendar.getPrimaryKey()); primaryKeys.add(pk); Map<Serializable, Calendar> calendars = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, calendars.size()); Assert.assertEquals(newCalendar, calendars.get(newCalendar.getPrimaryKey())); }
public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Calendar)) { return false; } Calendar calendar = (Calendar) obj; long primaryKey = calendar.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } }
@Override public boolean hasAddPermission( PermissionChecker permissionChecker, long groupId, long classTypeId) throws Exception { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(permissionChecker.getCompanyId()); CalendarResource calendarResource = CalendarResourceUtil.getScopeGroupCalendarResource(groupId, serviceContext); if (calendarResource == null) { return false; } Calendar calendar = calendarResource.getDefaultCalendar(); return CalendarPermission.contains( permissionChecker, calendar.getCalendarId(), CalendarActionKeys.MANAGE_BOOKINGS); }
@Override protected Document doGetDocument(Calendar calendar) throws Exception { Document document = getBaseModelDocument(CLASS_NAME, calendar); document.addLocalizedText(Field.DESCRIPTION, calendar.getDescriptionMap()); document.addLocalizedText(Field.NAME, calendar.getNameMap()); document.addKeyword("calendarId", calendar.getCalendarId()); Locale defaultLocale = LocaleUtil.getSiteDefault(); String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale); document.addText("defaultLanguageId", defaultLanguageId); CalendarResource calendarResource = calendar.getCalendarResource(); document.addLocalizedText("resourceName", calendarResource.getNameMap()); return document; }
protected Map<Locale, String> getCalendarNameMap( PortletDataContext portletDataContext, Calendar calendar) throws Exception { String calendarName = calendar.getName(LocaleUtil.getDefault()); Group sourceGroup = GroupLocalServiceUtil.fetchGroup(portletDataContext.getSourceGroupId()); if ((sourceGroup == null) || !calendarName.equals(sourceGroup.getDescriptiveName())) { return calendar.getNameMap(); } Map<Locale, String> calendarNameMap = new HashMap<>(); Group scopeGroup = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId()); calendarNameMap.put(LocaleUtil.getDefault(), scopeGroup.getName()); return calendarNameMap; }
public int compareTo(Calendar calendar) { int value = 0; value = getName().compareTo(calendar.getName()); if (value != 0) { return value; } return 0; }
@Test public void testDynamicQueryByProjectionExisting() throws Exception { Calendar newCalendar = addCalendar(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Calendar.class, _dynamicQueryClassLoader); dynamicQuery.setProjection(ProjectionFactoryUtil.property("calendarId")); Object newCalendarId = newCalendar.getCalendarId(); dynamicQuery.add(RestrictionsFactoryUtil.in("calendarId", new Object[] {newCalendarId})); List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Object existingCalendarId = result.get(0); Assert.assertEquals(existingCalendarId, newCalendarId); }
@Override @SystemEvent(action = SystemEventConstants.ACTION_SKIP, type = SystemEventConstants.TYPE_DELETE) public CalendarResource deleteCalendarResource(CalendarResource calendarResource) throws PortalException { // Calendar resource calendarResourcePersistence.remove(calendarResource); // Resources resourceLocalService.deleteResource(calendarResource, ResourceConstants.SCOPE_INDIVIDUAL); // Calendars List<Calendar> calendars = calendarPersistence.findByG_C( calendarResource.getGroupId(), calendarResource.getCalendarResourceId()); for (Calendar calendar : calendars) { calendarPersistence.remove(calendar); resourceLocalService.deleteResource(calendar, ResourceConstants.SCOPE_INDIVIDUAL); calendarNotificationTemplateLocalService.deleteCalendarNotificationTemplates( calendar.getCalendarId()); } // Calendar bookings List<CalendarBooking> calendarBookings = calendarBookingPersistence.findByCalendarResourceId( calendarResource.getCalendarResourceId()); for (CalendarBooking calendarBooking : calendarBookings) { calendarBookingLocalService.deleteCalendarBooking(calendarBooking); } return calendarResource; }
protected static boolean isCurrentUserCalendar(long userId, Calendar calendar) throws PortalException, SystemException { CalendarResource calendarResource = calendar.getCalendarResource(); if (calendarResource.getClassName().equals(User.class.getName()) && (calendarResource.getClassPK() == userId)) { return true; } else { return false; } }
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, Calendar calendar) throws Exception { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, calendar, calendar.getCalendarResource(), PortletDataContext.REFERENCE_TYPE_STRONG); Element calendarElement = portletDataContext.getExportDataElement(calendar); portletDataContext.addClassedModel( calendarElement, ExportImportPathUtil.getModelPath(calendar), calendar); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception { Calendar newCalendar1 = addCalendar(); Calendar newCalendar2 = addCalendar(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newCalendar1.getPrimaryKey()); primaryKeys.add(newCalendar2.getPrimaryKey()); Map<Serializable, Calendar> calendars = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(2, calendars.size()); Assert.assertEquals(newCalendar1, calendars.get(newCalendar1.getPrimaryKey())); Assert.assertEquals(newCalendar2, calendars.get(newCalendar2.getPrimaryKey())); }
@Override protected void doDelete(Calendar calendar) throws Exception { deleteDocument(calendar.getCompanyId(), calendar.getCalendarId()); }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); Calendar newCalendar = _persistence.create(pk); newCalendar.setUuid(RandomTestUtil.randomString()); newCalendar.setGroupId(RandomTestUtil.nextLong()); newCalendar.setCompanyId(RandomTestUtil.nextLong()); newCalendar.setUserId(RandomTestUtil.nextLong()); newCalendar.setUserName(RandomTestUtil.randomString()); newCalendar.setCreateDate(RandomTestUtil.nextDate()); newCalendar.setModifiedDate(RandomTestUtil.nextDate()); newCalendar.setResourceBlockId(RandomTestUtil.nextLong()); newCalendar.setCalendarResourceId(RandomTestUtil.nextLong()); newCalendar.setName(RandomTestUtil.randomString()); newCalendar.setDescription(RandomTestUtil.randomString()); newCalendar.setTimeZoneId(RandomTestUtil.randomString()); newCalendar.setColor(RandomTestUtil.nextInt()); newCalendar.setDefaultCalendar(RandomTestUtil.randomBoolean()); newCalendar.setEnableComments(RandomTestUtil.randomBoolean()); newCalendar.setEnableRatings(RandomTestUtil.randomBoolean()); newCalendar.setLastPublishDate(RandomTestUtil.nextDate()); _calendars.add(_persistence.update(newCalendar)); Calendar existingCalendar = _persistence.findByPrimaryKey(newCalendar.getPrimaryKey()); Assert.assertEquals(existingCalendar.getUuid(), newCalendar.getUuid()); Assert.assertEquals(existingCalendar.getCalendarId(), newCalendar.getCalendarId()); Assert.assertEquals(existingCalendar.getGroupId(), newCalendar.getGroupId()); Assert.assertEquals(existingCalendar.getCompanyId(), newCalendar.getCompanyId()); Assert.assertEquals(existingCalendar.getUserId(), newCalendar.getUserId()); Assert.assertEquals(existingCalendar.getUserName(), newCalendar.getUserName()); Assert.assertEquals( Time.getShortTimestamp(existingCalendar.getCreateDate()), Time.getShortTimestamp(newCalendar.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingCalendar.getModifiedDate()), Time.getShortTimestamp(newCalendar.getModifiedDate())); Assert.assertEquals(existingCalendar.getResourceBlockId(), newCalendar.getResourceBlockId()); Assert.assertEquals( existingCalendar.getCalendarResourceId(), newCalendar.getCalendarResourceId()); Assert.assertEquals(existingCalendar.getName(), newCalendar.getName()); Assert.assertEquals(existingCalendar.getDescription(), newCalendar.getDescription()); Assert.assertEquals(existingCalendar.getTimeZoneId(), newCalendar.getTimeZoneId()); Assert.assertEquals(existingCalendar.getColor(), newCalendar.getColor()); Assert.assertEquals(existingCalendar.getDefaultCalendar(), newCalendar.getDefaultCalendar()); Assert.assertEquals(existingCalendar.getEnableComments(), newCalendar.getEnableComments()); Assert.assertEquals(existingCalendar.getEnableRatings(), newCalendar.getEnableRatings()); Assert.assertEquals( Time.getShortTimestamp(existingCalendar.getLastPublishDate()), Time.getShortTimestamp(newCalendar.getLastPublishDate())); }
/** * Converts the soap model instance into a normal model instance. * * @param soapModel the soap model instance to convert * @return the normal model instance */ public static Calendar toModel(CalendarSoap soapModel) { if (soapModel == null) { return null; } Calendar model = new CalendarImpl(); model.setUuid(soapModel.getUuid()); model.setCalendarId(soapModel.getCalendarId()); model.setGroupId(soapModel.getGroupId()); model.setCompanyId(soapModel.getCompanyId()); model.setUserId(soapModel.getUserId()); model.setUserName(soapModel.getUserName()); model.setCreateDate(soapModel.getCreateDate()); model.setModifiedDate(soapModel.getModifiedDate()); model.setResourceBlockId(soapModel.getResourceBlockId()); model.setCalendarResourceId(soapModel.getCalendarResourceId()); model.setName(soapModel.getName()); model.setDescription(soapModel.getDescription()); model.setColor(soapModel.getColor()); model.setDefaultCalendar(soapModel.getDefaultCalendar()); model.setEnableComments(soapModel.getEnableComments()); model.setEnableRatings(soapModel.getEnableRatings()); return model; }
@Override public String getDisplayName(Calendar calendar) { return calendar.getNameCurrentValue(); }
protected Calendar addCalendar() throws Exception { long pk = RandomTestUtil.nextLong(); Calendar calendar = _persistence.create(pk); calendar.setUuid(RandomTestUtil.randomString()); calendar.setGroupId(RandomTestUtil.nextLong()); calendar.setCompanyId(RandomTestUtil.nextLong()); calendar.setUserId(RandomTestUtil.nextLong()); calendar.setUserName(RandomTestUtil.randomString()); calendar.setCreateDate(RandomTestUtil.nextDate()); calendar.setModifiedDate(RandomTestUtil.nextDate()); calendar.setResourceBlockId(RandomTestUtil.nextLong()); calendar.setCalendarResourceId(RandomTestUtil.nextLong()); calendar.setName(RandomTestUtil.randomString()); calendar.setDescription(RandomTestUtil.randomString()); calendar.setTimeZoneId(RandomTestUtil.randomString()); calendar.setColor(RandomTestUtil.nextInt()); calendar.setDefaultCalendar(RandomTestUtil.randomBoolean()); calendar.setEnableComments(RandomTestUtil.randomBoolean()); calendar.setEnableRatings(RandomTestUtil.randomBoolean()); calendar.setLastPublishDate(RandomTestUtil.nextDate()); _calendars.add(_persistence.update(calendar)); return calendar; }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, Calendar calendar) throws Exception { long userId = portletDataContext.getUserId(calendar.getUserUuid()); Map<Long, Long> calendarResourceIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(CalendarResource.class); long calendarResourceId = MapUtil.getLong( calendarResourceIds, calendar.getCalendarResourceId(), calendar.getCalendarResourceId()); Map<Locale, String> calendarNameMap = getCalendarNameMap(portletDataContext, calendar); ServiceContext serviceContext = portletDataContext.createServiceContext(calendar); Calendar importedCalendar = null; if (portletDataContext.isDataStrategyMirror()) { Calendar existingCalendar = fetchStagedModelByUuidAndGroupId( calendar.getUuid(), portletDataContext.getScopeGroupId()); if (existingCalendar == null) { serviceContext.setUuid(calendar.getUuid()); importedCalendar = CalendarLocalServiceUtil.addCalendar( userId, portletDataContext.getScopeGroupId(), calendarResourceId, calendarNameMap, calendar.getDescriptionMap(), calendar.getTimeZoneId(), calendar.getColor(), calendar.isDefaultCalendar(), calendar.isEnableComments(), calendar.isEnableRatings(), serviceContext); } else { importedCalendar = CalendarLocalServiceUtil.updateCalendar( existingCalendar.getCalendarId(), calendar.getNameMap(), calendar.getDescriptionMap(), calendar.getTimeZoneId(), calendar.getColor(), calendar.isDefaultCalendar(), calendar.isEnableComments(), calendar.isEnableRatings(), serviceContext); } } else { importedCalendar = CalendarLocalServiceUtil.addCalendar( userId, portletDataContext.getScopeGroupId(), calendarResourceId, calendarNameMap, calendar.getDescriptionMap(), calendar.getTimeZoneId(), calendar.getColor(), calendar.isDefaultCalendar(), calendar.isEnableComments(), calendar.isEnableRatings(), serviceContext); } portletDataContext.importClassedModel(calendar, importedCalendar); }
public CalendarBooking addCalendarBooking( long userId, long calendarId, long[] childCalendarIds, long parentCalendarBookingId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String location, long startDate, long endDate, boolean allDay, String recurrence, long firstReminder, String firstReminderType, long secondReminder, String secondReminderType, ServiceContext serviceContext) throws PortalException, SystemException { // Calendar booking User user = userPersistence.findByPrimaryKey(userId); Calendar calendar = calendarPersistence.findByPrimaryKey(calendarId); java.util.Calendar startDateJCalendar = JCalendarUtil.getJCalendar(startDate); java.util.Calendar endDateJCalendar = JCalendarUtil.getJCalendar(endDate); if (allDay) { startDateJCalendar = JCalendarUtil.toMidnightJCalendar(startDateJCalendar); endDateJCalendar = JCalendarUtil.toLastHourJCalendar(endDateJCalendar); } if (firstReminder < secondReminder) { long originalSecondReminder = secondReminder; secondReminder = firstReminder; firstReminder = originalSecondReminder; } Date now = new Date(); validate(titleMap, startDateJCalendar, endDateJCalendar); long calendarBookingId = counterLocalService.increment(); CalendarBooking calendarBooking = calendarBookingPersistence.create(calendarBookingId); calendarBooking.setUuid(serviceContext.getUuid()); calendarBooking.setGroupId(calendar.getGroupId()); calendarBooking.setCompanyId(user.getCompanyId()); calendarBooking.setUserId(user.getUserId()); calendarBooking.setUserName(user.getFullName()); calendarBooking.setCreateDate(serviceContext.getCreateDate(now)); calendarBooking.setModifiedDate(serviceContext.getModifiedDate(now)); calendarBooking.setCalendarId(calendarId); calendarBooking.setCalendarResourceId(calendar.getCalendarResourceId()); if (parentCalendarBookingId > 0) { calendarBooking.setParentCalendarBookingId(parentCalendarBookingId); } else { calendarBooking.setParentCalendarBookingId(calendarBookingId); } calendarBooking.setTitleMap(titleMap); calendarBooking.setDescriptionMap(descriptionMap); calendarBooking.setLocation(location); calendarBooking.setStartDate(startDateJCalendar.getTimeInMillis()); calendarBooking.setEndDate(endDateJCalendar.getTimeInMillis()); calendarBooking.setAllDay(allDay); calendarBooking.setRecurrence(recurrence); calendarBooking.setFirstReminder(firstReminder); calendarBooking.setFirstReminderType(firstReminderType); calendarBooking.setSecondReminder(secondReminder); calendarBooking.setSecondReminderType(secondReminderType); int status = CalendarBookingWorkflowConstants.STATUS_PENDING; if (parentCalendarBookingId == 0) { status = CalendarBookingWorkflowConstants.STATUS_APPROVED; } calendarBooking.setStatus(status); calendarBooking.setStatusDate(serviceContext.getModifiedDate(now)); calendarBookingPersistence.update(calendarBooking, false); addChildCalendarBookings(calendarBooking, childCalendarIds, serviceContext); // Workflow calendarBookingApprovalWorkflow.startWorkflow(userId, calendarBookingId, serviceContext); return calendarBooking; }