OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 182 | Go to most recent revision | 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;
180 ilm 32
    private boolean encrypted;
149 ilm 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");
180 ilm 46
        this.encrypted = rowAttachment.getBoolean("ENCRYPTED");
149 ilm 47
    }
48
 
49
    public int getId() {
180 ilm 50
        return this.id;
149 ilm 51
    }
52
 
53
    public String getName() {
180 ilm 54
        return this.name;
149 ilm 55
    }
56
 
57
    public void setName(String newName) {
58
        this.name = newName;
59
    }
60
 
61
    public String getMimeType() {
180 ilm 62
        return this.mimeType;
149 ilm 63
    }
64
 
65
    public String getFileName() {
180 ilm 66
        return this.fileName;
149 ilm 67
    }
68
 
69
    public int getFileSize() {
180 ilm 70
        return this.fileSize;
149 ilm 71
    }
72
 
73
    public String getStorageFileName() {
180 ilm 74
        return this.storageFileName;
149 ilm 75
    }
76
 
77
    public String getStoragePath() {
180 ilm 78
        return this.storagePath;
149 ilm 79
    }
80
 
81
    public String getSourceTable() {
180 ilm 82
        return this.sourceTable;
149 ilm 83
    }
84
 
85
    public int getSourceId() {
180 ilm 86
        return this.sourceId;
149 ilm 87
    }
88
 
89
    public int getParentId() {
180 ilm 90
        return this.parentId;
149 ilm 91
    }
92
 
93
    public boolean isFolder() {
94
        return this.mimeType.equals(MIMETYPE_FOLDER);
95
    }
96
 
180 ilm 97
    public boolean isEncrypted() {
98
        return this.encrypted;
99
    }
100
 
149 ilm 101
    @Override
102
    public String toString() {
103
        return super.toString() + " attachment id:" + this.getId() + " name:" + this.getName();
104
    }
105
 
106
    @Override
107
    public boolean equals(Object obj) {
108
        if (obj == null)
109
            return false;
110
 
111
        if (this.getClass() != obj.getClass())
112
            return false;
113
 
114
        return this.getId() == ((Attachment) obj).getId();
115
    }
116
 
117
    @Override
118
    public int hashCode() {
119
        return getId();
120
    }
121
}