updating sharing..
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@69210 82a268e6-3cf1-43bd-a215-b396298e98cftask/19600
parent
7fa36d874d
commit
b9e0cca41f
@ -0,0 +1,143 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
|
||||
import com.liferay.portal.model.Organization;
|
||||
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||
|
||||
/**
|
||||
* @author "Federico De Faveri defaveri@isti.cnr.it"
|
||||
*
|
||||
*/
|
||||
public class FeedScheduler {
|
||||
|
||||
protected Timer scheduler;
|
||||
protected Map<GCUBEScope, NotificationsProducer> scheduledScopes;
|
||||
protected Logger logger = Logger.getLogger(FeedScheduler.class);
|
||||
|
||||
public FeedScheduler(long refreshTime)
|
||||
{
|
||||
scheduledScopes = new HashMap<GCUBEScope, NotificationsProducer>();
|
||||
scheduler = new Timer(true);
|
||||
scheduler.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkScopes();
|
||||
}
|
||||
}, 0, refreshTime);
|
||||
}
|
||||
|
||||
public void schedule() throws Exception
|
||||
{
|
||||
List<GCUBEScope> scopes = getAvailableScopes();
|
||||
for (GCUBEScope scope:scopes) {
|
||||
logger.trace("checking scope: "+scope);
|
||||
if (isServicePresentInScope(scope)) {
|
||||
logger.trace("service present");
|
||||
schedule(scope);
|
||||
} else logger.trace("service not present");
|
||||
}
|
||||
|
||||
checkScopes();
|
||||
}
|
||||
|
||||
protected void schedule(GCUBEScope scope)
|
||||
{
|
||||
// if (!scheduledScopes.containsKey(scope)) {
|
||||
// NotificationsProducer feeder = new NotificationsProducer(scope);
|
||||
// scheduledScopes.put(scope, feeder);
|
||||
// }
|
||||
}
|
||||
|
||||
protected void checkScopes()
|
||||
{
|
||||
for (NotificationsProducer feeder:scheduledScopes.values()) {
|
||||
try {
|
||||
// feeder.checkOperatorsForFeed();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isServicePresentInScope(GCUBEScope scope) throws Exception
|
||||
{
|
||||
ISClient isClient = GHNContext.getImplementation(ISClient.class);
|
||||
GCUBERIQuery query = isClient.getQuery(GCUBERIQuery.class);
|
||||
query.addAtomicConditions(new AtomicCondition("/Profile/ServiceName", "statistical-manager-gcubews"));
|
||||
query.addAtomicConditions(new AtomicCondition("/Profile/ServiceClass", "DataAnalysis"));
|
||||
|
||||
return isClient.execute(query, scope).size()>0;
|
||||
}
|
||||
|
||||
protected static List<GCUBEScope> getAvailableScopes() throws Exception
|
||||
{
|
||||
//FIXME for test only
|
||||
//return Arrays.asList(GCUBEScope.getScope("/gcube/devsec/devVRE"));
|
||||
|
||||
GHNContext ctx = GHNContext.getContext();
|
||||
String rootScopeName = (String) ctx.getProperty(GHNContext.INFRASTRUCTURE_NAME, true);
|
||||
GCUBEScope rootScope = GCUBEScope.getScope("/"+rootScopeName);
|
||||
List<GCUBEScope> scopes = findAvailableScopes(rootScope);
|
||||
return scopes;
|
||||
}
|
||||
|
||||
protected static List<GCUBEScope> findAvailableScopes(GCUBEScope infrastructure) throws Exception {
|
||||
|
||||
List<GCUBEScope> scopes = new ArrayList<GCUBEScope>();
|
||||
|
||||
//************* PORTAL MODE, Checking organizations
|
||||
scopes.add(infrastructure);
|
||||
|
||||
///************* GET ROOT ORGANIZATION
|
||||
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount());
|
||||
Organization rootOrganization = null;
|
||||
for (Organization organization : organizations) {
|
||||
if (organization.getName().equals(infrastructure.getName()) ) {
|
||||
rootOrganization = organization;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(rootOrganization==null) throw new Exception("Unable to find infrastructure scope "+infrastructure.getName()+" among organizations");
|
||||
//************** GET VO
|
||||
for (Organization vOrg : rootOrganization.getSuborganizations()){
|
||||
String VOScopeString="/"+vOrg.getParentOrganization().getName()+"/"+vOrg.getName();
|
||||
try{
|
||||
scopes.add(GCUBEScope.getScope(VOScopeString));
|
||||
for (Organization vre : vOrg.getSuborganizations()){
|
||||
String VREScopeString=VOScopeString+"/"+vre.getName();
|
||||
try{
|
||||
scopes.add(GCUBEScope.getScope(VREScopeString));
|
||||
}catch(Exception e){
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
}
|
||||
//************* GET VRE
|
||||
}
|
||||
|
||||
return scopes;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
|
||||
FeedScheduler scheduler = new FeedScheduler(1000);
|
||||
scheduler.schedule();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.server.util.Util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class NotificationsProducer {
|
||||
|
||||
protected Logger logger = Logger.getLogger(NotificationsProducer.class);
|
||||
protected GCUBEScope scope;
|
||||
|
||||
protected NotificationsManager notificationsMng;
|
||||
protected ASLSession aslSession;
|
||||
protected String userId;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param aslSession
|
||||
*/
|
||||
public NotificationsProducer(ASLSession aslSession) {
|
||||
this.notificationsMng = Util.getNotificationManager(aslSession);
|
||||
this.aslSession = aslSession;
|
||||
this.userId = aslSession.getUsername();
|
||||
}
|
||||
|
||||
public NotificationsManager getNotificationsMng() {
|
||||
return notificationsMng;
|
||||
}
|
||||
|
||||
public void setNotificationMng(NotificationsManager notificationMng) {
|
||||
this.notificationsMng = notificationMng;
|
||||
}
|
||||
|
||||
public ASLSession getAslSession() {
|
||||
return aslSession;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input
|
||||
* @param listContacts
|
||||
* @param sharedFolder
|
||||
*/
|
||||
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final WorkspaceFolder sharedFolder) {
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getId().compareTo(userId)!=0){
|
||||
logger.trace("Send notify folder sharing for user "+infoContactModel.getId());
|
||||
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getId(), sharedFolder);
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getId());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderSharing ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("share notifications is completed");
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input
|
||||
* @param listContacts
|
||||
* @param sharedFolder
|
||||
*/
|
||||
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceFolder sharedFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
printContacts(listContacts);
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getId().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Send notify folder un share user "+infoContactModel.getId());
|
||||
System.out.println("Send notify folder un share user "+infoContactModel.getId());
|
||||
|
||||
boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getId(), sharedFolder, userId);
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getId());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderSharing ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("un share notifications is completed");
|
||||
System.out.println("un share folder completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
private void printContacts(List<InfoContactModel> listContacts){
|
||||
|
||||
System.out.println("Print contacts");
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
System.out.println(infoContactModel);
|
||||
}
|
||||
System.out.println("End print contacts");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
String sessionID = "1";
|
||||
String user = "francesco.mangiacrapa";
|
||||
String scopeString = "/gcube/devsec/devVRE";
|
||||
String fullName = "Francesco Mangiacrapa";
|
||||
|
||||
GCUBEScope scope;
|
||||
ASLSession session;
|
||||
|
||||
session = SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
scope = GCUBEScope.getScope(scopeString);
|
||||
session.setScope(scope.toString());
|
||||
session.setUserAvatarId(user + "Avatar");
|
||||
session.setUserFullName(fullName);
|
||||
|
||||
|
||||
NotificationsProducer feeder = new NotificationsProducer(session);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue