2014-02-25 15:58:42 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.workspacesharingwidget.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import org.gcube.common.homelibrary.home.User;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
|
2014-02-27 16:03:30 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USER_TYPE;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* @Feb 25, 2014
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class GWTWorkspaceSharingBuilder {
|
|
|
|
|
|
|
|
|
|
|
|
protected static Logger logger = Logger.getLogger(GWTWorkspaceSharingBuilder.class);
|
|
|
|
|
|
|
|
private InfoContactModel userLogged;
|
|
|
|
|
|
|
|
protected static HashMap<String, InfoContactModel> hashTestUser = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used in test mode
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static HashMap<String, InfoContactModel> getHashTestUsers(){
|
|
|
|
|
|
|
|
if(hashTestUser==null){
|
|
|
|
hashTestUser = new HashMap<String, InfoContactModel>();
|
|
|
|
hashTestUser.put("federico.defaveri", new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri"));
|
|
|
|
hashTestUser.put("antonio.gioia", new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia"));
|
|
|
|
hashTestUser.put("fabio.sinibaldi", new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi"));
|
|
|
|
hashTestUser.put("pasquale.pagano", new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano"));
|
|
|
|
hashTestUser.put(WsUtil.TEST_USER.toString(), new InfoContactModel(WsUtil.TEST_USER, WsUtil.TEST_USER, WsUtil.TEST_USER_FULL_NAME));
|
|
|
|
hashTestUser.put("francesco.mangiacrapa", new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa"));
|
|
|
|
hashTestUser.put("massimiliano.assante", new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return hashTestUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param infoContactModel
|
|
|
|
*/
|
|
|
|
public void setUserLogged(InfoContactModel infoContactModel) {
|
|
|
|
this.userLogged = infoContactModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param listUsers
|
|
|
|
* @return
|
|
|
|
* @throws InternalErrorException
|
|
|
|
*/
|
|
|
|
public List<InfoContactModel> buildGXTListContactsModel(List<UserModel> listUsers) throws InternalErrorException {
|
|
|
|
|
|
|
|
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
|
|
|
|
|
|
|
|
if(listUsers==null)
|
|
|
|
return listContactsModel;
|
|
|
|
|
|
|
|
logger.trace("List<UserModel> size returned from Portal VO is: "+ listUsers.size());
|
|
|
|
|
|
|
|
logger.trace("Building list contact model list user model");
|
|
|
|
for (UserModel userModel : listUsers) {
|
|
|
|
String fullName = userModel.getFullname();
|
|
|
|
|
|
|
|
if(fullName!=null && !fullName.isEmpty())
|
|
|
|
listContactsModel.add(new InfoContactModel(userModel.getUserId()+"", userModel.getScreenName(), fullName));
|
|
|
|
else
|
|
|
|
logger.trace("buildGXTListContactsModel doesn't return user: "+userModel.getScreenName()+ "because name is null or empty");
|
|
|
|
}
|
|
|
|
logger.trace("List contact model completed, return " +listContactsModel.size()+" contacts");
|
|
|
|
|
|
|
|
return listContactsModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param listPortalLogin
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<InfoContactModel> buildGxtInfoContactsFromPortalLogins(List<String> listPortalLogin){
|
|
|
|
|
|
|
|
List<InfoContactModel> listContact = new ArrayList<InfoContactModel>();
|
|
|
|
for (String portalLogin : listPortalLogin)
|
|
|
|
listContact.add(buildGxtInfoContactFromPortalLogin(portalLogin));
|
|
|
|
|
|
|
|
return listContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param portalLogin
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected InfoContactModel buildGxtInfoContactFromPortalLogin(String portalLogin){
|
|
|
|
|
|
|
|
if(portalLogin==null){
|
|
|
|
logger.warn("portal login is null, return empty");
|
|
|
|
portalLogin = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used in test mode
|
|
|
|
* @param listPortalLogin
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected List<InfoContactModel> buildGxtInfoContactFromPortalLoginTestMode(List<String> listPortalLogin){
|
|
|
|
|
|
|
|
List<InfoContactModel> listContact = new ArrayList<InfoContactModel>();
|
|
|
|
|
|
|
|
for (String portalLogin : listPortalLogin)
|
|
|
|
listContact.add(getHashTestUsers().get(portalLogin));
|
|
|
|
|
|
|
|
return listContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param user
|
|
|
|
* @return
|
|
|
|
* @throws InternalErrorException
|
|
|
|
*/
|
|
|
|
public InfoContactModel buildGXTInfoContactModel(User user) throws InternalErrorException{
|
|
|
|
|
|
|
|
if(user!=null)
|
|
|
|
return new InfoContactModel(user.getId(), user.getPortalLogin(), UserUtil.getUserFullName(user.getPortalLogin()));
|
|
|
|
|
|
|
|
return new InfoContactModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<WorkspaceACL> getWorkspaceACLFromACLs(List<ACLType> types) throws Exception{
|
|
|
|
|
|
|
|
List<WorkspaceACL> acls = new ArrayList<WorkspaceACL>();
|
|
|
|
|
|
|
|
for (ACLType acl : types) {
|
|
|
|
|
|
|
|
switch (acl) {
|
2014-02-27 16:03:30 +01:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
case ADMINISTRATOR:
|
2014-02-27 16:03:30 +01:00
|
|
|
acls.add(new WorkspaceACL(acl.toString(), ACL_TYPE.ADMINISTRATOR, "Admin", false, USER_TYPE.ADMINISTRATOR, ""));
|
2014-02-25 15:58:42 +01:00
|
|
|
break;
|
|
|
|
case READ_ONLY:
|
2014-02-27 16:03:30 +01:00
|
|
|
acls.add(new WorkspaceACL(acl.toString(), ACL_TYPE.READ_ONLY, "Read Only", false, USER_TYPE.OTHER, "Users can read any file but cannot update/delete"));
|
2014-02-25 15:58:42 +01:00
|
|
|
break;
|
|
|
|
case WRITE_OWNER:
|
2014-02-27 16:03:30 +01:00
|
|
|
acls.add(new WorkspaceACL(acl.toString(), ACL_TYPE.WRITE_OWNER, "Write Own", true, USER_TYPE.OTHER, "Users can update/delete only their files"));
|
2014-02-25 15:58:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WRITE_ALL:
|
2014-02-27 16:03:30 +01:00
|
|
|
acls.add(new WorkspaceACL(acl.toString(), ACL_TYPE.WRITE_ANY, "Write Any", false, USER_TYPE.OTHER,"Any user can update/delete any file"));
|
2014-02-25 15:58:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-02-27 16:03:30 +01:00
|
|
|
acls.add(new WorkspaceACL(acl.toString(), ACL_TYPE.WRITE_OWNER, acl.toString(), false, USER_TYPE.OTHER, ""));
|
2014-02-25 15:58:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(acls.size()==0)
|
|
|
|
throw new Exception("No ACLs rules found!");
|
|
|
|
|
|
|
|
return acls;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|