예제 #1
0
  /** @param path location of the project in the resource tree */
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void deleteProject(String path) throws ProjectException {
    try {

      String caller = membership.getProfilePathForConnectedIdentifier();

      pep.checkSecurity(caller, path, "delete");

      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);
      Project project = em.find(Project.class, identifier.getId());

      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }
      em.remove(project);

      String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false);
      pap.deletePolicy(policyId);

      binding.unbind(path);
      notification.throwEvent(
          new Event(
              path,
              membership.getProfilePathForConnectedIdentifier(),
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "delete"),
              ""));

    } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new ProjectException("unable to delete the project at path " + path);
    }
  }
예제 #2
0
 @Override
 public Document[] getThreadAttachments(String path) throws ForumServiceException {
   logIt("get attached documents " + path);
   Document[] listDoc = null;
   try {
     String caller = membership.getProfilePathForConnectedIdentifier();
     if (caller == null) {
       throw new ForumServiceException("Could not get connected profile");
     }
     logIt("caller: " + caller);
     pep.checkSecurity(caller, path, "read");
     // Check if given path is valid ThreadMessage
     FactoryResourceIdentifier identifier = binding.lookup(path);
     checkResourceType(identifier, ThreadMessage.RESOURCE_NAME);
     // Get attachments
     listDoc = getAttachments(path);
   } catch (Exception e) {
     // ctx.setRollbackOnly();
     logger.error(
         "Unable to retrieve attached documents for the thread message at path " + path, e);
     throw new ForumServiceException(
         "Unable to retrieve documents for the thread message at path " + path, e);
   }
   return listDoc;
 }
예제 #3
0
  /**
   * @param path the location of the project
   * @return a Project entity
   */
  @TransactionAttribute(TransactionAttributeType.SUPPORTS)
  public Project getProject(String path) throws ProjectException {
    try {
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, path, "read");

      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }

      project.setResourcePath(path);
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "read"),
              ""));

      return project;

    } catch (Exception e) {
      throw new ProjectException(e);
    }
  }
예제 #4
0
 @Override
 public void throw2SameEvent(String path)
     throws NotificationServiceException, MembershipServiceException {
   String caller = membership.getProfilePathForConnectedIdentifier();
   Event e = new Event(path, caller, "Name", "greeting.name.create", "");
   notification.throwEvent(e);
   notification.throwEvent(e);
 }
예제 #5
0
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void deleteThreadMessage(String path) throws ForumServiceException {
    logIt("deleteThreadMessage(...) called");
    logger.debug("params : path=" + path);

    try {
      // Security check
      String caller = membership.getProfilePathForConnectedIdentifier();
      if (caller == null) {
        throw new ForumServiceException("Could not get connected profile");
      }
      logIt("caller: " + caller);
      pep.checkSecurity(caller, path, "delete");
      // Look up given path and check resource type
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, ThreadMessage.RESOURCE_NAME);
      // Find the entity
      ThreadMessage msg = em.find(ThreadMessage.class, identifier.getId());
      if (msg == null) {
        throw new ForumServiceException("unable to find a msg for id " + identifier.getId());
      }
      if (!browser.hasChildren(path)) {
        HashMap<String, String> values = forumWS.deleteThreadMessage(msg.getId());
        if (values != null && !values.isEmpty()) {
          String code = (String) values.get("statusCode");
          String msgTxt = (String) values.get("statusMessage");
          logIt("Message Code:" + code + " Message: " + msgTxt);
          if (!code.equals(CollaborationUtils.SUCCESS_CODE)) {
            throw new ForumServiceException(
                "Error code recieved from the WS." + " Code" + code + " Message:" + msgTxt);
          }
          em.remove(msg);
          // Delete the policy and unbind the resource from this path
          String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false);
          pap.deletePolicy(policyId);
          binding.unbind(path);
          // notify
          notification.throwEvent(
              new Event(
                  path,
                  caller,
                  ThreadMessage.RESOURCE_NAME,
                  Event.buildEventType(
                      ForumService.SERVICE_NAME, ThreadMessage.RESOURCE_NAME, "delete"),
                  ""));
        } else {
          throw new ForumServiceException("No valid answer from the WS.Check logs.");
        }
      } else {
        throw new ForumServiceException("Thread message has children and cannot be deleted.");
      }
    } catch (Exception e) {
      // ctx.setRollbackOnly();
      logger.error("Unable to delete the message at path " + path, e);
      throw new ForumServiceException("Unable to delete the message at path " + path, e);
    }
  }
