Esempio n. 1
0
 public List<ContentIndexEntity> findByContentKey(ContentKey contentKey) {
   return findByNamedQuery(
       ContentIndexEntity.class,
       "ContentIndexEntity.findByContentKey",
       "contentKey",
       contentKey.toInt());
 }
Esempio n. 2
0
 public int findCountByContentKey(ContentKey contentKey) {
   return findSingleByNamedQuery(
           Long.class,
           "ContentIndexEntity.findCountByContentKey",
           "contentKey",
           contentKey.toInt())
       .intValue();
 }
Esempio n. 3
0
  @Test
  @Ignore
  public void request_content_image_with_label_small() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    String imageRequestPath = "_image/" + contentKey.toString() + "/label/small";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");
    imageController.handleRequestInternal(httpServletRequest, httpServletResponse);

    assertEquals("image/png", httpServletResponse.getContentType());
    assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus());
  }
  private SectionContentEntity createSectionContent(ContentKey contentKey, String contentName) {

    ContentEntity content = new ContentEntity();
    content.setKey(contentKey);
    content.setName(contentName);

    SectionContentEntity sectionContent = new SectionContentEntity();
    sectionContent.setKey(new SectionContentKey(contentKey.toString()));
    sectionContent.setContent(content);

    return sectionContent;
  }
Esempio n. 5
0
  public int removeByContentKey(ContentKey contentKey) {

    List<ContentIndexEntity> existing =
        findByNamedQuery(
            ContentIndexEntity.class,
            "ContentIndexEntity.findByContentKey",
            "contentKey",
            contentKey.toInt());

    for (ContentIndexEntity contentIndex : existing) {
      delete(contentIndex);
    }
    return existing.size();
  }
  @Test
  public void parentRelation_with_positive_childrenLevel_and_positive_parentLevel() {
    // setup:
    ContentKey grandSon =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory", createMyRelatedContentData("Grand son"), "content-creator"));

    ContentKey grandDaughter =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory", createMyRelatedContentData("Grand daughter"), "content-creator"));

    ContentKey son =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Son", grandSon, grandDaughter),
                "content-creator"));

    ContentKey daughter =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory", createMyRelatedContentData("Daughter"), "content-creator"));

    ContentKey father =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Father", son, daughter),
                "content-creator"));

    ContentKey grandFather =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Grand father", father),
                "content-creator"));

    ContentKey grandMother =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Grand mother", father),
                "content-creator"));

    ContentKey grandMothersMother =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Grand mothers mother", grandMother),
                "content-creator"));

    ContentKey grandMothersFather =
        contentService.createContent(
            createCreateContentCommand(
                "MyCategory",
                createMyRelatedContentData("Grand mothers father", grandMother),
                "content-creator"));

    // setup: verify content is created
    assertEquals(9, fixture.countAllContent());

    // exercise
    DataSourceContext context = new DataSourceContext();
    context.setUser(fixture.findUserByName("content-querier"));

    int[] contentKeys = new int[] {father.toInt()};
    int relation = -1;
    String query = "";
    String orderBy = "";
    int index = 0;
    int count = 100;
    boolean includeData = true;
    int childrenLevel = 10;
    int parentLevel = 10;

    XMLDocument xmlDocResult =
        dataSourceService.getRelatedContent(
            context,
            contentKeys,
            relation,
            query,
            orderBy,
            index,
            count,
            includeData,
            childrenLevel,
            parentLevel);

    // verify
    Document jdomDocResult = xmlDocResult.getAsJDOMDocument();

    assertXPathEquals("/contents/@totalcount", jdomDocResult, "2");
    assertXPathEquals("/contents/content/@key", jdomDocResult, grandFather, grandMother);
    assertXPathEquals(
        "/contents/content[title = 'Grand father']/relatedcontentkeys/@count", jdomDocResult, "1");
    assertXPathEquals(
        "/contents/content[title = 'Grand father']/relatedcontentkeys/relatedcontentkey [@level = 1]/@key",
        jdomDocResult,
        father);
    assertXPathEquals(
        "/contents/content[title = 'Grand mother']/relatedcontentkeys/@count", jdomDocResult, "3");
    assertXPathEquals(
        "/contents/content[title = 'Grand mother']/relatedcontentkeys/relatedcontentkey[@level = 1]/@key",
        jdomDocResult,
        father);
    assertXPathEquals(
        "/contents/content[title = 'Grand mother']/relatedcontentkeys/relatedcontentkey[@level = -1]/@key",
        jdomDocResult,
        grandMothersMother,
        grandMothersFather);

    assertXPathEquals("/contents/relatedcontents/@count", jdomDocResult, "7");
    assertXPathEquals(
        "/contents/relatedcontents/content/@key",
        jdomDocResult,
        father,
        son,
        daughter,
        grandSon,
        grandDaughter,
        grandMothersMother,
        grandMothersFather);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Father']/relatedcontentkeys/@count",
        jdomDocResult,
        "2");
    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Father']/relatedcontentkeys/relatedcontentkey[@level = 1]/@key",
        jdomDocResult,
        son,
        daughter);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Son']/relatedcontentkeys/@count",
        jdomDocResult,
        "2");
    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Son']/relatedcontentkeys/relatedcontentkey[@level = 1]/@key",
        jdomDocResult,
        grandDaughter,
        grandSon);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Daughter']/relatedcontentkeys/@count",
        jdomDocResult,
        "0");
    assertXPathNotExist(
        "/contents/relatedcontents/content[title = 'Daughter']/relatedcontentkeys/relatedcontentkey",
        jdomDocResult);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Grand son']/relatedcontentkeys/@count",
        jdomDocResult,
        "0");
    assertXPathNotExist(
        "/contents/relatedcontents/content[title = 'Grand son']/relatedcontentkeys/relatedcontentkey",
        jdomDocResult);
    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Grand daughter']/relatedcontentkeys/@count",
        jdomDocResult,
        "0");
    assertXPathNotExist(
        "/contents/relatedcontents/content[title = 'Grand daughter']/relatedcontentkeys/relatedcontentkey",
        jdomDocResult);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Grand mothers mother']/relatedcontentkeys/@count",
        jdomDocResult,
        "0");
    assertXPathNotExist(
        "/contents/relatedcontents/content[title = 'Grand mothers mother']/relatedcontentkeys/relatedcontentkey",
        jdomDocResult);

    assertXPathEquals(
        "/contents/relatedcontents/content[title = 'Grand mothers father']/relatedcontentkeys/@count",
        jdomDocResult,
        "0");
    assertXPathNotExist(
        "/contents/relatedcontents/content[title = 'Grand mothers father']/relatedcontentkeys/relatedcontentkey",
        jdomDocResult);
  }