mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
ALF-9957 - MT: test and fix subscriptions (followers)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30999 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
fddcc01209
commit
4b6325059e
@ -87,6 +87,7 @@
|
|||||||
<property name="contentService" ref="ContentService"/>
|
<property name="contentService" ref="ContentService"/>
|
||||||
<property name="permissionService" ref="PermissionService"/>
|
<property name="permissionService" ref="PermissionService"/>
|
||||||
<property name="subscriptionService" ref="SubscriptionService"/>
|
<property name="subscriptionService" ref="SubscriptionService"/>
|
||||||
|
<property name="tenantService" ref="tenantService"/>
|
||||||
|
|
||||||
<property name="templateSearchPaths">
|
<property name="templateSearchPaths">
|
||||||
<list>
|
<list>
|
||||||
|
@ -118,7 +118,7 @@ public class ActivityPostServiceImpl implements ActivityPostService
|
|||||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||||
ParameterCheck.mandatory("typeQName", typeQName);
|
ParameterCheck.mandatory("typeQName", typeQName);
|
||||||
ParameterCheck.mandatory("parentNodeRef", parentNodeRef);
|
ParameterCheck.mandatory("parentNodeRef", parentNodeRef);
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append("{").append("\""+PostLookup.JSON_NODEREF_LOOKUP+"\":\"").append(nodeRef.toString()).append("\"").append(",")
|
sb.append("{").append("\""+PostLookup.JSON_NODEREF_LOOKUP+"\":\"").append(nodeRef.toString()).append("\"").append(",")
|
||||||
.append("\""+PostLookup.JSON_NAME+"\":\"").append(name).append("\"").append(",")
|
.append("\""+PostLookup.JSON_NAME+"\":\"").append(name).append("\"").append(",")
|
||||||
@ -171,31 +171,12 @@ public class ActivityPostServiceImpl implements ActivityPostService
|
|||||||
|
|
||||||
if (AuthenticationUtil.isMtEnabled())
|
if (AuthenticationUtil.isMtEnabled())
|
||||||
{
|
{
|
||||||
// MT share - required for canRead
|
// MT share - add tenantDomain
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JSONObject jo = new JSONObject(new JSONTokener(activityData));
|
JSONObject jo = new JSONObject(new JSONTokener(activityData));
|
||||||
|
jo.put(PostLookup.JSON_TENANT_DOMAIN, tenantService.getCurrentUserDomain());
|
||||||
boolean update = false;
|
activityData = jo.toString();
|
||||||
|
|
||||||
if (! jo.isNull(PostLookup.JSON_NODEREF))
|
|
||||||
{
|
|
||||||
String nodeRefStr = jo.getString(PostLookup.JSON_NODEREF);
|
|
||||||
jo.put(PostLookup.JSON_NODEREF, tenantService.getName(new NodeRef(nodeRefStr)));
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! jo.isNull(PostLookup.JSON_NODEREF_PARENT))
|
|
||||||
{
|
|
||||||
String nodeRefStr = jo.getString(PostLookup.JSON_NODEREF_PARENT);
|
|
||||||
jo.put(PostLookup.JSON_NODEREF_PARENT, tenantService.getName(new NodeRef(nodeRefStr)));
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update)
|
|
||||||
{
|
|
||||||
activityData = jo.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (JSONException e)
|
catch (JSONException e)
|
||||||
{
|
{
|
||||||
|
@ -38,11 +38,13 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.alfresco.repo.activities.post.lookup.PostLookup;
|
||||||
import org.alfresco.repo.domain.activities.ActivityFeedDAO;
|
import org.alfresco.repo.domain.activities.ActivityFeedDAO;
|
||||||
import org.alfresco.repo.domain.activities.ActivityFeedEntity;
|
import org.alfresco.repo.domain.activities.ActivityFeedEntity;
|
||||||
import org.alfresco.repo.domain.activities.ActivityPostEntity;
|
import org.alfresco.repo.domain.activities.ActivityPostEntity;
|
||||||
import org.alfresco.repo.domain.activities.FeedControlEntity;
|
import org.alfresco.repo.domain.activities.FeedControlEntity;
|
||||||
import org.alfresco.repo.template.ISO8601DateFormatMethod;
|
import org.alfresco.repo.template.ISO8601DateFormatMethod;
|
||||||
|
import org.alfresco.repo.tenant.TenantService;
|
||||||
import org.alfresco.util.JSONtoFmModel;
|
import org.alfresco.util.JSONtoFmModel;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -207,7 +209,27 @@ public abstract class FeedTaskProcessor
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String thisSite = (activityPost.getSiteNetwork() != null ? activityPost.getSiteNetwork() : "");
|
// note: for MT share, site id should already be mangled - in addition to extra tenant domain info
|
||||||
|
|
||||||
|
String thisSite = activityPost.getSiteNetwork();
|
||||||
|
String tenantDomain = (String)model.get(PostLookup.JSON_TENANT_DOMAIN);
|
||||||
|
|
||||||
|
if (thisSite != null)
|
||||||
|
{
|
||||||
|
if (tenantDomain != null)
|
||||||
|
{
|
||||||
|
thisSite = getTenantName(thisSite, tenantDomain);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// for backwards compatibility
|
||||||
|
tenantDomain = getTenantDomain(thisSite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tenantDomain == null)
|
||||||
|
{
|
||||||
|
tenantDomain = TenantService.DEFAULT_DOMAIN;
|
||||||
|
}
|
||||||
|
|
||||||
model.put(ActivityFeedEntity.KEY_ACTIVITY_FEED_TYPE, activityPost.getActivityType());
|
model.put(ActivityFeedEntity.KEY_ACTIVITY_FEED_TYPE, activityPost.getActivityType());
|
||||||
model.put(ActivityFeedEntity.KEY_ACTIVITY_FEED_SITE, thisSite);
|
model.put(ActivityFeedEntity.KEY_ACTIVITY_FEED_SITE, thisSite);
|
||||||
@ -230,7 +252,7 @@ public abstract class FeedTaskProcessor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Repository callback to get site members
|
// Repository callback to get site members
|
||||||
connectedUsers = getSiteMembers(ctx, thisSite);
|
connectedUsers = getSiteMembers(ctx, thisSite, tenantDomain);
|
||||||
connectedUsers.add(""); // add empty posting userid - to represent site feed !
|
connectedUsers.add(""); // add empty posting userid - to represent site feed !
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
@ -248,11 +270,15 @@ public abstract class FeedTaskProcessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add followers to recipient list
|
// Add followers to recipient list
|
||||||
Set<String> followerUsers = followers.get(activityPost.getUserId());
|
|
||||||
if(followerUsers == null) {
|
// MT Share - mangle key to be within context of tenant
|
||||||
|
String key = getTenantKey(activityPost.getUserId(), tenantDomain);
|
||||||
|
Set<String> followerUsers = followers.get(key);
|
||||||
|
if (followerUsers == null)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
followerUsers = getFollowers(activityPost.getUserId());
|
followerUsers = getFollowers(activityPost.getUserId(), tenantDomain);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@ -261,13 +287,13 @@ public abstract class FeedTaskProcessor
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
followers.put(activityPost.getUserId(), followerUsers);
|
followers.put(key, followerUsers);
|
||||||
}
|
}
|
||||||
recipients.addAll(followerUsers);
|
recipients.addAll(followerUsers);
|
||||||
|
|
||||||
// Add the originator to recipients
|
// Add the originator to recipients
|
||||||
recipients.add(activityPost.getUserId());
|
recipients.add(activityPost.getUserId());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
startTransaction();
|
startTransaction();
|
||||||
@ -472,9 +498,27 @@ public abstract class FeedTaskProcessor
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<String> getSiteMembers(RepoCtx ctx, String siteId) throws Exception
|
protected String getTenantName(String name, String tenantDomain)
|
||||||
{
|
{
|
||||||
|
// note: for MT impl, see override in LocalFeedTaskProcessor
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getTenantDomain(String name)
|
||||||
|
{
|
||||||
|
// note: for MT impl, see override in LocalFeedTaskProcessor
|
||||||
|
return TenantService.DEFAULT_DOMAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getTenantKey(String name, String tenantDomain)
|
||||||
|
{
|
||||||
|
return tenantDomain + "." + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Set<String> getSiteMembers(RepoCtx ctx, String siteId, String tenantDomain) throws Exception
|
||||||
|
{
|
||||||
|
// note: tenant domain ignored her - it should already be part of the siteId
|
||||||
Set<String> members = new HashSet<String>();
|
Set<String> members = new HashSet<String>();
|
||||||
if ((siteId != null) && (siteId.length() != 0))
|
if ((siteId != null) && (siteId.length() != 0))
|
||||||
{
|
{
|
||||||
@ -503,8 +547,9 @@ public abstract class FeedTaskProcessor
|
|||||||
|
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Set<String> getFollowers(String userId) throws Exception;
|
|
||||||
|
protected abstract Set<String> getFollowers(String userId, String tenantDomain) throws Exception;
|
||||||
|
|
||||||
protected boolean canRead(RepoCtx ctx, final String connectedUser, Map<String, Object> model) throws Exception
|
protected boolean canRead(RepoCtx ctx, final String connectedUser, Map<String, Object> model) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@ -26,6 +26,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.repo.activities.feed.FeedTaskProcessor;
|
import org.alfresco.repo.activities.feed.FeedTaskProcessor;
|
||||||
import org.alfresco.repo.activities.feed.RepoCtx;
|
import org.alfresco.repo.activities.feed.RepoCtx;
|
||||||
@ -38,6 +39,7 @@ import org.alfresco.repo.domain.activities.FeedControlDAO;
|
|||||||
import org.alfresco.repo.domain.activities.FeedControlEntity;
|
import org.alfresco.repo.domain.activities.FeedControlEntity;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.template.ClassPathRepoTemplateLoader;
|
import org.alfresco.repo.template.ClassPathRepoTemplateLoader;
|
||||||
|
import org.alfresco.repo.tenant.TenantService;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
@ -78,6 +80,7 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
private SubscriptionService subscriptionService;
|
private SubscriptionService subscriptionService;
|
||||||
|
private TenantService tenantService;
|
||||||
|
|
||||||
private String defaultEncoding;
|
private String defaultEncoding;
|
||||||
private List<String> templateSearchPaths;
|
private List<String> templateSearchPaths;
|
||||||
@ -123,6 +126,11 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
{
|
{
|
||||||
this.subscriptionService = subscriptionService;
|
this.subscriptionService = subscriptionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTenantService(TenantService tenantService)
|
||||||
|
{
|
||||||
|
this.tenantService = tenantService;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDefaultEncoding(String defaultEncoding)
|
public void setDefaultEncoding(String defaultEncoding)
|
||||||
{
|
{
|
||||||
@ -183,17 +191,54 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
{
|
{
|
||||||
return feedControlDAO.selectFeedControls(userId);
|
return feedControlDAO.selectFeedControls(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> getSiteMembers(final RepoCtx ctx, final String siteId) throws Exception
|
protected String getTenantName(String name, String tenantDomain)
|
||||||
|
{
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
String nameDomain = getTenantDomain(name);
|
||||||
|
if (nameDomain.equals(TenantService.DEFAULT_DOMAIN))
|
||||||
|
{
|
||||||
|
if (! TenantService.DEFAULT_DOMAIN.equals(tenantDomain))
|
||||||
|
{
|
||||||
|
// no domain, so add it as a prefix (between two domain separators)
|
||||||
|
name = TenantService.SEPARATOR + tenantDomain + TenantService.SEPARATOR + name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (! tenantDomain.equals(nameDomain))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("domain mismatch: expected = " + tenantDomain + ", actual = " + nameDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTenantDomain(String name)
|
||||||
|
{
|
||||||
|
return tenantService.getDomain(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<String> getSiteMembers(final RepoCtx ctx, String siteIdIn, final String tenantDomain) throws Exception
|
||||||
{
|
{
|
||||||
if (useRemoteCallbacks)
|
if (useRemoteCallbacks)
|
||||||
{
|
{
|
||||||
// as per 3.0, 3.1
|
// as per 3.0, 3.1
|
||||||
return super.getSiteMembers(ctx, siteId);
|
return super.getSiteMembers(ctx, siteIdIn, tenantDomain);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
final String siteId = tenantService.getBaseName(siteIdIn, true);
|
||||||
|
|
||||||
// optimise for non-remote implementation - override remote repo callback (to "List Site Memberships" web script) with embedded call
|
// optimise for non-remote implementation - override remote repo callback (to "List Site Memberships" web script) with embedded call
|
||||||
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Set<String>>()
|
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Set<String>>()
|
||||||
{
|
{
|
||||||
@ -203,7 +248,7 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
if ((siteId != null) && (siteId.length() != 0))
|
if ((siteId != null) && (siteId.length() != 0))
|
||||||
{
|
{
|
||||||
Map<String, String> mapResult = siteService.listMembers(siteId, null, null, 0, true);
|
Map<String, String> mapResult = siteService.listMembers(siteId, null, null, 0, true);
|
||||||
|
|
||||||
if ((mapResult != null) && (mapResult.size() != 0))
|
if ((mapResult != null) && (mapResult.size() != 0))
|
||||||
{
|
{
|
||||||
for (String userName : mapResult.keySet())
|
for (String userName : mapResult.keySet())
|
||||||
@ -216,10 +261,10 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
}, AuthenticationUtil.getSystemUserName());
|
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,26 +282,30 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
// if permission service not configured then fallback (ie. no read permission check)
|
// if permission service not configured then fallback (ie. no read permission check)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF);
|
String nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF);
|
||||||
if (nodeRefStr == null)
|
if (nodeRefStr == null)
|
||||||
{
|
{
|
||||||
nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF_PARENT);
|
nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF_PARENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeRefStr != null)
|
if (nodeRefStr != null)
|
||||||
{
|
{
|
||||||
final NodeRef nodeRef = new NodeRef(nodeRefStr);
|
final NodeRef nodeRef = new NodeRef(nodeRefStr);
|
||||||
|
|
||||||
|
// MT share
|
||||||
|
String tenantDomain = (String)model.get(PostLookup.JSON_TENANT_DOMAIN);
|
||||||
|
if (tenantDomain == null) { tenantDomain = TenantService.DEFAULT_DOMAIN; }
|
||||||
|
|
||||||
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>()
|
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>()
|
||||||
{
|
{
|
||||||
public Boolean doWork() throws Exception
|
public Boolean doWork() throws Exception
|
||||||
{
|
{
|
||||||
return canReadImpl(connectedUser, nodeRef);
|
return canReadImpl(connectedUser, nodeRef);
|
||||||
}
|
}
|
||||||
}, AuthenticationUtil.getSystemUserName());
|
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -431,7 +480,7 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
for (Resource resource : resources)
|
for (Resource resource : resources)
|
||||||
{
|
{
|
||||||
String resourcePath = resource.getURL().toExternalForm();
|
String resourcePath = resource.getURL().toExternalForm();
|
||||||
|
|
||||||
int idx = resourcePath.lastIndexOf(classPath);
|
int idx = resourcePath.lastIndexOf(classPath);
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
{
|
{
|
||||||
@ -446,21 +495,29 @@ public class LocalFeedTaskProcessor extends FeedTaskProcessor implements Applica
|
|||||||
}
|
}
|
||||||
return documentPaths;
|
return documentPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<String> getFollowers(String userId) throws Exception
|
protected Set<String> getFollowers(final String userId, String tenantDomain) throws Exception
|
||||||
{
|
{
|
||||||
Set<String> result = new HashSet<String>();
|
final Set<String> result = new HashSet<String>();
|
||||||
|
|
||||||
if (subscriptionService.isActive())
|
if (subscriptionService.isActive())
|
||||||
{
|
{
|
||||||
PagingFollowingResults fr = subscriptionService.getFollowers(userId, new PagingRequest(1000000, null));
|
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
|
||||||
|
|
||||||
if (fr.getPage() != null)
|
|
||||||
{
|
{
|
||||||
result.addAll(fr.getPage());
|
public Void doWork() throws Exception
|
||||||
}
|
{
|
||||||
|
PagingFollowingResults fr = subscriptionService.getFollowers(userId, new PagingRequest(1000000, null));
|
||||||
|
|
||||||
|
if (fr.getPage() != null)
|
||||||
|
{
|
||||||
|
result.addAll(fr.getPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@ -76,6 +76,8 @@ public class PostLookup
|
|||||||
public static final String JSON_PARENT_NODEREF = "parentNodeRef";
|
public static final String JSON_PARENT_NODEREF = "parentNodeRef";
|
||||||
public static final String JSON_DISPLAY_PATH = "displayPath";
|
public static final String JSON_DISPLAY_PATH = "displayPath";
|
||||||
|
|
||||||
|
public static final String JSON_TENANT_DOMAIN = "tenantDomain";
|
||||||
|
|
||||||
|
|
||||||
public void setPostDAO(ActivityPostDAO postDAO)
|
public void setPostDAO(ActivityPostDAO postDAO)
|
||||||
{
|
{
|
||||||
@ -149,100 +151,122 @@ public class PostLookup
|
|||||||
{
|
{
|
||||||
final String postUserId = activityPost.getUserId();
|
final String postUserId = activityPost.getUserId();
|
||||||
|
|
||||||
// MT share
|
try
|
||||||
String tenantDomain = tenantService.getUserDomain(postUserId);
|
|
||||||
|
|
||||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
|
||||||
{
|
{
|
||||||
public Object doWork() throws Exception
|
// MT share
|
||||||
|
String tenantDomain = TenantService.DEFAULT_DOMAIN;
|
||||||
|
|
||||||
|
final JSONObject jo = new JSONObject(new JSONTokener(activityPost.getActivityData()));
|
||||||
|
if (! jo.isNull(JSON_TENANT_DOMAIN))
|
||||||
{
|
{
|
||||||
try
|
tenantDomain = jo.getString(JSON_TENANT_DOMAIN);
|
||||||
{
|
|
||||||
postDAO.startTransaction();
|
|
||||||
|
|
||||||
JSONObject jo = new JSONObject(new JSONTokener(activityPost.getActivityData()));
|
|
||||||
|
|
||||||
String activityDataStr = null;
|
|
||||||
|
|
||||||
if (! jo.isNull(JSON_NODEREF_LOOKUP))
|
|
||||||
{
|
|
||||||
String nodeRefStr = jo.getString(JSON_NODEREF_LOOKUP);
|
|
||||||
NodeRef nodeRef = new NodeRef(nodeRefStr);
|
|
||||||
|
|
||||||
// lookup additional node data
|
|
||||||
JSONObject activityData = lookupNode(nodeRef, postUserId, jo);
|
|
||||||
activityDataStr = activityData.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// lookup additional person data
|
|
||||||
Pair<String, String> firstLastName = lookupPerson(postUserId);
|
|
||||||
if (firstLastName != null)
|
|
||||||
{
|
|
||||||
jo.put(JSON_FIRSTNAME, firstLastName.getFirst());
|
|
||||||
jo.put(JSON_LASTNAME, firstLastName.getSecond());
|
|
||||||
|
|
||||||
activityDataStr = jo.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activityDataStr != null)
|
|
||||||
{
|
|
||||||
activityPost.setActivityData(activityDataStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((activityPost.getActivityData() != null) && (activityPost.getActivityData().length() > ActivityPostDAO.MAX_LEN_ACTIVITY_DATA))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Invalid activity data - exceeds " + ActivityPostDAO.MAX_LEN_ACTIVITY_DATA + " chars: " + activityPost.getActivityData());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((activityPost.getSiteNetwork() != null) && (activityPost.getSiteNetwork().length() > ActivityPostDAO.MAX_LEN_SITE_ID))
|
|
||||||
{
|
|
||||||
// belts-and-braces - should not get here since checked during post (and not modified)
|
|
||||||
throw new IllegalArgumentException("Invalid siteId - exceeds " + ActivityPostDAO.MAX_LEN_SITE_ID + " chars: " + activityPost.getSiteNetwork());
|
|
||||||
}
|
|
||||||
|
|
||||||
activityPost.setLastModified(new Date());
|
|
||||||
|
|
||||||
postDAO.updatePost(activityPost.getId(), activityPost.getSiteNetwork(), activityPost.getActivityData(), ActivityPostEntity.STATUS.POSTED);
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
activityPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString()); // for debug output
|
|
||||||
logger.debug("Updated: " + activityPost);
|
|
||||||
}
|
|
||||||
|
|
||||||
postDAO.commitTransaction();
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e)
|
|
||||||
{
|
|
||||||
// log error, but consume exception (skip this post)
|
|
||||||
logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
|
|
||||||
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
|
|
||||||
|
|
||||||
postDAO.commitTransaction();
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
// log error, but consume exception (skip this post)
|
|
||||||
logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
|
|
||||||
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
|
|
||||||
|
|
||||||
postDAO.commitTransaction();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
logger.error("Exception during update of post", e);
|
|
||||||
throw new JobExecutionException(e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
postDAO.endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||||
|
{
|
||||||
|
public Object doWork() throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
postDAO.startTransaction();
|
||||||
|
|
||||||
|
String activityDataStr = null;
|
||||||
|
|
||||||
|
if (! jo.isNull(JSON_NODEREF_LOOKUP))
|
||||||
|
{
|
||||||
|
String nodeRefStr = jo.getString(JSON_NODEREF_LOOKUP);
|
||||||
|
NodeRef nodeRef = new NodeRef(nodeRefStr);
|
||||||
|
|
||||||
|
// lookup additional node data
|
||||||
|
JSONObject activityData = lookupNode(nodeRef, postUserId, jo);
|
||||||
|
activityDataStr = activityData.toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// lookup additional person data
|
||||||
|
Pair<String, String> firstLastName = lookupPerson(postUserId);
|
||||||
|
if (firstLastName != null)
|
||||||
|
{
|
||||||
|
jo.put(JSON_FIRSTNAME, firstLastName.getFirst());
|
||||||
|
jo.put(JSON_LASTNAME, firstLastName.getSecond());
|
||||||
|
|
||||||
|
activityDataStr = jo.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activityDataStr != null)
|
||||||
|
{
|
||||||
|
activityPost.setActivityData(activityDataStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((activityPost.getActivityData() != null) && (activityPost.getActivityData().length() > ActivityPostDAO.MAX_LEN_ACTIVITY_DATA))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid activity data - exceeds " + ActivityPostDAO.MAX_LEN_ACTIVITY_DATA + " chars: " + activityPost.getActivityData());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((activityPost.getSiteNetwork() != null) && (activityPost.getSiteNetwork().length() > ActivityPostDAO.MAX_LEN_SITE_ID))
|
||||||
|
{
|
||||||
|
// belts-and-braces - should not get here since checked during post (and not modified)
|
||||||
|
throw new IllegalArgumentException("Invalid siteId - exceeds " + ActivityPostDAO.MAX_LEN_SITE_ID + " chars: " + activityPost.getSiteNetwork());
|
||||||
|
}
|
||||||
|
|
||||||
|
activityPost.setLastModified(new Date());
|
||||||
|
|
||||||
|
postDAO.updatePost(activityPost.getId(), activityPost.getSiteNetwork(), activityPost.getActivityData(), ActivityPostEntity.STATUS.POSTED);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
activityPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString()); // for debug output
|
||||||
|
logger.debug("Updated: " + activityPost);
|
||||||
|
}
|
||||||
|
|
||||||
|
postDAO.commitTransaction();
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
// log error, but consume exception (skip this post)
|
||||||
|
logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
|
||||||
|
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
|
||||||
|
|
||||||
|
postDAO.commitTransaction();
|
||||||
|
}
|
||||||
|
catch (JSONException e)
|
||||||
|
{
|
||||||
|
// log error, but consume exception (skip this post)
|
||||||
|
logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
|
||||||
|
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
|
||||||
|
|
||||||
|
postDAO.commitTransaction();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
logger.error("Exception during update of post", e);
|
||||||
|
throw new JobExecutionException(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
postDAO.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
||||||
|
}
|
||||||
|
catch (JSONException e)
|
||||||
|
{
|
||||||
|
// log error, but consume exception (skip this post)
|
||||||
|
logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
|
||||||
|
postDAO.commitTransaction();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
postDAO.endTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.tenant;
|
package org.alfresco.repo.tenant;
|
||||||
@ -538,7 +538,7 @@ public class MultiTServiceImpl implements TenantService
|
|||||||
*/
|
*/
|
||||||
public boolean isTenantName(String name)
|
public boolean isTenantName(String name)
|
||||||
{
|
{
|
||||||
return false == getDomain(name, false).isEmpty();
|
return (! TenantService.DEFAULT_DOMAIN.equals(getDomain(name, false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -576,10 +576,10 @@ public class MultiTServiceImpl implements TenantService
|
|||||||
*/
|
*/
|
||||||
public String getDomain(String name)
|
public String getDomain(String name)
|
||||||
{
|
{
|
||||||
return getDomain(name, false);
|
return getDomain(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDomain(String name, boolean checkCurrentDomain)
|
public String getDomain(String name, boolean checkCurrentDomain)
|
||||||
{
|
{
|
||||||
ParameterCheck.mandatory("name", name);
|
ParameterCheck.mandatory("name", name);
|
||||||
|
|
||||||
@ -591,14 +591,14 @@ public class MultiTServiceImpl implements TenantService
|
|||||||
int idx2 = name.indexOf(SEPARATOR, 1);
|
int idx2 = name.indexOf(SEPARATOR, 1);
|
||||||
nameDomain = getTenantDomain(name.substring(1, idx2));
|
nameDomain = getTenantDomain(name.substring(1, idx2));
|
||||||
|
|
||||||
if (checkCurrentDomain)
|
if (checkCurrentDomain)
|
||||||
{
|
{
|
||||||
String tenantDomain = getCurrentUserDomain();
|
String tenantDomain = getCurrentUserDomain();
|
||||||
|
|
||||||
if ((! tenantDomain.equals(DEFAULT_DOMAIN)) && (! tenantDomain.equals(nameDomain)))
|
if ((! tenantDomain.equals(DEFAULT_DOMAIN)) && (! tenantDomain.equals(nameDomain)))
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("domain mismatch: expected = " + tenantDomain + ", actual = " + nameDomain);
|
throw new AlfrescoRuntimeException("domain mismatch: expected = " + tenantDomain + ", actual = " + nameDomain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user