예제 #6
0
 @Override
 @TransactionAttribute(TransactionAttributeType.REQUIRED)
 public void updateForum(String path, String name, String date) throws ForumServiceException {
   logger.debug("Update forum " + path);
   try {
     // Check name
     if (name == null || name == "") {
       throw new ForumServiceException("Forum name is mandatory.");
     }
     // Security check
     String caller = membership.getProfilePathForConnectedIdentifier();
     if (caller == null) {
       throw new ForumServiceException("Could not get connected profile");
     }
     logIt("caller: " + caller);
     pep.checkSecurity(caller, path, "update");
     // Look up given path and check resource type
     FactoryResourceIdentifier identifier = binding.lookup(path);
     checkResourceType(identifier, Forum.RESOURCE_NAME);
     // Find the entity
     Forum forum = em.find(Forum.class, identifier.getId());
     if (forum == null) {
       throw new ForumServiceException("Unable to find a forum for id " + identifier.getId());
     }
     HashMap<String, String> values = forumWS.updateForum(forum.getId(), name, date);
     if (values != null && !values.isEmpty()) {
       String code = (String) values.get("statusCode");
       String msg = (String) values.get("statusMessage");
       logIt("Message Code:" + code + " Message: " + msg);
       if (!code.equals(CollaborationUtils.SUCCESS_CODE)) {
         throw new ForumServiceException(
             "Error code recieved from the WS." + " Code" + code + " Message:" + msg);
       }
       // Update the entity
       forum.setName(name);
       forum.setDate(date);
       forum.setResourcePath(path);
       em.merge(forum);
       binding.setProperty(
           path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
       // notify
       notification.throwEvent(
           new Event(
               path,
               caller,
               Forum.RESOURCE_NAME,
               Event.buildEventType(ForumService.SERVICE_NAME, Forum.RESOURCE_NAME, "update"),
               ""));
       logIt(forum.toString());
     } else {
       throw new ForumServiceException("Error in recieving extra details from WS.");
     }
   } catch (Exception e) {
     // ctx.setRollbackOnly();
     logger.error("Unable to update the forum at path " + path, e);
     throw new ForumServiceException("Unable to update the forum at path " + path, e);
   }
 }
예제 #7
0
  /**
   * @param name the name of the project
   * @param summary the description of the project
   * @param path the target location of the new resource
   * @param licence
   */
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void createProject(String path, String name, String summary, String licence)
      throws ProjectException {
    logger.debug("starting project creation");
    try {

      if (name == null || name == "")
        throw new ProjectException("your must specify a name for your project");
      if (summary.length() < 10)
        throw new ProjectException("describe in a more comprehensive manner your project");
      if (summary.length() > 255)
        throw new ProjectException(
            "Your project description is too long. Please make it smaller than 256 bytes.");

      String caller = membership.getProfilePathForConnectedIdentifier();
      // create entity object
      Project project = new Project();
      project.setName(name);
      project.setSummary(summary);
      project.setLicence(licence);
      project.setId(UUID.randomUUID().toString());
      em.persist(project);
      // service orchestration
      pep.checkSecurity(caller, PathHelper.getParentPath(path), "create");

      binding.bind(project.getFactoryResourceIdentifier(), path);
      binding.setProperty(
          path, FactoryResourceProperty.CREATION_TIMESTAMP, System.currentTimeMillis() + "");
      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      binding.setProperty(path, FactoryResourceProperty.AUTHOR, caller);

      // create default policy
      String policyId = UUID.randomUUID().toString();
      pap.createPolicy(policyId, PAPServiceHelper.buildOwnerPolicy(policyId, caller, path));
      binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
      binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);

      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "create"),
              ""));

    } catch (Exception e) {

      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }
예제 #8
0
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void deleteName(String path) throws GreetingServiceException {
    logger.info("deleteName(...) called");
    logger.debug("params : path=" + path);

    try {
      // Checking if the connected user has the permission to delete the resource giving pep :
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, path, "delete");

      // Performing a lookup in the naming to recover the Resource Identifier
      FactoryResourceIdentifier identifier = binding.lookup(path);

      // Checking if this resource identifier is really a resource managed by this service (a Hello
      // resource)
      checkResourceType(identifier, Name.RESOURCE_NAME);

      // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS
      Name name = em.find(Name.class, identifier.getId());
      if (name == null) {
        throw new GreetingServiceException("unable to find a name for id " + identifier.getId());
      }
      em.remove(name);
      // END OF EXTERNAL SERVICE INVOCATION

      // Removing the security policy of this node :
      String policyId = binding.getProperty(path, FactoryResourceProperty.POLICY_ID, false);
      pap.deletePolicy(policyId);

      // Unbinding the resource from this path :
      binding.unbind(path);

      // Using the notification service to throw an event :
      notification.throwEvent(
          new Event(
              path,
              caller,
              Name.RESOURCE_NAME,
              Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "delete"),
              ""));

      // Using the indexing service to unindex the name
      indexing.remove(getServiceName(), path);

    } catch (Exception e) {
      // ctx.setRollbackOnly();
      logger.error("unable to delete the name at path " + path, e);
      throw new GreetingServiceException("unable to delete the name at path " + path, e);
    }
  }
