@Test public void testProcessPRAck() throws Exception{ File requestFile = new File(new File(FIXTURE_LOADER.getResource(getName()).getFile()), "ack_request.xml"); String requestContent = IOHandler.readString(new InputStreamReader(new FileInputStream(requestFile))); IncomingMessageHandler handler = sfrmProcessor.getIncomingMessageHandler(); SFRMAcknowledgementParser requestParser = new SFRMAcknowledgementParser(requestContent); SFRMMessageDVO mDVO = SFRMProcessor.getInstance().getMessageHandler().retrieveMessage("testProcessPRAck", SFRMConstant.MSGBOX_IN); String responseContent = handler.processPRAck(mDVO, requestParser); SFRMAcknowledgementParser responseParser = new SFRMAcknowledgementParser(responseContent); SFRMMessageSegmentDAO dao = (SFRMMessageSegmentDAO) sfrmProcessor.getDAOFactory().createDAO(SFRMMessageSegmentDAO.class); SFRMMessageSegmentDVO dvo = (SFRMMessageSegmentDVO) dao.createDVO(); dvo.setMessageId("testProcessPRAck"); dvo.setMessageBox(SFRMConstant.MSGBOX_IN); dvo.setSegmentType(SFRMConstant.MSGT_PAYLOAD); dvo.setSegmentNo(2); assertFalse("Message segment 2 should be deleted", dao.retrieve(dvo)); assertEquals("Status for segment 2 should be " + SFRMConstant.MSGS_DELIVERY_FAILURE, SFRMConstant.MSGS_DELIVERY_FAILURE, responseParser.getMessageSegmentStatus("testProcessPRAck", 2)); dvo.setSegmentNo(1); assertTrue("Message segment 1 should still exist", dao.retrieve(dvo)); assertEquals("Status of Message segment 1 should be updated to " + SFRMConstant.MSGS_PROCESSED, SFRMConstant.MSGS_PROCESSED, dvo.getStatus()); assertEquals("Status for segment 1 should be " + SFRMConstant.MSGS_PROCESSED, SFRMConstant.MSGS_PROCESSED, responseParser.getMessageSegmentStatus("testProcessPRAck", 1)); dvo.setSegmentNo(3); dao.retrieve(dvo); assertTrue("Message segment 3 should still exist", dao.retrieve(dvo)); assertEquals("Status of Message segment 3 should be updated to " + SFRMConstant.MSGS_PROCESSING, SFRMConstant.MSGS_PROCESSING, dvo.getStatus()); assertEquals("Status for segment 3 should be " + SFRMConstant.MSGS_PROCESSING, SFRMConstant.MSGS_PROCESSING, responseParser.getMessageSegmentStatus("testProcessPRAck", 3)); }
public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser) throws DAOException{ SFRMMessageSegmentHandler msHandler = this.getMessageSegmentHandler(); SFRMAcknowledgementBuilder ackBuilder = new SFRMAcknowledgementBuilder(); SFRMMessageSegmentDAO msDAO = (SFRMMessageSegmentDAO) msHandler.getDAOInstance(); List<Integer> segmentNums = parser.getMessageSegmentNums(mDVO.getMessageId()); ackBuilder.setMessage(mDVO.getMessageId(), mDVO.getStatus()); if(segmentNums.size() > 0){ List segDVOs = msHandler.retrieveMessages(mDVO.getMessageId(), SFRMConstant.MSGBOX_IN, SFRMConstant.MSGT_PAYLOAD, segmentNums); for(int i=0 ; segDVOs.size() > i ; i++){ SFRMMessageSegmentDVO msDVO = (SFRMMessageSegmentDVO) segDVOs.get(i); if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERED)){ msDVO.setStatus(SFRMConstant.MSGS_PROCESSED); msDVO.setCompletedTimestamp(new Timestamp(System.currentTimeMillis())); if(!msDAO.persist(msDVO)){ throw new DAOException("Error when updating the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_PROCESSED); } else if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERY_FAILURE)){ if(!msDAO.remove(msDVO)){ throw new DAOException("Error when removing the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_DELIVERY_FAILURE); }else{ ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), msDVO.getStatus()); } } } return ackBuilder.toString(); }
IncomingMessageHandler extends SFRMComponent { public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser) throws DAOException{ SFRMMessageSegmentHandler msHandler = this.getMessageSegmentHandler(); SFRMAcknowledgementBuilder ackBuilder = new SFRMAcknowledgementBuilder(); SFRMMessageSegmentDAO msDAO = (SFRMMessageSegmentDAO) msHandler.getDAOInstance(); List<Integer> segmentNums = parser.getMessageSegmentNums(mDVO.getMessageId()); ackBuilder.setMessage(mDVO.getMessageId(), mDVO.getStatus()); if(segmentNums.size() > 0){ List segDVOs = msHandler.retrieveMessages(mDVO.getMessageId(), SFRMConstant.MSGBOX_IN, SFRMConstant.MSGT_PAYLOAD, segmentNums); for(int i=0 ; segDVOs.size() > i ; i++){ SFRMMessageSegmentDVO msDVO = (SFRMMessageSegmentDVO) segDVOs.get(i); if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERED)){ msDVO.setStatus(SFRMConstant.MSGS_PROCESSED); msDVO.setCompletedTimestamp(new Timestamp(System.currentTimeMillis())); if(!msDAO.persist(msDVO)){ throw new DAOException("Error when updating the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_PROCESSED); } else if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERY_FAILURE)){ if(!msDAO.remove(msDVO)){ throw new DAOException("Error when removing the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_DELIVERY_FAILURE); }else{ ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), msDVO.getStatus()); } } } return ackBuilder.toString(); } }
IncomingMessageHandler extends SFRMComponent { public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser) throws DAOException{ SFRMMessageSegmentHandler msHandler = this.getMessageSegmentHandler(); SFRMAcknowledgementBuilder ackBuilder = new SFRMAcknowledgementBuilder(); SFRMMessageSegmentDAO msDAO = (SFRMMessageSegmentDAO) msHandler.getDAOInstance(); List<Integer> segmentNums = parser.getMessageSegmentNums(mDVO.getMessageId()); ackBuilder.setMessage(mDVO.getMessageId(), mDVO.getStatus()); if(segmentNums.size() > 0){ List segDVOs = msHandler.retrieveMessages(mDVO.getMessageId(), SFRMConstant.MSGBOX_IN, SFRMConstant.MSGT_PAYLOAD, segmentNums); for(int i=0 ; segDVOs.size() > i ; i++){ SFRMMessageSegmentDVO msDVO = (SFRMMessageSegmentDVO) segDVOs.get(i); if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERED)){ msDVO.setStatus(SFRMConstant.MSGS_PROCESSED); msDVO.setCompletedTimestamp(new Timestamp(System.currentTimeMillis())); if(!msDAO.persist(msDVO)){ throw new DAOException("Error when updating the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_PROCESSED); } else if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERY_FAILURE)){ if(!msDAO.remove(msDVO)){ throw new DAOException("Error when removing the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_DELIVERY_FAILURE); }else{ ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), msDVO.getStatus()); } } } return ackBuilder.toString(); }  }
IncomingMessageHandler extends SFRMComponent { public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser) throws DAOException{ SFRMMessageSegmentHandler msHandler = this.getMessageSegmentHandler(); SFRMAcknowledgementBuilder ackBuilder = new SFRMAcknowledgementBuilder(); SFRMMessageSegmentDAO msDAO = (SFRMMessageSegmentDAO) msHandler.getDAOInstance(); List<Integer> segmentNums = parser.getMessageSegmentNums(mDVO.getMessageId()); ackBuilder.setMessage(mDVO.getMessageId(), mDVO.getStatus()); if(segmentNums.size() > 0){ List segDVOs = msHandler.retrieveMessages(mDVO.getMessageId(), SFRMConstant.MSGBOX_IN, SFRMConstant.MSGT_PAYLOAD, segmentNums); for(int i=0 ; segDVOs.size() > i ; i++){ SFRMMessageSegmentDVO msDVO = (SFRMMessageSegmentDVO) segDVOs.get(i); if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERED)){ msDVO.setStatus(SFRMConstant.MSGS_PROCESSED); msDVO.setCompletedTimestamp(new Timestamp(System.currentTimeMillis())); if(!msDAO.persist(msDVO)){ throw new DAOException("Error when updating the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_PROCESSED); } else if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERY_FAILURE)){ if(!msDAO.remove(msDVO)){ throw new DAOException("Error when removing the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_DELIVERY_FAILURE); }else{ ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), msDVO.getStatus()); } } } return ackBuilder.toString(); }  static IncomingMessageHandler getInstance(); SFRMPartnershipDVO extractPartnership(SFRMMessage incomingMessage); boolean isDuplicateSegment(SFRMMessage incomingMessage); boolean isProcessingMessage(SFRMMessage incomingMessage); boolean isNotEnoughRoom(SFRMMessage incomingMessage, long threshold); void unpackIncomingMessage(SFRMMessage message, SFRMPartnershipDVO partnershipDVO); boolean initGuardForSegment(final SFRMMessage incomingMessage); boolean resolveGuardOwnerForSegment(final SFRMMessage incomingMessage); boolean releaseGuardForSegment(final SFRMMessage incomingMessage); SFRMMessage processIncomingMessage(SFRMMessage incomingMessage, final Object[] params); SFRMMessage processHandshakingMessage(
			SFRMMessage 		rawMessage,
			final Object[] 		params); SFRMMessage processMetaMessage(
			SFRMMessage 		inputMessage,
			SFRMPartnershipDVO 	partnershipDVO, 
			final Object[] 		params); SFRMMessage processSegmentMessage(SFRMMessage rawMessage, final Object[] params); SFRMMessage processAcknowledgement(SFRMMessage msg, SFRMPartnershipDVO pDVO); String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser); String processPDFAck(SFRMMessageDVO mDVO); String processPPSAck(SFRMMessageDVO mDVO); String processPSDAck(SFRMMessageDVO mDVO); String processPRSAck(SFRMMessageDVO mDVO); }
