001package org.kuali.ole.response;
002
003import org.apache.commons.lang3.StringUtils;
004import org.kuali.ole.bo.OLELookupUser;
005import org.kuali.ole.constants.OLESIP2Constants;
006import org.kuali.ole.response.OLESIP2Response;
007import org.kuali.ole.common.MessageUtil;
008import org.kuali.ole.common.OLESIP2Util;
009import org.kuali.ole.request.OLESIP2PatronEnableRequestParser;
010
011/**
012 * Created by gayathria on 10/11/14.
013 */
014public class OLESIP2PatronEnableResponse extends OLESIP2Response {
015
016
017    public OLESIP2PatronEnableResponse() {
018        this.code = OLESIP2Constants.PATRON_ENABLE_RESPONSE;
019    }
020
021    public String getSIP2PatronEnableResponse(OLELookupUser oleLookupUser, OLESIP2PatronEnableRequestParser sip2PatronEnableRequestParser) {
022
023        StringBuilder builder = new StringBuilder();
024        builder.append(code);
025        builder.append("YYYYYYYYYYYYYY");
026        builder.append("001");
027        builder.append(MessageUtil.getSipDateTime());
028        builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
029        builder.append(StringUtils.isNotBlank(sip2PatronEnableRequestParser.getInstitutionId()) ? sip2PatronEnableRequestParser.getInstitutionId() : "");
030        builder.append(OLESIP2Constants.SPLIT+
031                OLESIP2Constants.PATRON_IDENTIFIER_CODE);
032        builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronId()) ? oleLookupUser.getPatronId() : sip2PatronEnableRequestParser.getPatronIdentifier());
033        builder.append(OLESIP2Constants.SPLIT+
034                OLESIP2Constants.PERSONAL_NAME_CODE);
035        builder.append(oleLookupUser.getPatronName() != null ? oleLookupUser.getPatronName().getFirstName() + " " + oleLookupUser.getPatronName().getLastName() : "");
036        builder.append(OLESIP2Constants.SPLIT+
037                OLESIP2Constants.VALID_PATRON_CODE);
038        builder.append(OLESIP2Util.bool2Char(oleLookupUser.isValidPatron()));
039        builder.append(OLESIP2Constants.SPLIT+
040                OLESIP2Constants.SCREEN_MSG_CODE);
041        builder.append(OLESIP2Constants.PATRON_ENABLED);
042        if (sip2PatronEnableRequestParser.getSequenceNum() != null && !sip2PatronEnableRequestParser.getSequenceNum().equalsIgnoreCase("")) {
043            builder.append(OLESIP2Constants.SPLIT+
044                    OLESIP2Constants.SEQUENCE_NUM_CODE);
045            builder.append(sip2PatronEnableRequestParser.getSequenceNum());
046            builder.append(MessageUtil.computeChecksum(builder.toString()));
047        }
048        return builder.toString() + '\r';
049
050    }
051}