19 package org.turro.documentation.model;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.List;
25 import org.turro.string.Strings;
26 import org.turro.action.MailSenders;
27 import org.turro.action.PushSenders;
28 import org.turro.assistant.AssistantListbox;
29 import org.turro.attach.db.AttachPU;
30 import org.turro.attach.entity.EntityDocumentation;
31 import org.turro.attach.entity.EntityDocumentationStatus;
32 import org.turro.auth.Authentication;
33 import org.turro.documentation.DocumentDefinition;
34 import org.turro.elephant.context.ElephantContext;
35 import org.turro.elephant.util.Messages;
36 import org.turro.entities.Entities;
37 import org.turro.entities.EntityRole;
38 import org.turro.entities.IElephantEntity;
39 import org.turro.file.Document;
40 import org.turro.file.FileWrapper;
41 import org.turro.file.Folder;
42 import org.turro.i18n.I_;
43 import org.turro.jpa.Dao;
44 import org.turro.log.SystemLogger;
45 import org.turro.plugin.contacts.IContact;
46 import org.turro.sql.SqlClause;
47 import org.turro.upload.Medias;
48 import org.turro.zkoss.dialog.DialogField;
49 import org.turro.zkoss.dialog.Dialogs;
50 import org.zkoss.bind.BindUtils;
51 import org.zkoss.bind.annotation.BindingParam;
52 import org.zkoss.bind.annotation.Command;
53 import org.zkoss.bind.annotation.ExecutionArgParam;
54 import org.zkoss.bind.annotation.Init;
55 import org.zkoss.bind.annotation.NotifyChange;
56 import org.zkoss.util.media.Media;
57 import org.zkoss.zk.ui.Executions;
58 import org.zkoss.zul.Datebox;
59 import org.zkoss.zul.Label;
60 import org.zkoss.zul.Space;
61 import org.zkoss.zul.Textbox;
70 private List<String> contactIds;
72 private boolean canCreate;
73 private List<EntityDocumentation> model;
76 public void init(@ExecutionArgParam(
"entityPath") String entityPath) {
77 if(Strings.isBlank(entityPath)) {
78 entityPath = Executions.getCurrent().getParameter(
"entityPath");
80 if(!Strings.isBlank(entityPath)) {
103 AssistantListbox al = new AssistantListbox();
104 al.setWebUsers(true);
105 al.setEntityPath(iee.getPath());
106 al.setMold(
"select");
111 if(require !=
null && require.
isValid()) {
112 document.getAssistantIds().add(require.
getId());
113 getDao().saveObject(document);
118 .send(
I_.
get(
"Documentation"),
I_.
get(
"Pending upload documents"), document.getEntity().getEntityUrl());
122 .silentSendTemplate(document,
"required",
I_.
get(
"Pending upload documents"));
130 @NotifyChange(
"model")
135 long count = folder.count();
137 for(Media media : medias) {
138 if(++count > dd.
getMax() && !exists(folder, media))
break;
149 document.reviewStatus();
150 getDao().saveObject(document);
154 .addContact(document.getRequester())
155 .send(
I_.
get(
"Documentation"),
I_.
get(
"Pending to validate"), document.getEntity().getEntityUrl());
158 .addContact(document.getRequester())
159 .silentSendTemplate(document,
"uploaded",
I_.
get(
"Pending to validate"));
164 public
void download(@BindingParam("document") Document document) {
168 @Command(
"deleteDoc")
169 public
void deleteDoc(@BindingParam("document") Document document) {
176 @NotifyChange(
"model")
180 getDao().saveObject(document);
183 .addContact(document.getContact())
184 .addContacts(document.getAssistants())
185 .send(
I_.
get(
"Documentation"),
I_.
get(
"Validated"), document.getEntity().getEntityUrl());
188 .addContact(document.getContact())
189 .addContacts(document.getAssistants())
190 .silentSendTemplate(document,
"validated",
I_.
get(
"Validated"));
200 String comment = dialogs.<Textbox>getEditor(
"Reason").getValue();
202 document.setComment(comment);
203 getDao().saveObject(document);
207 .addContact(document.getContact())
208 .addContacts(document.getAssistants())
209 .send(
I_.
get(
"Documentation"),
I_.
get(
"Denied"), document.getEntity().getEntityUrl());
212 .addContact(document.getContact())
213 .addContacts(document.getAssistants())
214 .silentSendTemplate(document,
"denied",
I_.
get(
"Denied") +
": " + document.getComment());
223 document.getFolder().
remove();
247 AssistantListbox al = new AssistantListbox();
248 al.setWebUsers(true);
249 al.setEntityPath(iee.getPath());
250 al.setMold(
"select");
254 Datebox dl = new Datebox();
255 dl.setFormat(
"short");
259 DocumentationListbox dl = new DocumentationListbox(iee.getRoot());
260 dl.setSelectFirst(false);
261 dl.setCheckmark(true);
262 dl.setMultiple(true);
269 if(require !=
null && require.
isValid()) {
270 List<EntityDocumentation> eds =
new ArrayList<>();
278 ed.
setDeadline(dialogs.<Datebox>getEditor(
"Deadline").getValue());
291 .silentSendTemplate(document,
"required",
I_.
get(
"Pending upload documents"));
299 private String selectedType;
306 this.selectedType = selectedType;
311 List<String> types =
new ArrayList<>();
313 types.addAll(model.stream().map(ed -> ed.getDefinition().getName()).distinct().toList());
319 String orderBy = canCreate ?
"ed.status, ed.entityPath, ed.documentation" :
321 model = SqlClause.select(
"ed")
322 .from(
"EntityDocumentation ed")
326 .and().in(
"ed.contactId", contactIds)
327 .or().equal(
"ed.requesterId", contact.
getId())
328 .or().members(
"ed.assistantIds", contactIds)
332 .and().equal(
"ed.entityPath", iee.
getPath())
340 List<EntityDocumentation> invalids =
new ArrayList<>();
341 model.removeIf(ed -> !ed.isValid(invalids));
343 model.forEach(ed -> ed.reviewStatus());
345 if(!Strings.isBlank(selectedType)) {
346 model.removeIf(ed -> !selectedType.equals(ed.getDefinition().getName()));
351 private void prepareValues() {
352 if(contact ==
null) {
360 contactIds =
new ArrayList<>();
361 contactIds.add(contact.
getId());
367 private boolean exists(Folder folder, Media media) {
368 String correctedName = Document.correctName(media.getName());
369 Document document = Document.from(folder.path().resolve(correctedName));
370 return document.exists();
373 private boolean guessOverrides(Folder folder, Media media) {
374 String correctedName = Document.correctName(media.getName());
375 Document document = Document.from(folder.path().resolve(correctedName));
376 if(document.exists()) {
377 String entityPath =
"/file" + ElephantContext.getRelativePath(document.path().toString());
378 Date lastDownload = SystemLogger.getInstance().getLastDateOf(entityPath,
"downloaded");
379 return lastDownload ==
null || document.modified().after(lastDownload);
388 private Dao getDao() {
390 _dao =
new AttachPU();
static IMailSender getPool()
static IPushSender getPool()
void setDocumentation(String documentation)
void setRequesterId(String requesterId)
IElephantEntity getEntity()
void setDeadline(Date deadline)
void setContactId(String contactId)
void setEntityPath(String entityPath)
void setStatus(EntityDocumentationStatus status)
static IContact getIContact()
boolean isUploadControl()
boolean isAllowMultiple()
List< String > getDocumentationTypes()
void deleteDoc(@BindingParam("document") Document document)
void upload(@BindingParam("document") EntityDocumentation document, @BindingParam("medias") Media medias[])
void deny(@BindingParam("document") EntityDocumentation document)
List< EntityDocumentation > getModel()
void delete(@BindingParam("document") EntityDocumentation document)
void validate(@BindingParam("document") EntityDocumentation document)
void info(@BindingParam("document") DocumentDefinition document)
void init(@ExecutionArgParam("entityPath") String entityPath)
void setSelectedType(String selectedType)
void download(@BindingParam("document") Document document)
void add(@BindingParam("document") EntityDocumentation document)
Messages format(String word, Object... args)
static Messages confirmDeletion()
Messages add(String word)
static IElephantEntity getController(String path)
static IElephantEntity emptyController()
static String get(String msg)
void deleteObject(Object obj)
void saveCollection(Collection objs)
void deleteCollection(Collection objs)
static DialogField field(String label)
Dialogs width(String width)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
static Dialogs title(String title)
Dialogs addComponent(HtmlBasedComponent component)
Dialogs addField(DialogField field)
IMailSender setRoot(String root)
boolean hasRelatedRole(EntityRole role, IContact contact)