예제 #9
0
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateName(String path, String value) throws GreetingServiceException {
    logger.info("updateName(...) called");
    logger.debug("params : path=" + path + ", value=" + value);

    try {
      // Checking if the connected user has the permission to update the resource giving pep :
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, path, "update");

      // Performing a lookup in the naming to recover the Resource Identifier
      FactoryResourceIdentifier identifier = binding.lookup(path);

      // Checking if this resource identifier is really a resource managed by this service (a Hello
      // resource)
      checkResourceType(identifier, Name.RESOURCE_NAME);

      // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS
      Name name = em.find(Name.class, identifier.getId());
      if (name == null) {
        throw new GreetingServiceException("unable to find a name for id " + identifier.getId());
      }
      name.setValue(value);
      em.merge(name);
      // END OF EXTERNAL SERVICE INVOCATION

      // Need to set some properties on the node :
      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");

      // Using the notification service to throw an event :
      notification.throwEvent(
          new Event(
              path,
              caller,
              Name.RESOURCE_NAME,
              Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "update"),
              ""));

      // Using the indexing service to reindex the name newly updated
      indexing.reindex(getServiceName(), path);

    } catch (Exception e) {
      //   ctx.setRollbackOnly();
      logger.error("unable to update the name at path " + path, e);
      throw new GreetingServiceException("unable to update the name at path " + path, e);
    }
  }
예제 #10
0
 @Override
 public Forum[] getForumsByStatus(String path, String status) throws ForumServiceException {
   Forum[] items = null;
   logIt("get forums under" + path + " with status " + status);
   try {
     // Security check
     String caller = membership.getProfilePathForConnectedIdentifier();
     if (caller == null) {
       throw new ForumServiceException("Could not get connected profile");
     }
     logIt("caller: " + caller);
     pep.checkSecurity(caller, path, "read");
     // Check if given path is valid
     FactoryResourceIdentifier identifier = binding.lookup(path);
     // FIXME change restriction of parent. Forum should be created under
     // any path
     if (identifier != null
         && (identifier.getService().equals(SERVICE_NAME)
             || identifier.getService().equals(CoreService.SERVICE_NAME)
             || identifier.getService().equals(DocumentService.SERVICE_NAME))) {
       String servicePattern = ForumService.SERVICE_NAME;
       String typePattern = Forum.RESOURCE_NAME;
       String[] forumChildren = browser.listChildrenOfType(path, servicePattern, typePattern);
       if (forumChildren != null && forumChildren.length > 0) {
         logIt("Number of forums under " + path + " : " + forumChildren.length);
         Vector<Forum> forumsVector = new Vector<Forum>();
         for (int i = 0; i < forumChildren.length; i++) {
           logIt("child #" + i + ". " + forumChildren[i]);
           Forum tmpForum = readForum(forumChildren[i]);
           if (tmpForum != null && tmpForum.getStatus().equals(status)) {
             forumsVector.add(tmpForum);
           }
         }
         if (forumsVector != null && forumsVector.size() > 0) {
           items = forumsVector.toArray(new Forum[forumsVector.size()]);
         }
       }
     } else {
       throw new ForumServiceException("Given path is not valid.");
     }
   } catch (Exception e) {
     // ctx.setRollbackOnly();
     logger.error("Unable to retrieve the forums at path " + path, e);
     throw new ForumServiceException("Unable to retrieve the forums at path " + path, e);
   }
   return items;
 }
  /**
   * Test Right Throw one event into one queue and assert the event is inserted only in one queue
   * the test assert too that no other event appears into the queue
   *
   * @throws Exception
   */
  @Test(timeout = 30000)
  public void testNotificationSimple() throws Exception {
    logger.info("testNotificationSimple() called");
    String caller = membership.getProfilePathForConnectedIdentifier();

    greeting.sayHello(pathResource);
    Event[] lEvent1 = new Event[] {};
    // wait that an event appears into the queue
    while (lEvent1.length == 0) {
      lEvent1 = eqs.getEvents(pathQueue1);
    }
    assertTrue(lEvent1.length == 1);
    Event e = lEvent1[0];
    assertEquals(
        "TestNotification1 : event resource expected /name but found " + e.getFromResource(),
        e.getFromResource(),
        pathResource);
    assertEquals(
        "TestNotification1 : event type expected greeting.name.create but found "
            + e.getEventType(),
        e.getEventType(),
        "greeting.name.say-hello");
    assertEquals(
        "TestNotification1 : event throwedBy expected " + caller + " but found" + e.getThrowedBy(),
        e.getThrowedBy(),
        caller);

    Event[] lEvent2 = eqs.getEvents(pathQueue2);
    assertTrue(
        "TestNotification1 : expected 0 event into queue2("
            + pathQueue2
            + ") but found "
            + lEvent2.length,
        lEvent2.length == 0);

    Thread.sleep(10);
    // assert that no other events happen
    lEvent1 = eqs.getEvents(pathQueue1);
    assertTrue(
        "TestNotification1 : expected 0 event into queue1("
            + pathQueue1
            + ") but found "
            + lEvent1.length,
        lEvent1.length == 1);
  }
