use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationContext appContext = getServer().getApplicationContext();
namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
workflowService = (WorkflowService) appContext.getBean("WorkflowService");
MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
PersonService personService = (PersonService) appContext.getBean("PersonService");
SearchService searchService = (SearchService) appContext.getBean("SearchService");
FileFolderService fileFolderService = (FileFolderService) appContext.getBean("FileFolderService");
nodeService = (NodeService) appContext.getBean("NodeService");
// for the purposes of the tests make sure workflow engine is enabled/visible.
WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) appContext.getBean("workflowAdminService");
this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
AuthorityService authorityService = (AuthorityService) appContext.getBean("AuthorityService");
personManager = new TestPersonManager(authenticationService, personService, nodeService);
groupManager = new TestGroupManager(authorityService);
authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");
personManager.createPerson(USER1);
personManager.createPerson(USER2);
personManager.createPerson(USER3);
authenticationComponent.setSystemUserAsCurrentUser();
groupManager.addUserToGroup(GROUP, USER2);
packageRef = workflowService.createPackage(null);
NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);
contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
authenticationComponent.clearCurrentSecurityContext();
}
use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
personService = ctx.getBean("PersonService", PersonService.class);
lockService = ctx.getBean("LockService", LockService.class);
contentService = ctx.getBean("contentService", ContentService.class);
checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
actionService = ctx.getBean("ActionService", ActionService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
txn = transactionService.getUserTransaction();
txn.begin();
createUser(USER1_NAME);
createUser(USER2_NAME);
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
testDataIS.close();
davLockInfoAdminIS.close();
davLockInfoUser2IS.close();
// Create a test file with versionable aspect and content
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
versionableDocName = "doc-" + GUID.generate();
properties.put(ContentModel.PROP_NAME, versionableDocName);
versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class PutMethod method executeImpl.
/**
* Execute the WebDAV request
*
* @exception WebDAVServerException
*/
protected void executeImpl() throws WebDAVServerException, Exception {
if (logger.isDebugEnabled()) {
String path = getPath();
String userName = getDAVHelper().getAuthenticationService().getCurrentUserName();
logger.debug("Put node: \n" + " user: " + userName + "\n" + " path: " + path + "\n" + "noContent: " + noContent);
}
FileFolderService fileFolderService = getFileFolderService();
// Get the status for the request path
LockInfo nodeLockInfo = null;
try {
contentNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
// make sure that we are not trying to use a folder
if (contentNodeInfo.isFolder()) {
throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
}
nodeLockInfo = checkNode(contentNodeInfo);
// 'Unhide' nodes hidden by us and behave as though we created them
NodeRef contentNodeRef = contentNodeInfo.getNodeRef();
if (fileFolderService.isHidden(contentNodeRef) && !getDAVHelper().isRenameShuffle(getPath())) {
fileFolderService.setHidden(contentNodeRef, false);
created = true;
}
} catch (FileNotFoundException e) {
// the file doesn't exist - create it
String[] paths = getDAVHelper().splitPath(getPath());
try {
FileInfo parentNodeInfo = getNodeForPath(getRootNodeRef(), paths[0]);
// create file
contentNodeInfo = getDAVHelper().createFile(parentNodeInfo, paths[1]);
created = true;
} catch (FileNotFoundException ee) {
// bad path
throw new WebDAVServerException(HttpServletResponse.SC_CONFLICT);
} catch (FileExistsException ee) {
// ALF-7079 fix, retry: it looks like concurrent access (file not found but file exists)
throw new ConcurrencyFailureException("Concurrent access was detected.", ee);
}
}
String userName = getDAVHelper().getAuthenticationService().getCurrentUserName();
LockInfo lockInfo = getDAVLockService().getLockInfo(contentNodeInfo.getNodeRef());
if (lockInfo != null) {
if (lockInfo.isLocked() && !lockInfo.getOwner().equals(userName)) {
if (logger.isDebugEnabled()) {
String path = getPath();
String owner = lockInfo.getOwner();
logger.debug("Node locked: path=[" + path + "], owner=[" + owner + "], current user=[" + userName + "]");
}
// Indicate that the resource is locked
throw new WebDAVServerException(WebDAV.WEBDAV_SC_LOCKED);
}
}
// ALF-16808: We disable the versionable aspect if we are overwriting
// empty content because it's probably part of a compound operation to
// create a new single version
boolean disabledVersioning = false;
try {
// Disable versioning if we are overwriting an empty file with content
NodeRef nodeRef = contentNodeInfo.getNodeRef();
ContentData contentData = (ContentData) getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
if ((contentData == null || contentData.getSize() == 0) && getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
getDAVHelper().getPolicyBehaviourFilter().disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
disabledVersioning = true;
}
// Access the content
ContentWriter writer = fileFolderService.getWriter(contentNodeInfo.getNodeRef());
// set content properties
writer.guessMimetype(contentNodeInfo.getName());
writer.guessEncoding();
// Get the input stream from the request data
InputStream is = m_request.getInputStream();
// Write the new data to the content node
writer.putContent(is);
// - the node does not have any content (zero length binaries included)
if (nodeLockInfo != null && nodeLockInfo.isExclusive() && !(ContentData.hasContent(contentData) && contentData.getSize() > 0)) {
getNodeService().addAspect(contentNodeInfo.getNodeRef(), ContentModel.ASPECT_NO_CONTENT, null);
}
// Ask for the document metadata to be extracted
Action extract = getActionService().createAction(ContentMetadataExtracter.EXECUTOR_NAME);
if (extract != null) {
extract.setExecuteAsynchronously(false);
getActionService().executeAction(extract, contentNodeInfo.getNodeRef());
}
// from the original specified in the request, update it.
if (m_strContentType == null || !m_strContentType.equals(writer.getMimetype())) {
String oldMimeType = m_strContentType;
m_strContentType = writer.getMimetype();
if (logger.isDebugEnabled()) {
logger.debug("Mimetype originally specified as " + oldMimeType + ", now guessed to be " + m_strContentType);
}
}
// Record the uploaded file's size
fileSize = writer.getSize();
// Set the response status, depending if the node existed or not
m_response.setStatus(created ? HttpServletResponse.SC_CREATED : HttpServletResponse.SC_NO_CONTENT);
} catch (AccessDeniedException e) {
throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN, e);
} catch (Throwable e) {
// we are about to give up
if (noContent && RetryingTransactionHelper.extractRetryCause(e) == null) {
// remove the 0 bytes content if save operation failed or was cancelled
final NodeRef nodeRef = contentNodeInfo.getNodeRef();
getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
getNodeService().deleteNode(nodeRef);
if (logger.isDebugEnabled()) {
logger.debug("Put failed. DELETE " + getPath());
}
return null;
}
}, false, false);
}
throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
} finally {
if (disabledVersioning) {
getDAVHelper().getPolicyBehaviourFilter().enableBehaviour(contentNodeInfo.getNodeRef(), ContentModel.ASPECT_VERSIONABLE);
}
}
postActivity();
}
use of org.alfresco.service.cmr.model.FileFolderService in project alfresco-remote-api by Alfresco.
the class WebDAVHelper method getPathFromNode.
/**
* Return the relative path for the node walking back to the specified root node
*
* @param rootNodeRef the root below which the path will be valid
* @param nodeRef the node's path to get
* @return Returns string of form <b>/A/B/C</b> where C represents the from node and
*/
public final String getPathFromNode(NodeRef rootNodeRef, NodeRef nodeRef) throws FileNotFoundException {
// Check if the nodes are valid, or equal
if (rootNodeRef == null || nodeRef == null)
throw new IllegalArgumentException("Invalid node(s) in getPathFromNode call");
// short cut if the path node is the root node
if (rootNodeRef.equals(nodeRef))
return "";
FileFolderService fileFolderService = getFileFolderService();
// get the path elements
List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, nodeRef);
// build the path string
StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
for (String fileInfo : pathInfos) {
sb.append(WebDAVHelper.PathSeperatorChar);
sb.append(fileInfo);
}
// done
if (logger.isDebugEnabled()) {
logger.debug("Build name path for node: \n" + " root: " + rootNodeRef + "\n" + " target: " + nodeRef + "\n" + " path: " + sb);
}
return sb.toString();
}
use of org.alfresco.service.cmr.model.FileFolderService 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;
}
Aggregations