2013-03-11 16:37:10 +01:00
|
|
|
package org.gcube.portlets.user.workspace.server.util;
|
|
|
|
|
2013-03-25 17:35:27 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
import org.apache.log4j.Logger;
|
2013-03-25 17:35:27 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
2013-03-11 16:37:10 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
2016-05-31 17:11:53 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
2016-07-14 10:28:22 +02:00
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
|
2016-09-14 12:54:24 +02:00
|
|
|
|
2015-11-17 18:14:16 +01:00
|
|
|
/**
|
|
|
|
* The Class UserUtil.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
2016-09-14 12:54:24 +02:00
|
|
|
* Sep 14, 2016
|
2015-11-17 18:14:16 +01:00
|
|
|
*/
|
2013-03-11 16:37:10 +01:00
|
|
|
public class UserUtil {
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
static UserManager um = new LiferayUserManager();
|
|
|
|
protected static Logger logger = Logger.getLogger(UserUtil.class);
|
|
|
|
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
/**
|
2015-11-17 18:14:16 +01:00
|
|
|
* Gets the user full name.
|
|
|
|
*
|
|
|
|
* @param portalLogin the portal login
|
|
|
|
* @return the user full name if is available, the input parameter portalLogin otherwise
|
2013-03-11 16:37:10 +01:00
|
|
|
*/
|
|
|
|
public static String getUserFullName(String portalLogin){
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-03 15:49:22 +02:00
|
|
|
if(portalLogin==null)
|
|
|
|
return "";
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2015-01-28 15:02:18 +01:00
|
|
|
if (WsUtil.isWithinPortal()) { //INTO PORTAL
|
2016-05-31 17:11:53 +02:00
|
|
|
|
|
|
|
GCubeUser curr = null;
|
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
try {
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2016-09-14 12:54:24 +02:00
|
|
|
curr = um.getUserByScreenName(portalLogin);
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2016-09-14 12:54:24 +02:00
|
|
|
} catch (UserManagementSystemException e) {
|
|
|
|
logger.error("UserManagementSystemException, during getting fullname for: "+portalLogin);
|
|
|
|
} catch (UserRetrievalFault e) {
|
|
|
|
logger.error("UserRetrievalFault, during getting fullname for: "+portalLogin);
|
2013-09-03 15:49:22 +02:00
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("An error occurred in getUserFullName "+e,e);
|
|
|
|
logger.warn("Return portal login "+portalLogin);
|
|
|
|
return portalLogin;
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2016-09-14 12:54:24 +02:00
|
|
|
if (curr != null)
|
2013-09-03 15:49:22 +02:00
|
|
|
return curr.getFullname();
|
2016-09-14 12:54:24 +02:00
|
|
|
|
2013-03-11 19:06:56 +01:00
|
|
|
}else{
|
2015-01-28 15:02:18 +01:00
|
|
|
logger.trace("DEVELOPEMENT MODE ON");
|
2015-11-17 18:34:35 +01:00
|
|
|
logger.trace("Returning input login: "+portalLogin);
|
|
|
|
return portalLogin;
|
2013-03-11 16:37:10 +01:00
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-10 18:47:49 +01:00
|
|
|
logger.trace("Return portal login as full name for: "+portalLogin);
|
|
|
|
return portalLogin;
|
2013-03-11 16:37:10 +01:00
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2015-11-17 18:14:16 +01:00
|
|
|
/**
|
|
|
|
* Gets the list login by info contact model.
|
|
|
|
*
|
|
|
|
* @param listContacts the list contacts
|
|
|
|
* @return the list login by info contact model
|
|
|
|
*/
|
2013-03-25 17:35:27 +01:00
|
|
|
public static List<String> getListLoginByInfoContactModel(List<InfoContactModel> listContacts){
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-03-25 17:35:27 +01:00
|
|
|
List<String> listUsers = new ArrayList<String>();
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-03-25 17:35:27 +01:00
|
|
|
for (InfoContactModel infoContactModel : listContacts) {
|
|
|
|
listUsers.add(infoContactModel.getLogin());
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-03-25 17:35:27 +01:00
|
|
|
return listUsers;
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2015-11-17 18:14:16 +01:00
|
|
|
/**
|
|
|
|
* Separate users names to comma.
|
|
|
|
*
|
|
|
|
* @param listContacts the list contacts
|
|
|
|
* @return the string
|
|
|
|
*/
|
2013-09-02 18:16:37 +02:00
|
|
|
public static String separateUsersNamesToComma(List<InfoContactModel> listContacts){
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
String users = "";
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
for (int i = 0; i < listContacts.size()-1; i++) {
|
|
|
|
users+= listContacts.get(i).getName() + ", ";
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
if(listContacts.size()>1)
|
|
|
|
users += listContacts.get(listContacts.size()-1).getName();
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
return users;
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
|
|
|
|
2015-11-17 18:14:16 +01:00
|
|
|
/**
|
|
|
|
* Separate full name to comma for portal login.
|
|
|
|
*
|
|
|
|
* @param listLogin the list login
|
|
|
|
* @return the string
|
|
|
|
*/
|
2013-09-02 18:16:37 +02:00
|
|
|
public static String separateFullNameToCommaForPortalLogin(List<String> listLogin){
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
String users = "";
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
logger.trace("SeparateFullNameToCommaForPortalLogin converting: "+listLogin);
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
//N-1 MEMBERS
|
2013-09-02 18:16:37 +02:00
|
|
|
for (int i = 0; i < listLogin.size()-1; i++) {
|
2016-07-04 14:15:31 +02:00
|
|
|
// logger.trace("Converting: "+i+") "+listLogin.get(i));
|
2013-09-02 18:16:37 +02:00
|
|
|
users+= getUserFullName(listLogin.get(i)) + ", ";
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
//LAST MEMBER
|
|
|
|
if(listLogin.size()>=1){
|
2016-07-04 14:15:31 +02:00
|
|
|
// logger.trace("Converting: "+(listLogin.size()-1)+") " +listLogin.get(listLogin.size()-1));
|
2013-09-02 18:16:37 +02:00
|
|
|
users += getUserFullName(listLogin.get(listLogin.size()-1));
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
logger.trace("SeparateFullNameToCommaForPortalLogin returning: "+users);
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2013-09-02 18:16:37 +02:00
|
|
|
return users;
|
|
|
|
}
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2015-11-17 18:14:16 +01:00
|
|
|
/**
|
|
|
|
* The main method.
|
|
|
|
*
|
|
|
|
* @param args the arguments
|
|
|
|
*/
|
2014-03-17 14:43:06 +01:00
|
|
|
public static void main(String[] args) {
|
|
|
|
List<String> login = new ArrayList<String>();
|
2016-07-04 14:15:31 +02:00
|
|
|
// login.add("ale");
|
|
|
|
// login.add("pepe");
|
2014-03-17 14:43:06 +01:00
|
|
|
System.out.println(separateFullNameToCommaForPortalLogin(login));
|
2016-05-31 17:11:53 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2016-07-04 14:15:31 +02:00
|
|
|
|
2013-03-11 16:37:10 +01:00
|
|
|
}
|