19 package org.turro.contacts.content;
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Date;
26 import java.util.EnumSet;
27 import java.util.HashSet;
28 import java.util.List;
30 import java.util.stream.Collectors;
31 import org.turro.string.Strings;
32 import org.turro.attach.www.AttachCtrl;
33 import org.turro.collections.ExpressionSet;
34 import org.turro.contacts.Contact;
35 import org.turro.contacts.ContactType;
36 import org.turro.contacts.db.ContactsPU;
37 import org.turro.contacts.profile.ProfileContext;
38 import org.turro.contacts.relation.FuzzyRelationTypes;
39 import org.turro.elephant.context.ElephantContext;
40 import org.turro.elephant.context.IConstructor;
41 import org.turro.elephant.db.WhereClause;
42 import org.turro.elephant.impl.repository.Repository;
43 import org.turro.elephant.impl.repository.RepositoryFile;
44 import org.turro.elephant.security.IUser;
45 import org.turro.elephant.web.SocialImageMap;
46 import org.turro.elephant.web.SocialNet;
47 import org.turro.entities.Entities;
48 import org.turro.file.util.FileAttach;
49 import org.turro.indicator.Statistics;
50 import org.turro.jpa.content.EntityDaoContentIterator;
51 import org.turro.jpa.search.DaoHtmlSearch;
52 import org.turro.jpa.search.DaoSearchKey;
53 import org.turro.marker.ElephantMarker;
54 import org.turro.plugin.contacts.IContact;
55 import org.turro.polls.PollsCtrl;
56 import org.turro.skills.tags.SkillCloud;
57 import org.turro.skills.tags.SkillSet;
58 import org.turro.skills.tags.SkillTags;
59 import org.turro.www.commentit.CommentItCtrl;
60 import org.turro.www.describeit.DescribeItCtrl;
61 import org.turro.www.starit.StarItCtrl;
62 import org.turro.www.voteit.VoteItCtrl;
70 private Set<DirectoryType> types;
71 private ExpressionSet syndications;
72 private List<String> contactIds;
82 public void setTypes(Set<DirectoryType> types) {
87 String type[] = types.split(
"\\s*,\\s*");
88 Set<DirectoryType>
set =
new HashSet<>();
89 for(
int i = 0; i < type.length; i++) {
90 if(
"typed".equals(type[i])) {
92 }
else if(
"companies".equals(type[i])) {
94 }
else if(
"centers".equals(type[i])) {
96 }
else if(
"professionals".equals(type[i])) {
98 }
else if(
"educators".equals(type[i])) {
100 }
else if(
"students".equals(type[i])) {
102 }
else if(
"singletons".equals(type[i])) {
110 this.syndications =
new ExpressionSet(syndications);
114 if(!Strings.isBlank(syndications)) {
115 this.syndications =
new ExpressionSet(Strings.csvToList(syndications));
120 this.contactIds = contactIds;
134 wc.
addClause(
"select distinct contact from Contact contact");
135 wc.
addClause(
"left outer join contact.connectors connector on connector.description = :trade");
136 wc.
addClause(
"left outer join contact.businessRelations relation");
137 wc.
addClause(
"left outer join relation.business business");
138 wc.
addClause(
"left outer join business.connectors bconnector on bconnector.description = :trade");
140 if(syndications !=
null && !syndications.isEmpty()) {
141 wc.
addClause(
"left outer join contact.syndications syndication");
148 .setEntityFields(
"contact",
"id")
149 .setDefaultSorting(
"contact.name")
150 .onCriteria(w -> addCriteria(w))
157 wc.
addClause(
"select count(distinct contact) from Contact contact");
158 wc.
addClause(
"left outer join contact.connectors connector on connector.description = :trade");
159 wc.
addClause(
"left outer join contact.businessRelations relation");
160 wc.
addClause(
"left outer join relation.business business");
161 wc.
addClause(
"left outer join business.connectors bconnector on bconnector.description = :trade");
163 if(syndications !=
null && !syndications.isEmpty()) {
164 wc.
addClause(
"left outer join contact.syndications syndication");
174 prepareValues(e, page);
182 prepareValues(e, page);
194 wc.
addClause(
"select distinct contact from Contact contact");
195 wc.
addClause(
"left outer join contact.connectors connector on connector.description = :trade");
196 wc.
addClause(
"left outer join contact.businessRelations relation");
197 wc.
addClause(
"left outer join relation.business business");
198 wc.
addClause(
"left outer join business.connectors bconnector on bconnector.description = :trade");
200 if(syndications !=
null && !syndications.isEmpty()) {
201 wc.
addClause(
"left outer join contact.syndications syndication");
210 wc.
addClause(
"where contact.type <> :type");
211 wc.
addClause(
"and (business is null or business.type <> :type)");
219 "contact.name",
"business.name",
"connector.value",
"bconnector.value" }),
false);
223 if(types !=
null && !types.isEmpty()) {
225 Date now =
new Date();
228 FuzzyRelationTypes.isSingleton(wc,
"",
"contact",
"relation");
229 }
else if(isTyped()) {
230 FuzzyRelationTypes.isTyped(wc,
"",
"relation");
233 FuzzyRelationTypes.isJuridical(wc,
"",
"contact");
236 wc.
addClause(sep +
"contact.type = :ctype");
241 wc.
addClause(sep +
"contact.type = :ltype");
242 wc.
addNamedValue(
"ltype", ContactType.CONTACT_LEARNINGCENTER);
248 FuzzyRelationTypes.isNatural(wc,
"",
"relation");
249 wc.
addClause(
"and (relation.startDate is null or relation.startDate <= :now)");
250 wc.
addClause(
"and (relation.endDate is null or relation.endDate >= :now))");
256 FuzzyRelationTypes.isWorker(wc,
"",
"relation");
257 wc.
addClause(
"and (relation.startDate is null or relation.startDate <= :now)");
258 wc.
addClause(
"and (relation.endDate is null or relation.endDate >= :now))");
262 if(isProfessionals()) {
264 FuzzyRelationTypes.isProfessional(wc,
"",
"relation");
265 wc.
addClause(
"and (relation.startDate is null or relation.startDate <= :now)");
266 wc.
addClause(
"and (relation.endDate is null or relation.endDate >= :now))");
272 FuzzyRelationTypes.isEducator(wc,
"",
"relation");
273 wc.
addClause(
"and (relation.startDate is null or relation.startDate <= :now)");
274 wc.
addClause(
"and (relation.endDate is null or relation.endDate >= :now))");
281 FuzzyRelationTypes.isStudent(wc,
"",
"relation");
282 wc.
addClause(
"and (relation.startDate is null or relation.startDate <= :now)");
283 wc.
addClause(
"and (relation.endDate is null or relation.endDate >= :now))");
291 if(isOnlyStudents()) {
292 if(syndications ==
null) {
293 syndications =
new ExpressionSet(loadNegativesFrom(ProfileContext.getNetworkingRoles()));
295 syndications.addAll(loadNegativesFrom(ProfileContext.getNetworkingRoles()));
297 syndications.add(
"!brightside_admin");
299 if(syndications !=
null && !syndications.isEmpty()) {
300 if(syndications.hasPositives()) {
301 wc.
addIn(
"and",
"syndication.name", syndications.getPositives());
303 if(syndications.hasNegatives()) {
304 wc.
addClause(
"and not exists (select s from Syndication s");
305 wc.
addIn(
"where",
"s.name", syndications.getNegatives());
306 wc.
addClause(
"and s.contact = contact)");
309 if(contactIds !=
null && !contactIds.isEmpty()) {
310 wc.
addIn(
"and",
"contact.id", contactIds);
312 if(SkillCloud.hasSelected(
constructor,
"contact", isUserType())) {
313 wc.
addIn(
"and",
"contact.id", SkillCloud.getIdentifiers(
constructor,
"contact", isUserType()));
319 return super.isValid(e);
322 private void prepareValues(
final Contact e,
int page) {
329 if(!Strings.isBlank(e.
getName())) {
337 ArrayList<RepositoryFile> files =
new ArrayList<>();
352 return isMail() ?
"content/newsletter/sections/directory" :
"directory";
405 if(Strings.isBlank(path)) {
408 if(Strings.isBlank(path)) {
416 return "/user/profile";
421 private boolean isTyped() {
429 private boolean isJuridical() {
430 return types.contains(DirectoryType.DIRECTORY_COMPANIES) &&
431 types.contains(DirectoryType.DIRECTORY_CENTERS);
434 private boolean isNatural() {
435 return types.contains(DirectoryType.DIRECTORY_PROFESSIONALS) &&
436 types.contains(DirectoryType.DIRECTORY_EDUCATORS) &&
437 types.contains(DirectoryType.DIRECTORY_STUDENTS);
440 private boolean isCompanies() {
441 return types.contains(DirectoryType.DIRECTORY_COMPANIES);
444 private boolean isCenters() {
445 return types.contains(DirectoryType.DIRECTORY_CENTERS);
448 private boolean isWorkers() {
449 return types.contains(DirectoryType.DIRECTORY_PROFESSIONALS) &&
450 types.contains(DirectoryType.DIRECTORY_EDUCATORS);
453 private boolean isProfessionals() {
454 return types.contains(DirectoryType.DIRECTORY_PROFESSIONALS);
457 private boolean isEducators() {
458 return types.contains(DirectoryType.DIRECTORY_EDUCATORS);
461 private boolean isStudents() {
462 return types.contains(DirectoryType.DIRECTORY_STUDENTS);
465 private boolean isOnlyStudents() {
466 return EnumSet.of(DirectoryType.DIRECTORY_STUDENTS).equals(types);
469 private boolean isSingleton() {
470 return types.contains(DirectoryType.DIRECTORY_SINGLETONS);
473 private boolean canShowSkills() {
474 return isNatural() ^ isJuridical();
477 private boolean isUserType() {
478 return types ==
null || isNatural();
481 private List<String> loadNegativesFrom(String networkingRoles) {
482 return Strings.extractAll(networkingRoles,
"\\@([a-zA-Z0-9]+):on")
483 .stream().map(s ->
"!" + s).collect(Collectors.toList());
void renderItem(ElephantMarker marker, Contact e, int page)
Object doFilesCtrl(Contact e)
Object doVotesCtrl(Contact e)
WhereClause getCountClause()
DirectoryContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String contextPath)
Object doInterestCtrl(Contact e)
String getRestrictedLink()
void setContactIds(List< String > contactIds)
Set< DirectoryType > getTypes()
void setSyndications(List< String > syndications)
String getItemLink(Contact e)
WhereClause getWhereClause()
SkillSet getCloudSkills()
boolean isValid(Contact e)
void setSyndications(String syndications)
SkillSet getEntitySkills(Object entity)
void renderSummary(ElephantMarker marker, Contact e, int page)
Contact entity(String value)
Object doCommentsCtrl(Contact e)
Object doAttachmentsCtrl(Contact e)
Object doDescriptionsCtrl(Contact e)
void setTypes(String types)
Object doPollsCtrl(Contact e)
void setTypes(Set< DirectoryType > types)
Collection< String > metas(Contact e)
static String getContextVariable(IConstructor constructor)
static String getEntityWebContext(String path)
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
static IElephantEntity getController(String path)
Repository getPublishableRepository(IConstructor constructor)
static Statistics load(IConstructor constructor, String rankingInstance, String matchingInstance, WhereClause wc)
Object getSingleResultOrNull(SqlClause sc)
void prepareControls(E entity, int page)
String doItemLink(E entity, ID id, boolean obfuscated)
boolean isAllowMatching()
String getSummaryTemplate()
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static final String CONNECTOR_TRADE
Object configureCtrl(Object ctrl, IContact contact)