Massimiliano Assante 2012-12-12 16:16:21 +00:00
parent e7e121addd
commit 5014089ac5
3 changed files with 39 additions and 40 deletions

View File

@ -4,13 +4,13 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServlet;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.XMLResult;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Application;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.FeedType;
@ -24,7 +24,7 @@ import org.gcube.portlets.user.homelibrary.home.data.application.ApplicationData
*
* use to share updates from within your application, the update will be published in the Users News Feed belonging to the VRE your application runs into
*/
public class AslNewsManager extends SocialPortalBridge implements NewsManager {
public class ApplicationNewsManager extends SocialPortalBridge implements NewsManager {
private Application application;
/**
@ -32,7 +32,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager {
* @param aslSession the ASLSession instance
* @param applicationClass your servlet class name will be used ad unique identifier for your application
*/
public AslNewsManager(ASLSession session, Class<?> applicationClass) {
public ApplicationNewsManager(ASLSession session, Class<? extends HttpServlet> applicationClass) {
super(session);
this.application = getProfileFromInfrastrucure(applicationClass);
}
@ -41,7 +41,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager {
* @param applicationClass
* @return the application profile
*/
private Application getProfileFromInfrastrucure(Class<?> applicationClass) {
private Application getProfileFromInfrastrucure(Class<? extends HttpServlet> applicationClass) {
try {
Application toReturn = new Application();
ISClient client = GHNContext.getImplementation(ISClient.class);
@ -97,46 +97,41 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager {
*/
@Override
public boolean shareApplicationUpdate(String description) {
String descToAdd = escapeHtml(description);
Feed toShare = new Feed(
UUID.randomUUID().toString(),
FeedType.PUBLISH,
application.getName(),
new Date(),
getScopeByOrganizationId(""+aslSession.getGroupId()),
"",
"",
descToAdd,
PrivacyLevel.SINGLE_VRE,
"fullName",
"email",
"thumbnailURL",
"linkTitle",
"linkDescription",
"linkHost");
return getStoreInstance().saveAppFeed(toShare);
return getStoreInstance().saveAppFeed(buildFeed(description, "", "", "", ""));
}
/**
* {@inheritDoc}
*/
@Override
public boolean shareApplicationUpdate(String description, String uri) {
return true;
return getStoreInstance().saveAppFeed(buildFeed(description, uri, "", "", ""));
}
/**
* {@inheritDoc}
*/
@Override
public boolean shareApplicationUpdate(String description, String uri, String previewTitle, String previewDescription, String previewThumbnailUrl) {
return true;
return getStoreInstance().saveAppFeed(buildFeed(description, uri, previewTitle, previewDescription, previewThumbnailUrl));
}
@Override
public DatabookStore connect() {
return new DBCassandraAstyanaxImpl();
private Feed buildFeed(String description, String uri, String previewTitle, String previewDescription, String previewThumbnailUrl) {
String descToAdd = escapeHtml(description);
Feed toReturn = new Feed(
UUID.randomUUID().toString(),
FeedType.PUBLISH,
application.getKey(),
new Date(),
getScopeByOrganizationId(""+aslSession.getGroupId()),
uri,
previewThumbnailUrl,
descToAdd,
PrivacyLevel.SINGLE_VRE,
application.getName(),
"no-email",
application.getImageUrl(),
previewTitle,
previewDescription,
"");
return toReturn;
}
}

View File

@ -1,6 +1,5 @@
package org.gcube.applicationsupportlayer.social;
import org.gcube.portal.databook.server.DatabookStore;
/**
@ -39,5 +38,4 @@ public interface NewsManager {
* @return true if the update is correctly delivered, false otherwise
*/
boolean shareApplicationUpdate(String description, String uri, String previewTitle, String previewDescription, String previewThumbnailUrl);
DatabookStore connect();
}

View File

@ -11,7 +11,7 @@ import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
* @author Massimiliano Assante, ISTI-CNR
* @version 0.1 Dec 2012
*
* use to notify users from within your application
* superclass for social portal bridge
*/
public abstract class SocialPortalBridge {
@ -19,11 +19,17 @@ public abstract class SocialPortalBridge {
protected ASLSession aslSession;
//unique instance
private static DatabookStore store;
/**
*
* @param session
*/
public SocialPortalBridge(ASLSession session) {
this.aslSession = session;
}
/**
*
* @return the unique instance of the store
*/
public static synchronized DatabookStore getStoreInstance() {
if (store == null) {
store = new DBCassandraAstyanaxImpl();
@ -31,7 +37,7 @@ public abstract class SocialPortalBridge {
return store;
}
String getScopeByOrganizationId(String vreid) {
protected String getScopeByOrganizationId(String vreid) {
GroupManager gm = new LiferayGroupManager();
try {
return gm.getScope(vreid);
@ -47,7 +53,7 @@ public abstract class SocialPortalBridge {
* @param html the html string to escape
* @return the escaped string
*/
String escapeHtml(String html) {
protected String escapeHtml(String html) {
if (html == null) {
return null;
}