19 package org.turro.action;
21 import java.util.List;
22 import java.util.Optional;
23 import java.util.SortedMap;
24 import java.util.TreeMap;
25 import java.util.stream.Collectors;
26 import org.turro.mail.MailValidator;
27 import org.turro.string.Strings;
28 import org.turro.annotation.ElephantContact;
29 import org.turro.collections.KeyValueMap;
30 import org.turro.elephant.context.Application;
31 import org.turro.elephant.security.IUser;
32 import org.turro.lock.Initializer;
33 import org.turro.path.Path;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.reflection.ClassNames;
36 import org.turro.reflection.Reflections;
44 public final static String
46 BEHAVEAS_ICONTACT =
"behaveAsIContact";
48 public static boolean exists(String idContact) {
53 return contact !=
null && contact.
isValid();
57 for(Class javaClass :
instance().values()) {
59 if(contact !=
null)
return contact;
65 for(Class javaClass :
instance().values()) {
67 if(contact !=
null && contact.
accepts(
object))
return contact;
73 if(!Strings.isBlank(
id) &&
id.startsWith(
"/contact/")) {
74 id =
new Path(
id).getNode(1);
77 if(iContact !=
null && !Strings.isBlank(
id)) {
85 if(iContact !=
null) {
91 public static List<IContact>
getWebUsers(List<IContact> contacts) {
92 return contacts.stream().filter((contact) -> (contact.isWebUser())).collect(Collectors.toList());
100 if(Strings.isBlank(email) || email.contains(
"nomail"))
return false;
101 return MailValidator.single().silently(email);
105 return "nomail@nomail.no";
110 if(
object instanceof String) {
114 if(contact !=
null) {
124 if(contact !=
null) {
157 if(contact ==
null) {
165 if(iContact !=
null) {
171 return Optional.ofNullable(contact).filter(c -> c.isValid() && c.isCompany()).isPresent();
175 return Optional.ofNullable(contact).filter(c -> c.isValid() && c.isCenter()).isPresent();
179 return Optional.ofNullable(contact).filter(c -> c.isValid() && c.isWorker()).isPresent();
183 return Optional.ofNullable(contact).filter(c -> c.isValid() && c.isHHRR()).isPresent();
187 return Optional.ofNullable(contact).filter(c -> c.isValid() && c.isStudent()).isPresent();
192 private static final Initializer<SortedMap<Integer, Class>> INIT =
new Initializer<>();
194 public static SortedMap<Integer, Class>
instance() {
195 return INIT.instance(() -> getContactClasses());
202 private static SortedMap<Integer, Class> getContactClasses() {
203 SortedMap<Integer, Class> contactMap =
new TreeMap<>();
204 List<String> contactClasses = ClassNames.cached().byAnnotation(
ElephantContact.class.getName());
205 if(contactClasses !=
null) {
206 for(String contactClass : contactClasses) {
207 Class iContactClass = Reflections.check(contactClass);
208 if(iContactClass !=
null) {
IConstructor getConstructor()
HttpSession getHttpSession(boolean create)
static Application getApplication()
static final String CONNECTOR_EMAIL