com.lionbridge.content.sdk.models.LBFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liox-content-sdk-java Show documentation
Show all versions of liox-content-sdk-java Show documentation
Client for Lionbridge Ondemand API
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;
import static java.lang.String.format;
@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 != fileStatusTemp) {
fileStatusTemp = fileStatusTemp.replaceAll("\\s+","");
setFileStatus(FileStatus.valueOf(fileStatusTemp));
}
if (name == null || name.isEmpty()) {
name = fileName;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Example: 2014-01-25T10:32:02Z
try {
if(this.uploadDateString != null && !uploadDateString.isEmpty()) {
setUploadDate(dateFormat.parse(uploadDateString));
}
if(urlString != null && !urlString.isEmpty()) {
url = new URI(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) {
return format("%s ", url.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 (String idString : ids) {
LBFile file = new LBFile();
int id = Integer.parseInt(idString);
file.setAssetId(id);
list.add(file);
}
}
return list;
}
public URI getUrl() {
return url;
}
public void setUrl(final URI url) {
this.url = url;
}
public FileStatus getFileStatus() {
return fileStatus;
}
public void setFileStatus(final FileStatus fileStatus) {
this.fileStatus = fileStatus;
}
public String getFileStatusTemp() {
return fileStatusTemp;
}
public void setFileStatusTemp(final String fileStatusTemp) {
this.fileStatusTemp = fileStatusTemp;
}
public String getUrlString() {
return urlString;
}
public void setUrlString(final String urlString) {
this.urlString = urlString;
}
public int getAssetId() {
return assetId;
}
public void setAssetId(final int assetId) {
this.assetId = assetId;
}
public int getProjectId() {
return projectId;
}
public void setProjectId(final int projectId) {
this.projectId = projectId;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getFileName() {
return fileName;
}
public void setFileName(final String fileName) {
this.fileName = fileName;
}
public SourceLanguage getSourceLanguage() {
return sourceLanguage;
}
public void setSourceLanguage(final SourceLanguage sourceLanguage) {
this.sourceLanguage = sourceLanguage;
}
public List 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;
}
}