예제 #12
0
  @Override
  @TransactionAttribute(TransactionAttributeType.SUPPORTS)
  public String sayHello(String path) throws GreetingServiceException {
    logger.info("sayHello(...) called");
    logger.debug("params : path=" + path);

    try {
      // Checking if the connected user has the permission to say-hello the resource giving pep :
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, path, "say-hello");

      // Performing a lookup in the naming to recover the Resource Identifier
      FactoryResourceIdentifier identifier = binding.lookup(path);

      // Checking if this resource identifier is really a resource managed by this service (a Hello
      // resource)
      checkResourceType(identifier, Name.RESOURCE_NAME);

      // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS
      Name name = em.find(Name.class, identifier.getId());
      if (name == null) {
        throw new GreetingServiceException("unable to find a name for id " + identifier.getId());
      }
      // END OF EXTERNAL SERVICE INVOCATION

      // Building hello message :
      String message = "Hello dear " + name.getValue() + " !!";

      // Using the notification service to throw an event :
      notification.throwEvent(
          new Event(
              path,
              caller,
              Name.RESOURCE_NAME,
              Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "say-hello"),
              ""));

      return message;
    } catch (Exception e) {
      //  ctx.setRollbackOnly();
      logger.error("unable to say hello to the name at path " + path, e);
      throw new GreetingServiceException("unable to say hello to the name at path " + path, e);
    }
  }
예제 #13
0
  /**
   * @param path the location of the project in the resource tree
   * @param name
   * @param status if the project is on alpha, beta or release state
   * @param summary
   * @param licence
   */
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateProject(String path, String name, String status, String summary, String licence)
      throws ProjectException {
    try {
      if (name == null || name == "")
        throw new ProjectException("your must specify a name for your project");
      if (summary.length() < 10)
        throw new ProjectException("describe in a more comprehensive manner your project");
      if (summary.length() > 255)
        throw new ProjectException(
            "Your project description is too long. Please make it smaller than 256 bytes.");

      String caller = membership.getProfilePathForConnectedIdentifier();

      pep.checkSecurity(caller, path, "update");
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }
      project.setName(name);
      project.setDev_status(status);
      project.setSummary(summary);
      project.setLicence(licence);
      em.merge(project);

      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"),
              ""));

    } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }
예제 #14
0
  /**
   * update meta information about the project
   *
   * @param path the location of the project in the resource tree
   * @param os the operating system used by this project
   * @param topics
   * @param language natural language used by this project
   * @param programming_language programming language used by this project
   * @param intended_audience
   */
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTagsProject(
      String path,
      String[] os,
      String[] topics,
      String[] language,
      String[] programming_language,
      String[] intended_audience)
      throws ProjectException {
    try {
      String caller = membership.getProfilePathForConnectedIdentifier();

      pep.checkSecurity(caller, path, "update");
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }
      project.setOs(os);
      project.setTopics(topics);
      project.setSpoken_language(language);
      project.setProgramming_language(programming_language);
      project.setIntended_audience(intended_audience);
      em.merge(project);

      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"),
              ""));

    } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }
예제 #15
0
  /**
   * Give name at the given path.
   *
   * @param pepCheck true to make the check.
   * @param path the path to the name.
   * @throws GreetingServiceException if the name can't be find.
   */
  @TransactionAttribute(TransactionAttributeType.SUPPORTS)
  private Name readName(String path, boolean pepCheck) throws GreetingServiceException {
    try {
      // Checking if the connected user has the permission to read the resource giving pep :
      String caller = membership.getProfilePathForConnectedIdentifier();

      if (pepCheck) pep.checkSecurity(caller, path, "read");

      // Performing a lookup in the naming to recover the Resource Identifier
      FactoryResourceIdentifier identifier = binding.lookup(path);

      // Checking if this resource identifier is really a resource managed by this service (a Hello
      // resource)
      checkResourceType(identifier, Name.RESOURCE_NAME);

      // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE LOADING OR METHOD CALLS
      Name name = em.find(Name.class, identifier.getId());
      if (name == null) {
        throw new GreetingServiceException("unable to find a name for id " + identifier.getId());
      }
      name.setResourcePath(path);
      // END OF EXTERNAL SERVICE INVOCATION

      // Using the notification service to throw an event :
      notification.throwEvent(
          new Event(
              path,
              caller,
              Name.RESOURCE_NAME,
              Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "read"),
              ""));

      return name;
    } catch (Exception e) {
      logger.error("unable to read the name at path " + path, e);
      throw new GreetingServiceException("unable to read the name at path " + path, e);
    }
  }
