com.creditcloud.investmentfund.model.lion.moneyfund.response.NotificationResponseMessage.java Source code

Java tutorial

Introduction

Here is the source code for com.creditcloud.investmentfund.model.lion.moneyfund.response.NotificationResponseMessage.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.creditcloud.investmentfund.model.lion.moneyfund.response;

import com.creditcloud.investmentfund.api.utils.StringUtils;
import com.creditcloud.investmentfund.constant.FundInterfaceConstants;
import com.creditcloud.model.BaseObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * ???<br>
 * ? : ??-v2.0.27(?).docx <br>
 *
 * @author guohuazhang
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class NotificationResponseMessage extends BaseObject {

    private String tradeacco;//      char(32)   R   
    private String applicationNo;//   ??   char (32)   R   ??
    private String status;//   ??   char(1)   R   0?1.??10???
    private String errorCode;//   ?   char (4)   R   ?0000
    private String errorMessage;//??   char (256)   O   
    private String sign;//   ??   char(500)   R   

    public Map<String, String> toMap() {
        Map<String, String> parameters = new HashMap<>();

        parameters.put("tradeacco", StringUtils.nonNull(tradeacco));
        parameters.put("applicationNo", StringUtils.nonNull(applicationNo));
        parameters.put("status", StringUtils.nonNull(status));
        parameters.put("errorCode", StringUtils.nonNull(errorCode));
        parameters.put("errorMessage", StringUtils.nonNull(errorMessage));
        parameters.put("sign", StringUtils.nonNull(sign));

        return parameters;
    }

    /**
     *  status,errorCode 00000
     */
    public void markAsSuccess() {
        final String ERROR_CODE_SUCCESS = "0000";
        setErrorCode(ERROR_CODE_SUCCESS);

        final String STATUS_SUCCESS = "0";
        setStatus(STATUS_SUCCESS);
    }

    /**
     * ???XML?
     *
     * @return
     * @throws JsonProcessingException
     * @throws org.dom4j.DocumentException
     */
    public String toXMLMessage() throws JsonProcessingException, DocumentException {
        final String rootXMLNodeName = "Message";
        ObjectMapper xmlMapper = new XmlMapper();
        String xml = xmlMapper.writeValueAsString(this);
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        root.setName(rootXMLNodeName);
        doc.setXMLEncoding(FundInterfaceConstants.LION_MONEY_FUND_HTTP_ENCODING);
        xml = doc.asXML();
        return xml;
    }
}