OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
149 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.edm;
15
 
16
import org.openconcerto.sql.model.SQLRowValues;
17
 
156 ilm 18
import java.io.File;
149 ilm 19
import java.io.Serializable;
20
 
21
public class Attachment implements Serializable {
22
    private final int id;
23
    private String name;
24
    private String mimeType;
25
    private String fileName;
26
    private int fileSize;
27
    private String storagePath;
28
    private String storageFileName;
29
    private String sourceTable;
30
    private int sourceId;
31
    private int parentId;
32
 
33
    public static final String MIMETYPE_FOLDER = "inode/directory";
34
 
35
    public Attachment(SQLRowValues rowAttachment) {
36
        this.id = rowAttachment.getID();
37
        this.name = rowAttachment.getString("NAME");
38
        this.mimeType = rowAttachment.getString("MIMETYPE");
39
        this.fileName = rowAttachment.getString("FILENAME");
40
        this.fileSize = rowAttachment.getInt("FILESIZE");
156 ilm 41
        this.storagePath = rowAttachment.getString("STORAGE_PATH").replace('\\', File.separatorChar);
149 ilm 42
        this.storageFileName = rowAttachment.getString("STORAGE_FILENAME");
43
        this.sourceTable = rowAttachment.getString("SOURCE_TABLE");
44
        this.sourceId = rowAttachment.getInt("SOURCE_ID");
45
        this.parentId = rowAttachment.getInt("ID_PARENT");
46
    }
47
 
48
    public int getId() {
49
        return id;
50
    }
51
 
52
    public String getName() {
53
        return name;
54
    }
55
 
56
    public void setName(String newName) {
57
        this.name = newName;
58
    }
59
 
60
    public String getMimeType() {
61
        return mimeType;
62
    }
63
 
64
    public String getFileName() {
65
        return fileName;
66
    }
67
 
68
    public int getFileSize() {
69
        return fileSize;
70
    }
71
 
72
    public String getStorageFileName() {
73
        return storageFileName;
74
    }
75
 
76
    public String getStoragePath() {
77
        return storagePath;
78
    }
79
 
80
    public String getSourceTable() {
81
        return sourceTable;
82
    }
83
 
84
    public int getSourceId() {
85
        return sourceId;
86
    }
87
 
88
    public int getParentId() {
89
        return parentId;
90
    }
91
 
92
    public boolean isFolder() {
93
        return this.mimeType.equals(MIMETYPE_FOLDER);
94
    }
95
 
96
    @Override
97
    public String toString() {
98
        return super.toString() + " attachment id:" + this.getId() + " name:" + this.getName();
99
    }
100
 
101
    @Override
102
    public boolean equals(Object obj) {
103
        if (obj == null)
104
            return false;
105
 
106
        if (this.getClass() != obj.getClass())
107
            return false;
108
 
109
        return this.getId() == ((Attachment) obj).getId();
110
    }
111
 
112
    @Override
113
    public int hashCode() {
114
        return getId();
115
    }
116
}