BrightSide Workbench Full Report + Source Code
DocumentationTask.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.documentation;
20 
21 import java.util.stream.Stream;
22 import org.turro.action.MailSenders;
23 import org.turro.action.PushSenders;
24 import org.turro.attach.db.AttachPU;
25 import org.turro.attach.entity.EntityDocumentation;
26 import org.turro.attach.entity.EntityDocumentationStatus;
27 import org.turro.i18n.I_;
28 import org.turro.scheduler.task.AbstractTask;
29 import org.turro.sql.SqlClause;
30 import org.turro.time.Time;
31 import org.turro.util.Converter;
32 
37 public class DocumentationTask extends AbstractTask {
38 
39  @Override
40  public void execute() {
41  Time time = Time.now().addDays((Converter.STANDARD.convert(getSettings().getData(), Long.class)));
42  try(Stream<EntityDocumentation> documentation = SqlClause.select("d").from("EntityDocumentation d")
43  .where().isNotNull("deadline")
44  .and().smallerOrEqual("deadline", time.getDate())
45  .and().in("status", EntityDocumentationStatus.pendingStatusList())
46  .dao(new AttachPU())
47  .stream(EntityDocumentation.class)) {
48  documentation.forEach((ed) -> {
49  if(EntityDocumentationStatus.PENDING_VALIDATION.equals(ed.getStatus())) {
50  PushSenders.getPool()
51  .addContact(ed.getRequester())
52  .send(I_.get("Documentation"), I_.get("Pending to validate"), ed.getEntity().getEntityUrl());
53  MailSenders.getPool().setRoot("/documentation")
54  .addAdministrators()
55  .addContact(ed.getRequester())
56  .silentSendTemplate(ed, "uploaded", I_.get("Pending to validate"));
57  } else {
58  PushSenders.getPool()
59  .addContact(ed.getContact())
60  .addContact(ed.getRequester())
61  .send(I_.get("Documentation"), I_.get("Pending upload documents"), ed.getEntity().getEntityUrl());
62  MailSenders.getPool().setRoot("/documentation")
63  .addContact(ed.getContact())
64  .addContact(ed.getRequester())
65  .silentSendTemplate(ed, "required", I_.get("Pending upload documents"));
66  }
67  });
68  }
69  }
70 
71  @Override
72  public boolean isSystem() {
73  return false;
74  }
75 
76  @Override
77  public String getName() {
78  return I_.get("Documentation deadline check");
79  }
80 
81  @Override
82  public String getDataLabel() {
83  return "Days before deadline";
84  }
85 
86 }
static String get(String msg)
Definition: I_.java:41
static List< EntityDocumentationStatus > pendingStatusList()