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

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

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

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.LBFileConverter;
import com.lionbridge.content.sdk.definitions.FileStatus;

import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@JsonDeserialize(converter=LBFileConverter.class)
@JacksonXmlRootElement(localName="File")
@XmlRootElement
public class LBFile {
	@JacksonXmlProperty(localName="AssetID")
	private int assetId;

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

	private FileStatus fileStatus;

	@JacksonXmlProperty(localName="URL")
	private String urlString;

	private URI url;

	@JacksonXmlProperty(localName="ProjectID")
	private int projectId;

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

	@JacksonXmlProperty(localName="FileName")
	private String fileName;

	@JacksonXmlProperty(localName="UploadDate")
	private String uploadDateString;

	private Date uploadDate;

	@JacksonXmlProperty(localName="SourceLanguage")
	private SourceLanguage sourceLanguage;

	@JacksonXmlElementWrapper(useWrapping=true)
	@JacksonXmlProperty(localName="TargetLanguages")
	private List targetLanguages = new ArrayList<>();

	@JacksonXmlProperty(localName="AcceptedBy")
	private String acceptedBy;

    @JacksonXmlProperty(localName="AcceptedDate")
    private String acceptedDate;

    @JacksonXmlProperty(localName="AcceptedMethod")
    private String acceptedMethod;

    public void runValidations() {
		if(null != this.fileStatusTemp) {
			this.fileStatusTemp = this.fileStatusTemp.replaceAll("\\s+","");
			
			if(null != FileStatus.valueOf(this.fileStatusTemp)) {
				this.setFileStatus(FileStatus.valueOf(this.fileStatusTemp));
			}
		}

		if (this.name == null || this.name.isEmpty()) {
			this.name = this.fileName;
		}
		final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Example: 2014-01-25T10:32:02Z
		try {
			if(this.uploadDateString != null && !this.uploadDateString.isEmpty()) {
				this.setUploadDate(dateFormat.parse(this.uploadDateString));
			}
			if(this.urlString != null && !this.urlString.isEmpty()) {
				this.url = new URI(this.urlString);
			}
		} catch (Exception e) { // Throws URISyntaxException, ParseException
			// Leave uploadDate blank. TODO: Is this proper form? If I throw, my converter will fail.
		}
	}

	public String getUploadDateString() {
		return uploadDateString;
	}

	public void setUploadDateString(final String uploadDateString) {
		this.uploadDateString = uploadDateString;
	}

	public Date getUploadDate() {
		return uploadDate;
	}

	public void setUploadDate(final Date uploadDate) {
		this.uploadDate = uploadDate;
	}

	public static String toXmlStringByUrl(URI url) {
		StringBuilder builder = new StringBuilder();
		builder.append("")
			.append(url.toString())
			.append("");
		return builder.toString();
	}

	public String toXmlString() {
		return toXmlString(false);
	}

	public String toXmlString(boolean areReferenceFiles) {
		StringBuilder builder = new StringBuilder();

		if (areReferenceFiles) {
			builder.append("").append(String.valueOf(this.assetId)).append("");
		} else {
			builder.append("").append(String.valueOf(this.assetId)).append("");
		}

		return builder.toString();
	}
	
	public static List getFilesFromAssetIds(List ids) throws NumberFormatException {
		List list = new ArrayList<>();
		if (ids != null) {
			for(int i=0; i getTargetLanguages() {
		return targetLanguages;
	}

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

	public String getAcceptedBy() {
		return acceptedBy;
	}

    public String getAcceptedDate() {
        return acceptedDate;
    }

    public String getAcceptedMethod() {
        return acceptedMethod;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy