예제 #1
0
 private ThreadMessage convertDTO(MessageDTO msgDTO) {
   ThreadMessage msg = null;
   if (msgDTO != null) {
     msg = new ThreadMessage();
     msg.setAuthor(msgDTO.getAuthor());
     msg.setDatePosted(msgDTO.getDatePosted());
     msg.setForumId(msgDTO.getForumId());
     msg.setId(msgDTO.getId());
     msg.setMessageBody(msgDTO.getMessageBody());
     msg.setName(msgDTO.getName());
     msg.setNumReplies(msgDTO.getNumReplies());
     msg.setParentId(msgDTO.getParentId());
   }
   return msg;
 }
예제 #2
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);
    }
  }