예제 #16
0
  @Override
  public ThreadMessage[] getThreadReplies(String path) throws ForumServiceException {
    logIt("get thread replies " + path);
    ThreadMessage[] listofThreads = null;
    try {
      String caller = membership.getProfilePathForConnectedIdentifier();
      if (caller == null) {
        throw new ForumServiceException("Could not get connected profile");
      }
      logIt("caller: " + caller);
      pep.checkSecurity(caller, path, "read");
      // Check if given path is valid threadMessage
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, ThreadMessage.RESOURCE_NAME);
      // Get messages
      String servicePattern = ForumService.SERVICE_NAME;
      String typePattern = ThreadMessage.RESOURCE_NAME;
      String[] threadsArray = browser.listChildrenOfType(path, servicePattern, typePattern);
      if (threadsArray != null && threadsArray.length > 0) {
        Vector<ThreadMessage> threadsVector = new Vector<ThreadMessage>();

        for (int i = 0; i < threadsArray.length; i++) {

          logIt("child #" + i + ". " + threadsArray[i]);
          threadsVector.add(readThreadMessage(threadsArray[i]));
          threadsVector = getChildren(threadsVector, threadsArray[i]);
        }
        listofThreads = threadsVector.toArray(new ThreadMessage[threadsVector.size()]);
      }
    } catch (Exception e) {
      // ctx.setRollbackOnly();
      logger.error("Unable to retrieve message for the forum at path " + path, e);
      throw new ForumServiceException(
          "Unable to retrieve message for the forum at path " + path, e);
    }
    return listofThreads;
  }
예제 #17
0
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void createName(String path, String value) throws GreetingServiceException {

    logger.info("createName(...) called");
    logger.debug("params : path=" + path + ", value=" + value);

    try {
      // Checking if the connected user has the permission to create a resource giving pep :
      //  - the profile path of the connected user (caller)
      //  - the parent of the path (we check the 'create' permission on the parent of the given
      // path)
      //  - the name of the permission to check ('create')
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, PathHelper.getParentPath(path), "create");

      // STARTING SPECIFIC EXTERNAL SERVICE RESOURCE CREATION OR METHOD CALL
      Name name = new Name();
      name.setId(UUID.randomUUID().toString());
      name.setValue(value);
      em.persist(name);
      // END OF EXTERNAL INVOCATION

      // Binding the external resource in the naming using the generated resource ID :
      binding.bind(name.getFactoryResourceIdentifier(), path);

      // Need to set some properties on the node :
      binding.setProperty(
          path, FactoryResourceProperty.CREATION_TIMESTAMP, "" + System.currentTimeMillis());
      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, "" + System.currentTimeMillis());
      binding.setProperty(path, FactoryResourceProperty.AUTHOR, caller);

      // Need to create a new security policy for this resource :
      // Giving the caller the Owner permission (aka all permissions)
      String policyId = UUID.randomUUID().toString();
      pap.createPolicy(policyId, PAPServiceHelper.buildOwnerPolicy(policyId, caller, path));
      pap.createPolicy(
          UUID.randomUUID().toString(),
          PAPServiceHelper.buildPolicy(policyId, caller, path, new String[] {"read"}));

      // Setting security properties on the node :
      binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
      binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);

      // Using the notification service to throw an event :
      notification.throwEvent(
          new Event(
              path,
              caller,
              Name.RESOURCE_NAME,
              Event.buildEventType(GreetingService.SERVICE_NAME, Name.RESOURCE_NAME, "create"),
              ""));

      // Using the indexing service to index the name newly created
      indexing.index(getServiceName(), path);
    } catch (Exception e) {
      ctx.setRollbackOnly();
      logger.error("unable to create the name at path " + path, e);
      throw new GreetingServiceException("unable to create the name at path " + path, e);
    }
  }
  /**
   * Test Right Throw 2 events matching by one queue, but user can read only one event
   *
   * @throws MembershipServiceException
   * @throws GreetingServiceException
   * @throws EventQueueServiceException
   * @throws InterruptedException
   * @throws LoginException
   */
  @Test(timeout = 50000)
  public void testNotificationRightEvent()
      throws MembershipServiceException, GreetingServiceException, EventQueueServiceException,
          InterruptedException, LoginException {
    logger.info("testNotificationRightEvent() called");
    String caller = membership.getProfilePathForConnectedIdentifier();

    // root permit to kermit to create something on /
    greeting.giveAutorization("/", "/profiles/kermit", new String[] {"create"});

    loginContext.logout();

    // login kermit
    UsernamePasswordHandler uph = new UsernamePasswordHandler("kermit", "thefrog");
    loginContext = new LoginContext("qualipso", uph);
    loginContext.login();

    // kermit create a folder and a resource on this folder and
    // create a read event on this name
    greeting.createFolder("/kermitFolder", "kermitFolder");
    greeting.createName("/kermitFolder/kermitName", "kermitName");
    greeting.readName("/kermitFolder/kermitName");
    greeting.deleteName("/kermitFolder/kermitName");
    greeting.deleteFolder("/kermitFolder");

    loginContext.logout();

    uph = new UsernamePasswordHandler("root", AllTests.ROOT_ACCOUNT_PASS);
    loginContext = new LoginContext("qualipso", uph);
    loginContext.login();

    greeting.readName(pathResource);

    Event[] lEvent2 = new Event[] {};

    while (lEvent2.length < 1) {
      lEvent2 = eqs.getEvents(pathQueue2);
    }

    assertTrue(
        "TestNotificationRighEvent : expected 1 events into queue2("
            + pathQueue2
            + ") but found "
            + lEvent2.length,
        lEvent2.length == 1);
    Event e = lEvent2[0];
    assertEquals(
        "TestNotificationRighEvent : event resource expected "
            + pathResource
            + " but found "
            + e.getFromResource(),
        e.getFromResource(),
        pathResource);
    assertEquals(
        "TestNotificationRighEvent : event type expected greeting.name.create but found "
            + e.getEventType(),
        e.getEventType(),
        "greeting.name.read");
    assertEquals(
        "TestNotificationRighEvent : event throwedBy expected "
            + caller
            + " but found"
            + e.getThrowedBy(),
        e.getThrowedBy(),
        caller);

    Thread.sleep(60);

    assertTrue(
        "TestNotificationRighEvent : expected 1 event into queue1 but found "
            + eqs.getEvents(pathQueue2).length,
        eqs.getEvents(pathQueue2).length == 1);
  }
예제 #19
0
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public String createForum(String parentPath, String name) throws ForumServiceException {
    String newForumId = null;
    logIt("Create forum under" + parentPath);
    try {
      // Check name
      if (name == null || name == "") {
        throw new ForumServiceException("Forum name is mandatory.");
      }
      // Security check
      String caller = membership.getProfilePathForConnectedIdentifier();
      if (caller == null) {
        throw new ForumServiceException("Could not get connected profile");
      }
      logIt("caller: " + caller);
      // FIXME
      // String path = forumsPath + "/" +
      // CollaborationUtils.normalizeForPath(name);
      // logIt("path:" + path);
      pep.checkSecurity(caller, parentPath, "create");

      // Call WS to create forum
      HashMap<String, String> values = forumWS.createForum(name);
      if (values != null && !values.isEmpty()) {
        String code = (String) values.get("statusCode");
        String msg = (String) values.get("statusMessage");
        String forumId = (String) values.get("forumId");
        logIt("Message Code:" + code + " Message: " + msg);
        if (!code.equals(CollaborationUtils.SUCCESS_CODE)
            || (forumId == null || forumId.equals(""))) {
          throw new ForumServiceException(
              "Error code recieved from the WS." + " Code" + code + " Message:" + msg);
        }
        // Create path based on id that is returned by the Mermig WS
        String path = PathHelper.normalize(parentPath + "/" + forumId);
        logIt("path:" + path);
        // Save the new entity in the factory and bind it
        // We persist only id,path,name
        Forum forum = new Forum();
        forum.setId(forumId);
        forum.setName(name);
        forum.setResourcePath(path);
        // save it
        em.persist(forum);
        // Bind the entity with the path and the identifier
        binding.bind(forum.getFactoryResourceIdentifier(), path);
        binding.setProperty(
            path, FactoryResourceProperty.CREATION_TIMESTAMP, "" + System.currentTimeMillis());
        binding.setProperty(
            path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, "" + System.currentTimeMillis());
        binding.setProperty(path, FactoryResourceProperty.AUTHOR, caller);
        // Create policy (owner)
        String policyId = UUID.randomUUID().toString();
        pap.createPolicy(policyId, PAPServiceHelper.buildOwnerPolicy(policyId, caller, path));
        binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
        binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);
        // notify
        notification.throwEvent(
            new Event(
                path,
                caller,
                Forum.RESOURCE_NAME,
                Event.buildEventType(ForumService.SERVICE_NAME, Forum.RESOURCE_NAME, "create"),
                ""));
        newForumId = forumId;
      } else {
        throw new ForumServiceException("No valid answer from the WS.Check logs.");
      }
      return newForumId;
    } catch (Exception e) {
      // ctx.setRollbackOnly();
      logger.error("Unable to create the forum at path " + parentPath, e);
      throw new ForumServiceException("Unable to create the forum at path " + parentPath, e);
    }
  }
