better exceptions management

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-mail-servlet@117444 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/21689
Massimiliano Assante 9 years ago
parent ff629c7c2f
commit 43206e6229

@ -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<User> getAllLiferayUsers() throws SystemException, PortalException {
private List<User> 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<User> toReturn = new ArrayList<User>();
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;
}
}

@ -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();

Loading…
Cancel
Save