BrightSide Workbench Full Report + Source Code
DossierOffer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.dossier.entity;
20 
21 import java.io.IOException;
22 import java.io.Serializable;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.Lob;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.Temporal;
37 import org.turro.action.Contacts;
38 import org.turro.elephant.context.ElephantContext;
39 import org.turro.file.Document;
40 import org.turro.file.Folder;
41 import org.turro.jpa.entity.IDaoEntity;
42 import org.turro.plugin.contacts.IContact;
43 import org.turro.string.Strings;
44 
49 @Entity
50 public class DossierOffer implements Serializable, IDaoEntity {
51 
52  @Id
53  @GeneratedValue(strategy=GenerationType.IDENTITY)
54  @Column(name="IDENTIFIER")
55  private Long id;
56 
57  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
58  private java.util.Date creation;
59 
60  @Lob
61  @Column(length=4096)
62  private String description;
63 
64  private String bidderId;
65 
66  private boolean accepted, declined;
67 
68  @ManyToOne
69  @JoinColumn(name="DOSSIER_FK")
70  private Dossier dossier;
71 
72  public Long getId() {
73  return id;
74  }
75 
76  public void setId(Long id) {
77  this.id = id;
78  }
79 
80  public Date getCreation() {
81  return creation;
82  }
83 
84  public void setCreation(Date creation) {
85  this.creation = creation;
86  }
87 
88  public String getDescription() {
89  return description;
90  }
91 
92  public void setDescription(String description) {
93  this.description = description;
94  }
95 
96  public String getBidderId() {
97  return bidderId;
98  }
99 
100  public void setBidderId(String bidderId) {
101  this.bidderId = bidderId;
102  }
103 
104  public boolean isAccepted() {
105  return accepted;
106  }
107 
108  public void setAccepted(boolean accepted) {
109  this.accepted = accepted;
110  }
111 
112  public boolean isDeclined() {
113  return declined;
114  }
115 
116  public void setDeclined(boolean declined) {
117  this.declined = declined;
118  }
119 
120  public Dossier getDossier() {
121  return dossier;
122  }
123 
124  public void setDossier(Dossier dossier) {
125  this.dossier = dossier;
126  }
127 
128  /* Documentation */
129 
130  public List<Document> getDocuments() {
131  Folder folder = getFolder();
132  if(folder.exists()) try {
133  return folder.documents();
134  } catch (IOException ex) {
135  Logger.getLogger(DossierOffer.class.getName()).log(Level.SEVERE, null, ex);
136  }
137  return Collections.EMPTY_LIST;
138  }
139 
140  public Folder getFolder() {
141  return Folder.from(ElephantContext.getRealPath(getFolderString()));
142  }
143 
144  public String getFolderString() {
145  return "/WEB-INF/files/dossier/" + dossier.getId() + "/dossier-offer/" + id;
146  }
147 
148  /* Bidder */
149 
150  public IContact getBidder() {
151  return Contacts.getContact(bidderId);
152  }
153 
154  public void setBidder(IContact contact) {
155  bidderId = contact.getId();
156  }
157 
158  /* IDaoEntity */
159 
160  @Override
161  public Object entityId() {
162  return id;
163  }
164 
165  @Override
166  public boolean isEmpty() {
167  return dossier == null || Strings.isBlank(bidderId) || Strings.isBlank(description);
168  }
169 
170 }
static IContact getContact(Object object)
Definition: Contacts.java:109
void setDescription(String description)