19 package org.turro.alliance.client;
21 import java.time.Instant;
22 import java.util.Date;
23 import java.util.List;
25 import java.util.TreeSet;
26 import org.turro.alliance.db.entities.AxProjectGrant;
27 import org.turro.string.Strings;
28 import org.turro.time.Time;
29 import org.zkoss.bind.BindUtils;
30 import org.zkoss.zul.Checkbox;
40 private String search,
template;
42 private final Set<String> sources =
new TreeSet<>();
43 private final Set<String> tags =
new TreeSet<>();
45 private Boolean minimis,
46 subvention, loan, inKind,
48 micro, small, medium, big, otherOrgs,
49 hiring, idi, investment, startUp, formation,
50 active, endOfBudget, recurrent;
61 return Strings.isBlank(
template,
"items");
65 this.
template =
template;
66 BindUtils.postNotifyChange(vm,
"grants");
75 BindUtils.postNotifyChange(vm,
"grants");
79 return getTristate(minimis);
83 this.minimis = setTristate(minimis);
84 BindUtils.postNotifyChange(vm,
"grants");
88 return getTristate(subvention);
92 this.subvention = setTristate(subvention);
93 BindUtils.postNotifyChange(vm,
"grants");
97 return getTristate(loan);
101 this.loan = setTristate(loan);
102 BindUtils.postNotifyChange(vm,
"grants");
106 return getTristate(inKind);
110 this.inKind = setTristate(inKind);
111 BindUtils.postNotifyChange(vm,
"grants");
115 return getTristate(collaboration);
119 this.collaboration = setTristate(collaboration);
120 BindUtils.postNotifyChange(vm,
"grants");
124 return getTristate(micro);
128 this.micro = setTristate(micro);
129 BindUtils.postNotifyChange(vm,
"grants");
133 return getTristate(small);
137 this.small = setTristate(small);
138 BindUtils.postNotifyChange(vm,
"grants");
142 return getTristate(medium);
146 this.medium = setTristate(medium);
147 BindUtils.postNotifyChange(vm,
"grants");
151 return getTristate(big);
155 this.big = setTristate(big);
156 BindUtils.postNotifyChange(vm,
"grants");
160 return getTristate(otherOrgs);
164 this.otherOrgs = setTristate(otherOrgs);
165 BindUtils.postNotifyChange(vm,
"grants");
169 return getTristate(hiring);
173 this.hiring = setTristate(hiring);
174 BindUtils.postNotifyChange(vm,
"grants");
178 return getTristate(idi);
182 this.idi = setTristate(idi);
183 BindUtils.postNotifyChange(vm,
"grants");
187 return getTristate(investment);
191 this.investment = setTristate(investment);
192 BindUtils.postNotifyChange(vm,
"grants");
196 return getTristate(startUp);
200 this.startUp = setTristate(startUp);
201 BindUtils.postNotifyChange(vm,
"grants");
205 return getTristate(formation);
209 this.formation = setTristate(formation);
210 BindUtils.postNotifyChange(vm,
"grants");
214 return getTristate(active);
218 this.active = setTristate(active);
219 BindUtils.postNotifyChange(vm,
"grants");
223 return getTristate(endOfBudget);
227 this.endOfBudget = setTristate(endOfBudget);
228 BindUtils.postNotifyChange(vm,
"grants");
232 return getTristate(recurrent);
236 this.recurrent = setTristate(recurrent);
237 BindUtils.postNotifyChange(vm,
"grants");
249 sources.remove(value);
253 return sources.contains(value);
273 return tags.contains(value);
286 collaboration =
null;
304 public List<AxProjectGrant>
process(List<AxProjectGrant> grants, List<TagItem> itags) {
305 return grants.stream()
306 .filter(g -> fits(g, itags))
310 private boolean fits(
AxProjectGrant projectGrant, List<TagItem> itags) {
311 return (Strings.isBlank(search) || Strings.findsIgnoreCase(projectGrant.
getTitle(), search)) &&
312 (minimis ==
null || (minimis.equals(projectGrant.
isMinimis()))) &&
313 (subvention ==
null || subvention.equals(projectGrant.
isSubvention())) &&
314 (loan ==
null || loan.equals(projectGrant.
isLoan())) &&
315 (inKind ==
null || inKind.equals(projectGrant.
isInKind())) &&
316 (collaboration ==
null || collaboration.equals(projectGrant.
isCollaboration())) &&
317 (micro ==
null || micro.equals(projectGrant.
isMicro())) &&
318 (small ==
null || small.equals(projectGrant.
isSmall())) &&
319 (medium ==
null || medium.equals(projectGrant.
isMedium())) &&
320 (big ==
null || big.equals(projectGrant.
isBig())) &&
321 (otherOrgs ==
null || otherOrgs.equals(projectGrant.
isOtherOrgs())) &&
322 (hiring ==
null || hiring.equals(projectGrant.
isHiring())) &&
323 (idi ==
null || idi.equals(projectGrant.
isIdi())) &&
324 (investment ==
null || investment.equals(projectGrant.
isInvestment())) &&
325 (startUp ==
null || startUp.equals(projectGrant.
isStartUp())) &&
326 (formation ==
null || formation.equals(projectGrant.
isFormation())) &&
327 (endOfBudget ==
null || endOfBudget.equals(projectGrant.
isEndOfBudget())) &&
328 (recurrent ==
null || recurrent.equals(projectGrant.
isRecurrent())) &&
329 (active ==
null || active.equals(isActive(projectGrant.
getEndDate()))) &&
330 (sources.isEmpty() || sources.contains(projectGrant.
getSource())) &&
331 (tags.isEmpty() || itags.stream()
332 .filter(t -> t.id().equals(projectGrant.
getId()))
333 .anyMatch(t -> tags.contains(t.tag())));
337 private boolean isActive(Date value) {
338 return value ==
null || Time.from(value).isAfter(Instant.now());
341 private Checkbox.State getTristate(Boolean value) {
342 return value ==
null ? Checkbox.State.INDETERMINATE :
343 (value ? Checkbox.State.CHECKED : Checkbox.State.UNCHECKED);
346 private Boolean setTristate(Checkbox.State value) {
347 return switch(value) {
348 case CHECKED ->
true;
349 case UNCHECKED ->
false;
354 public record
TagItem(String tag, String
id) {};
Checkbox.State getHiring()
Set< String > getSources()
void setRecurrent(Checkbox.State recurrent)
void setMinimis(Checkbox.State minimis)
Checkbox.State getEndOfBudget()
Checkbox.State getRecurrent()
void setSmall(Checkbox.State small)
void setEndOfBudget(Checkbox.State endOfBudget)
void setVm(ProjectGrantVM vm)
boolean containsSource(String value)
void addTag(String value)
Checkbox.State getSmall()
void setSubvention(Checkbox.State subvention)
Checkbox.State getStartUp()
record TagItem(String tag, String id)
Checkbox.State getFormation()
void removeSource(String value)
void setStartUp(Checkbox.State startUp)
void setCollaboration(Checkbox.State collaboration)
void setBig(Checkbox.State big)
void setInKind(Checkbox.State inKind)
ProjectGrantFilter(ProjectGrantVM vm)
void setMicro(Checkbox.State micro)
Checkbox.State getMicro()
void setInvestment(Checkbox.State investment)
void setSearch(String search)
Checkbox.State getActive()
void setLoan(Checkbox.State loan)
List< AxProjectGrant > process(List< AxProjectGrant > grants, List< TagItem > itags)
void setFormation(Checkbox.State formation)
void setOtherOrgs(Checkbox.State otherOrgs)
Checkbox.State getSubvention()
Checkbox.State getOtherOrgs()
void setActive(Checkbox.State active)
void addSource(String value)
Checkbox.State getInvestment()
void setHiring(Checkbox.State hiring)
void removeTag(String value)
Checkbox.State getCollaboration()
boolean containsTag(String value)
Checkbox.State getMinimis()
Checkbox.State getInKind()
void setIdi(Checkbox.State idi)
void setMedium(Checkbox.State medium)
Checkbox.State getMedium()
void setTemplate(String template)
boolean isCollaboration()