@Override public CalendarResource updateCalendarResource( long calendarResourceId, Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, boolean active, ServiceContext serviceContext) throws PortalException { // Calendar resource validate(nameMap); CalendarResource calendarResource = calendarResourcePersistence.findByPrimaryKey(calendarResourceId); calendarResource.setModifiedDate(serviceContext.getModifiedDate(null)); calendarResource.setNameMap(nameMap); calendarResource.setDescriptionMap(descriptionMap); calendarResource.setActive(active); calendarResourcePersistence.update(calendarResource); // Asset updateAsset( calendarResource.getUserId(), calendarResource, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames()); return calendarResource; }
/** * 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 CalendarResource toModel(CalendarResourceSoap soapModel) { CalendarResource model = new CalendarResourceImpl(); model.setUuid(soapModel.getUuid()); model.setCalendarResourceId(soapModel.getCalendarResourceId()); 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.setClassNameId(soapModel.getClassNameId()); model.setClassPK(soapModel.getClassPK()); model.setClassUuid(soapModel.getClassUuid()); model.setName(soapModel.getName()); model.setDescription(soapModel.getDescription()); model.setActive(soapModel.getActive()); return model; }
protected CalendarResource addCalendarResource() throws Exception { long pk = RandomTestUtil.nextLong(); CalendarResource calendarResource = _persistence.create(pk); calendarResource.setUuid(RandomTestUtil.randomString()); calendarResource.setGroupId(RandomTestUtil.nextLong()); calendarResource.setCompanyId(RandomTestUtil.nextLong()); calendarResource.setUserId(RandomTestUtil.nextLong()); calendarResource.setUserName(RandomTestUtil.randomString()); calendarResource.setCreateDate(RandomTestUtil.nextDate()); calendarResource.setModifiedDate(RandomTestUtil.nextDate()); calendarResource.setResourceBlockId(RandomTestUtil.nextLong()); calendarResource.setClassNameId(RandomTestUtil.nextLong()); calendarResource.setClassPK(RandomTestUtil.nextLong()); calendarResource.setClassUuid(RandomTestUtil.randomString()); calendarResource.setCode(RandomTestUtil.randomString()); calendarResource.setName(RandomTestUtil.randomString()); calendarResource.setDescription(RandomTestUtil.randomString()); calendarResource.setActive(RandomTestUtil.randomBoolean()); calendarResource.setLastPublishDate(RandomTestUtil.nextDate()); _calendarResources.add(_persistence.update(calendarResource)); return calendarResource; }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); CalendarResource newCalendarResource = _persistence.create(pk); newCalendarResource.setUuid(RandomTestUtil.randomString()); newCalendarResource.setGroupId(RandomTestUtil.nextLong()); newCalendarResource.setCompanyId(RandomTestUtil.nextLong()); newCalendarResource.setUserId(RandomTestUtil.nextLong()); newCalendarResource.setUserName(RandomTestUtil.randomString()); newCalendarResource.setCreateDate(RandomTestUtil.nextDate()); newCalendarResource.setModifiedDate(RandomTestUtil.nextDate()); newCalendarResource.setResourceBlockId(RandomTestUtil.nextLong()); newCalendarResource.setClassNameId(RandomTestUtil.nextLong()); newCalendarResource.setClassPK(RandomTestUtil.nextLong()); newCalendarResource.setClassUuid(RandomTestUtil.randomString()); newCalendarResource.setCode(RandomTestUtil.randomString()); newCalendarResource.setName(RandomTestUtil.randomString()); newCalendarResource.setDescription(RandomTestUtil.randomString()); newCalendarResource.setActive(RandomTestUtil.randomBoolean()); newCalendarResource.setLastPublishDate(RandomTestUtil.nextDate()); _calendarResources.add(_persistence.update(newCalendarResource)); CalendarResource existingCalendarResource = _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey()); Assert.assertEquals(existingCalendarResource.getUuid(), newCalendarResource.getUuid()); Assert.assertEquals( existingCalendarResource.getCalendarResourceId(), newCalendarResource.getCalendarResourceId()); Assert.assertEquals(existingCalendarResource.getGroupId(), newCalendarResource.getGroupId()); Assert.assertEquals( existingCalendarResource.getCompanyId(), newCalendarResource.getCompanyId()); Assert.assertEquals(existingCalendarResource.getUserId(), newCalendarResource.getUserId()); Assert.assertEquals(existingCalendarResource.getUserName(), newCalendarResource.getUserName()); Assert.assertEquals( Time.getShortTimestamp(existingCalendarResource.getCreateDate()), Time.getShortTimestamp(newCalendarResource.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingCalendarResource.getModifiedDate()), Time.getShortTimestamp(newCalendarResource.getModifiedDate())); Assert.assertEquals( existingCalendarResource.getResourceBlockId(), newCalendarResource.getResourceBlockId()); Assert.assertEquals( existingCalendarResource.getClassNameId(), newCalendarResource.getClassNameId()); Assert.assertEquals(existingCalendarResource.getClassPK(), newCalendarResource.getClassPK()); Assert.assertEquals( existingCalendarResource.getClassUuid(), newCalendarResource.getClassUuid()); Assert.assertEquals(existingCalendarResource.getCode(), newCalendarResource.getCode()); Assert.assertEquals(existingCalendarResource.getName(), newCalendarResource.getName()); Assert.assertEquals( existingCalendarResource.getDescription(), newCalendarResource.getDescription()); Assert.assertEquals(existingCalendarResource.getActive(), newCalendarResource.getActive()); Assert.assertEquals( Time.getShortTimestamp(existingCalendarResource.getLastPublishDate()), Time.getShortTimestamp(newCalendarResource.getLastPublishDate())); }
@Override public CalendarResource addCalendarResource( long userId, long groupId, long classNameId, long classPK, String classUuid, String code, Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, boolean active, ServiceContext serviceContext) throws PortalException { // Calendar resource User user = userPersistence.findByPrimaryKey(userId); long calendarResourceId = counterLocalService.increment(); if (classNameId == classNameLocalService.getClassNameId(CalendarResource.class)) { classPK = calendarResourceId; } if (PortletPropsValues.CALENDAR_RESOURCE_FORCE_AUTOGENERATE_CODE || Validator.isNull(code)) { code = String.valueOf(calendarResourceId); } else { code = code.trim(); code = StringUtil.toUpperCase(code); } Date now = new Date(); validate(groupId, classNameId, classPK, code, nameMap); CalendarResource calendarResource = calendarResourcePersistence.create(calendarResourceId); calendarResource.setUuid(serviceContext.getUuid()); calendarResource.setGroupId(groupId); calendarResource.setCompanyId(user.getCompanyId()); calendarResource.setUserId(user.getUserId()); calendarResource.setUserName(user.getFullName()); calendarResource.setCreateDate(serviceContext.getCreateDate(now)); calendarResource.setModifiedDate(serviceContext.getModifiedDate(now)); calendarResource.setClassNameId(classNameId); calendarResource.setClassPK(classPK); calendarResource.setClassUuid(classUuid); calendarResource.setCode(code); calendarResource.setNameMap(nameMap); calendarResource.setDescriptionMap(descriptionMap); calendarResource.setActive(active); calendarResourcePersistence.update(calendarResource); // Resources resourceLocalService.addModelResources(calendarResource, serviceContext); // Calendar if (!ExportImportThreadLocal.isImportInProcess()) { serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); calendarLocalService.addCalendar( userId, calendarResource.getGroupId(), calendarResourceId, nameMap, descriptionMap, calendarResource.getTimeZoneId(), PortletPropsValues.CALENDAR_COLOR_DEFAULT, true, false, false, serviceContext); } // Asset updateAsset( calendarResource.getUserId(), calendarResource, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames()); return calendarResource; }