diff --git a/src/main/java/org/gcube/portal/ldapexport/LDAPSync.java b/src/main/java/org/gcube/portal/ldapexport/LDAPSync.java index bf5c7df..f8e4352 100644 --- a/src/main/java/org/gcube/portal/ldapexport/LDAPSync.java +++ b/src/main/java/org/gcube/portal/ldapexport/LDAPSync.java @@ -1,5 +1,6 @@ package org.gcube.portal.ldapexport; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -52,7 +53,7 @@ public class LDAPSync implements Runnable { } _log.debug("Initializing LDAP exporter ..."); - + Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); @@ -73,7 +74,10 @@ public class LDAPSync implements Runnable { _log.error("Something went Wrong during LDAP Sync"); e.printStackTrace(); } - _log.info("LDAP Sync Completed OK!"); + if (! users.isEmpty()) + _log.info("LDAP Sync Completed OK!"); + else + _log.warn("LDAP Sync cycle skipped this time"); } @@ -89,7 +93,7 @@ public class LDAPSync implements Runnable { try { answer = ctx.search(getSubContext(username), filter, ctls); } catch (NamingException e) { - _log.info("user: " + username + " not found checkIfLDAPUserExists returning false"); + _log.info("user: " + username + " not found in LDAP, trying to export it"); return false; } return answer.hasMoreElements(); @@ -116,7 +120,7 @@ public class LDAPSync implements Runnable { Attribute sn = new BasicAttribute("sn"); Attribute mail = new BasicAttribute("mail"); Attribute userPassword = new BasicAttribute("userPassword"); - + givenName.add(name); cn.add(fullName); sn.add(lastName); @@ -139,11 +143,18 @@ public class LDAPSync implements Runnable { } } - private List getAllLiferayUsers() throws SystemException, PortalException { + private List getAllLiferayUsers() { String infraName = PortalContext.getConfiguration().getInfrastructureName(); _log.debug("Reading users belonging to: /" + infraName); - Organization rootInfra = OrganizationLocalServiceUtil.getOrganization(OrganizationsUtil.getCompany().getCompanyId(), infraName); - return UserLocalServiceUtil.getOrganizationUsers(rootInfra.getOrganizationId()); + List toReturn = new ArrayList(); + Organization rootInfra; + try { + rootInfra = OrganizationLocalServiceUtil.getOrganization(OrganizationsUtil.getCompany().getCompanyId(), infraName); + toReturn = UserLocalServiceUtil.getOrganizationUsers(rootInfra.getOrganizationId()); + } catch (PortalException | SystemException e) { + _log.error("Error during LDAP Sync, could not retrieve users from LR DB: " + e.getMessage()); + } + return toReturn; } } diff --git a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java index 8ec46d8..f163377 100644 --- a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java +++ b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java @@ -155,7 +155,7 @@ public class PeriodicTask implements Runnable { String feedId = extractFeedId(message); String commentText = extractText(portalName, feedId, message); - + _log.info("Extracted id: " + feedId + " text=" + commentText); String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText); Address[] froms = message.getFrom();