private UpdateContentCommand updateContentCommand( ContentKey contentKeyToUpdate, ContentData contentData, String updaterUid) { ContentEntity contentToUpdate = fixture.findContentByKey(contentKeyToUpdate); UpdateContentCommand command = UpdateContentCommand.storeNewVersionEvenIfUnchanged( contentToUpdate.getMainVersion().getKey()); command.setUpdateAsMainVersion(true); command.setSyncAccessRights(false); command.setSyncRelatedContent(true); command.setContentKey(contentToUpdate.getKey()); command.setUpdateStrategy(UpdateContentCommand.UpdateStrategy.MODIFY); command.setModifier(fixture.findUserByName(updaterUid).getKey()); command.setPriority(0); command.setLanguage(fixture.findLanguageByCode("en")); command.setStatus(ContentStatus.APPROVED); command.setContentData(contentData); command.setAvailableFrom(DATE_TIME_2010_01_01.toDate()); return command; }
public int updateContent(UpdateContentParams params) { validateUpdateContentParams(params); final ContentVersionKey contentVersionKey = resolveContentVersionKey( params.createNewVersion, params.contentKey, params.contentVersionKey); UpdateContentCommand command; if (params.createNewVersion) { command = UpdateContentCommand.storeNewVersionEvenIfUnchanged(contentVersionKey); } else { command = UpdateContentCommand.updateExistingVersion2(contentVersionKey); } command.setContentName(params.name); command.setSyncRelatedContent(true); command.setSyncAccessRights(false); command.setModifier(securityService.getImpersonatedPortalUser()); command.setUpdateAsMainVersion(params.setAsCurrentVersion); command.setContentKey(new ContentKey(params.contentKey)); command.setAvailableFrom(params.publishFrom); command.setAvailableTo(params.publishTo); command.setStatus(ContentStatus.get(params.status)); command.setUseCommandsBinaryDataToRemove(true); command.setUseCommandsBinaryDataToAdd(true); command.setChangeComment(params.changeComment); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } if (params.contentData != null) { final ContentTypeEntity contentType = resolveContentType(params.contentKey); final ContentDataResolver customContentResolver = new ContentDataResolver(); final CustomContentData newContentData = customContentResolver.resolveContentdata(params.contentData, contentType); command.setContentData(newContentData); if (!params.createNewVersion) { // only delete previous binaries if we are overwriting current version final ContentVersionEntity persistedVersion = contentVersionDao.findByKey(contentVersionKey); final CustomContentData persistedContentData = (CustomContentData) persistedVersion.getContentData(); final List<BinaryDataEntry> deletedBinaries = persistedContentData.getRemovedBinaryDataEntries(newContentData); command.setBinaryDataToRemove(BinaryDataEntry.createBinaryDataKeyList(deletedBinaries)); command.setUseCommandsBinaryDataToRemove(true); } // Find new binaries final List<BinaryDataEntry> binaryEntries = newContentData.getBinaryDataEntryList(); command.setBinaryDataToAdd(BinaryDataAndBinary.convert(binaryEntries)); command.setUseCommandsBinaryDataToAdd(true); } else { // only update the meta data in this case.. } if (params.updateStrategy == ContentDataInputUpdateStrategy.REPLACE_NEW) { command.setUpdateStrategy(UpdateStrategy.MODIFY); } final UpdateContentResult updateContentResult = contentService.updateContent(command); if (updateContentResult.isAnyChangesMade()) { new PageCacheInvalidatorForContent(pageCacheService) .invalidateForContent(updateContentResult.getTargetedVersion()); } return updateContentResult.getTargetedVersionKey().toInt(); }