OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
149 ilm 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;
182 ilm 33
    public static final String MIMETYPE_URL = "application/url-mime-type";
149 ilm 34
    public static final String MIMETYPE_FOLDER = "inode/directory";
35
 
36
    public Attachment(SQLRowValues rowAttachment) {
37
        this.id = rowAttachment.getID();
38
        this.name = rowAttachment.getString("NAME");
39
        this.mimeType = rowAttachment.getString("MIMETYPE");
40
        this.fileName = rowAttachment.getString("FILENAME");
41
        this.fileSize = rowAttachment.getInt("FILESIZE");
156 ilm 42
        this.storagePath = rowAttachment.getString("STORAGE_PATH").replace('\\', File.separatorChar);
149 ilm 43
        this.storageFileName = rowAttachment.getString("STORAGE_FILENAME");
44
        this.sourceTable = rowAttachment.getString("SOURCE_TABLE");
45
        this.sourceId = rowAttachment.getInt("SOURCE_ID");
46
        this.parentId = rowAttachment.getInt("ID_PARENT");
180 ilm 47
        this.encrypted = rowAttachment.getBoolean("ENCRYPTED");
149 ilm 48
    }
49
 
50
    public int getId() {
180 ilm 51
        return this.id;
149 ilm 52
    }
53
 
54
    public String getName() {
180 ilm 55
        return this.name;
149 ilm 56
    }
57
 
58
    public void setName(String newName) {
59
        this.name = newName;
60
    }
61
 
62
    public String getMimeType() {
180 ilm 63
        return this.mimeType;
149 ilm 64
    }
65
 
66
    public String getFileName() {
180 ilm 67
        return this.fileName;
149 ilm 68
    }
69
 
70
    public int getFileSize() {
180 ilm 71
        return this.fileSize;
149 ilm 72
    }
73
 
74
    public String getStorageFileName() {
180 ilm 75
        return this.storageFileName;
149 ilm 76
    }
77
 
78
    public String getStoragePath() {
180 ilm 79
        return this.storagePath;
149 ilm 80
    }
81
 
82
    public String getSourceTable() {
180 ilm 83
        return this.sourceTable;
149 ilm 84
    }
85
 
86
    public int getSourceId() {
180 ilm 87
        return this.sourceId;
149 ilm 88
    }
89
 
90
    public int getParentId() {
180 ilm 91
        return this.parentId;
149 ilm 92
    }
93
 
94
    public boolean isFolder() {
95
        return this.mimeType.equals(MIMETYPE_FOLDER);
96
    }
97
 
180 ilm 98
    public boolean isEncrypted() {
99
        return this.encrypted;
100
    }
101
 
149 ilm 102
    @Override
103
    public String toString() {
104
        return super.toString() + " attachment id:" + this.getId() + " name:" + this.getName();
105
    }
106
 
107
    @Override
108
    public boolean equals(Object obj) {
109
        if (obj == null)
110
            return false;
111
 
112
        if (this.getClass() != obj.getClass())
113
            return false;
114
 
115
        return this.getId() == ((Attachment) obj).getId();
116
    }
117
 
118
    @Override
119
    public int hashCode() {
120
        return getId();
121
    }
122
}