コード例 #1
0
  private void createUpdateContentWithBinary() {
    UserEntity runningUser = fixture.findUserByName("testuser");

    // prepare: save a new content
    ContentEntity content = new ContentEntity();
    content.setPriority(0);
    content.setAvailableFrom(null);
    content.setAvailableTo(null);
    content.setCategory(fixture.findCategoryByName("MyCategory"));
    content.setLanguage(fixture.findLanguageByCode("en"));
    content.setName("testcontentwithbinary");

    ContentVersionEntity version = new ContentVersionEntity();
    version.setContent(content);
    version.setModifiedBy(runningUser);
    version.setStatus(com.enonic.cms.core.content.ContentStatus.DRAFT);
    version.setContent(content);
    CustomContentData contentData =
        new CustomContentData(
            fixture.findContentTypeByName("MyContentType").getContentTypeConfig());

    TextDataEntryConfig titleConfig =
        (TextDataEntryConfig)
            contentData.getContentTypeConfig().getForm().getInputConfig("myTitle");
    TextDataEntryConfig updateFieldConfig =
        (TextDataEntryConfig)
            contentData.getContentTypeConfig().getForm().getInputConfig("fieldToUpdate");
    BinaryDataEntryConfig binaryConfig =
        (BinaryDataEntryConfig)
            contentData.getContentTypeConfig().getForm().getInputConfig("myBinaryfile");

    contentData.add(new TextDataEntry(titleConfig, "testitle"));
    contentData.add(new TextDataEntry(updateFieldConfig, "foobar"));
    contentData.add(new BinaryDataEntry(binaryConfig, "%0"));

    version.setContentData(contentData);
    version.setTitle(contentData.getTitle());

    CreateContentCommand createContentCommand = new CreateContentCommand();
    createContentCommand.setCreator(runningUser);

    createContentCommand.populateCommandWithContentValues(content);
    createContentCommand.populateCommandWithContentVersionValues(version);

    List<BinaryDataAndBinary> binaryDatas = new ArrayList<BinaryDataAndBinary>();
    binaryDatas.add(factory.createBinaryDataAndBinary("dummyBinary", dummyBinary));

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

    contentWithBinaryKey = contentService.createContent(createContentCommand);

    fixture.flushAndClearHibernateSession();
  }
 private CreateContentCommand createCreateContentCommand(
     String categoryName, ContentData contentData, String creatorUid) {
   CreateContentCommand createContentCommand = new CreateContentCommand();
   createContentCommand.setCategory(fixture.findCategoryByName(categoryName));
   createContentCommand.setCreator(fixture.findUserByName(creatorUid).getKey());
   createContentCommand.setLanguage(fixture.findLanguageByCode("en"));
   createContentCommand.setStatus(ContentStatus.APPROVED);
   createContentCommand.setPriority(0);
   createContentCommand.setAccessRightsStrategy(
       CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY);
   createContentCommand.setContentData(contentData);
   createContentCommand.setAvailableFrom(DATE_TIME_2010_01_01.toDate());
   createContentCommand.setAvailableTo(null);
   createContentCommand.setContentName("testcontent");
   return createContentCommand;
 }
コード例 #3
0
  private void createUpdateContent() {
    UserEntity runningUser = fixture.findUserByName("testuser");

    // prepare: save a new content
    ContentEntity content = new ContentEntity();
    content.setPriority(0);
    content.setAvailableFrom(new Date());
    content.setAvailableTo(null);
    content.setCategory(fixture.findCategoryByName("MyCategory"));
    content.setLanguage(fixture.findLanguageByCode("en"));
    content.setName("testcontent");

    ContentVersionEntity version = new ContentVersionEntity();
    version.setContent(content);
    version.setModifiedBy(runningUser);
    version.setStatus(com.enonic.cms.core.content.ContentStatus.APPROVED);
    version.setContent(content);
    CustomContentData contentData =
        new CustomContentData(
            fixture.findContentTypeByName("MyContentType").getContentTypeConfig());

    TextDataEntryConfig titleConfig =
        (TextDataEntryConfig)
            contentData.getContentTypeConfig().getForm().getInputConfig("myTitle");
    TextDataEntryConfig updateFieldConfig =
        (TextDataEntryConfig)
            contentData.getContentTypeConfig().getForm().getInputConfig("fieldToUpdate");
    contentData.add(new TextDataEntry(titleConfig, "testitle"));
    contentData.add(new TextDataEntry(updateFieldConfig, "foobar"));

    version.setContentData(contentData);
    version.setTitle(contentData.getTitle());

    CreateContentCommand createContentCommand = new CreateContentCommand();
    createContentCommand.setCreator(runningUser);
    createContentCommand.setAccessRightsStrategy(AccessRightsStrategy.USE_GIVEN);

    createContentCommand.populateCommandWithContentValues(content);
    createContentCommand.populateCommandWithContentVersionValues(version);

    updateContentKey = contentService.createContent(createContentCommand);

    fixture.flushAndClearHibernateSession();
  }
  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;
  }