19 package org.turro.contacts.model;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.EnumSet;
24 import java.util.HashSet;
25 import java.util.List;
27 import java.util.stream.Collectors;
28 import org.turro.action.Plugins;
29 import org.turro.command.Context;
30 import org.turro.contacts.Contact;
31 import org.turro.contacts.ContactType;
32 import org.turro.contacts.content.DirectoryType;
33 import org.turro.contacts.db.ContactsPU;
34 import org.turro.contacts.form.ContactWrapper;
35 import org.turro.contacts.relation.FuzzyRelationTypes;
36 import org.turro.contacts.social.SocialGroupListbox;
37 import org.turro.contacts.social.SocialGroupValue;
38 import org.turro.contacts.util.ContactList;
39 import org.turro.contacts.zul.contact.ContactTypeListbox;
40 import org.turro.contacts.zul.menu.ContactMenu;
41 import org.turro.elephant.context.Application;
42 import org.turro.elephant.db.WhereClause;
43 import org.turro.elephant.util.Components;
44 import org.turro.elephant.zkoss.ModalWindow;
45 import org.turro.entities.IElephantEntity;
46 import org.turro.i18n.I_;
47 import org.turro.jpa.Dao;
48 import org.turro.menu.ElephantMenu;
49 import org.turro.plugin.IPlugin;
50 import org.turro.security.SecItem;
51 import org.turro.security.Secs;
52 import org.turro.security.SecurityGroups;
53 import org.turro.security.SocialGroups;
54 import org.turro.skills.tags.SkillItem;
55 import org.turro.skills.tags.SkillTags;
56 import org.turro.tags.TagItem;
57 import org.turro.tags.Tags;
58 import org.turro.zkoss.dialog.DialogField;
59 import org.turro.zkoss.dialog.Dialogs;
60 import org.turro.zul.frame.Framework;
61 import org.zkoss.bind.BindUtils;
62 import org.zkoss.bind.annotation.BindingParam;
63 import org.zkoss.bind.annotation.Command;
64 import org.zkoss.bind.annotation.NotifyChange;
65 import org.zkoss.zk.ui.Component;
66 import org.zkoss.zul.Button;
67 import org.zkoss.zul.ListModel;
68 import org.zkoss.zul.ListModelSet;
69 import org.zkoss.zul.Row;
77 private final boolean allContacts;
80 private Set<DirectoryType> typeSet;
81 private Set<SecItem> secSet;
82 private Set<TagItem> tagSet;
83 private Set<SkillItem> skillSet;
84 private String searchValue;
85 private boolean doNotLoad;
91 this.typeSet =
new HashSet<>(EnumSet.allOf(
DirectoryType.class));
92 this.secSet =
new HashSet<>();
93 this.tagSet =
new HashSet<>();
94 this.skillSet =
new HashSet<>();
102 .map(sg -> sg.getTags()).flatMap(Set::stream).collect(Collectors.toList()));
105 @NotifyChange(
"model")
107 public void sec(@BindingParam(
"selected") Set<SecItem> selected ) {
108 secSet =
new HashSet<>(selected);
111 @NotifyChange(
"model")
113 public void tag(@BindingParam(
"selected") Set<TagItem> selected ) {
114 tagSet =
new HashSet<>(selected);
117 @NotifyChange(
"model")
119 public void skill(@BindingParam(
"selected") Set<SkillItem> selected ) {
120 skillSet =
new HashSet<>(selected);
154 public void delete(@BindingParam(
"item")
ContactItem item, @BindingParam("ctrl") Component ctrl) {
157 public Object execute(Context context) {
158 ModalWindow mw = (ModalWindow) context.get(
"win");
159 if(mw.getResult() == 1) {
160 new ContactWrapper(item.getContact()).delete();
161 Row row = Components.from(ctrl).parent(Row.class);
162 if(row != null) row.detach();
169 @NotifyChange(
"model")
180 @NotifyChange(
"model")
189 @NotifyChange(
"model")
198 @NotifyChange(
"model")
211 ((
IPlugin) export).setData(
"export", contactsFromModel());
227 if(model !=
null && !model.
getSelected().isEmpty()) {
232 SocialGroupListbox sglb = new SocialGroupListbox();
233 sglb.setMultiple(true);
234 sglb.setCheckmark(true);
236 sglb.loadSocialGroups(true);
242 List<Contact> selection = model.
getSelected().stream().map(ci -> ci.getContact()).collect(Collectors.toList());
245 sgs.stream().map(sgv -> sgv.getKey()).collect(Collectors.toSet()),
248 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
258 if(model !=
null && !model.
getSelected().isEmpty()) {
263 SocialGroupListbox sglb = new SocialGroupListbox();
264 sglb.setMultiple(true);
265 sglb.setCheckmark(true);
267 sglb.loadSocialGroups(true);
273 List<Contact> selection = model.
getSelected().stream().map(ci -> ci.getContact()).collect(Collectors.toList());
276 sgs.stream().map(sgv -> sgv.getKey()).collect(Collectors.toSet()),
279 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
289 if(model !=
null && !model.
getSelected().isEmpty()) {
290 List<Contact> selection = model.
getSelected().stream().map(ci -> ci.getContact()).collect(Collectors.toList());
295 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
301 if(model !=
null && !model.
getSelected().isEmpty()) {
306 ContactTypeListbox ctl = new ContactTypeListbox();
307 ctl.setSelectFirst(false);
308 ctl.setCheckmark(true);
315 List<Contact> contacts = model.
getSelected().stream().map(ci -> ci.getContact())
316 .collect(Collectors.toList());
317 contacts.forEach(contact -> contact.setType(type));
318 getDao().saveCollection(contacts);
319 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
329 if(model !=
null && !model.
getSelected().isEmpty()) {
330 List<Contact> contacts = model.
getSelected().stream().map(ci -> ci.getContact())
331 .collect(Collectors.toList());
332 contacts.forEach(contact -> contact.setDeactivated(
false));
333 getDao().saveCollection(contacts);
334 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
340 if(model !=
null && !model.
getSelected().isEmpty()) {
341 List<Contact> contacts = model.
getSelected().stream().map(ci -> ci.getContact())
342 .collect(Collectors.toList());
343 contacts.forEach(contact -> contact.setDeactivated(
true));
344 getDao().saveCollection(contacts);
345 BindUtils.postNotifyChange(
null,
null,
ContactsVM.this,
"model");
349 @NotifyChange(
"model")
351 public
void update() {}
358 this.typeSet = typeSet;
366 this.searchValue = searchValue;
399 if(selected !=
null) {
403 if(typeSet.isEmpty())
return new ContactModel(getDao(), Collections.EMPTY_LIST);
405 wc.
addClause(
"select distinct contact.id from Contact contact");
406 wc.
addClause(
"left outer join contact.businessRelations relation");
407 wc.
addClause(
"left outer join contact.connectors connector");
408 wc.
addClause(
"left outer join contact.addresses address");
409 wc.
addClause(
"left outer join contact.syndications syndication");
410 wc.
addClause(
"left outer join contact.comments comment");
411 search.
apply(
"where", searchValue, wc, secSet.isEmpty() && tagSet.isEmpty() && skillSet.isEmpty());
416 wc.
addClause(sep +
"contact.type = :typeb");
421 wc.
addClause(sep +
"contact.type = :typec");
443 if(secSet !=
null && !secSet.isEmpty()) {
445 if(ids ==
null || ids.isEmpty()) {
448 wc.
addIn(
"and",
"contact.id", ids);
451 if(tagSet !=
null && !tagSet.isEmpty()) {
453 if(ids ==
null || ids.isEmpty()) {
456 wc.
addIn(
"and",
"contact.id", ids);
459 if(skillSet !=
null && !skillSet.isEmpty()) {
461 if(ids ==
null || ids.isEmpty()) {
464 wc.
addIn(
"and",
"contact.id", ids);
468 wc.
addIn(
"and",
"syndication.name",
472 model =
new ContactModel(getDao(), getDao().getResultList(wc));
481 private List contactsFromModel() {
485 list.
add(mi.getContact());
491 private List relationsFromModel() {
492 ContactList list =
new ContactList();
495 list.addAll(mi.getContact().getCoworkers(mi.getContact()));
505 private Dao getDao() {
507 _dao =
new ContactsPU();
static< T > T loadImplementation(Class< T > jclass)
boolean isInRole(String role)
static Application getApplication()
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
static String get(String msg)
static void removeSyndication(Dao dao, String syndication)
static List< String > getIdentifiers(Dao dao, Set< SecItem > sets)
static Collection< SecurityGroup > getAll()
static Collection< SecurityGroup > allowedSocialGroups()
static void unsyndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static void resyndicate(List< Contact > contacts, Dao dao)
static void checkInheritance(List< Contact > contacts, Dao dao)
static void syndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static DialogField field(String label)
Dialogs width(String width)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
static Dialogs title(String title)
Dialogs addField(DialogField field)
static FrameClipboard getClipboard()