예제 #20
0
 @Override
 @TransactionAttribute(TransactionAttributeType.SUPPORTS)
 public Forum readForum(String path) throws ForumServiceException {
   logIt("Read forum " + path);
   try {
     // Security check
     String caller = membership.getProfilePathForConnectedIdentifier();
     if (caller == null) {
       throw new ForumServiceException("Could not get connected profile");
     }
     logIt("caller: " + caller);
     pep.checkSecurity(caller, path, "read");
     // Look up given path and check resource type
     FactoryResourceIdentifier identifier = binding.lookup(path);
     if (identifier == null) {
       throw new ForumServiceException("Identifier is null");
     }
     checkResourceType(identifier, Forum.RESOURCE_NAME);
     // Find the entity
     Forum forum = em.find(Forum.class, identifier.getId());
     if (forum == null) {
       throw new ForumServiceException("Unable to find a forum for id " + identifier.getId());
     }
     // Call the Mermig WS to retrieve info based on forum.getId()
     HashMap<String, Object> values = forumWS.readForum(forum.getId());
     if (values != null && !values.isEmpty()) {
       String code = (String) values.get("statusCode");
       String msg = (String) values.get("statusMessage");
       logIt("Message Code:" + code + " Message: " + msg);
       if (!code.equals(CollaborationUtils.SUCCESS_CODE) || values.get("forum") == null) {
         throw new ForumServiceException(
             "Error code recieved from the WS." + " Code" + code + " Message:" + msg);
       }
       // We don't perist the date,status and messages
       ForumDTO forWS = (ForumDTO) values.get("forum");
       forum.setDate(forWS.getDate());
       forum.setStatus(forWS.getStatus());
       // FIXME The path is missing in the mgs list.
       // WE NEED TO USE the browse for thread messages
       if (forWS.getMessages() != null) {
         forum.setMessages(convertHashMap(path, forWS.getMessages()));
       }
       forum.setResourcePath(path);
       // notify
       notification.throwEvent(
           new Event(
               path,
               caller,
               Forum.RESOURCE_NAME,
               Event.buildEventType(ForumService.SERVICE_NAME, Forum.RESOURCE_NAME, "read"),
               ""));
       logIt(forum.toString());
     } else {
       throw new ForumServiceException("Error in recieving extra details from WS.");
     }
     return forum;
   } catch (Exception e) {
     logger.error("Unable to read the forum at path " + path, e);
     throw new ForumServiceException("Unable to read the forum at path " + path, e);
   }
 }
예제 #21
0
 @Override
 @TransactionAttribute(TransactionAttributeType.SUPPORTS)
 public ThreadMessage readThreadMessage(String path) throws ForumServiceException {
   logIt("readThreadMessage(...) called");
   logger.debug("params : path=" + path);
   ThreadMessage msg = null;
   try {
     // Security check
     String caller = membership.getProfilePathForConnectedIdentifier();
     if (caller == null) {
       throw new ForumServiceException("Could not get connected profile");
     }
     logIt("caller: " + caller);
     pep.checkSecurity(caller, path, "read");
     // Look up given path and check resource type
     FactoryResourceIdentifier identifier = binding.lookup(path);
     checkResourceType(identifier, ThreadMessage.RESOURCE_NAME);
     // sFind the entity
     msg = em.find(ThreadMessage.class, identifier.getId());
     if (msg == null) {
       throw new ForumServiceException("Unable to find a message for id " + identifier.getId());
     }
     // Call the WS to retrieve values that are not stored in
     // factory
     HashMap<String, Object> values = forumWS.readThreadMessage(msg.getForumId(), msg.getId());
     if (values != null && !values.isEmpty()) {
       String code = (String) values.get("statusCode");
       String msgTxt = (String) values.get("statusMessage");
       logIt("Message Code:" + code + " Message: " + msgTxt);
       if (!code.equals(CollaborationUtils.SUCCESS_CODE) || values.get("ThreadMessage") == null) {
         throw new ForumServiceException(
             "Error code recieved from the WS." + " Code" + code + " Message:" + msgTxt);
       }
       // FIXME The path is missing in the replies list....Use Browser
       // method
       MessageDTO msgWS = (MessageDTO) values.get("ThreadMessage");
       if (msgWS != null) {
         // We don't persist the following
         // (messageBody,datePosted,numReplies,messageReplies)
         // so we retrieve values from WS
         msg.setMessageBody(msgWS.getMessageBody());
         msg.setDatePosted(msgWS.getDatePosted());
         msg.setNumReplies(msgWS.getNumReplies());
         if (msgWS.getMessageReplies() != null) {
           msg.setMessageReplies(convertHashMap(path, msgWS.getMessageReplies()));
         }
         // notify
         notification.throwEvent(
             new Event(
                 path,
                 caller,
                 ThreadMessage.RESOURCE_NAME,
                 Event.buildEventType(
                     ForumService.SERVICE_NAME, ThreadMessage.RESOURCE_NAME, "read"),
                 ""));
         logIt(msg.toString());
       } else {
         throw new ForumServiceException("Error in WS response.");
       }
     } else {
       throw new ForumServiceException("Error in recieving extra details from WS.");
     }
     return msg;
   } catch (Exception e) {
     logger.error("unable to read the message at path " + path, e);
     throw new ForumServiceException("unable to read the message at path " + path, e);
   }
 }
