use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class DeleteMethod method executeImpl.
/**
* Execute the request
*
* @exception WebDAVServerException
*/
protected void executeImpl() throws WebDAVServerException, Exception {
if (logger.isDebugEnabled()) {
logger.debug("WebDAV DELETE: " + getPath());
}
final FileFolderService fileFolderService = getFileFolderService();
final PermissionService permissionService = getPermissionService();
NodeRef rootNodeRef = getRootNodeRef();
String path = getPath();
FileInfo fileInfo = null;
try {
// get the node to delete
fileInfo = getNodeForPath(rootNodeRef, path);
} catch (FileNotFoundException e) {
if (logger.isDebugEnabled()) {
logger.debug("Node not found: " + getPath());
}
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
checkNode(fileInfo);
final NodeService nodeService = getNodeService();
final NodeRef nodeRef = fileInfo.getNodeRef();
if (permissionService.hasPermission(nodeRef, PermissionService.DELETE) == AccessStatus.ALLOWED) {
// As this content will be deleted, we need to extract some info before it's no longer available.
String siteId = getSiteId();
NodeRef deletedNodeRef = fileInfo.getNodeRef();
FileInfo parentFile = getDAVHelper().getParentNodeForPath(getRootNodeRef(), path);
// Don't post activity data for hidden files, resource forks etc.
if (!getDAVHelper().isRenameShuffle(path)) {
postActivity(parentFile, fileInfo, siteId);
}
// MNT-181: working copies and versioned nodes are hidden rather than deleted
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) || nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
// Mark content as hidden. This breaks many contracts and will be fixed for "ALF-18619 WebDAV/SPP file shuffles"
fileFolderService.setHidden(nodeRef, true);
{
// Workaround for MNT-8704: WebDAV:Content does not disappear after being deleted
// Get the current user
final String deleteDelayUser = AuthenticationUtil.getFullyAuthenticatedUser();
// Add a timed task to really delete the file
TimerTask deleteDelayTask = new TimerTask() {
@Override
public void run() {
RunAsWork<Void> deleteDelayRunAs = new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// Ignore if it is NOT hidden: the shuffle may have finished; the operation may have failed
if (!nodeService.exists(nodeRef) || !fileFolderService.isHidden(nodeRef)) {
return null;
}
// Since this will run in a different thread, the client thread-local must be set
// or else unhiding the node will not unhide it for WebDAV.
FileFilterMode.setClient(FileFilterMode.Client.webdav);
// Unhide the node, e.g. for archiving
fileFolderService.setHidden(nodeRef, false);
// This is the transaction-aware service
fileFolderService.delete(nodeRef);
return null;
}
};
try {
AuthenticationUtil.runAs(deleteDelayRunAs, deleteDelayUser);
} catch (Throwable e) {
// consume exception to avoid it leaking from the TimerTask and causing the Timer to
// no longer accept tasks to be scheduled.
logger.info("Exception thrown during WebDAV delete timer task.", e);
}
}
};
// Schedule a real delete 5 seconds after the current time
deleteDelayTimer.schedule(deleteDelayTask, 5000L);
}
// node is is actually locked before unlocking to avoid access denied
if (getDAVLockService().getLockInfo(nodeRef).isLocked()) {
getDAVLockService().unlock(nodeRef);
}
} else // We just ensure already-hidden nodes are left unlocked
if (fileFolderService.isHidden(nodeRef)) {
getDAVLockService().unlock(nodeRef);
} else // A 'real' delete
{
// Delete it
fileFolderService.delete(deletedNodeRef);
}
} else {
// access denied
throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN);
}
}
use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class GetMethod method executeImpl.
/**
* Exceute the WebDAV request
*
* @exception WebDAVServerException
*/
protected void executeImpl() throws WebDAVServerException, Exception {
FileFolderService fileFolderService = getFileFolderService();
NodeRef rootNodeRef = getRootNodeRef();
String path = getPath();
if (!m_returnContent) {
// There are multiple cases where no content is sent (due to a HEAD request).
// All of them require that the content length is set appropriately.
m_response.setContentLength(0);
}
FileInfo nodeInfo = null;
try {
nodeInfo = getDAVHelper().getNodeForPath(rootNodeRef, path);
} catch (FileNotFoundException e) {
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
FileInfo realNodeInfo = nodeInfo;
// This is at least consistent with the way the CIFS server handles links. See org.alfresco.filesys.repo.ContentDiskDriver.openFile().
if (realNodeInfo.isLink()) {
Path pathToNode = getNodeService().getPath(nodeInfo.getLinkNodeRef());
if (pathToNode.size() > 2) {
pathToNode = pathToNode.subPath(2, pathToNode.size() - 1);
}
String rootURL = getDAVHelper().getURLForPath(m_request, pathToNode.toDisplayPath(getNodeService(), getPermissionService()), true);
if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
rootURL = rootURL + WebDAVHelper.PathSeperator;
}
String fname = (String) getNodeService().getProperty(nodeInfo.getLinkNodeRef(), ContentModel.PROP_NAME);
StringBuilder urlStr = new StringBuilder(200);
urlStr.append("[InternetShortcut]\r\n");
urlStr.append("URL=file://");
urlStr.append(m_request.getServerName());
// Only append the port if it is non-default for compatibility with XP
int port = m_request.getServerPort();
if (port != 80) {
urlStr.append(":").append(port);
}
urlStr.append(rootURL).append(WebDAVHelper.encodeURL(fname, m_userAgent));
urlStr.append("\r\n");
m_response.setHeader(WebDAV.HEADER_CONTENT_TYPE, "text/plain; charset=ISO-8859-1");
m_response.setHeader(WebDAV.HEADER_CONTENT_LENGTH, String.valueOf(urlStr.length()));
m_response.getWriter().write(urlStr.toString());
} else // Check if the node is a folder
if (realNodeInfo.isFolder()) {
// is content required
if (!m_returnContent) {
// ALF-7883 fix, HEAD for collection (see http://www.webdav.org/specs/rfc2518.html#rfc.section.8.4)
return;
}
// Generate a folder listing
m_response.setContentType("text/html;charset=UTF-8");
generateDirectoryListing(nodeInfo);
} else {
// Return the node details, and content if requested, check that the node passes the pre-conditions
checkPreConditions(realNodeInfo);
// Build the response header
m_response.setHeader(WebDAV.HEADER_ETAG, getDAVHelper().makeQuotedETag(nodeInfo));
Date modifiedDate = realNodeInfo.getModifiedDate();
if (modifiedDate != null) {
long modDate = DefaultTypeConverter.INSTANCE.longValue(modifiedDate);
m_response.setHeader(WebDAV.HEADER_LAST_MODIFIED, WebDAV.formatHeaderDate(modDate));
}
m_response.setHeader("Content-Disposition", getContentDispositionHeader(nodeInfo));
ContentReader reader = fileFolderService.getReader(realNodeInfo.getNodeRef());
// ensure that we generate something, even if the content is missing
reader = FileContentReader.getSafeContentReader((ContentReader) reader, I18NUtil.getMessage(FileContentReader.MSG_MISSING_CONTENT), realNodeInfo.getNodeRef(), reader);
readContent(realNodeInfo, reader);
}
}
use of org.alfresco.service.cmr.model.FileFolderService 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.FileFolderService in project acs-community-packaging by Alfresco.
the class MySpacesBean method createSpace.
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void createSpace() throws Exception {
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String path = (String) requestMap.get("path");
String name = (String) requestMap.get("name");
String title = (String) requestMap.get("title");
String description = (String) requestMap.get("description");
if (logger.isDebugEnabled())
logger.debug("MySpacesBean.createSpace() path=" + path + " name=" + name + " title=" + title + " description=" + description);
try {
if (path != null && name != null) {
NodeRef containerRef = FileUploadBean.pathToNodeRef(fc, path);
if (containerRef != null) {
NodeService nodeService = Repository.getServiceRegistry(fc).getNodeService();
FileFolderService ffService = Repository.getServiceRegistry(fc).getFileFolderService();
FileInfo folderInfo = ffService.create(containerRef, name, ContentModel.TYPE_FOLDER);
if (logger.isDebugEnabled())
logger.debug("Created new folder: " + folderInfo.getNodeRef().toString());
// apply the uifacets aspect - icon, title and description properties
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, title);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, description);
nodeService.addAspect(folderInfo.getNodeRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
out.write("OK: " + folderInfo.getNodeRef().toString());
}
}
} catch (FileExistsException ferr) {
out.write("ERROR: A file with that name already exists.");
} catch (Throwable err) {
out.write("ERROR: " + err.getMessage());
}
}
use of org.alfresco.service.cmr.model.FileFolderService in project acs-community-packaging by Alfresco.
the class WorkspaceClipboardItem method paste.
/**
* @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
*/
public boolean paste(final FacesContext fc, String viewId, final int action) {
final ServiceRegistry serviceRegistry = getServiceRegistry();
final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
final DictionaryService dd = serviceRegistry.getDictionaryService();
final NodeService nodeService = serviceRegistry.getNodeService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
final CopyService copyService = serviceRegistry.getCopyService();
final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
final boolean isPrimaryParent;
final ChildAssociationRef assocRef;
if (getParent() == null) {
assocRef = nodeService.getPrimaryParent(getNodeRef());
isPrimaryParent = true;
} else {
NodeRef parentNodeRef = getParent();
List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
ChildAssociationRef foundRef = null;
if (assocList != null) {
for (ChildAssociationRef assocListEntry : assocList) {
if (parentNodeRef.equals(assocListEntry.getParentRef())) {
foundRef = assocListEntry;
break;
}
}
}
assocRef = foundRef;
isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
}
// initial name to attempt the copy of the item with
String name = getName();
String translationPrefix = "";
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// copy as link was specifically requested by the user
String linkTo = Application.getMessage(fc, MSG_LINK_TO);
name = linkTo + ' ' + name;
}
// Loop until we find a target name that doesn't exist
for (; ; ) {
try {
final String currentTranslationPrefix = translationPrefix;
final String currentName = name;
// attempt each copy/paste in its own transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
if (getMode() == ClipboardStatus.COPY) {
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// LINK operation
if (logger.isDebugEnabled())
logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
// create the node using the nodeService (can only use FileFolderService for content)
if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
String newName = currentName + LINK_NODE_EXTENSION;
props.put(ContentModel.PROP_NAME, newName);
props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
// create File Link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, currentName);
titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
} else {
// create Folder link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
}
}
} else {
// COPY operation
if (logger.isDebugEnabled())
logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
// first check that we are not attempting to copy a duplicate into the same parent
if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
// manually change the name if this occurs
throw new FileExistsException(destRef, currentName);
}
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// copy the file/folder
fileFolderService.copy(getNodeRef(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
} else {
// copy the node
if (checkExists(currentName, destRef) == false) {
copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
}
}
}
} else {
// MOVE operation
if (logger.isDebugEnabled())
logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// move the file/folder
fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
} else {
if (isPrimaryParent) {
// move the node
nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
} else {
nodeService.removeChild(getParent(), getNodeRef());
nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
}
}
}
return null;
}
});
// We got here without error, so no need to loop with a new name
break;
} catch (FileExistsException fileExistsErr) {
// If mode is COPY, have another go around the loop with a new name
if (getMode() == ClipboardStatus.COPY) {
String copyOf = Application.getMessage(fc, MSG_COPY_OF);
name = copyOf + ' ' + name;
translationPrefix = copyOf + ' ' + translationPrefix;
} else {
// we should not rename an item when it is being moved - so exit
throw fileExistsErr;
}
}
}
return true;
} else {
return false;
}
}
Aggregations