Example #1
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'READ,WRITE,ADMIN')")
  @RequestMapping(value = "/{filterId}", method = RequestMethod.GET)
  public @ResponseBody Filter getFilter(@PathVariable String boardId, @PathVariable String filterId)
      throws Exception {

    ObjectContentManager ocm = ocmFactory.getOcm();
    Filter filter = null;
    try {
      filter =
          (Filter) ocm.getObject(Filter.class, String.format(URI.FILTER_URI, boardId, filterId));
      if (filter == null) {
        throw new ResourceNotFoundException();
      }
    } finally {
      ocm.logout();
    }
    return filter;
  }
  public void testRetrieveSingleton() {

    try {
      ObjectContentManager ocm = this.getObjectContentManager();

      // ---------------------------------------------------------------------------------------------------------
      // Insert
      // ---------------------------------------------------------------------------------------------------------
      AnotherDescendant anotherDescendant = new AnotherDescendant();
      anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
      anotherDescendant.setAncestorField("ancestorValue");
      anotherDescendant.setPath("/test");
      ocm.insert(anotherDescendant);

      ocm.save();

      // ---------------------------------------------------------------------------------------------------------
      // Retrieve
      // ---------------------------------------------------------------------------------------------------------
      Interface result = (Interface) ocm.getObject("/test");
      assertNotNull("Object is null", result);
      anotherDescendant = (AnotherDescendant) result;

      assertEquals("Descendant path is invalid", anotherDescendant.getPath(), "/test");
      assertEquals(
          "Descendant ancestorField is invalid",
          anotherDescendant.getAncestorField(),
          "ancestorValue");
      assertEquals(
          "Descendant descendantField is invalid",
          anotherDescendant.getAnotherDescendantField(),
          "anotherDescendantValue");

    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
  }