BrightSide Workbench Full Report + Source Code
DossierWarnings.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.warnings;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.stream.Stream;
25 import org.turro.annotation.ElephantWarning;
26 import org.turro.dossier.db.DossierPU;
27 import org.turro.dossier.entity.CategoryRequest;
28 import org.turro.dossier.entity.ParticipantRequest;
29 import org.turro.elephant.context.Application;
30 import org.turro.i18n.I_;
31 
36 @ElephantWarning
37 public class DossierWarnings implements IElephantWarning {
38 
39  @Override
40  public String getHeader() {
41  return I_.get("Dossiers");
42  }
43 
44  @Override
45  public List<IWarning> getWarnings() {
46  if(Application.getApplication().isInRole("dossier:all")) {
47  return createModel();
48  }
49  return Collections.EMPTY_LIST;
50  }
51 
52  private List<IWarning> createModel() {
53  List<IWarning> warnings = new ArrayList<>();
54  try(Stream<ParticipantRequest> requests = new DossierPU().stream(ParticipantRequest.class, "select c from ParticipantRequest c")) {
55  requests.forEach((request) -> {
56  checkParticipantRequest(warnings, request);
57  });
58  }
59  try(Stream<CategoryRequest> requests = new DossierPU().stream(CategoryRequest.class, "select c from CategoryRequest c")) {
60  requests.forEach((request) -> {
61  checkCategoryRequest(warnings, request);
62  });
63  }
64  return warnings;
65  }
66 
67  private void checkParticipantRequest(List<IWarning> warnings, ParticipantRequest request) {
68  Warning warning = new Warning();
69  warning.setEntity(request.getDossier());
70  warning.addMessage(I_.format("Pending request from %s", request.getIContact().getName()));
71  if(!warning.getMessages().isEmpty()) {
72  warnings.add(warning);
73  }
74  }
75 
76  private void checkCategoryRequest(List<IWarning> warnings, CategoryRequest request) {
77  Warning warning = new Warning();
78  warning.setEntity(request.getCategory());
79  warning.addMessage(I_.format("Pending request from %s", request.getIContact().getName()));
80  if(!warning.getMessages().isEmpty()) {
81  warnings.add(warning);
82  }
83  }
84 
85 }
static String get(String msg)
Definition: I_.java:41