001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.fileservice;
017
018import javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlRootElement;
022
023import core.tut.pori.users.UserIdentity;
024
025/**
026 * Details of a single uploaded file.
027 * 
028 * The saved name (file system name) should not be shown to the user, even though it can be figured out from the URL. 
029 * The name parameter is the filename used provided when uploading/creating the file.
030 * 
031 * <h3>XML Example</h3>
032 * 
033 * {@doc.restlet service="[service.tut.pori.fileservice.reference.Definitions#SERVICE_FS_REFERENCE_EXAMPLE]" method="[service.tut.pori.fileservice.Definitions#ELEMENT_FILE]" type="GET" query="" body_uri=""}
034 * 
035 * <h2>Optional elements</h2>
036 * <ul>
037 *  <li>{@link service.tut.pori.fileservice.Definitions#ELEMENT_NAME}</li>
038 * </ul>
039 * 
040 */
041@XmlRootElement(name=Definitions.ELEMENT_FILE)
042@XmlAccessorType(value=XmlAccessType.NONE)
043public class File {
044  @XmlElement(name = Definitions.ELEMENT_FILE_ID)
045  private Long _fileId = null;
046  @XmlElement(name = Definitions.ELEMENT_NAME)
047  private String _name = null;
048  private String _savedName = null;
049  @XmlElement(name = Definitions.ELEMENT_URL)
050  private String _url = null;
051  private UserIdentity _userId = null;
052  
053  /**
054   * System specified file identifier.
055   * 
056   * @return the fileId
057   * @see #setFileId(Long)
058   */
059  public Long getFileId() {
060    return _fileId;
061  }
062  
063  /**
064   * @param fileId the fileId to set
065   * @see #getFileId()
066   */
067  public void setFileId(Long fileId) {
068    _fileId = fileId;
069  }
070  
071  /**
072   * @return the original file name or null if none was given
073   * @see #setName(String)
074   */
075  public String getName() {
076    return _name;
077  }
078  
079  /**
080   * @param name the orginal file name
081   * @see #getName()
082   */
083  public void setName(String name) {
084    _name = name;
085  }
086  
087  /**
088   * @return the userId of the file uploader.
089   * @see #setUserId(UserIdentity)
090   */
091  public UserIdentity getUserId() {
092    return _userId;
093  }
094  
095  /**
096   * @param userId the userId to set
097   * @see #getUserId()
098   */
099  public void setUserId(UserIdentity userId) {
100    _userId = userId;
101  }
102  
103  /**
104   * 
105   * @param userId
106   * @see #setUserId(UserIdentity)
107   */
108  @SuppressWarnings("unused") // for serialization
109  private void setUserIdValue(Long userId){
110    _userId = (userId == null ? null : new UserIdentity(userId));
111  }
112  
113  /**
114   * 
115   * @return user id value
116   * @see #getUserId()
117   */
118  public Long getUserIdValue(){
119    return (_userId == null ? null : _userId.getUserId());
120  }
121
122  /**
123   * @return the file download url
124   * @see #setUrl(String)
125   */
126  public String getUrl() {
127    return _url;
128  }
129
130  /**
131   * @param url the url to set
132   * @see #getUrl()
133   */
134  public void setUrl(String url) {
135    _url = url;
136  }
137
138  /**
139   * @return the file name used to save the file to the system
140   */
141  public String getSavedName() {
142    return _savedName;
143  }
144
145  /**
146   * @param savedName the name used to save the file to the system
147   */
148  public void setSavedName(String savedName) {
149    _savedName = savedName;
150  }
151}