예제 #22
0
  @Override
  public String createMessage(String path, ThreadMessage message, String isReply)
      throws ForumServiceException {

    logIt("createThreadMessage(...) called");
    logger.debug("params : path=" + path + " isReply: " + message);
    String newMsgId = null;
    try {
      // check supplied values
      checkThreadValues(
          message.getName(),
          message.getForumId(),
          message.getMessageBody(),
          message.getDatePosted());
      // Security check
      String caller = membership.getProfilePathForConnectedIdentifier();
      if (caller == null) {
        throw new ForumServiceException("Could not get connected profile");
      }
      logIt("caller: " + caller);
      String parentPath = PathHelper.getParentPath(path);
      pep.checkSecurity(caller, parentPath, "create");
      //
      String parentId = "";
      boolean isReplyBoolean = Boolean.valueOf(isReply);
      logIt("Is Reply: " + isReplyBoolean);
      if (isReplyBoolean) {
        try {
          // Check if parent is thread
          ThreadMessage parentMsg = readThreadMessage(parentPath);
          parentId = parentMsg.getId();
          logIt("Succefully read parent thread. Id: " + parentId);
        } catch (Exception e) {
          throw new ForumServiceException(
              "Path is not valid for replying to a thread.Please check " + path);
        }
      }
      // Call Mermig WS
      HashMap<String, String> values =
          forumWS.createThreadMessage(
              message.getForumId(),
              parentId,
              message.getName(),
              message.getMessageBody(),
              isReplyBoolean);
      //
      if (values != null && !values.isEmpty()) {
        String code = (String) values.get("statusCode");
        String msg = (String) values.get("statusMessage");
        logIt("Message Code:" + code + " Message: " + msg);
        if (!code.equals(CollaborationUtils.SUCCESS_CODE)) {
          throw new ForumServiceException(
              "Error code recieved from the WS." + " Code" + code + " Message:" + msg);
        }
        // We persist only id,path,name,parentId,forumId and author
        String newId = (String) values.get("messageId");
        ThreadMessage tm = new ThreadMessage();
        tm.setId(newId);
        tm.setResourcePath(path);
        tm.setName(message.getName());
        tm.setParentId(parentId);
        tm.setForumId(message.getForumId());
        // FIXME we need author not profile path.
        tm.setAuthor(caller);
        em.persist(tm);
        // Bind the entity with the path and the identifier
        logIt("Bind the " + tm.getFactoryResourceIdentifier() + " to " + path);
        binding.bind(tm.getFactoryResourceIdentifier(), path);
        binding.setProperty(
            path, FactoryResourceProperty.CREATION_TIMESTAMP, "" + System.currentTimeMillis());
        binding.setProperty(
            path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, "" + System.currentTimeMillis());
        binding.setProperty(path, FactoryResourceProperty.AUTHOR, caller);
        // Create policy (owner)
        String policyId = UUID.randomUUID().toString();
        pap.createPolicy(policyId, PAPServiceHelper.buildOwnerPolicy(policyId, caller, path));
        binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
        binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);
        // notify
        notification.throwEvent(
            new Event(
                path,
                caller,
                ThreadMessage.RESOURCE_NAME,
                Event.buildEventType(
                    ForumService.SERVICE_NAME, ThreadMessage.RESOURCE_NAME, "create"),
                ""));
        //
        newMsgId = tm.getId();
        logIt(tm.toString());
      } else {
        throw new ForumServiceException("No valid answer from the WS.Check logs.");
      }
      return newMsgId;
    } catch (Exception e) {
      // ctx.setRollbackOnly();
      logger.error("Unable to create the thread message at path " + path, e);
      throw new ForumServiceException("Unable to create the thread message at path " + path, e);
    }
  }