private PageTemplate createPageTemplate() { final PropertyTree pageTemplateConfig = new PropertyTree(); pageTemplateConfig.addLong("pause", 10000L); PageRegions pageRegions = PageRegions.create() .add( Region.create() .name("main-region") .add(PartComponent.create().name(ComponentName.from("mypart")).build()) .build()) .build(); final PageTemplate.Builder builder = PageTemplate.newPageTemplate() .key(PageTemplateKey.from("abc")) .canRender(ContentTypeNames.from("myapplication:article", "myapplication:banner")) .regions(pageRegions) .config(pageTemplateConfig); builder.controller(DescriptorKey.from("mainapplication:landing-page")); builder.displayName("Main page template"); builder.displayName("Main page template"); builder.name("main-page-template"); builder.parentPath(ContentPath.ROOT); return builder.build(); }
@Test public void getContentShortcut() throws Exception { final PropertyTree rootDataSet = new PropertyTree(); rootDataSet.addReference("target", Reference.from("ref")); final Content content = Content.create() .id(ContentId.from("id")) .path(ContentPath.from("site/somepath/shortcut")) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifier(PrincipalKey.from("user:system:admin")) .type(ContentTypeName.shortcut()) .data(rootDataSet) .build(); Mockito.when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content); Mockito.when(this.portalUrlService.pageUrl(Mockito.any(PageUrlParams.class))) .thenReturn("/master/site/otherpath"); this.request.setContentPath(ContentPath.from("/site/somepath/shortcut")); final PortalResponse res = this.handler.handle(this.request); assertNotNull(res); assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus()); assertEquals("/master/site/otherpath", res.getHeaders().get("Location")); }
private Content createPage(final String id, final String name, final String contentTypeName) { PropertyTree rootDataSet = new PropertyTree(); rootDataSet.addString("property1", "value1"); Region region = Region.create() .name("myRegion") .add( PartComponent.create() .name("myPartComponent") .descriptor(DescriptorKey.from("myapplication:myparttemplate")) .build()) .build(); PageRegions pageRegions = PageRegions.create().add(region).build(); Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).build(); return Content.create() .id(ContentId.from(id)) .path(ContentPath.from(name)) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifier(PrincipalKey.from("user:system:admin")) .type(ContentTypeName.from(contentTypeName)) .page(page) .build(); }
protected Node createNode(final NodePath parentPath, final String name) { final PropertyTree data = new PropertyTree(); data.setString("displayName", "This is brand new node"); final PropertySet someData = data.addSet("someData"); someData.setString("cars", "skoda"); someData.addString("cars", "tesla model x"); someData.setString("likes", "plywood"); someData.setLong("numberOfUselessGadgets", 123L); final PatternIndexConfigDocument indexConfig = PatternIndexConfigDocument.create() .defaultConfig(IndexConfig.MINIMAL) .add("displayName", IndexConfig.FULLTEXT) .build(); return Node.create() .id(NodeId.from("nodeId")) .parentPath(parentPath) .name(name) .data(data) .indexConfigDocument(indexConfig) .permissions( AccessControlList.create() .add( AccessControlEntry.create() .principal(PrincipalKey.ofRole("admin")) .allowAll() .build()) .build()) .nodeState(NodeState.DEFAULT) .nodeVersionId(NodeVersionId.from("versionKey")) .timestamp(Instant.parse("2010-10-10T10:10:10.10Z")) .build(); }
private Content createPage( final String id, final String path, final String contentTypeName, final boolean withPage) { PropertyTree rootDataSet = new PropertyTree(); rootDataSet.addString("property1", "value1"); final Content.Builder content = Content.create() .id(ContentId.from(id)) .path(ContentPath.from(path)) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifier(PrincipalKey.from("user:system:admin")) .type(ContentTypeName.from(contentTypeName)); if (withPage) { PageRegions pageRegions = PageRegions.create() .add( Region.create() .name("main-region") .add(PartComponent.create().name(ComponentName.from("mypart")).build()) .build()) .build(); Page page = Page.create() .template(PageTemplateKey.from("my-page")) .regions(pageRegions) .config(rootDataSet) .build(); content.page(page); } return content.build(); }
@Test public void fulltext_norwegian_characters() throws Exception { final PropertyTree data = new PropertyTree(); data.addString("myProperty", "æ"); final PropertySet userdata = data.addSet("data"); userdata.addString("displayName", "ø å"); final Node node = createNode( CreateNodeParams.create() .name("my-node-1") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); refresh(); printContentRepoIndex(); final NodeQuery query = NodeQuery.create() .query( QueryExpr.from( new DynamicConstraintExpr( FunctionExpr.from( "fulltext", ValueExpr.string(NodeIndexPath.ALL_TEXT.getPath()), ValueExpr.string("æ"), ValueExpr.string("OR"))))) .build(); final FindNodesByQueryResult result = doFindByQuery(query); assertEquals(1, result.getNodes().getSize()); assertNotNull(result.getNodes().getNodeById(node.id())); final NodeQuery query2 = NodeQuery.create() .query( QueryExpr.from( new DynamicConstraintExpr( FunctionExpr.from( "fulltext", ValueExpr.string("data.displayName"), ValueExpr.string("ø å"), ValueExpr.string("OR"))))) .build(); final FindNodesByQueryResult result2 = doFindByQuery(query2); assertEquals(1, result2.getNodes().getSize()); assertNotNull(result2.getNodes().getNodeById(node.id())); }
@Test public void negate() throws Exception { final PropertyTree data = new PropertyTree(); data.addString("title", "fisk kake"); final Node node = createNode( CreateNodeParams.create() .name("my-node-1") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); final PropertyTree data2 = new PropertyTree(); data2.addString("title", "fisk båt"); createNode( CreateNodeParams.create() .name("my-node-2") .parent(NodePath.ROOT) .data(data2) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); final NodeQuery query = NodeQuery.create() .query( QueryExpr.from( new DynamicConstraintExpr( FunctionExpr.from( "fulltext", ValueExpr.string("title"), ValueExpr.string("fisk -båt"), ValueExpr.string("AND"))))) .build(); final FindNodesByQueryResult result = doFindByQuery(query); assertEquals(1, result.getNodes().getSize()); assertNotNull(result.getNodes().getNodeById(node.id())); }
private Site createSite(final String id, final String name, final String contentTypeName) { PropertyTree rootDataSet = new PropertyTree(); rootDataSet.addString("property1", "value1"); Page page = Page.create().template(PageTemplateKey.from("my-page")).config(rootDataSet).build(); return Site.create() .id(ContentId.from(id)) .path(ContentPath.from(name)) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifier(PrincipalKey.from("user:system:admin")) .type(ContentTypeName.from(contentTypeName)) .page(page) .build(); }
@Test public void fulltext_wildcard_paths() throws Exception { final PropertyTree data = new PropertyTree(); final String path1 = "test.of.string-1.with.path-1"; final String value1 = "fisk ost pølse løk"; data.setString(path1, value1); createNode( CreateNodeParams.create() .name("node1") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); final PropertyTree data2 = new PropertyTree(); final String path2 = "test.of.string-2.with.path-2"; final String value2 = "fisk ost pølse løk"; data2.setString(path2, value2); createNode( CreateNodeParams.create() .name("node2") .parent(NodePath.ROOT) .data(data2) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); queryAndAssert("fulltext('test*', 'leter etter fisk', 'OR')", 2); queryAndAssert("fulltext('test.*', 'leter etter fisk', 'OR')", 2); queryAndAssert("fulltext('test.of*', 'leter etter fisk', 'OR')", 2); queryAndAssert("fulltext('test.of.string*', 'leter etter fisk', 'OR')", 2); queryAndAssert("fulltext('test.of.string-1.*', 'leter etter fisk', 'OR')", 1); queryAndAssert("fulltext('test.of.string-2.*', 'leter etter fisk', 'OR')", 1); queryAndAssert("fulltext('*path*', 'leter etter fisk', 'OR')", 2); queryAndAssert("fulltext('*path', 'leter etter fisk', 'OR')", 0); queryAndAssert("fulltext('*path-1', 'leter etter fisk', 'OR')", 1); queryAndAssert("fulltext('*path-2', 'leter etter fisk', 'OR')", 1); }
private Media createMedia( final String id, final String contentPath, final Attachment... attachments) { final PropertyTree data = new PropertyTree(); data.addString("media", attachments[0].getName()); return Media.create() .id(ContentId.from(id)) .path(contentPath) .createdTime(Instant.now()) .type(ContentTypeName.imageMedia()) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifiedTime(Instant.now()) .modifier(PrincipalKey.from("user:system:admin")) .data(data) .attachments(Attachments.from(attachments)) .build(); }
private BinaryAttachments processBinaryAttachments( final VirtualFile nodeFile, final Node newNode) { final PropertyTree data = newNode.data(); final ImmutableList<Property> binaryReferences = data.getProperties(ValueTypes.BINARY_REFERENCE); if (binaryReferences.isEmpty()) { return BinaryAttachments.empty(); } final BinaryAttachments.Builder builder = BinaryAttachments.create(); for (final Property binaryReference : binaryReferences) { addBinary(nodeFile, builder, binaryReference); } return builder.build(); }
@Test public void fulltext_with_path() throws Exception { final PropertyTree data = new PropertyTree(); final String path1 = "test.of.string.with.path"; final String value1 = "fisk ost pølse løk"; data.setString(path1, value1); final String path2 = "mystring.with.path2"; final String value2 = "vif rbk lsk sif"; data.setString(path2, value2); final Node node = createNode( CreateNodeParams.create() .name("fisk ost") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); final NodeQuery query = NodeQuery.create() .query( QueryExpr.from( new DynamicConstraintExpr( FunctionExpr.from( "fulltext", ValueExpr.string(path1), ValueExpr.string("leter etter fisk"), ValueExpr.string("OR"))))) .build(); final FindNodesByQueryResult result = doFindByQuery(query); assertEquals(1, result.getNodes().getSize()); assertNotNull(result.getNodes().getNodeById(node.id())); }
@Test public void word_delimiter_testing_dot() throws Exception { final PropertyTree data = new PropertyTree(); data.addString("title", "testing.delimiter"); final Node node = createNode( CreateNodeParams.create() .name("my-node-1") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); queryAndAssert("fulltext('title', 'testing', 'AND')", 1); queryAndAssert("fulltext('title', 'delimiter', 'AND')", 1); }
@Test public void fulltext_word_breaking_character() throws Exception { final PropertyTree data = new PropertyTree(); data.addString("title", "Levenshteins-algorithm"); final Node node = createNode( CreateNodeParams.create() .name("my-node-1") .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); queryAndAssert("fulltext('title', 'levenshteins algorithm', 'AND')", 1); queryAndAssert("fulltext('title', 'levenshteins-algorithm', 'AND')", 1); }
private void createWithTitleAndDescription( final String id, final String title, final String description) { final PropertyTree data = new PropertyTree(); data.addString("title", title); if (!Strings.isNullOrEmpty(description)) { data.addString("description", description); } createNode( CreateNodeParams.create() .setNodeId(NodeId.from(id)) .name(title) .parent(NodePath.ROOT) .data(data) .indexConfigDocument( PatternIndexConfigDocument.create() .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER) .defaultConfig(IndexConfig.BY_TYPE) .build()) .build()); }
private Node createNode(final Instant instantValue, final String name, final NodePath parent) { final PropertyTree data = new PropertyTree(); data.addInstant("instant", instantValue); return createNode(CreateNodeParams.create().parent(parent).name(name).data(data).build()); }