use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class UnlockMethod method attemptUnlock.
/**
* The main unlock implementation.
*
* @throws WebDAVServerException
*/
protected void attemptUnlock() throws WebDAVServerException {
if (logger.isDebugEnabled()) {
logger.debug("Unlock node; path=" + getPath() + ", token=" + getLockToken());
}
FileInfo lockNodeInfo = null;
try {
lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
} catch (FileNotFoundException e) {
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
// Parse the lock token
String[] lockInfoFromRequest = WebDAV.parseLockToken(getLockToken());
if (lockInfoFromRequest == null) {
// Bad lock token
throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
}
NodeRef nodeRef = lockNodeInfo.getNodeRef();
LockInfo lockInfo = getDAVLockService().getLockInfo(nodeRef);
if (lockInfo == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Not locked - no info in lock store.");
}
// Node is not locked
throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
}
if (!lockInfo.isLocked()) {
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Not locked");
}
// Node is not locked
throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
} else if (lockInfo.isExpired()) {
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Lock expired");
}
// Return a success status
m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
removeNoContentAspect(nodeRef);
} else if (lockInfo.isExclusive()) {
String currentUser = getAuthenticationService().getCurrentUserName();
if (currentUser.equals(lockInfo.getOwner())) {
try {
getDAVLockService().unlock(nodeRef);
} catch (UnableToReleaseLockException e) {
throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED, e);
}
// Indicate that the unlock was successful
m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
removeNoContentAspect(nodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Successful");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Not lock owner");
}
// Node is not locked
throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
}
} else if (lockInfo.isShared()) {
Set<String> sharedLocks = lockInfo.getSharedLockTokens();
if (sharedLocks.contains(m_strLockToken)) {
sharedLocks.remove(m_strLockToken);
// Indicate that the unlock was successful
m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
removeNoContentAspect(nodeRef);
// DEBUG
if (logger.isDebugEnabled()) {
logger.debug("Unlock token=" + getLockToken() + " Successful");
}
}
} else {
throw new IllegalStateException("Invalid LockInfo state: " + lockInfo);
}
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class WebDAVHelper method getNodeForPath.
/**
* Get the file info for the given paths
*
* @param rootNodeRef the acting webdav root
* @param path the path to search for
* @return Return the file info for the path
* @throws FileNotFoundException
* if the path doesn't refer to a valid node
*/
public FileInfo getNodeForPath(NodeRef rootNodeRef, String path) throws FileNotFoundException {
if (rootNodeRef == null) {
throw new IllegalArgumentException("Root node may not be null");
} else if (path == null) {
throw new IllegalArgumentException("Path may not be null");
}
FileFolderService fileFolderService = getFileFolderService();
// Check for the root path
if (path.length() == 0 || path.equals(PathSeperator)) {
return fileFolderService.getFileInfo(rootNodeRef);
}
// split the paths up
List<String> splitPath = splitAllPaths(path);
// find it
FileInfo fileInfo = m_fileFolderService.resolveNamePath(rootNodeRef, splitPath);
String fileName = splitPath.get(splitPath.size() - 1);
if (!fileInfo.getName().equals(fileName)) {
throw new FileNotFoundException("Requested filename " + fileName + " does not match case of " + fileInfo.getName());
}
// done
if (logger.isDebugEnabled()) {
logger.debug("Fetched node for path: \n" + " root: " + rootNodeRef + "\n" + " path: " + path + "\n" + " result: " + fileInfo);
}
return fileInfo;
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class WebDAVMethod method getWorkingCopy.
/**
* Returns a working copy of node for current user.
*
* @param nodeRef node reference
* @return Returns the working copy's file information
*/
protected FileInfo getWorkingCopy(NodeRef nodeRef) {
FileInfo result = null;
NodeRef workingCopy = getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(nodeRef);
if (workingCopy != null) {
String workingCopyOwner = getNodeService().getProperty(workingCopy, ContentModel.PROP_WORKING_COPY_OWNER).toString();
if (workingCopyOwner.equals(getAuthenticationService().getCurrentUserName())) {
result = getFileFolderService().getFileInfo(workingCopy);
}
}
return result;
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method resolveNodeByPath.
protected NodeRef resolveNodeByPath(final NodeRef parentNodeRef, String path, boolean checkForCompanyHome) {
final List<String> pathElements = getPathElements(path);
if (!pathElements.isEmpty() && checkForCompanyHome) {
/*
if (nodeService.getRootNode(parentNodeRef.getStoreRef()).equals(parentNodeRef))
{
// special case
NodeRef chNodeRef = repositoryHelper.getCompanyHome();
String chName = (String) nodeService.getProperty(chNodeRef, ContentModel.PROP_NAME);
if (chName.equals(pathElements.get(0)))
{
pathElements = pathElements.subList(1, pathElements.size());
parentNodeRef = chNodeRef;
}
}
*/
}
FileInfo fileInfo = null;
try {
if (!pathElements.isEmpty()) {
fileInfo = fileFolderService.resolveNamePath(parentNodeRef, pathElements);
} else {
fileInfo = fileFolderService.getFileInfo(parentNodeRef);
if (fileInfo == null) {
throw new EntityNotFoundException(parentNodeRef.getId());
}
}
} catch (FileNotFoundException fnfe) {
// convert checked exception
throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
} catch (AccessDeniedException ade) {
// return 404 instead of 403 (as per security review - uuid vs path)
throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
}
return fileInfo.getNodeRef();
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method getActivityInfo.
// note: see also org.alfresco.opencmis.ActivityPosterImpl
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef) {
// runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not)
SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>() {
@Override
public SiteInfo doWork() throws Exception {
return siteService.getSite(nodeRef);
}
}, AuthenticationUtil.getSystemUserName());
String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
if (siteId != null && !siteId.equals("")) {
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
if (fileInfo != null) {
boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);
if (fileInfo.isFolder() || isContent) {
return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Non-site activity, so ignored " + nodeRef);
}
}
return null;
}
Aggregations