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

com.lionbridge.content.sdk.models.Project Maven / Gradle / Ivy

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

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.lionbridge.content.sdk.validations.ProjectConverter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.StringWriter;
import java.net.URI;
import java.util.Date;
import java.util.List;

import static java.lang.String.format;

@JsonDeserialize(converter=ProjectConverter.class)
@JacksonXmlRootElement(localName="Project")
@JsonIgnoreProperties({"Errors", "Products"})
@XmlRootElement
public class Project {
	@JacksonXmlProperty(localName="ProjectID")
	private int projectId;

	@JacksonXmlProperty(localName="ProjectName")
	private String name;

	@JacksonXmlProperty(localName="ServiceID")
	private int serviceId;

    @JacksonXmlProperty(localName="CreationDate")
    private Date CreationDate;

    @JacksonXmlProperty(localName="Price")
    private String price;

    @JacksonXmlProperty(localName="Currency")
    private String currency;

	@JacksonXmlProperty(localName="Status")
	private String status;

	@JacksonXmlProperty(localName="QuoteID")
	private int quoteId;

    @JacksonXmlProperty(localName="SpecialInstructions")
    private String specialInstructions;

	/**
	 * This URL value is returned from getProject and listProject
	 */
	@JacksonXmlProperty(localName="URL")
	private String url;
	
	/**
	 * ProjectURL is returned from getQuote
	 */
	@JacksonXmlProperty(localName="ProjectURL")
	private String projectUrlString;
	private URI projectUrl;

	/**
	 * This due date is returned from getQuote. using a string here since it's
	 * information only on this path, and the format can be different from other
	 * dates, which causes deserialization errors.
	 */
	@JacksonXmlProperty(localName="ProjectDueDate")
	private String projectDueDate;

	/**
	 * These two are returned from getProject and listProject
	 */
	@JacksonXmlProperty(localName="DueDate")
	private Date dueDate;

	@JacksonXmlProperty(localName="CompletionDate")
	private Date completionDate;

	@JacksonXmlProperty(localName="SourceLanguage")
	private SourceLanguage sourceLanguage; //NOTE: This was a string in original library.

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="TargetLanguages")
	private List targetLanguages; //NOTE: This was a string in original library.

	// Deliberately leaving out products

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="Files")
	private List files;

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="ReferenceFiles")
	private List referenceFiles;

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="Errors")
	private List errors;

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="NotificationSubscriptions")
	private List notificationSubscriptions;

	public void runValidations() {
		try {
			if (this.projectUrlString != null && !this.projectUrlString.isEmpty()) {
				this.projectUrl = new URI(this.projectUrlString);
			}
		} catch (Exception e) { // Throws URISyntaxException, ParseException
			// Leave projectUrl blank. TODO: Is this proper form? If I throw, my converter will fail.
		}
	}

	public String toXmlStringSimple() {
	    String xmlString = "";
	    try {
	        JAXBContext context = JAXBContext.newInstance(this.getClass());
	        Marshaller m = context.createMarshaller();

	        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // To format XML

	        StringWriter sw = new StringWriter();
	        m.marshal(this, sw);
	        xmlString = sw.toString();

	    } catch (JAXBException e) {
	        e.printStackTrace();
	    }

	    return xmlString;
	}
	
	/**
	 * Create an XML representation of this project but only include the ID.
	 * This is used for generating a quote.
	 * @return XML representation of the Project as a String
	 */
	public String idToXmlString() {
		return format("%d", this.getProjectId());
	}
	
	public String printTargetLanguages() {
		StringBuilder builder = new StringBuilder();
		builder.append("");
		if (null != this.getTargetLanguages() && !this.getTargetLanguages().isEmpty()) {
			for (TargetLanguage tgtLang : this.getTargetLanguages()) {
				builder.append("");
				builder.append("").append(tgtLang.getLanguageCode()).append("");
				builder.append("");
			}
		}
		builder.append("");
		return builder.toString();
	}

	public int getProjectId() {
		return this.projectId;
	}

	public void setProjectId(final int projectId) {
		this.projectId = projectId;
	}

	public String getName() {
		return this.name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public int getServiceId() {
		return this.serviceId;
	}

	public void setServiceId(final int serviceId) {
		this.serviceId = serviceId;
	}

	public URI getProjectUrl() {
		return this.projectUrl;
	}

	public void setProjectUrl(final URI projectUrl) {
		this.projectUrl = projectUrl;
	}

	public Date getCreationDate() {
		return this.CreationDate;
	}

	public void setCreationDate(final Date creationDate) {
		this.CreationDate = creationDate;
	}

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

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

	public String getUrl() {
		return this.url;
	}

	public void setUrl(final String url) {
		this.url = url;
	}

	public String getProjectUrlString() {
		return this.projectUrlString;
	}

	public void setProjectUrlString(final String projectUrlString) {
		this.projectUrlString = projectUrlString;
	}

	public String getPrice() {
		return this.price;
	}

	public void setPrice(final String price) {
		this.price = price;
	}

	public String getCurrency() {
		return this.currency;
	}

	public void setCurrency(final String currency) {
		this.currency = currency;
	}

	public String getProjectDueDate() {
		return this.projectDueDate;
	}

	public void setProjectDueDate(final String projectDueDate) {
		this.projectDueDate = projectDueDate;
	}

	public Date getDueDate() {
		return this.dueDate;
	}

	public void setDueDate(final Date dueDate) {
		this.dueDate = dueDate;
	}

	public Date getCompletionDate() {
		return this.completionDate;
	}

	public void setCompletionDate(final Date completionDate) {
		this.completionDate = completionDate;
	}

	public SourceLanguage getSourceLanguage() {
		return this.sourceLanguage;
	}

	public void setSourceLanguage(final SourceLanguage sourceLanguage) {
		this.sourceLanguage = sourceLanguage;
	}

	public List getTargetLanguages() {
		return this.targetLanguages;
	}

	public void setTargetLanguages(final List targetLanguages) {
		this.targetLanguages = targetLanguages;
	}

	public List getFiles() {
		return this.files;
	}

	public void setFiles(final List files) {
		this.files = files;
	}

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

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

	public List getReferenceFiles() {
		return referenceFiles;
	}

	public void setReferenceFiles(List referenceFiles) {
		this.referenceFiles = referenceFiles;
	}

	public int getQuoteId() {
		return quoteId;
	}

	public void setQuoteId(int quoteId) {
		this.quoteId = quoteId;
	}

    public String getSpecialInstructions() {
        return specialInstructions;
    }

    public void setSpecialInstructions(String specialInstructions) {
        this.specialInstructions = specialInstructions;
    }

	public List getNotificationSubscriptions() {
		return notificationSubscriptions;
	}

	public void setNotificationSubscriptions(List notificationSubscriptions) {
		this.notificationSubscriptions = notificationSubscriptions;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy