Esempio n. 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;
 }
Esempio n. 2
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);
   }
 }