@Test
 public void testNormalizePath() {
   for (String path : normalizePaths) {
     try {
       PathHelper.valid(path);
       fail("path [" + path + "] should NOT be valid BEFORE normalization");
     } catch (InvalidPathException ive) {
       //
     }
     try {
       PathHelper.valid(PathHelper.normalize(path));
     } catch (InvalidPathException ive) {
       fail("path [" + path + "] should be valid AFTER normalization");
     }
   }
   try {
     assertEquals("/test", PathHelper.normalize("/././././test/./"));
     assertEquals("/", PathHelper.normalize("/test/../../../bidi/../../.."));
     assertEquals("/bidi", PathHelper.normalize("/test/../../../bidi"));
     assertEquals("/bidi/budu", PathHelper.normalize("/test/../bidi/bada/../budu"));
     assertEquals("/bidi/budu", PathHelper.normalize("/test/../bidi/bada/byby/.././../budu"));
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
  @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);
    }
  }
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public String createThreadMessage(
      String parentPath,
      String name,
      String forumId,
      String messageBody,
      String datePosted,
      String isReply)
      throws ForumServiceException {

    logIt("createThreadMessage(...) called");
    logger.debug("params : path=" + parentPath + " isReply: " + isReply);
    String newMsgId = null;
    try {
      // check supplied values
      checkThreadValues(name, forumId, messageBody, datePosted);
      // 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 " + parentPath);
        }
      }
      // Call Mermig WS
      HashMap<String, String> values =
          forumWS.createThreadMessage(forumId, parentId, name, messageBody, isReplyBoolean);
      //
      if (values != null && !values.isEmpty() && values.get("messageId") != null) {
        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");
        // Create path based on parent path and the id that is returned
        // by the Mermig WS
        String path = PathHelper.normalize(parentPath + "/" + newId);
        ThreadMessage tm = new ThreadMessage();
        tm.setId(newId);
        tm.setResourcePath(path);
        tm.setName(name);
        tm.setParentId(parentId);
        tm.setForumId(forumId);
        // 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 " + parentPath, e);
      throw new ForumServiceException(
          "Unable to create the thread message at path " + parentPath, e);
    }
  }