|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package org.gcube.portlets.admin.vredeployer.server;
|
|
|
|
|
|
|
|
|
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
|
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
|
|
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
|
|
|
|
|
|
|
@ -36,15 +37,16 @@ import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.usermanager.GCubeGroup;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.common.resources.gcore.GenericResource;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.Util;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
|
|
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
|
|
|
|
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
|
|
|
@ -77,6 +79,7 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemExcep
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityItem;
|
|
|
|
|
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHN;
|
|
|
|
@ -127,7 +130,7 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|
|
|
|
|
|
|
|
|
protected static final String ORGANIZATION_DEFAULT_LOGO = "/org/gcube/portal/custom/communitymanager/resources/default_logo.png";
|
|
|
|
|
protected static final String ORGANIZATION_DEFAULT_LOGO_URL = "http://ftp.d4science.org/apps/profiles/d4slogo.png";
|
|
|
|
|
|
|
|
|
|
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
@ -690,84 +693,45 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|
|
|
|
* @throws GroupRetrievalFault
|
|
|
|
|
* @throws UserManagementSystemException
|
|
|
|
|
*/
|
|
|
|
|
private void createVRESharedGroupFolder(org.gcube.vomanagement.usermanagement.model.GCubeGroup vreCreated, String designer, String manager, String description) throws Exception {
|
|
|
|
|
|
|
|
|
|
String currScope = ScopeProvider.instance.get();
|
|
|
|
|
ScopeProvider.instance.set("/"+getRootOrganizationName());
|
|
|
|
|
private void createVRESharedGroupFolder(UserManager uMan, org.gcube.vomanagement.usermanagement.model.GCubeGroup vreCreated, String designer, String manager, String description) throws Exception {
|
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
|
|
|
|
|
|
org.gcube.vomanagement.usermanagement.model.GCubeGroup group = vreCreated;
|
|
|
|
|
long groupId = group.getGroupId();
|
|
|
|
|
|
|
|
|
|
String vreName = group.getGroupName();
|
|
|
|
|
String vreScope = gm.getInfrastructureScope(groupId);
|
|
|
|
|
|
|
|
|
|
List<GCubeUser> users = um.listUsersByGroup(group.getGroupId());
|
|
|
|
|
String vreDesignerUserName = designer;
|
|
|
|
|
if (vreDesignerUserName != null) {
|
|
|
|
|
Workspace ws = HomeLibrary
|
|
|
|
|
.getHomeManagerFactory()
|
|
|
|
|
.getHomeManager()
|
|
|
|
|
.getHome(vreDesignerUserName)
|
|
|
|
|
.getWorkspace();
|
|
|
|
|
|
|
|
|
|
GCubeGroup gGroup = createGroup(vreScope, users);
|
|
|
|
|
String groupid = (gGroup == null) ? vreScope : gGroup.getName();
|
|
|
|
|
WorkspaceSharedFolder wSharedFolder =createVREFolder(vreScope, vreName, groupid, ws);
|
|
|
|
|
|
|
|
|
|
List<String> groups = new ArrayList<String>();
|
|
|
|
|
groups.add(gGroup.getName());
|
|
|
|
|
wSharedFolder.setACL(groups, ACLType.WRITE_OWNER);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
log.error("NO VRE-MANAGER FOUND IN THIS VRE");
|
|
|
|
|
String previousToken = SecurityTokenProvider.instance.get();
|
|
|
|
|
//get the super user
|
|
|
|
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
|
|
|
|
long groupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
|
|
|
|
RoleManager rm = new LiferayRoleManager();
|
|
|
|
|
long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
|
|
|
|
|
List<GCubeUser> users = uMan.listUsersByGroupAndRole(groupId, roleId);
|
|
|
|
|
if (users.isEmpty()) {
|
|
|
|
|
log.error("Cannot create the VRE Folder: there is no user having role {} on context {}", AUTORISED_INFRA_ROLE , infraContext);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ScopeProvider.instance.set(currScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* return the infrastructure name
|
|
|
|
|
*/
|
|
|
|
|
private static String getRootOrganizationName() {
|
|
|
|
|
return PortalContext.getConfiguration().getInfrastructureName();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param vreScope
|
|
|
|
|
* @param vreName
|
|
|
|
|
* @param groupId
|
|
|
|
|
* @param ws
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private static WorkspaceSharedFolder createVREFolder(String vreScope, String vreName, String groupId, Workspace ws) throws Exception {
|
|
|
|
|
|
|
|
|
|
WorkspaceSharedFolder folder = ws.createSharedFolder(vreScope, "Special Shared folder for VRE " + vreName, groupId, ws.getRoot().getId(), vreName, true);
|
|
|
|
|
System.out.println(folder.getPath());
|
|
|
|
|
return folder;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Create the group in HL and assign users to it
|
|
|
|
|
* @param vreScope the scope of the vre as name
|
|
|
|
|
* @param usersToAdd the listo of users to add
|
|
|
|
|
* @throws InternalErrorException
|
|
|
|
|
*/
|
|
|
|
|
private static GCubeGroup createGroup(String vreScope, List<GCubeUser> usersToAdd) throws InternalErrorException {
|
|
|
|
|
org.gcube.common.homelibrary.home.workspace.usermanager.UserManager gm = HomeLibrary
|
|
|
|
|
.getHomeManagerFactory().getUserManager();
|
|
|
|
|
GCubeGroup group = gm.createGroup(vreScope);
|
|
|
|
|
for (GCubeUser user : usersToAdd) {
|
|
|
|
|
group.addMember(user.getUsername());
|
|
|
|
|
else {
|
|
|
|
|
GCubeUser theAdmin = users.get(0);
|
|
|
|
|
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
|
|
|
|
|
List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
|
|
|
|
|
List<String> rolesString = new ArrayList<String>();
|
|
|
|
|
for (GCubeRole gCubeRole : theAdminRoles) {
|
|
|
|
|
rolesString.add(gCubeRole.getRoleName());
|
|
|
|
|
}
|
|
|
|
|
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
|
|
|
|
SecurityTokenProvider.instance.set(theAdminToken);
|
|
|
|
|
String newVreContext = gm.getInfrastructureScope(vreCreated.getGroupId());
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
String vreFolderName = Util.getVREGroupFromContext(newVreContext);
|
|
|
|
|
VREFolderManager vreFolderMaanger = shc.getVreFolderManager(vreFolderName);
|
|
|
|
|
vreFolderMaanger.createVRE(AccessType.WRITE_OWNER, designer);
|
|
|
|
|
vreFolderMaanger.setAdmin(designer);
|
|
|
|
|
if (designer.compareTo(manager) != 0) {
|
|
|
|
|
vreFolderMaanger.addUser(manager);
|
|
|
|
|
vreFolderMaanger.setAdmin(manager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("Created the VRE Folder on storageHub: {} ", vreFolderName);
|
|
|
|
|
|
|
|
|
|
SecurityTokenProvider.instance.set(previousToken);
|
|
|
|
|
}
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return the html representation of the report
|
|
|
|
@ -971,8 +935,8 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|
|
|
|
String currUser = session.getUsername();
|
|
|
|
|
log.info("***Username of who triggered the creation is: " + currUser);
|
|
|
|
|
|
|
|
|
|
log.info("Trying to create VRE Group Folder through HomeLibrary ...");
|
|
|
|
|
createVRESharedGroupFolder(vreCreated, designer, manager, description);
|
|
|
|
|
log.info("Trying to create VRE Group Folder through Storage Hub ...");
|
|
|
|
|
createVRESharedGroupFolder(uman, vreCreated, designer, manager, description);
|
|
|
|
|
|
|
|
|
|
log.info("--- createVRESharedGroupFolder OK, sending Message to designer.");
|
|
|
|
|
|
|
|
|
|