mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
196 lines
5.3 KiB
Java
196 lines
5.3 KiB
Java
package org.alfresco.repo.webdav;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.tenant.TenantService;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.cmr.repository.StoreRef;
|
|
import org.alfresco.service.cmr.search.SearchService;
|
|
import org.alfresco.service.namespace.NamespaceService;
|
|
import org.alfresco.util.PropertyCheck;
|
|
|
|
/**
|
|
* In-memory cache that stores nodeRefs per tenant.
|
|
* It is initialized using path to node and allows to retrieve nodeRef for current tenant.
|
|
*
|
|
* @author Stas Sokolovsky
|
|
* @author Mark Rogers
|
|
*/
|
|
public class MTNodesCache2
|
|
{
|
|
private boolean enabled = false;
|
|
private NodeService nodeService;
|
|
private SearchService searchService;
|
|
private NamespaceService namespaceService;
|
|
private TenantService tenantService;
|
|
private Map<String, NodeRef> nodesCache = new ConcurrentHashMap<String, NodeRef>();
|
|
private NodeRef defaultNode = null;
|
|
private String storeName;
|
|
private String rootPath;
|
|
|
|
|
|
/**
|
|
* Spring bean init method
|
|
*/
|
|
public void init()
|
|
{
|
|
PropertyCheck.mandatory(this, "nodeService", getNodeService());
|
|
PropertyCheck.mandatory(this, "searchService", getSearchService());
|
|
PropertyCheck.mandatory(this, "namespaceService", getNamespaceService());
|
|
PropertyCheck.mandatory(this, "tenantService", getTenantService());
|
|
PropertyCheck.mandatory(this, "storeName", storeName);
|
|
PropertyCheck.mandatory(this, "rootPath", rootPath);
|
|
}
|
|
|
|
public void setNodeService(NodeService nodeService)
|
|
{
|
|
this.nodeService = nodeService;
|
|
}
|
|
|
|
public NodeService getNodeService()
|
|
{
|
|
return nodeService;
|
|
}
|
|
|
|
/**
|
|
* Returns nodeRef for current user tenant
|
|
*
|
|
* @return nodeRef Node Reference
|
|
*/
|
|
public NodeRef getNodeForCurrentTenant()
|
|
{
|
|
NodeRef result = null;
|
|
|
|
if (!getTenantService().isEnabled())
|
|
{
|
|
result = defaultNode;
|
|
}
|
|
else
|
|
{
|
|
String domain = getTenantService().getCurrentUserDomain();
|
|
if (nodesCache.containsKey(domain))
|
|
{
|
|
result = nodesCache.get(domain);
|
|
}
|
|
else
|
|
{
|
|
result = getTenantService().getRootNode(nodeService, getSearchService(), getNamespaceService(), rootPath, defaultNode);
|
|
nodesCache.put(domain, result);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void onBootstrap()
|
|
{
|
|
if (!enabled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
nodesCache.clear();
|
|
|
|
AuthenticationUtil.setRunAsUserSystem();
|
|
try
|
|
{
|
|
StoreRef storeRef = new StoreRef(storeName);
|
|
|
|
if (nodeService.exists(storeRef) == false)
|
|
{
|
|
throw new RuntimeException("No store for path: " + storeName);
|
|
}
|
|
|
|
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
|
|
|
List<NodeRef> nodeRefs = getSearchService().selectNodes(storeRootNodeRef, rootPath, null, getNamespaceService(), false);
|
|
|
|
if (nodeRefs.size() > 1)
|
|
{
|
|
throw new RuntimeException("Multiple possible children for : \n" + " path: " + rootPath + "\n" + " results: " + nodeRefs);
|
|
}
|
|
else if (nodeRefs.size() == 0)
|
|
{
|
|
throw new RuntimeException("Node is not found for : \n" + " root path: " + rootPath);
|
|
}
|
|
|
|
defaultNode = nodeRefs.get(0);
|
|
}
|
|
finally
|
|
{
|
|
AuthenticationUtil.clearCurrentSecurityContext();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return Returns the name of the store
|
|
*/
|
|
public String getStoreName()
|
|
{
|
|
return storeName;
|
|
}
|
|
|
|
public void setStoreName(String storeName)
|
|
{
|
|
this.storeName = storeName;
|
|
}
|
|
|
|
/**
|
|
* @return Returns the WebDAV root path within the store
|
|
*/
|
|
public String getRootPath()
|
|
{
|
|
return rootPath;
|
|
}
|
|
|
|
public void setRootPath(String rootPath)
|
|
{
|
|
this.rootPath = rootPath;
|
|
}
|
|
|
|
public void setSearchService(SearchService searchService)
|
|
{
|
|
this.searchService = searchService;
|
|
}
|
|
|
|
public SearchService getSearchService()
|
|
{
|
|
return searchService;
|
|
}
|
|
|
|
public void setNamespaceService(NamespaceService namespaceService)
|
|
{
|
|
this.namespaceService = namespaceService;
|
|
}
|
|
|
|
public NamespaceService getNamespaceService()
|
|
{
|
|
return namespaceService;
|
|
}
|
|
|
|
public void setTenantService(TenantService tenantService)
|
|
{
|
|
this.tenantService = tenantService;
|
|
}
|
|
|
|
public TenantService getTenantService()
|
|
{
|
|
return tenantService;
|
|
}
|
|
|
|
public boolean getEnabled()
|
|
{
|
|
return enabled;
|
|
}
|
|
|
|
public void setEnabled(boolean enabled)
|
|
{
|
|
this.enabled = enabled;
|
|
}
|
|
}
|