public int createContent(CreateContentParams params) throws ClientException {
    final CategoryEntity category = validateCreateContentParams(params);

    final CreateContentCommand command = new CreateContentCommand();
    command.setPriority(0);
    command.setAvailableFrom(params.publishFrom);
    command.setAvailableTo(params.publishTo);
    command.setCategory(category);
    command.setLanguage(category.getUnitExcludeDeleted().getLanguage());

    command.setStatus(ContentStatus.get(params.status));

    command.setChangeComment(params.changeComment);

    // content data
    final ContentTypeEntity contentType = category.getContentType();
    if (contentType == null) {
      throw new IllegalArgumentException(
          "Unable to create content in category "
              + category.getKey()
              + ". Category has no contenttype set.");
    }

    final ContentDataResolver customContentResolver = new ContentDataResolver();

    final CustomContentData contentdata =
        customContentResolver.resolveContentdata(params.contentData, contentType);

    command.setContentData(contentdata);
    command.setContentName(
        new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle()));

    final List<BinaryDataAndBinary> binaryDatas =
        BinaryDataAndBinary.convertFromBinaryInputs(params.contentData.getBinaryInputs());

    command.setBinaryDatas(binaryDatas);
    command.setUseCommandsBinaryDataToAdd(true);

    command.setAccessRightsStrategy(
        CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY);
    command.setCreator(securityService.getImpersonatedPortalUser());

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

    return contentService.createContent(command).toInt();
  }
  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();
  }