onModuleLoad()
.
+ *
+ * @author Costantino Perciante at ISTI-CNR
+ */
+public class Statistics implements EntryPoint {
+
+ /**
+ * This is the entry point method.
+ */
+ public void onModuleLoad() {
+ ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallbacktrue
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;
+ }
+ }
+
+ /**
+ * Online or in development mode?
+ * @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;
+ }
+ }
+
+ /**
+ * when packaging test will fail if the user is not set to test.user
+ * @return .
+ */
+ public String getDevelopmentUser() {
+ String user = userid;
+// user = "massimiliano.assante";
+ return user;
+ }
+
+
+ @Override
+ public String getTotalSpaceInUse() {
+
+ String storageInUse = null;
+
+ // get the session
+ ASLSession session = getASLSession();
+
+ //username
+ String userName = session.getUsername();
+
+ //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(userid) == 0) {
+
+ _log.debug("Found " + userName + " returning nothing");
+ return null;
+
+ }else{
+
+ _log.info("Getting " + userName + " amount of workspace in use.");
+
+ try{
+
+ long init = System.currentTimeMillis();
+
+ Workspace workspace = HomeLibrary.getUserWorkspace(userName);
+ long storage = workspace.getDiskUsage();
+ storageInUse = formatFileSize(storage);
+
+ long end = System.currentTimeMillis();
+ _log.info("[USER-STATISTICS] time taken to retrieve user space is " + (end - init) + "ms");
+
+ }catch(Exception e){
+
+ _log.error("Unable to retrieve workspace information!");
+
+ }
+ }
+ return storageInUse;
+
+ }
+
+ @Override
+ public int getProfileStrength() {
+
+ int profileStrenght = -1;
+
+ // get the session
+ ASLSession session = getASLSession();
+
+ //username
+ String userName = session.getUsername();
+
+ //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(userid) == 0) {
+ _log.debug("Found " + userName + " returning nothing");
+ return profileStrenght;
+ }else{
+
+ // valuate profile strength
+ if(isWithinPortal()){
+
+ try{
+
+ // check if the avatar is present
+ boolean avatarPresent = session.getUserAvatarId() != null;
+
+ long init = System.currentTimeMillis();
+
+ User user = OrganizationsUtil.validateUser(userName);
+ profileStrenght = evaluateProfileStrenght(user, avatarPresent);
+
+ long end = System.currentTimeMillis();
+ _log.info("[USER-STATISTICS] time taken to evaluate user profile strenght is " + (end - init) + "ms");
+
+ }catch(Exception e){
+
+ _log.error("Profile strenght evaluation failed!!");
+
+ }
+ }
+ }
+ return profileStrenght;
+
+ }
+
+ @Override
+ public UserInformation getUserSettings() {
+
+ // get the session
+ ASLSession session = getASLSession();
+
+ //username
+ String userName = session.getUsername();
+
+ //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(userid) == 0) {
+ _log.debug("Found " + userName + " returning nothing");
+ return null;
+ }
+
+ if(isWithinPortal()){
+ // If the user is in the root panel, we have to send him the overall number of posts made, comments/likes(received) and the space in use.
+ // Otherwise we have to filter on the vre.
+ boolean isInfrastructure = isInfrastructureScope();
+ _log.info("User scope is " + (isInfrastructure ? " the whole infrastucture " : " a VRE"));
+
+ // get path of the avatar
+ String thumbnailURL = session.getUserAvatarId();
+ _log.info(userName + " avatar has url " + thumbnailURL);
+
+ // get the vre (if not in the infrastructure)
+ String actualVre = null;
+
+ if(!isInfrastructure){
+
+ String[] temp = session.getScope().split("/");
+ actualVre = temp[temp.length - 1];
+
+ }
+
+ // url account to change the avatar
+ String accountURL = null;
+ ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
+ accountURL = themeDisplay.getURLMyAccount().toString();
+ _log.info("Account url for " + userName + " is " + accountURL);
+
+ return new UserInformation(isInfrastructure, thumbnailURL, userName, actualVre, accountURL);
+ }
+ else return new UserInformation(true, null, userName, null, null);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public PostsStatsBean getPostsStats(){
+
+ // get the session
+ ASLSession session = getASLSession();
+
+ //username
+ String userName = session.getUsername();
+
+ //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(userid) == 0) {
+ _log.debug("Found " + userName + " returning nothing");
+ return null;
+ }
+
+ long totalFeeds = 0, totalLikes = 0, totalComments = 0;
+
+ // check if the user is or not in a VRE
+ boolean isInfrastructure = isInfrastructureScope();
+
+ // date corresponding to one year ago
+ Date oneYearAgo = new Date();
+ oneYearAgo.setYear(oneYearAgo.getYear() - 1);
+
+ _log.info("Reference time is " + oneYearAgo.toString());
+
+ try {
+
+ long init = System.currentTimeMillis();
+ _log.info("Getting " + userName + " feeds in the last year.");
+
+ List