BrightSide Workbench Full Report + Source Code
WorksheetUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.util;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Objects;
26 import org.turro.string.Strings;
27 import org.turro.dossier.db.DossierPU;
28 import org.turro.dossier.entity.Issue;
29 import org.turro.dossier.entity.IssueParticipantRole;
30 import org.turro.dossier.entity.IssueStatus;
31 import org.turro.dossier.entity.Worksheet;
32 import org.turro.dossier.issue.IssueWrapper;
33 import org.turro.dossier.search.IssueResults;
34 import org.turro.jpa.Dao;
35 import org.turro.plugin.contacts.IContact;
36 
41 public class WorksheetUtil {
42 
43  public static Collection<Worksheet> getWorksheet(String idContact) {
44  Dao dao = new DossierPU();
45  return dao.getResultList(
46  "select w from Worksheet as w " +
47  "where w.idContact = ? " +
48  "order by w.sheetOrder",
49  new Object[] { idContact });
50  }
51 
52  public static Collection<Issue> getIssues(String idContact, String searchValue) {
53  Dao dao = new DossierPU();
54  if(!Strings.isBlank(searchValue)) {
55  return dao.getResultList(
56  "select w.issue from Worksheet as w " +
57  "where w.idContact = ? " +
58  "and w.issue.description like ? " +
59  "order by w.sheetOrder",
60  new Object[] { idContact, "%" + searchValue + "%" });
61  } else {
62  return dao.getResultList(
63  "select w.issue from Worksheet as w " +
64  "where w.idContact = ? " +
65  "order by w.sheetOrder",
66  new Object[] { idContact });
67  }
68  }
69 
70  public static List<IssueWrapper> getIssueWrappersForNow(IContact contact, String searchValue) {
71  ArrayList<IssueWrapper> list = new ArrayList<>();
72  for(Issue issue : getIssues(contact.getId(), searchValue)) {
73  IssueWrapper iw = new IssueWrapper(issue, contact);
74  list.add(iw);
75  }
76  return list;
77  }
78 
79  public static List<IssueWrapper> getIssueWrappers(IContact contact, String searchValue) {
80  ArrayList<IssueWrapper> list = new ArrayList<>();
81  for(Issue issue : getIssues(contact.getId(), searchValue)) {
82  IssueWrapper iw = new IssueWrapper(issue, contact);
83  list.add(iw);
84  }
85  return list;
86  }
87 
88  public static Collection<IssueWrapper> getNotIn(IContact contact, Collection<IssueWrapper> listws) {
89  ArrayList<IssueWrapper> list = new ArrayList<>();
90  if(contact.isValid()) {
91  IssueResults results = new IssueResults();
92  results.setByParticipant(contact);
93  results.setDossierId(0L);
94  for(IssueWrapper iw : results.getIssueList()) {
95  if(iw.getRelevanceOrderByContact() == 1) {
96  boolean exists = false;
97  for(IssueWrapper liw : listws) {
98  if(Objects.equals(liw.getIssue().getId(), iw.getIssue().getId())) {
99  exists = true;
100  break;
101  }
102  }
103  if(!exists) {
104  list.add(iw);
105  }
106  }
107  }
108  }
109  return list;
110  }
111 
112  public static void removeWorksheet(String idContact) {
113  Dao dao = new DossierPU();
114  dao.executeUpdate(
115  "delete from Worksheet " +
116  "where idContact = ? ",
117  new Object[] { idContact });
118  }
119 
120  public static void removeWorksheet(Long idIssue) {
121  Dao dao = new DossierPU();
122  dao.executeUpdate(
123  "delete from Worksheet " +
124  "where issue.id = ? ",
125  new Object[] { idIssue });
126  }
127 
128  public static Collection<String> getResponsibles() {
129  Dao dao = new DossierPU();
130  return dao.getResultList(
131  "select p.idContact from IssueParticipant as p " +
132  "where p.role = ? " +
133  "and p.issue.status <> ?",
135  }
136 
137  public static boolean cleared(Worksheet worksheet, IContact contact) {
138  Dao dao = new DossierPU();
139  if(isDone(worksheet, contact)) {
140  dao.deleteObject(worksheet);
141  return true;
142  }
143  return false;
144  }
145 
146  public static void clearDone(List<Worksheet> list, IContact contact) {
147  Dao dao = new DossierPU();
148  Iterator<Worksheet> it = list.iterator();
149  while(it.hasNext()) {
150  Worksheet worksheet = it.next();
151  if(isDone(worksheet, contact)) {
152  dao.deleteObject(worksheet);
153  it.remove();
154  }
155  }
156  }
157 
158  private static boolean isDone(Worksheet worksheet, IContact contact) {
159  IssueWrapper iw = new IssueWrapper(worksheet.getIssue(), contact);
160  return iw.getRelevanceOrderByContact() != 1;
161  }
162 
163  private WorksheetUtil() {
164  }
165 
166 }
java.util.List< IssueWrapper > getIssueList()
void setByParticipant(IContact byParticipant)
static void clearDone(List< Worksheet > list, IContact contact)
static void removeWorksheet(Long idIssue)
static Collection< Issue > getIssues(String idContact, String searchValue)
static boolean cleared(Worksheet worksheet, IContact contact)
static Collection< Worksheet > getWorksheet(String idContact)
static Collection< IssueWrapper > getNotIn(IContact contact, Collection< IssueWrapper > listws)
static List< IssueWrapper > getIssueWrappersForNow(IContact contact, String searchValue)
static void removeWorksheet(String idContact)
static Collection< String > getResponsibles()
static List< IssueWrapper > getIssueWrappers(IContact contact, String searchValue)
void deleteObject(Object obj)
Definition: Dao.java:162
int executeUpdate(String query)
Definition: Dao.java:463