All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lionbridge.content.sdk.ErrorManager Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.lionbridge.content.sdk;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import java.util.List;

public class ErrorManager {
	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="Errors")
	private List errors;
	@JacksonXmlProperty(localName="Status")
	private String status = "";
	private String errorCode="";

	public ContentAPIException generateException() {
		ContentAPIException exception;
		StringBuilder builder = new StringBuilder();

		LBError error = errors.get(0);

		if (error != null && error.getSimpleMessage() != null && !error.getSimpleMessage().isEmpty()) {
			if (error.getDetailedMessage() != null) {
				builder.append(error.getSimpleMessage()).append(": ").append(error.getDetailedMessage());
				exception = new ContentAPIException(builder.toString());
			} else{
				exception = new ContentAPIException(error.getSimpleMessage());
			}
		} else {
			exception = new ContentAPIException(this.errorCode);
		}

		exception.setErrors(errors);

		return exception;
	}

	public String toXmlString() {
		StringBuilder xmlString = new StringBuilder("\n");
		if(null != this.errors) {
			for(LBError currentError : this.errors) {
				xmlString.append("\n\t");
				xmlString.append("\n\t\t").append(currentError.getReasonCode()).append("");
				xmlString.append("\n\t\t").append(currentError.getSimpleMessage()).append("");
				xmlString.append("\n\t\t").append(currentError.getDetailedMessage()).append("");
				xmlString.append("\n\t");
			}
		}
		xmlString.append("\n");
		return xmlString.toString();
	}

	public List getErrors() {
		return this.errors;
	}

	public void setErrors(final List errors) {
		this.errors = errors;
	}

	public final String getStatus() {
		return this.status;
	}

	public final void setStatus(final String status) {
		this.status = status;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(final String errorCode) {
		this.errorCode = errorCode;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy