コード例 #1
0
  public int createFileContent(CreateFileContentParams params) {
    validateCreateFileContentParams(params);

    CategoryEntity category = categoryDao.findByKey(new CategoryKey(params.categoryKey));

    UserEntity runningUser = securityService.getImpersonatedPortalUser();

    LegacyFileContentData contentdata =
        (LegacyFileContentData) fileContentResolver.resolveContentdata(params.fileContentData);
    List<BinaryDataAndBinary> binaryDataEntries = new ArrayList<BinaryDataAndBinary>();
    binaryDataEntries.add(
        BinaryDataAndBinary.convertFromFileBinaryInput(params.fileContentData.binary));

    CreateContentCommand createCommand = new CreateContentCommand();
    createCommand.setAccessRightsStrategy(
        CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY);
    createCommand.setCreator(runningUser);
    createCommand.setStatus(ContentStatus.get(params.status));
    createCommand.setPriority(0);
    createCommand.setCategory(category);
    createCommand.setLanguage(category.getUnitExcludeDeleted().getLanguage());
    createCommand.setAvailableFrom(params.publishFrom);
    createCommand.setAvailableTo(params.publishTo);
    createCommand.setContentData(contentdata);
    createCommand.setContentName(
        new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle()));
    createCommand.setBinaryDatas(binaryDataEntries);
    createCommand.setUseCommandsBinaryDataToAdd(true);
    if (params.siteKey != null) {
      createCommand.setSiteKey(new SiteKey(params.siteKey));
    }

    ContentKey contentKey = contentService.createContent(createCommand);
    return contentKey.toInt();
  }
コード例 #2
0
  public int updateFileContent(UpdateFileContentParams params) {
    validateUpdateFileContentParams(params);

    ContentVersionKey contentVersionKey =
        resolveContentVersionKey(
            params.createNewVersion, params.contentKey, params.contentVersionKey);

    UpdateContentCommand command;
    if (params.createNewVersion) {
      command = UpdateContentCommand.storeNewVersionEvenIfUnchanged(contentVersionKey);
    } else {
      command = UpdateContentCommand.updateExistingVersion2(contentVersionKey);
    }

    command.setContentKey(new ContentKey(params.contentKey));
    command.setSyncRelatedContent(false);
    command.setSyncAccessRights(false);
    command.setModifier(securityService.getImpersonatedPortalUser());
    command.setAvailableFrom(params.publishFrom);
    command.setAvailableTo(params.publishTo);
    command.setStatus(ContentStatus.get(params.status));
    if (params.siteKey != null) {
      command.setSiteKey(new SiteKey(params.siteKey));
    }

    LegacyFileContentData newContentData;
    List<BinaryDataAndBinary> binariesToAdd = null;
    List<BinaryDataKey> binariesToRemove = null;
    if (params.fileContentData != null) {
      newContentData =
          (LegacyFileContentData) fileContentResolver.resolveContentdata(params.fileContentData);
      command.setContentData(newContentData);
      if (!params.createNewVersion) {
        // only delete previous binaries if we are overwriting current version
        ContentVersionEntity persistedVersion = contentVersionDao.findByKey(contentVersionKey);
        LegacyFileContentData previousContentData =
            (LegacyFileContentData) persistedVersion.getContentData();
        binariesToRemove = previousContentData.getRemovedBinaries(newContentData);
      }
      // Find new binaries
      binariesToAdd = newContentData.getBinaryDataAndBinaryList();
    } else {
      // only update the meta data in this case..
    }

    command.setUpdateAsMainVersion(params.setAsCurrentVersion);
    command.setUseCommandsBinaryDataToAdd(true);
    command.setBinaryDataToAdd(binariesToAdd);

    command.setUseCommandsBinaryDataToRemove(true);
    command.setBinaryDataToRemove(binariesToRemove);
    if (params.siteKey != null) {
      command.setSiteKey(new SiteKey(params.siteKey));
    }

    UpdateContentResult updateContentResult = contentService.updateContent(command);

    if (updateContentResult.isAnyChangesMade()) {
      new PageCacheInvalidatorForContent(pageCacheService)
          .invalidateForContent(updateContentResult.getTargetedVersion());
    }

    return updateContentResult.getTargetedVersionKey().toInt();
  }