Esempio n. 1
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
  @RequestMapping(value = "/{filterId}/conditions/{fieldId}", method = RequestMethod.DELETE)
  public @ResponseBody void deleteFilterField(
      @PathVariable String boardId, @PathVariable String filterId, @PathVariable String fieldId)
      throws Exception {

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
      String path = String.format(URI.FILTER_CONDITION_URI, boardId, filterId, fieldId);
      ocm.getSession().removeItem(path);
      ocm.save();
      this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
      ocm.logout();
    }
  }
Esempio n. 2
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;
  }
Esempio n. 3
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'READ,WRITE,ADMIN')")
  @RequestMapping(value = "/{filterId}/execute", method = RequestMethod.GET)
  public @ResponseBody Collection<Card> executeFilter(
      @PathVariable String boardId, @PathVariable String filterId) throws Exception {

    ObjectContentManager ocm = ocmFactory.getOcm();
    Collection<Card> cards = null;

    try {
      cards = listTools.query(boardId, null, filterId, ocm);

      for (Card card : cards) {
        card.setFields(this.cardTools.getFieldsForCard(card, "full", ocm));
      }
    } finally {
      ocm.logout();
    }
    return cards;
  }
Esempio n. 4
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
  @RequestMapping(value = "/{filterId}", method = RequestMethod.PUT)
  public @ResponseBody Filter updateFilter(
      @PathVariable String boardId, @PathVariable String filterId, @RequestBody Filter filter)
      throws Exception {

    if (filter.getPath() == null) {
      filter.setPath(String.format(URI.FILTER_URI, boardId, filterId));
    }

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
      ocm.update(filter);
      ocm.save();
      this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
      ocm.logout();
    }

    return filter;
  }
Esempio n. 5
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
  @RequestMapping(value = "", method = RequestMethod.POST)
  public @ResponseBody Filter createFilter(@PathVariable String boardId, @RequestBody Filter filter)
      throws Exception {
    if (filter.getPath() != null) {
      logger.warn("Attempt to update filter using POST");
      throw new Exception("Attempt to Update Filter using POST. Use PUT instead");
    }

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
      listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "filters", ocm.getSession());
      String newId = IdentifierTools.getIdFromNamedModelClass(filter);
      filter.setPath(String.format(URI.FILTER_URI, boardId, newId.toString()));
      ocm.insert(filter);
      ocm.save();
      this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
      ocm.logout();
    }
    return filter;
  }
Esempio n. 6
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
  @RequestMapping(value = "/{filterId}/conditions", method = RequestMethod.POST)
  public @ResponseBody Condition saveFilterField(
      @PathVariable String boardId,
      @PathVariable String filterId,
      @RequestBody Condition filterField)
      throws Exception {

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
      listTools.ensurePresence(
          String.format(URI.FILTER_URI, boardId, filterId), "conditions", ocm.getSession());
      filterField.setPath(
          String.format(URI.FILTER_CONDITION_URI, boardId, filterId, filterField.getFieldName()));
      ocm.insert(filterField);
      ocm.save();
      this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
      ocm.logout();
    }
    return filterField;
  }
  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();
    }
  }
Esempio n. 8
0
  @PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
  @RequestMapping(value = "/{filterId}", method = RequestMethod.DELETE)
  public @ResponseBody void deleteFilter(
      @PathVariable String boardId, @PathVariable String filterId) throws Exception {

    if (StringUtils.isBlank(filterId)) {
      return;
    }

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
      Node node = ocm.getSession().getNode(String.format(URI.FILTER_URI, boardId, filterId));

      if (node == null) {
        throw new ResourceNotFoundException();
      }

      node.remove();
      ocm.save();
      this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
      ocm.logout();
    }
  }
  public void testRetrieveCollection() {

    ObjectContentManager ocm = this.getObjectContentManager();

    // ---------------------------------------------------------------------------------------------------------
    // Insert  descendant objects
    // ---------------------------------------------------------------------------------------------------------
    Descendant descendant = new Descendant();
    descendant.setDescendantField("descendantValue");
    descendant.setAncestorField("ancestorValue");
    descendant.setPath("/descendant1");
    ocm.insert(descendant);

    descendant = new Descendant();
    descendant.setDescendantField("descendantValue2");
    descendant.setAncestorField("ancestorValue2");
    descendant.setPath("/descendant2");
    ocm.insert(descendant);

    SubDescendant subDescendant = new SubDescendant();
    subDescendant.setDescendantField("descendantValue2");
    subDescendant.setAncestorField("ancestorValue2");
    subDescendant.setPath("/subdescendant");
    subDescendant.setSubDescendantField("subdescendantvalue");
    ocm.insert(subDescendant);

    subDescendant = new SubDescendant();
    subDescendant.setDescendantField("descendantValue3");
    subDescendant.setAncestorField("ancestorValue2");
    subDescendant.setPath("/subdescendant2");
    subDescendant.setSubDescendantField("subdescendantvalue1");
    ocm.insert(subDescendant);

    AnotherDescendant anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
    anotherDescendant.setAncestorField("ancestorValue3");
    anotherDescendant.setPath("/anotherdescendant1");
    ocm.insert(anotherDescendant);

    anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
    anotherDescendant.setAncestorField("ancestorValue4");
    anotherDescendant.setPath("/anotherdescendant2");
    ocm.insert(anotherDescendant);

    anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue2");
    anotherDescendant.setAncestorField("ancestorValue5");
    anotherDescendant.setPath("/anotherdescendant3");
    ocm.insert(anotherDescendant);

    Atomic a = new Atomic();
    a.setPath("/atomic");
    a.setBooleanPrimitive(true);
    ocm.insert(a);

    ocm.save();

    // ---------------------------------------------------------------------------------------------------------
    // Retrieve Descendant class (implements  Interface.class)
    // ---------------------------------------------------------------------------------------------------------
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(Interface.class);
    Query query = queryManager.createQuery(filter);

    Collection result = ocm.getObjects(query);
    assertEquals("Invalid number of  interface  found", result.size(), 3);
    assertTrue(
        "Invalid item in the collection",
        this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
    assertTrue(
        "Invalid item in the collection",
        this.contains(result, "/anotherdescendant2", AnotherDescendant.class));
    assertTrue(
        "Invalid item in the collection",
        this.contains(result, "/anotherdescendant3", AnotherDescendant.class));

    // ---------------------------------------------------------------------------------------------------------
    // Retrieve Descendant class and its children (implements  AnotherInterface.class)
    // ---------------------------------------------------------------------------------------------------------
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(AnotherInterface.class);
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid number of  interface  found", result.size(), 4);
    assertTrue(
        "Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
    assertTrue(
        "Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
    assertTrue(
        "Invalid item in the collection",
        this.contains(result, "/subdescendant", SubDescendant.class));
    assertTrue(
        "Invalid item in the collection",
        this.contains(result, "/subdescendant2", SubDescendant.class));
  }