IncomingMessageHandler extends SFRMComponent { public String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser) throws DAOException{ SFRMMessageSegmentHandler msHandler = this.getMessageSegmentHandler(); SFRMAcknowledgementBuilder ackBuilder = new SFRMAcknowledgementBuilder(); SFRMMessageSegmentDAO msDAO = (SFRMMessageSegmentDAO) msHandler.getDAOInstance(); List<Integer> segmentNums = parser.getMessageSegmentNums(mDVO.getMessageId()); ackBuilder.setMessage(mDVO.getMessageId(), mDVO.getStatus()); if(segmentNums.size() > 0){ List segDVOs = msHandler.retrieveMessages(mDVO.getMessageId(), SFRMConstant.MSGBOX_IN, SFRMConstant.MSGT_PAYLOAD, segmentNums); for(int i=0 ; segDVOs.size() > i ; i++){ SFRMMessageSegmentDVO msDVO = (SFRMMessageSegmentDVO) segDVOs.get(i); if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERED)){ msDVO.setStatus(SFRMConstant.MSGS_PROCESSED); msDVO.setCompletedTimestamp(new Timestamp(System.currentTimeMillis())); if(!msDAO.persist(msDVO)){ throw new DAOException("Error when updating the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_PROCESSED); } else if(msDVO.getStatus().equals(SFRMConstant.MSGS_DELIVERY_FAILURE)){ if(!msDAO.remove(msDVO)){ throw new DAOException("Error when removing the message segment"); } ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), SFRMConstant.MSGS_DELIVERY_FAILURE); }else{ ackBuilder.setSegment(mDVO.getMessageId(), msDVO.getSegmentNo(), msDVO.getStatus()); } } } return ackBuilder.toString(); }  static IncomingMessageHandler getInstance(); SFRMPartnershipDVO extractPartnership(SFRMMessage incomingMessage); boolean isDuplicateSegment(SFRMMessage incomingMessage); boolean isProcessingMessage(SFRMMessage incomingMessage); boolean isNotEnoughRoom(SFRMMessage incomingMessage, long threshold); void unpackIncomingMessage(SFRMMessage message, SFRMPartnershipDVO partnershipDVO); boolean initGuardForSegment(final SFRMMessage incomingMessage); boolean resolveGuardOwnerForSegment(final SFRMMessage incomingMessage); boolean releaseGuardForSegment(final SFRMMessage incomingMessage); SFRMMessage processIncomingMessage(SFRMMessage incomingMessage, final Object[] params); SFRMMessage processHandshakingMessage(
			SFRMMessage 		rawMessage,
			final Object[] 		params); SFRMMessage processMetaMessage(
			SFRMMessage 		inputMessage,
			SFRMPartnershipDVO 	partnershipDVO, 
			final Object[] 		params); SFRMMessage processSegmentMessage(SFRMMessage rawMessage, final Object[] params); SFRMMessage processAcknowledgement(SFRMMessage msg, SFRMPartnershipDVO pDVO); String processPRAck(SFRMMessageDVO mDVO, SFRMAcknowledgementParser parser); String processPDFAck(SFRMMessageDVO mDVO); String processPPSAck(SFRMMessageDVO mDVO); String processPSDAck(SFRMMessageDVO mDVO); String processPRSAck(SFRMMessageDVO mDVO);  }