use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class MoveMethod method moveOrCopy.
protected void moveOrCopy(NodeRef sourceNodeRef, NodeRef sourceParentNodeRef, NodeRef destParentNodeRef, String name) throws Exception {
FileFolderService fileFolderService = getFileFolderService();
NodeRef rootNodeRef = getRootNodeRef();
String sourcePath = getPath();
List<String> sourcePathElements = getDAVHelper().splitAllPaths(sourcePath);
FileInfo sourceFileInfo = null;
String destPath = getDestinationPath();
List<String> destPathElements = getDAVHelper().splitAllPaths(destPath);
FileInfo destFileInfo = null;
boolean isMove = isMove();
try {
// get the node to move
sourceFileInfo = fileFolderService.resolveNamePath(rootNodeRef, sourcePathElements);
destFileInfo = fileFolderService.resolveNamePath(rootNodeRef, destPathElements);
} catch (FileNotFoundException e) {
if (sourceFileInfo == null) {
if (logger.isDebugEnabled()) {
logger.debug("Source node not found: " + sourcePath);
}
// nothing to move
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
}
LockInfo lockInfo = null;
if (isMove) {
lockInfo = checkNode(sourceFileInfo);
}
// this is a move
if (!sourceFileInfo.isFolder() && destFileInfo != null && !sourceFileInfo.equals(destFileInfo)) {
copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
fileFolderService.setHidden(destFileInfo.getNodeRef(), false);
if (isMove) {
if (getDAVHelper().isRenameShuffle(destPath) && !getDAVHelper().isRenameShuffle(sourcePath)) {
// if temporary or backup file already exists
// don't delete source that is node with version history
fileFolderService.setHidden(sourceNodeRef, true);
// As per the WebDAV spec, we make sure the node is unlocked once moved
unlock(sourceNodeRef, lockInfo);
} else {
fileFolderService.delete(sourceNodeRef);
}
}
} else // If this is a copy then the source is just copied to destination.
if (!isMove) {
// MNT-9939 - check overwrite
if (hasOverWrite() && destFileInfo != null) {
if (logger.isDebugEnabled()) {
logger.debug("Destination exists and overwrite is allowed");
}
fileFolderService.delete(destFileInfo.getNodeRef());
}
fileFolderService.copy(sourceNodeRef, destParentNodeRef, name);
} else // copied to destination and the source is hidden.
if (!sourceFileInfo.isFolder() && getDAVHelper().isRenameShuffle(destPath) && !getDAVHelper().isRenameShuffle(sourcePath)) {
destFileInfo = fileFolderService.create(destParentNodeRef, name, ContentModel.TYPE_CONTENT);
copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
fileFolderService.setHidden(sourceNodeRef, true);
// As per the WebDAV spec, we make sure the node is unlocked once moved
unlock(sourceNodeRef, lockInfo);
} else if (sourceParentNodeRef.equals(destParentNodeRef)) {
// MNT-9939 - check overwrite
if (hasOverWrite() && destFileInfo != null && !sourceFileInfo.equals(destFileInfo)) {
if (logger.isDebugEnabled()) {
logger.debug("Destination exists and overwrite is allowed");
}
fileFolderService.delete(destFileInfo.getNodeRef());
}
fileFolderService.rename(sourceNodeRef, name);
// MNT-13144 WebDav does not correctly version CAD drawings correctly when saved using Windows mapped drive
if (!sourceFileInfo.isFolder() && getDAVHelper().isRenameShuffle(name)) {
fileFolderService.setHidden(sourceFileInfo.getNodeRef(), true);
}
// As per the WebDAV spec, we make sure the node is unlocked once moved
unlock(sourceNodeRef, lockInfo);
} else {
// MNT-9939 - check overwrite
if (hasOverWrite() && destFileInfo != null) {
if (logger.isDebugEnabled()) {
logger.debug("Destination exists and overwrite is allowed");
}
fileFolderService.delete(destFileInfo.getNodeRef());
}
fileFolderService.moveFrom(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, name);
// As per the WebDAV spec, we make sure the node is unlocked once moved
unlock(sourceNodeRef, lockInfo);
}
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class PropFindMethod method executeImpl.
/**
* Execute the main WebDAV request processing
*
* @exception WebDAVServerException
*/
protected void executeImpl() throws WebDAVServerException, Exception {
m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);
FileInfo pathNodeInfo = null;
try {
// Check that the path exists
pathNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), m_strPath);
} catch (FileNotFoundException e) {
// The path is not valid - send a 404 error back to the client
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
// Note the null check, as root node may be null in cloud.
if (pathNodeInfo.getNodeRef() != null && getFileFolderService().isHidden(pathNodeInfo.getNodeRef())) {
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
// Set the response content type
m_response.setContentType(WebDAV.XML_CONTENT_TYPE);
// Create multistatus response
XMLWriter xml = createXMLWriter();
xml.startDocument();
String nsdec = generateNamespaceDeclarations(m_namespaces);
xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes());
// Create the path for the current location in the tree
StringBuilder baseBuild = new StringBuilder(256);
baseBuild.append(getPath());
if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) {
baseBuild.append(WebDAVHelper.PathSeperatorChar);
}
String basePath = baseBuild.toString();
// Output the response for the root node, depth zero
generateResponseForNode(xml, pathNodeInfo, basePath);
// level and output node details a level at a time
if (getDepth() != WebDAV.DEPTH_0 && pathNodeInfo.isFolder()) {
// Create the initial list of nodes to report
List<FileInfo> nodeInfos = new ArrayList<FileInfo>(10);
nodeInfos.add(pathNodeInfo);
int curDepth = WebDAV.DEPTH_1;
// Save the base path length
int baseLen = baseBuild.length();
// List of next level of nodes to report
List<FileInfo> nextNodeInfos = null;
if (getDepth() > WebDAV.DEPTH_1) {
nextNodeInfos = new ArrayList<FileInfo>(10);
}
// Loop reporting each level of nodes to the requested depth
while (curDepth <= getDepth() && nodeInfos != null) {
// Clear out the next level of nodes, if required
if (nextNodeInfos != null) {
nextNodeInfos.clear();
}
for (FileInfo curNodeInfo : nodeInfos) {
// Get the list of child nodes for the current node
List<FileInfo> childNodeInfos = getDAVHelper().getChildren(curNodeInfo);
// can skip the current node if it doesn't have children
if (childNodeInfos.size() == 0) {
continue;
}
// Output the child node details
// Generate the base path for the current parent node
baseBuild.setLength(baseLen);
try {
String pathSnippet = null;
if ((pathNodeInfo.getNodeRef() == null) && (curNodeInfo.getNodeRef() == null)) {
// TODO review - note: can be null in case of Thor
pathSnippet = "/";
} else {
pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(), curNodeInfo.getNodeRef());
}
baseBuild.append(pathSnippet);
} catch (FileNotFoundException e) {
// move to the next node
continue;
}
int curBaseLen = baseBuild.length();
// Output the child node details
for (FileInfo curChildInfo : childNodeInfos) {
// Build the path for the current child node
baseBuild.setLength(curBaseLen);
baseBuild.append(curChildInfo.getName());
// Output the current child node details
generateResponseForNode(xml, curChildInfo, baseBuild.toString());
// If the child is a folder add it to the list of next level nodes
if (nextNodeInfos != null && curChildInfo.isFolder()) {
nextNodeInfos.add(curChildInfo);
}
}
}
// Update the current tree depth
curDepth++;
// Move the next level of nodes to the current node list
nodeInfos = nextNodeInfos;
}
}
// Close the outer XML element
xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);
// Send remaining data
flushXML(xml);
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class PropPatchMethod method executeImpl.
@Override
protected void executeImpl() throws WebDAVServerException, Exception {
FileInfo pathNodeInfo = null;
try {
// Check that the path exists
pathNodeInfo = getNodeForPath(getRootNodeRef(), m_strPath);
} catch (FileNotFoundException e) {
// The path is not valid - send a 404 error back to the client
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
checkNode(pathNodeInfo);
// Create the path for the current location in the tree
StringBuilder baseBuild = new StringBuilder(256);
baseBuild.append(getPath());
if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) {
baseBuild.append(WebDAVHelper.PathSeperatorChar);
}
basePath = baseBuild.toString();
// Build the href string for the current node
boolean isFolder = pathNodeInfo.isFolder();
strHRef = getURLForPath(m_request, basePath, isFolder);
// Do the real work: patch the properties
patchProperties(pathNodeInfo, basePath);
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteContainers.
public PagingResults<SiteContainer> getSiteContainers(String siteId, Paging paging) {
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging));
List<FileInfo> containerFileInfos = pagingResults.getPage();
final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size());
for (FileInfo containerFileInfo : containerFileInfos) {
NodeRef nodeRef = containerFileInfo.getNodeRef();
String containerId = (String) nodeService.getProperty(nodeRef, SiteModel.PROP_COMPONENT_ID);
SiteContainer siteContainer = new SiteContainer(containerId, nodeRef);
siteContainers.add(siteContainer);
}
return new PagingResults<SiteContainer>() {
@Override
public List<SiteContainer> getPage() {
return siteContainers;
}
@Override
public boolean hasMoreItems() {
return pagingResults.hasMoreItems();
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
return pagingResults.getTotalResultCount();
}
@Override
public String getQueryExecutionId() {
return null;
}
};
}
use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.
the class ADMRemoteStore method deleteDocument.
/**
* Deletes an existing document.
* <p>
* Delete methods are user authenticated, so the deletion of the document must be
* allowed for the current user.
*
* @param path document path
*/
@Override
protected void deleteDocument(final WebScriptResponse res, final String store, final String path) {
final String encpath = encodePath(path);
final FileInfo fileInfo = resolveFilePath(encpath);
if (fileInfo == null || fileInfo.isFolder()) {
res.setStatus(Status.STATUS_NOT_FOUND);
return;
}
final String runAsUser = getPathRunAsUser(path);
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@SuppressWarnings("synthetic-access")
public Void doWork() throws Exception {
try {
final NodeRef fileRef = fileInfo.getNodeRef();
// MNT-16371: Revoke ownership privileges for surf-config folder contents, to tighten access for former SiteManagers.
nodeService.addAspect(fileRef, ContentModel.ASPECT_TEMPORARY, null);
// ALF-17729
NodeRef parentFolderRef = unprotNodeService.getPrimaryParent(fileRef).getParentRef();
behaviourFilter.disableBehaviour(parentFolderRef, ContentModel.ASPECT_AUDITABLE);
try {
nodeService.deleteNode(fileRef);
} finally {
behaviourFilter.enableBehaviour(parentFolderRef, ContentModel.ASPECT_AUDITABLE);
}
if (logger.isDebugEnabled())
logger.debug("deleteDocument: " + fileInfo.toString());
} catch (AccessDeniedException ae) {
res.setStatus(Status.STATUS_UNAUTHORIZED);
throw ae;
}
return null;
}
}, runAsUser);
}
Aggregations