18 package org.turro.contacts;
20 import java.io.Serializable;
22 import java.util.stream.Collectors;
23 import javax.persistence.*;
24 import org.turro.string.Strings;
25 import org.turro.action.Contacts;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.contacts.mydata.MyDataList;
28 import org.turro.contacts.profile.Profile;
29 import org.turro.contacts.relation.Business;
30 import org.turro.contacts.relation.Workers;
31 import org.turro.contacts.util.ContactList;
32 import org.turro.contacts.util.DefaultContact;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.context.IConstructor;
35 import org.turro.elephant.security.IUser;
36 import org.turro.i18n.I_;
37 import org.turro.jpa.Dao;
38 import org.turro.jpa.embeddables.ComplexName;
39 import org.turro.jpa.entity.EntityCollections;
40 import org.turro.jpa.entity.IDaoEntity;
41 import org.turro.plugin.contacts.IContact;
42 import org.turro.reflection.MappingSet;
43 import org.turro.security.Permissions;
44 import org.turro.security.SecurityGroups;
45 import org.turro.tags.Tags;
48 @org.hibernate.annotations.GenericGenerator(name =
"hibernate-uuid", strategy =
"uuid")
50 @NamedQuery(name=
"contactByLogin", query=
"select c from Contact c where c.login = :login")
55 @GeneratedValue(generator =
"hibernate-uuid")
56 @Column(name=
"IDENTIFIER")
61 private
boolean onlyOwner;
62 private
boolean webapp;
63 private
boolean userMenu;
64 private
boolean deactivated;
65 private
boolean inactive;
76 private TimeZone timeZone;
77 private Locale locale;
78 private Currency currency;
79 private String grouping;
80 private String idActivity;
81 private
double billing;
84 private
double latitude, longitude;
87 private String globalIdentifier;
89 private String langTranslator;
90 private
boolean cloudAdmin;
92 @Column(unique=true,nullable=true)
93 private String emailAccount;
95 @OneToOne(cascade = CascadeType.ALL, orphanRemoval=true)
98 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
99 @OrderBy(value="description")
102 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
103 @OrderBy(value="description")
106 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
107 @OrderBy(value="description")
110 @OneToMany(mappedBy = "business", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
111 @OrderBy(value="description")
114 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
115 @OrderBy(value="name")
118 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
119 @OrderBy(value="modification")
122 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
125 @OneToMany(mappedBy = "contact", fetch = FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
128 public String getId() {
141 this.emailAccount = emailAccount;
153 if(complexName ==
null) complexName =
new ComplexName();
158 this.complexName = complexName;
178 this.onlyOwner = onlyOwner;
186 this.webapp = webapp;
194 this.userMenu = userMenu;
202 this.deactivated = deactivated;
210 this.inactive = inactive;
222 if(currency ==
null) {
229 this.currency = currency;
240 this.locale = locale;
268 return globalIdentifier;
272 this.globalIdentifier = globalIdentifier;
280 this.timeZone = timeZone;
288 this.grouping = grouping;
296 this.idActivity = idActivity;
304 this.billing = billing;
320 this.latitude = latitude;
328 this.longitude = longitude;
332 return langTranslator;
336 this.langTranslator = langTranslator;
344 this.cloudAdmin = cloudAdmin;
352 this.jobBoard = jobBoard;
357 if(!Strings.isBlank(
id) && dao.
isNotLoaded(addresses)) {
358 addresses = dao.lazyLoader(
Contact.class,
this,
"addresses").addresses;
364 this.addresses = addresses;
369 if(!Strings.isBlank(
id) && dao.
isNotLoaded(connectors)) {
370 connectors = dao.lazyLoader(
Contact.class,
this,
"connectors").connectors;
376 this.connectors = connectors;
381 if(!Strings.isBlank(
id) && dao.
isNotLoaded(businessRelations)) {
382 businessRelations = dao.lazyLoader(
Contact.class,
this,
"businessRelations").businessRelations;
384 return businessRelations;
388 this.businessRelations = businessRelations;
393 if(!Strings.isBlank(
id) && dao.
isNotLoaded(workerRelations)) {
394 workerRelations = dao.lazyLoader(
Contact.class,
this,
"workerRelations").workerRelations;
396 return workerRelations;
400 this.workerRelations = workerRelations;
405 if(!Strings.isBlank(
id) && dao.
isNotLoaded(syndications)) {
406 syndications = dao.lazyLoader(
Contact.class,
this,
"syndications").syndications;
412 this.syndications = syndications;
417 if(!Strings.isBlank(
id) && dao.
isNotLoaded(comments)) {
418 comments = dao.lazyLoader(
Contact.class,
this,
"comments").comments;
424 this.comments = comments;
429 if(!Strings.isBlank(
id) && dao.
isNotLoaded(fieldValues)) {
430 fieldValues = dao.lazyLoader(
Contact.class,
this,
"fieldValues").fieldValues;
436 this.fieldValues = fieldValues;
441 if(!Strings.isBlank(
id) && dao.
isNotLoaded(services)) {
442 services = dao.lazyLoader(
Contact.class,
this,
"services").services;
448 this.services = services;
460 return Strings.isBlank(name);
466 return getComplexName().getFriendly();
470 return getComplexName().getSerious();
484 return latitude != 0.0 && longitude != 0.0;
496 return Strings.isBlank(trade !=
null ? trade.
getValue() :
null, getName());
520 String comment =
null, lang = key +
I_.
api().used();
521 for(
Comment c : getComments()) {
522 if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
523 comment = c.getComment().substring(lang.length());
527 if(org.turro.string.Strings.isBlank(comment)) {
529 for(
Comment c : getComments()) {
530 if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
531 comment = c.getComment().substring(lang.length());
541 private transient HashMap<String, Object> attributes =
new HashMap<>();
545 Contact business = getBusiness();
546 return getName() + (business !=
null ?
" (" + business.
getName() +
")" :
"");
550 attributes.put(key, value);
554 return attributes.get(key);
558 if(_myData ==
null) {
574 return Tags.
getTags(
this).stream().map(tag -> tag.getTagName())
575 .collect(Collectors.joining(
", ",
"[",
"]"));
580 .map(synd -> synd.getName()).collect(Collectors.toSet())).stream()
581 .collect(Collectors.joining(
", ",
"[",
"]"));
585 return getSyndications().stream()
587 .collect(Collectors.joining(
", ",
"[",
"]"));
591 String result =
null;
593 result = locale !=
null ? locale.getDisplayName(currLocale) :
"";
594 result = !Strings.isBlank(result) ? result +
" " :
"";
595 result += currency !=
null ? currency.toString() :
"";
602 return login !=
null && login.length() > 0;
611 private transient Business _business;
612 private transient Workers _workers;
615 if(_business ==
null) {
622 if(_workers ==
null) {
633 return getBusinessSet().getBusinessList();
637 return getBusinessSet().getCoworkers();
645 return getWorkerSet().getWorkers();
649 return worker !=
null && (equals(worker) || getWorkers().contains(worker));
661 return ao !=
null ? ao.
getObject() :
null;
678 "select ao from AssociatedObject as ao " +
679 "where contact = ? and key = ?",
687 private transient Profile profile;
690 if(profile ==
null) {
697 if(profile ==
null) {
698 profile =
new Profile(
this,
true);
706 MappingSet
set =
new MappingSet();
707 set.addMapping(
Contact.class, 1,
708 new String[] {
"id",
"type",
"name",
"login",
"pass1",
"pass2",
709 "globalIdentifier",
"emailAccount",
"webapp",
"userMenu",
"deactivated" },
710 new String[] {
"addresses",
"connectors",
"businessRelations",
"jobBoard",
711 "locale",
"timeZone",
"currency",
"syndications",
"comments",
712 "fieldValues",
"services",
"grouping",
"idActivity",
"billing",
"staff" });
713 set.addMapping(
Address.class, 2,
714 new String[] {
"id",
"description" },
715 new String[] {
"street",
"zipCode",
"province",
"state",
"latitude",
"longitude" });
717 new String[] {
"id",
"description" },
718 new String[] {
"value" });
720 new String[] {
"id",
"description",
"preferential",
"strong",
"validated",
721 "startDate",
"endDate" },
722 new String[] {
"business",
"relationType" });
724 new String[] {
"id",
"name" },
726 set.addMapping(
Comment.class, 2,
727 new String[] {
"id",
"modification" },
728 new String[] {
"comment" });
730 new String[] {
"value", },
731 new String[] {
"fieldDef" });
733 new String[] {
"id",
"tabKey",
"labeyKey",
"tagDiscriminator" },
736 new String[] {
"title", },
737 new String[] {
"text",
"contact",
"responsible" });
738 set.addMapping(
Contact.class, 3,
739 new String[] {
"id",
"name" },
741 set.addMapping(Currency.class, 2,
742 new String[] {
"currencyCode" },
744 set.addMapping(TimeZone.class, 2,
745 new String[] {
"displayName" },
748 new String[] {
"zipCode",
"commuting",
"available",
"updateDate" },
756 hash = 31 * hash + Objects.hashCode(this.
id);
768 if (getClass() != obj.getClass()) {
772 if (!Objects.equals(
this.id, other.id)) {
static Currency getContactCurrency()
static byte[] encrypt(byte[] value)
static Locale getContactLocale()
static String get(String msg)
static I18nApiWrapper api()
Object getSingleResult(WhereClause wc)
boolean isNotLoaded(Object o, String attribute)
static EntityCollections entities(Collection values)
static Set< String > getRoleNames()
static SecurityGroup get(String id)
static final String CONNECTOR_EMAIL
static final String CONNECTOR_TRADE