Full example for using ContentPropertyService to store JsonContentProperty with page

Hi,
I am really struggling with using the ContentPropertyService for storing a JsonContentProperty with a page. Is there any example for writing and loading of a JsonContentProperty?
Thanks
Tuelle

1 Like

Hi @ttwellmann,

I’m not sure if this will help, but I’ve searched thru our code base and this is a sample read and write:

    @Test
    public void testSimpleCreateRead() throws ServiceException, IOException {
        long pageId = TEST_PAGE.getId();
        ContentId apiPageId = ContentId.of(PAGE, pageId);
        String key = "my-super-key";
        JsonString value = makeTestString("I am saved");
        JsonContentProperty newProperty = JsonContentProperty.builder()
                .content(Reference.to(Content.builder().id(apiPageId).build()))
                .key(key)
                .value(value)
                .build();
        JsonContentProperty savedProperty = service.create(newProperty);
        assertThat(savedProperty.getContent(), nullValue());
        assertThat(savedProperty.getKey(), is(key));
        assertThat(savedProperty.getValue(), is(value));

        Option<JsonContentProperty> foundPropertyOpt = service.find().withContentId(apiPageId).withPropertyKey(key).fetchOne();
        assertThat(foundPropertyOpt.isDefined(), is(true));
        JsonContentProperty foundProperty = foundPropertyOpt.get();
        assertThat(foundProperty.getId(), is(savedProperty.getId()));
        assertThat(foundProperty.getContentRef().exists(), is(false));
        assertThat(foundProperty.getKey(), is(key));
        assertThat(foundProperty.getValue(), is(value));
        assertThat(foundProperty.getVersion(), is(savedProperty.getVersion()));
    }

Cheers,
Anne Calantog

1 Like

Is there any way to engage ContentPropertyService for setting and getting a JsonContentProperty in a user macro (using velocity)?

2 Likes

I really would love to know how to use ContentPropertyService for storing a JsonContentProperty with a page in a user macro.

Any ideas? Thx!

Thanks for this example. May you please provide details about method “makeTestString” which builds the JsonString object? Thank you in advance. Regards. Yves