diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..52f75c4 --- /dev/null +++ b/.classpath @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..dd7d610 --- /dev/null +++ b/.project @@ -0,0 +1,59 @@ + + + top-topics + trending-topics project + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + com.google.gdt.eclipse.core.webAppProjectValidator + + + + + com.google.gwt.eclipse.core.gwtProjectValidator + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + com.google.gwt.eclipse.core.gwtNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..ba3c245 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/.settings/com.google.appengine.eclipse.core.prefs b/.settings/com.google.appengine.eclipse.core.prefs new file mode 100644 index 0000000..a60576c --- /dev/null +++ b/.settings/com.google.appengine.eclipse.core.prefs @@ -0,0 +1,3 @@ +#Thu Jun 16 10:18:26 CEST 2011 +eclipse.preferences.version=1 +filesCopiedToWebInfLib= diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs new file mode 100644 index 0000000..f0782f7 --- /dev/null +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +jarsExcludedFromWebInfLib= +lastWarOutDir=/Users/massi/Documents/workspace/top-topics/target/top-topics-1.0.0-SNAPSHOT +warSrcDir=src/main/webapp +warSrcDirIsOutput=false diff --git a/.settings/com.google.gwt.eclipse.core.prefs b/.settings/com.google.gwt.eclipse.core.prefs new file mode 100644 index 0000000..c803c44 --- /dev/null +++ b/.settings/com.google.gwt.eclipse.core.prefs @@ -0,0 +1,5 @@ +#Thu Jun 16 11:14:17 CEST 2011 +eclipse.preferences.version=1 +entryPointModules= +filesCopiedToWebInfLib=gwt-servlet.jar +gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBWy13YXIgc3JjL21haW4vd2ViYXBwXV0+PC9leHRyYS1hcmdzPjx2bS1hcmdzPjwhW0NEQVRBWy1YbXg1MTJtXV0+PC92bS1hcmdzPjxlbnRyeS1wb2ludC1tb2R1bGU+Y29tLmNvbXBhbnkuU29tZU1vZHVsZTwvZW50cnktcG9pbnQtbW9kdWxlPjwvZ3d0LWNvbXBpbGUtc2V0dGluZ3M+ diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..443e085 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..01d0932 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..4045d87 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/.settings/org.maven.ide.eclipse.prefs b/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 0000000..dae95d4 --- /dev/null +++ b/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Thu Sep 02 10:42:12 CEST 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\\:testResources +skipCompilerPlugin=true +version=1 diff --git a/TrendingTopicsTest-dev.launch b/TrendingTopicsTest-dev.launch new file mode 100644 index 0000000..5b8d4cf --- /dev/null +++ b/TrendingTopicsTest-dev.launch @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/TrendingTopicsTest-prod.launch b/TrendingTopicsTest-prod.launch new file mode 100644 index 0000000..5f2b031 --- /dev/null +++ b/TrendingTopicsTest-prod.launch @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..139597f --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1,2 @@ + + diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..cdb5851 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,7 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. + diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..680cebb --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1,6 @@ +Mantainers +------- + +* Massimiliano Assante (massimiliano.assante@isti.cnr.it), CNR Pisa, + Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo". + diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..f5a71ff --- /dev/null +++ b/distro/README @@ -0,0 +1,35 @@ +The gCube System - Trending Topics Portlet +------------------------------------------------------------ + +This work is partially funded by the European Commission in the +context of the iMarine project (www.i-marine.eu), under the 1st call of FP7 IST priority. + +Authors +------- +Massimiliano Assante +* +Version and Release Date +------------------------ +Ovt 2014 + + +Description +----------- + + +Download information +-------------------- +Source code is available from SVN: +https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/trending-topics + +Binaries can be downloaded from: +http://software.d4science.research-infrastructures.eu/ + +Documentation +------------- +Documentation is available on-line from the Projects Documentation Wiki: + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..c2b4257 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + + First Release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..4efc827 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,48 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + target/apidocs + /${artifactId}/doc/api + true + 755 + + + + + ${distroDirectory}/profile.xml + ./ + true + + + target/${build.finalName}.war + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..ee9da4e --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Service + + gCube VRE Members Portlet + PortletUser + ${artifactId} + ${version} + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + target/${build.finalName}.war + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..edacb04 --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8d57ae0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,197 @@ + + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.portlets.user + top-topics + war + 1.0.0-SNAPSHOT + Top Topics Portlet + + Top Topics Portle shows the top 10 topics in the scope where is deployed. + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId} + + + + 2.5.1 + distro + + 1.7 + 1.7 + ${project.build.directory}/${project.build.finalName} + + UTF-8 + UTF-8 + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + + com.google.gwt + gwt-user + + + org.gcube.portlets.user + gcube-widgets + + + org.gcube.portal + custom-portal-handler + + + org.gcube.applicationsupportlayer + aslcore + + + org.gcube.portal + social-networking-library + + + org.gcube.dvos + usermanagement-core + + + com.google + gwt-jsonmaker + + + org.gcube.core + common-scope-maps + compile + + + com.liferay.portal + portal-service + provided + + + javax.portlet + portlet-api + provided + + + + + + ${webappDirectory}/WEB-INF/classes + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwtVersion} + + + + compile + + + + + + + MyVREs.html + ${webappDirectory} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + + compile + + exploded + + + + + ${webappDirectory} + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/topics/client/TopTopics.java b/src/main/java/org/gcube/portlets/user/topics/client/TopTopics.java new file mode 100644 index 0000000..84aa1f7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/client/TopTopics.java @@ -0,0 +1,17 @@ +package org.gcube.portlets.user.topics.client; + +import org.gcube.portlets.user.topics.client.panel.TopicsPanel; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.user.client.ui.RootPanel; +/** + * + * @author Massimiliano Assante, ISTI-CNR + * + */ +public class TopTopics implements EntryPoint { + + public void onModuleLoad() { + RootPanel.get("Trending-Topics-Container").add(new TopicsPanel()); + } +} diff --git a/src/main/java/org/gcube/portlets/user/topics/client/TopicService.java b/src/main/java/org/gcube/portlets/user/topics/client/TopicService.java new file mode 100644 index 0000000..994f82b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/client/TopicService.java @@ -0,0 +1,11 @@ +package org.gcube.portlets.user.topics.client; + +import org.gcube.portlets.user.topics.shared.HashtagsWrapper; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +@RemoteServiceRelativePath("topicservice") +public interface TopicService extends RemoteService { + HashtagsWrapper getHashtags(); +} diff --git a/src/main/java/org/gcube/portlets/user/topics/client/TopicServiceAsync.java b/src/main/java/org/gcube/portlets/user/topics/client/TopicServiceAsync.java new file mode 100644 index 0000000..38b92da --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/client/TopicServiceAsync.java @@ -0,0 +1,11 @@ +package org.gcube.portlets.user.topics.client; + +import org.gcube.portlets.user.topics.shared.HashtagsWrapper; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface TopicServiceAsync { + + void getHashtags(AsyncCallback callback); + +} diff --git a/src/main/java/org/gcube/portlets/user/topics/client/panel/TopicsPanel.java b/src/main/java/org/gcube/portlets/user/topics/client/panel/TopicsPanel.java new file mode 100644 index 0000000..db687c6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/client/panel/TopicsPanel.java @@ -0,0 +1,99 @@ +package org.gcube.portlets.user.topics.client.panel; + +import java.util.ArrayList; + +import org.gcube.portlets.user.topics.client.TopicService; +import org.gcube.portlets.user.topics.client.TopicServiceAsync; +import org.gcube.portlets.user.topics.shared.HashtagsWrapper; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasAlignment; +import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.VerticalPanel; +/** + * + * @author Massimiliano Assante, ISTI-CNR + * + */ +public class TopicsPanel extends Composite { + /** + * Create a remote service proxy to talk to the server-side Greeting service. + */ + private final TopicServiceAsync topicsService = GWT.create(TopicService.class); + + public static final String loading = GWT.getModuleBaseURL() + "../images/topics-loader.gif"; + public static final String DISPLAY_NAME = "Top Topics"; + + private Image loadingImage; + + private VerticalPanel mainPanel = new VerticalPanel(); + + public TopicsPanel() { + loadingImage = new Image(loading); + + initWidget(mainPanel); + showLoader(); + topicsService.getHashtags(new AsyncCallback() { + + @Override + public void onSuccess(HashtagsWrapper result) { + mainPanel.clear(); + mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); + mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); + + ArrayList hashtags = result.getHashtags(); + if (hashtags == null) { + showServError(); + } + else { + if (!result.isInfrastructure() && hashtags != null && !hashtags.isEmpty()) { + mainPanel.setStyleName("trending-frame"); + HTML name = new HTML(DISPLAY_NAME); + name.setStyleName("topic-title"); + mainPanel.add(name); + } + if (hashtags != null) { + for (String hashtag : hashtags) { + HTML toAdd = new HTML(hashtag); + toAdd.addStyleName("hashtag-label"); + mainPanel.add(toAdd); + } + } + } + } + + @Override + public void onFailure(Throwable caught) { + showConnError(); + } + }); + } + + private void showLoader() { + mainPanel.clear(); + mainPanel.setWidth("100%"); + mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); + mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + mainPanel.add(loadingImage); + } + + private void showConnError() { + mainPanel.clear(); + mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); + mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); + mainPanel.add(new HTML("
" + + "Sorry, looks like something is broken with the server connection
" + + "Please check your connection and try refresh this page.
")); + } + + private void showServError() { + mainPanel.clear(); + mainPanel.add(new HTML("
" + + "Sorry, we have problems in our servers ...
" + + "Please try in a while or report the issue.
")); + } +} diff --git a/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java new file mode 100644 index 0000000..e8267a7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/server/TopicServiceImpl.java @@ -0,0 +1,175 @@ +package org.gcube.portlets.user.topics.server; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; + +import org.apache.commons.codec.binary.Base64; +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.common.scope.impl.ScopeBean.Type; +import org.gcube.portal.custom.communitymanager.OrganizationsUtil; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portal.databook.client.GCubeSocialNetworking; +import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; +import org.gcube.portal.databook.server.DatabookStore; +import org.gcube.portlets.user.topics.client.TopicService; +import org.gcube.portlets.user.topics.shared.HashTagAndOccurrence; +import org.gcube.portlets.user.topics.shared.HashtagsWrapper; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.model.Organization; +import com.liferay.portal.model.User; +import com.liferay.portal.service.UserLocalServiceUtil; + +/** + * @author Massimiliano Assante, ISTI-CNR + */ +@SuppressWarnings("serial") +public class TopicServiceImpl extends RemoteServiceServlet implements TopicService { + private static final Logger _log = LoggerFactory.getLogger(TopicServiceImpl.class); + + public static final String TEST_USER = "test.user"; + /** + * The Cassandra store interface + */ + private DatabookStore store; + /** + * connect to cassandra at startup + */ + public void init() { + store = new DBCassandraAstyanaxImpl(); + } + + public void destroy() { + store.closeConnection(); + } + /** + * the current ASLSession + * @return the session + */ + private ASLSession getASLSession() { + String sessionID = this.getThreadLocalRequest().getSession().getId(); + String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); + if (user == null) { + _log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL"); + user = getDevelopmentUser(); + SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); + } + return SessionManager.getInstance().getASLSession(sessionID, user); + } + /** + * when packaging test will fail if the user is not set to test.user + * @return . + */ + public String getDevelopmentUser() { + String user = TEST_USER; + //user = "massimiliano.assante"; + return user; + } + /** + * + * @return true if you're running into the portal, false if in development + */ + private boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) { + _log.trace("Development Mode ON"); + return false; + } + } + /** + * return the top 10 hashtag with max occurrence + */ + @Override + public HashtagsWrapper getHashtags() { + ArrayList hashtagsChart = new ArrayList<>(); + ASLSession session = getASLSession(); + + String userName = session.getUsername(); + boolean isInfrastructure = isInfrastructureScope(); + try { + //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info) + //this check just return nothing if that happens + if (userName.compareTo("test.user") == 0) { + _log.debug("Found " + userName + " returning nothing"); + return null; + } + ArrayList toSort = new ArrayList(); + /** + * this handles the case where the portlet is deployed outside of VREs (regular) + */ + + if (isInfrastructure) { + _log.debug("****** retrieving hashtags for user VREs"); + User currUser = OrganizationsUtil.validateUser(userName); + GroupManager gm = new LiferayGroupManager(); + for (Organization org : currUser.getOrganizations()) { + if (gm.isVRE(org.getOrganizationId()+"")) { + String vreid = gm.getScope(""+org.getOrganizationId()); //get the scope + Map map = store.getVREHashtagsWithOccurrence(vreid); + for (String hashtag : map.keySet()) { + toSort.add(new HashTagAndOccurrence(hashtag, map.get(hashtag))); + } + } + } + } + //else must be in a VRE scope + else { + String scope = session.getScope(); + _log.debug("****** retrieving hashtags for scope " + scope); + Map map = store.getVREHashtagsWithOccurrence(scope); + for (String hashtag : map.keySet()) { + toSort.add(new HashTagAndOccurrence(hashtag, map.get(hashtag))); + } + } + + Collections.sort(toSort, Collections.reverseOrder()); + int i = 0; + for (HashTagAndOccurrence wrapper : toSort) { + String hashtag = wrapper.getHashtag(); + + String href="\"?"+ + new String(Base64.encodeBase64(GCubeSocialNetworking.HASHTAG_OID.getBytes()))+"="+ + new String(Base64.encodeBase64(hashtag.getBytes()))+"\""; + String hashtagLink = ""+hashtag+""; + hashtagsChart.add(hashtagLink); + i++; + if (i >= 10) + break; + } + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + return new HashtagsWrapper(isInfrastructure, hashtagsChart); + } + + + /** + * Indicates whether the scope is the whole infrastructure. + * @return true if it is, false otherwise. + */ + private boolean isInfrastructureScope() { + boolean toReturn = false; + try { + ScopeBean scope = new ScopeBean(getASLSession().getScope()); + toReturn = scope.is(Type.INFRASTRUCTURE); + return toReturn; + } + catch (NullPointerException e) { + _log.error("NullPointerException in isInfrastructureScope returning false"); + return false; + } + } + +} diff --git a/src/main/java/org/gcube/portlets/user/topics/server/portlet/TopicsPortlet.java b/src/main/java/org/gcube/portlets/user/topics/server/portlet/TopicsPortlet.java new file mode 100644 index 0000000..c648107 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/server/portlet/TopicsPortlet.java @@ -0,0 +1,26 @@ +package org.gcube.portlets.user.topics.server.portlet; + +import java.io.IOException; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.GenericPortlet; +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; + +public class TopicsPortlet extends GenericPortlet { + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); + ScopeHelper.setContext(request); + PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Topics_view.jsp"); + dispatcher.include(request, response); + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException { + } +} diff --git a/src/main/java/org/gcube/portlets/user/topics/shared/HashTagAndOccurrence.java b/src/main/java/org/gcube/portlets/user/topics/shared/HashTagAndOccurrence.java new file mode 100644 index 0000000..5315f7a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/shared/HashTagAndOccurrence.java @@ -0,0 +1,35 @@ +package org.gcube.portlets.user.topics.shared; + +public class HashTagAndOccurrence implements Comparable{ + private String hashtag; + private Integer occurrence; + public HashTagAndOccurrence(String hashtag, Integer occurrence) { + super(); + this.hashtag = hashtag; + this.occurrence = occurrence; + } + public String getHashtag() { + return hashtag; + } + public void setHashtag(String hashtag) { + this.hashtag = hashtag; + } + public Integer getOccurrence() { + return occurrence; + } + public void setOccurrence(Integer occurrence) { + this.occurrence = occurrence; + } + @Override + public String toString() { + return "HashTagAndOccurrence [hashtag=" + hashtag + ", occurrence=" + + occurrence + "]"; + } + @Override + public int compareTo(HashTagAndOccurrence o) { + if (this.occurrence == o.getOccurrence()) return 0; + return (this.occurrence > o.getOccurrence()) ? 1 : -1; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/topics/shared/HashtagsWrapper.java b/src/main/java/org/gcube/portlets/user/topics/shared/HashtagsWrapper.java new file mode 100644 index 0000000..63ed75f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/topics/shared/HashtagsWrapper.java @@ -0,0 +1,31 @@ +package org.gcube.portlets.user.topics.shared; + +import java.io.Serializable; +import java.util.ArrayList; + +public class HashtagsWrapper implements Serializable { + private boolean isInfrastructure; + private ArrayList hashtags; + public HashtagsWrapper(boolean isInfrastructure, ArrayList hashtags) { + super(); + this.isInfrastructure = isInfrastructure; + this.hashtags = hashtags; + } + public boolean isInfrastructure() { + return isInfrastructure; + } + public void setInfrastructure(boolean isInfrastructure) { + this.isInfrastructure = isInfrastructure; + } + public ArrayList getHashtags() { + return hashtags; + } + public void setHashtags(ArrayList hashtags) { + this.hashtags = hashtags; + } + public HashtagsWrapper() { + super(); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/resources/clientlog4j.properties b/src/main/resources/clientlog4j.properties new file mode 100644 index 0000000..4a2e1cd --- /dev/null +++ b/src/main/resources/clientlog4j.properties @@ -0,0 +1,12 @@ +log4j.rootLogger=DEBUG, A1 +log4j.appender.A1=org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout=org.apache.log4j.PatternLayout + +# Print the date in ISO 8601 format +log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +# Print only messages of level TRACE or above in the package org.gcube +log4j.logger.org.gcube=TRACE +log4j.logger.org.gcube.application.framework.core.session=INFO +log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR +log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR \ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml b/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml new file mode 100644 index 0000000..477a15c --- /dev/null +++ b/src/main/resources/org/gcube/portlets/user/topics/TopTopics.gwt.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/TopTopics.css b/src/main/webapp/TopTopics.css new file mode 100644 index 0000000..9cf9223 --- /dev/null +++ b/src/main/webapp/TopTopics.css @@ -0,0 +1,41 @@ +#Trending-Topics-Container { + margin-right: 20px; +} + +.topic-title { + display: block; + font-size: 16px; + color: #555; + font-weight: 400; + margin-bottom: 10px; +} + +.trending-frame { + margin: 0 0 10px; + padding: 10px; + margin: 0px 5px; + background-color: #FFF; + border-radius: 6px !important; + -moz-border-radius: 6px !important; + -webkit-border-radius: 6px !important; + border: 1px solid #DBDBDB; +} + +a.topiclink,a.topiclink:active,a.topiclink:visited { + font-family: 'Lucida Grande', Verdana, 'Bitstream Vera Sans', Arial, + sans-serif; + font-size: 15px; + cursor: pointer; + cursor: hand; + text-decoration: none; + color: #3B5998; +} + +a.topiclink:hover { + opacity: 0.8; + text-decoration: underline; +} + +.hashtag-label { + padding: 0 5px 1px; +} \ No newline at end of file diff --git a/src/main/webapp/TopTopics.html b/src/main/webapp/TopTopics.html new file mode 100644 index 0000000..f4b2ed1 --- /dev/null +++ b/src/main/webapp/TopTopics.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + +Trending Topics Project + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/jsp/Topics_view.jsp b/src/main/webapp/WEB-INF/jsp/Topics_view.jsp new file mode 100644 index 0000000..c8fd050 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/Topics_view.jsp @@ -0,0 +1,6 @@ +<%@page contentType="text/html"%> +<%@page pageEncoding="UTF-8"%> + + + + diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml new file mode 100644 index 0000000..869751a --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-display.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties new file mode 100644 index 0000000..b5e54b2 --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties @@ -0,0 +1,9 @@ +name=Topics +module-group-id=liferay +module-incremental-version=1 +tags= +short-description= +change-log= +page-url=http://www.d4science.org +author=D4Science.org +licenses=EUPL \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml new file mode 100644 index 0000000..c2546fd --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-portlet.xml @@ -0,0 +1,28 @@ + + + + + + Topics + false + false + false + /TrendingTopics.css + + + administrator + Administrator + + + guest + Guest + + + power-user + Power User + + + user + User + + diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml new file mode 100644 index 0000000..918ae16 --- /dev/null +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -0,0 +1,30 @@ + + + + + Topics + Top Topics + org.gcube.portlets.user.topics.server.portlet.TopicsPortlet + + view-jsp + /view.jsp + + 0 + + text/html + + + Top Topics + Top Topics + Top Topics + + + administrator + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..84454ed --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + + + + + topicsServlet + org.gcube.portlets.user.topics.server.TopicServiceImpl + + + + topicsServlet + /toptopics/topicservice + + + + + TrendingTopics.html + + + diff --git a/src/main/webapp/images/topics-loader.gif b/src/main/webapp/images/topics-loader.gif new file mode 100644 index 0000000..89ae681 Binary files /dev/null and b/src/main/webapp/images/topics-loader.gif differ diff --git a/src/test/java/org/gcube/portlets/user/topics/test/TestForDeploy.java b/src/test/java/org/gcube/portlets/user/topics/test/TestForDeploy.java new file mode 100644 index 0000000..9749c88 --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/topics/test/TestForDeploy.java @@ -0,0 +1,19 @@ +package org.gcube.portlets.user.topics.test; + +import static org.junit.Assert.*; + +import org.gcube.portlets.user.topics.server.TopicServiceImpl; +import org.junit.Test; + +public class TestForDeploy { + + @Test + public void testUserIsTestUser() { + TopicServiceImpl serviceImpl = new TopicServiceImpl(); + String username = serviceImpl.getDevelopmentUser(); + System.out.println("username for deploy is: " + username); + assertTrue(username.compareTo(TopicServiceImpl.TEST_USER) == 0); + System.out.println("Test OK!"); + } + +}