Esempio n. 1
0
  @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"));
  }
Esempio n. 2
0
  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();
  }
Esempio n. 3
0
  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();
  }
Esempio n. 4
0
 public Builder<BUILDER, C> type(final ContentTypeName type) {
   if (type.isDescendantOfMedia() && !(this instanceof Media.Builder)) {
     throw new IllegalArgumentException("Please create Builder via Media when creating a Media");
   }
   this.type = type;
   return this;
 }
Esempio n. 5
0
 public static Builder create(final ContentTypeName type) {
   if (type.isPageTemplate()) {
     final PageTemplate.Builder builder = PageTemplate.newPageTemplate();
     builder.type(type);
     return builder;
   } else if (type.isSite()) {
     Site.Builder builder = Site.create();
     builder.type(type);
     return builder;
   } else if (type.isDescendantOfMedia()) {
     Media.Builder builder = Media.create();
     builder.type(type);
     return builder;
   } else {
     Builder builder = Content.create();
     builder.type(type);
     return builder;
   }
 }
  @Test
  public void testRelationshipTypeIcon_default_image() throws Exception {
    RelationshipType relationshipType =
        RelationshipType.create()
            .name("myapplication:like")
            .fromSemantic("likes")
            .toSemantic("liked by")
            .addAllowedFromType(ContentTypeName.from("myapplication:person"))
            .addAllowedToType(ContentTypeName.from("myapplication:person"))
            .build();
    setupRelationshipType(relationshipType);

    // exercise
    final Response response = this.resource.getIcon("myapplication:like", 20, null);
    final BufferedImage mixinIcon = (BufferedImage) response.getEntity();

    // verify
    assertImage(mixinIcon, 20);
  }
  @Test
  public void testRelationshipTypeIcon() throws Exception {
    byte[] data = Resources.toByteArray(getClass().getResource("relationshipicon.png"));
    final Icon icon = Icon.from(data, "image/png", Instant.now());

    RelationshipType relationshipType =
        RelationshipType.create()
            .name("myapplication:like")
            .fromSemantic("likes")
            .toSemantic("liked by")
            .addAllowedFromType(ContentTypeName.from("myapplication:person"))
            .addAllowedToType(ContentTypeName.from("myapplication:person"))
            .icon(icon)
            .build();
    setupRelationshipType(relationshipType);

    // exercise
    final Response response = this.resource.getIcon("myapplication:like", 20, null);
    final BufferedImage mixinIcon = (BufferedImage) response.getEntity();

    // verify
    assertImage(mixinIcon, 20);
  }
Esempio n. 8
0
  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();
  }
  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();
  }
Esempio n. 10
0
  protected Content(final Builder builder) {
    Preconditions.checkNotNull(builder.name, "name is required for a Content");
    Preconditions.checkNotNull(builder.parentPath, "parentPath is required for a Content");
    Preconditions.checkNotNull(builder.data, "data is required for a Content");

    if (builder.page != null) {
      Preconditions.checkArgument(
          !(builder.page.getController() != null && builder.page.getTemplate() != null),
          "A Page cannot have both have a controller and a template set");
    }

    if (builder.type == null) {
      builder.type = ContentTypeName.unstructured();
    }

    this.valid = builder.valid;
    this.displayName = builder.displayName;
    this.type = builder.type;
    this.name = builder.name;
    this.parentPath = builder.parentPath;
    this.path = ContentPath.from(builder.parentPath, builder.name.toString());
    this.id = builder.id;
    this.data = builder.data;
    this.attachments = builder.attachments;
    this.extraDatas = builder.extraDatas;
    this.createdTime = builder.createdTime;
    this.modifiedTime = builder.modifiedTime;
    this.creator = builder.creator;
    this.modifier = builder.modifier;
    this.owner = builder.owner;
    this.page = builder.page;
    this.thumbnail = builder.thumbnail;
    this.hasChildren = builder.hasChildren;
    this.childOrder = builder.childOrder;
    this.permissions =
        builder.permissions == null ? AccessControlList.empty() : builder.permissions;
    this.inheritPermissions = builder.inheritPermissions;
    this.language = builder.language;
    this.contentState = builder.contentState == null ? ContentState.DEFAULT : builder.contentState;
  }