fix for enhancement Ticket #2226
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/vre-deploy@83309 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cd71acca78
commit
e9540121af
|
@ -9,10 +9,12 @@ import java.io.IOException;
|
|||
import java.io.StringReader;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
@ -42,6 +44,13 @@ import org.gcube.portal.custom.communitymanager.components.GCUBESiteLayout;
|
|||
import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl;
|
||||
import org.gcube.portal.custom.communitymanager.types.GCUBELayoutType;
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.FeedType;
|
||||
import org.gcube.portal.databook.shared.PrivacyLevel;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||
import org.gcube.portlets.admin.vredeployer.client.VredeployerService;
|
||||
import org.gcube.portlets.admin.vredeployer.client.model.VREFunctionalityModel;
|
||||
import org.gcube.portlets.admin.vredeployer.shared.GHNMemory;
|
||||
|
@ -96,11 +105,15 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|||
import com.liferay.portal.NoSuchRoleException;
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.util.WebKeys;
|
||||
import com.liferay.portal.model.Company;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.Organization;
|
||||
import com.liferay.portal.model.Role;
|
||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||
import com.liferay.portal.service.RoleLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.theme.ThemeDisplay;
|
||||
|
||||
|
||||
|
||||
|
@ -112,6 +125,8 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(VREDeployerServiceImpl.class);
|
||||
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";
|
||||
|
||||
private static final int LIFERAY_REGULAR_ROLE_ID = 1;
|
||||
/**
|
||||
*
|
||||
|
@ -676,16 +691,20 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|||
if (report.getStatus() == Status.Finished) {
|
||||
log.info("--- Create VRE COMPLETED, CREATING LAYOUTS AND COMMUNITY ... ");
|
||||
String name = "";
|
||||
String description = "";
|
||||
try {
|
||||
name = vreGenerator.getVREModel().name();
|
||||
VREDescription de = vreGenerator.getVREModel();
|
||||
name = de.name();
|
||||
description = de.description();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String designer = (String) getASLSession().getAttribute(DESIGNER);
|
||||
String manager = (String) getASLSession().getAttribute(MANAGER);
|
||||
if (createCommunityAndLayout(name)) {
|
||||
log.info("--- CREATED LAYOUTS AND COMMUNITY --- OK, sending Message to designer.");
|
||||
try {
|
||||
String designer = (String) getASLSession().getAttribute(DESIGNER);
|
||||
String manager = (String) getASLSession().getAttribute(MANAGER);
|
||||
|
||||
UserManager um = new LiferayUserManager();
|
||||
UserModel userDesigner = um.getUserByScreenName(designer);
|
||||
UserModel userManager = um.getUserByScreenName(manager);
|
||||
|
@ -703,6 +722,9 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
log.info("--- Trying to share a news for this VRE");
|
||||
shareCreatedVRENews(designer, manager, name, description);
|
||||
|
||||
} else
|
||||
log.error("--- DANGER DANGER DANGER!!!!! -> CREATED LAYOUTS AND COMMUNITY WITH ERRORS");
|
||||
|
||||
|
@ -718,6 +740,105 @@ public class VREDeployerServiceImpl extends RemoteServiceServlet implements Vre
|
|||
return convertServiceDeployReport(report);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param designer
|
||||
* @param manager
|
||||
* @param name
|
||||
*/
|
||||
private void shareCreatedVRENews(String designer, String manager, String name, String description) {
|
||||
|
||||
String text = "A new Virtual Research Environment is worming up. " + name + " announced open day is tomorrow!";
|
||||
Date feedDate = new Date();
|
||||
|
||||
UserInfo managerInfo = null;
|
||||
try {
|
||||
managerInfo = getuserInfo(manager);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
String previewTitle = "The new VRE " + name + " will be available starting from tomorrow";
|
||||
Feed toShare = new Feed(UUID.randomUUID().toString(), FeedType.TWEET, managerInfo.getUsername(), feedDate,
|
||||
"", "/group/data-e-infrastructure-gateway/join-new", ORGANIZATION_DEFAULT_LOGO_URL, text,
|
||||
PrivacyLevel.VRES,
|
||||
managerInfo.getFullName(),
|
||||
managerInfo.getEmailaddress(),
|
||||
managerInfo.getAvatarId(),
|
||||
previewTitle,
|
||||
description, "d4science.org", false);
|
||||
|
||||
|
||||
DatabookStore store = new DBCassandraAstyanaxImpl();
|
||||
log.trace("Attempting to save Feed with text: " + text);
|
||||
boolean result = store.saveUserFeed(toShare);
|
||||
if (result) {
|
||||
for (GroupModel vre : getUserVREs(manager)) {
|
||||
String vreScope = getScopeByOrganizationId(vre.getGroupId());
|
||||
log.trace("Attempting to write onto " + vreScope);
|
||||
try {
|
||||
store.saveFeedToVRETimeline(toShare.getKey(), vreScope);
|
||||
} catch (FeedIDNotFoundException e) {
|
||||
log.error("Error writing onto VRES Time Line" + vreScope);
|
||||
} //save the feed
|
||||
log.trace("Success writing onto " + vreScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getScopeByOrganizationId(String vreid) {
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
try {
|
||||
return gm.getScope(vreid);
|
||||
} catch (Exception e) {
|
||||
log.error("Could not find a scope for this VREid: " + vreid);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private UserInfo getuserInfo(String username) throws PortalException, SystemException {
|
||||
log.debug("getuserInfo for " + username);
|
||||
String email = username+"@isti.cnr.it";
|
||||
String fullName = username+" FULL";
|
||||
String thumbnailURL = "images/Avatar_default.png";
|
||||
String accountURL = "";
|
||||
if (!isTesting) {
|
||||
getUserVREs(username);
|
||||
com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
|
||||
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
||||
fullName = user.getFirstName() + " " + user.getLastName();
|
||||
email = user.getEmailAddress();
|
||||
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
|
||||
accountURL = themeDisplay.getURLMyAccount().toString();
|
||||
}
|
||||
return new UserInfo(username, fullName, thumbnailURL, email, accountURL, true, false, null);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
private ArrayList<GroupModel> getUserVREs(String username) {
|
||||
log.debug("getUserVREs for " + username);
|
||||
ArrayList<GroupModel> toReturn = new ArrayList<GroupModel>();
|
||||
com.liferay.portal.model.User currUser;
|
||||
try {
|
||||
GroupManager gm = new LiferayGroupManager();
|
||||
currUser = OrganizationsUtil.validateUser(username);
|
||||
|
||||
for (Organization org : currUser.getOrganizations())
|
||||
if (gm.isVRE(org.getOrganizationId()+"")) {
|
||||
GroupModel toAdd = gm.getGroup(""+org.getOrganizationId());
|
||||
toReturn.add(toAdd);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed reading User VREs for : " + username);
|
||||
e.printStackTrace();
|
||||
return toReturn;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the html representation of the report
|
||||
|
|
Loading…
Reference in New Issue