001package org.kuali.ole.sip2.sip2Response;
002
003import org.apache.commons.lang3.StringUtils;
004import org.kuali.ole.sip2.common.MessageUtil;
005import org.kuali.ole.sip2.common.OLESIP2Util;
006import org.kuali.ole.sip2.constants.OLESIP2Constants;
007import org.kuali.ole.sip2.requestParser.OLESIP2FeePaidRequestParser;
008
009/**
010 * Created by gayathria on 15/12/14.
011 */
012public class OLESIP2FeePaidResponse extends OLESIP2Response {
013
014    public OLESIP2FeePaidResponse() {
015        code = OLESIP2Constants.FEE_PAID_RESPONSE;
016    }
017
018    public String getFeePaidResponse(String message, OLESIP2FeePaidRequestParser sip2FeePaidRequestParser) {
019        StringBuilder sip2FeePaidResponseBuilder = new StringBuilder();
020        sip2FeePaidResponseBuilder.append(code);
021        if (message.equalsIgnoreCase(OLESIP2Constants.FEE_PAID)) {
022            sip2FeePaidResponseBuilder.append(OLESIP2Util.bool2Char(true));
023        } else {
024            sip2FeePaidResponseBuilder.append(OLESIP2Util.bool2Char(false));
025        }
026        sip2FeePaidResponseBuilder.append(MessageUtil.getSipDateTime());
027        sip2FeePaidResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
028        sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getInstitutionId() != null ? sip2FeePaidRequestParser.getInstitutionId() : "");
029        sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
030                OLESIP2Constants.PATRON_IDENTIFIER_CODE);
031        sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getPatronIdentifier());
032        if (StringUtils.isNotBlank(sip2FeePaidRequestParser.getTransactionId())) {
033            sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
034                    OLESIP2Constants.TRANSACTION_ID_CODE);
035            sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getTransactionId());
036        }
037        if (StringUtils.isNotBlank(message)) {
038            sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
039                    OLESIP2Constants.SCREEN_MSG_CODE);
040            sip2FeePaidResponseBuilder.append(message);
041        } else {
042            sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
043                    OLESIP2Constants.SCREEN_MSG_CODE);
044            sip2FeePaidResponseBuilder.append(OLESIP2Constants.SERVICE_ERROR);
045        }
046        if (StringUtils.isNotBlank(sip2FeePaidRequestParser.getSequenceNum())) {
047            sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
048                    OLESIP2Constants.SEQUENCE_NUM_CODE);
049            sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getSequenceNum());
050            sip2FeePaidResponseBuilder.append(MessageUtil.computeChecksum(sip2FeePaidResponseBuilder.toString()));
051        }
052        return sip2FeePaidResponseBuilder.toString() + '\r';
053    }
054}
055