BrightSide Workbench Full Report + Source Code
DossierImpl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.util;
19 
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import org.turro.string.Strings;
24 import org.turro.annotation.ElephantPlugin;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.dossier.DossierWrapper;
27 import org.turro.dossier.entity.Category;
28 import org.turro.dossier.entity.Dossier;
29 import org.turro.dossier.entity.DossierStatus;
30 import org.turro.dossier.zul.menu.DossierMenu;
31 import org.turro.elephant.entities.db.Related;
32 import org.turro.elephant.util.Images;
33 import org.turro.entities.Entities;
34 import org.turro.i18n.I_;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.plugin.dossier.ICategory;
37 import org.turro.plugin.dossier.IDossier;
38 import org.turro.plugin.dossier.IIssue;
39 import org.turro.related.AbstractAddRelated;
40 import org.turro.related.RelatedNew;
41 import org.turro.related.Relateds;
42 import org.zkoss.zk.ui.HtmlBasedComponent;
43 
48 @ElephantPlugin
49 public class DossierImpl extends AbstractAddRelated implements IDossier {
50 
51  private Collection<ICategory> categories = new ArrayList<>();
52  private Long idCategory;
53  private IContact subject;
54  private String path, description;
55  private Collection<IIssue> issues = new ArrayList<>();
56 
57  @Override
58  public Collection<ICategory> getCategories() {
59  return categories;
60  }
61 
62  @Override
63  public void setCategories(Collection<ICategory> categories) {
64  this.categories = categories;
65  }
66 
67  @Override
68  public String getDescription() {
69  return description;
70  }
71 
72  @Override
73  public void setDescription(String description) {
74  this.description = description;
75  }
76 
77  @Override
78  public Long getIdCategory() {
79  return idCategory;
80  }
81 
82  @Override
83  public void setIdCategory(Long idCategory) {
84  this.idCategory = idCategory;
85  }
86 
87  @Override
88  public Collection<IIssue> getIssues() {
89  return issues;
90  }
91 
92  @Override
93  public void setIssues(Collection<IIssue> issues) {
94  this.issues = issues;
95  }
96 
97  @Override
98  public String getPath() {
99  return path;
100  }
101 
102  @Override
103  public void setPath(String path) {
104  this.path = path;
105  }
106 
107  @Override
108  public IContact getSubject() {
109  return subject;
110  }
111 
112  @Override
113  public void setSubject(IContact subject) {
114  this.subject = subject;
115  }
116 
117  @Override
119  CategoryImpl cat = new CategoryImpl();
120  categories.add(cat);
121  return cat;
122  }
123 
124  @Override
125  public IIssue addIssue() {
126  IssueImpl issue = new IssueImpl();
127  issue.setDossier(this);
128  issues.add(issue);
129  return issue;
130  }
131 
132  @Override
133  public Dossier getEntity() {
134  return loadByPath(path);
135  }
136 
138  return new DossierPU().find(Category.class, idCategory);
139  }
140 
141  public static Dossier loadByPath(String path) {
142  for(Related rp : Relateds.from(path).destinations()) {
143  if(rp.getDestination().startsWith("/dossier")) {
144  return (Dossier) Entities.getController(rp.getDestination()).getEntity();
145  }
146  }
147  return null;
148  }
149 
150  @Override
151  protected HtmlBasedComponent getComponent() {
152  RelatedNew rpn = new RelatedNew();
153  rpn.setEntity(this, I_.get("New Dossier"), Images.getImage("dossier_new"), "dossier:new");
154  return rpn;
155  }
156 
157  @Override
158  protected void saveRelation(boolean showForm) {
159  if(Strings.isBlank(path)) return;
160  if(categories != null) {
161  for(ICategory cat : categories) {
162  cat.save();
163  }
164  // parents might be unassigned thus, iterate again
165  for(ICategory cat : categories) {
166  cat.save();
167  }
168  }
169  Dossier dossier = getEntity();
170  if(dossier == null) {
171  dossier = new Dossier();
172  dossier.setCategory(getCategory());
173  dossier.addSubject(subject);
174  dossier.setDescription(description);
175  dossier.getRelated().setRelatedPath(path);
176  dossier.setCreation(new Date());
178  if(!showForm) {
179  new DossierWrapper(dossier).save();
180  } else {
181  DossierMenu.showDossier(dossier);
182  }
183  }
184  }
185 
186 }
void setCategory(Category category)
Definition: Dossier.java:115
void setCreation(Date creation)
Definition: Dossier.java:139
void setDescription(String description)
Definition: Dossier.java:147
void setStatus(DossierStatus status)
Definition: Dossier.java:195
void addSubject(IContact contact)
Definition: Dossier.java:537
void setSubject(IContact subject)
void setCategories(Collection< ICategory > categories)
void saveRelation(boolean showForm)
Collection< IIssue > getIssues()
void setDescription(String description)
static Dossier loadByPath(String path)
HtmlBasedComponent getComponent()
Collection< ICategory > getCategories()
void setIdCategory(Long idCategory)
void setIssues(Collection< IIssue > issues)
void setDossier(IDossier dossier)
Definition: IssueImpl.java:63
static void showDossier(Dossier dossier)
static String getImage(String image)
Definition: Images.java:36
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String get(String msg)
Definition: I_.java:41
void setRelatedPath(String relatedPath)
void setEntity(IAddRelated entity, String label, String image, String role)
Definition: RelatedNew.java:42
static Relateds from(String entityPath)
Definition: Relateds.java:145
List< Related > destinations()
Definition: Relateds.java:68