use of org.alfresco.service.cmr.model.FileExistsException in project acs-community-packaging by Alfresco.
the class EditContentPropertiesDialog method formatErrorMessage.
/**
* Formats the error message to display if an error occurs during finish processing
*
* @param exception The exception
* @return The formatted message
*/
@Override
protected String formatErrorMessage(Throwable exception) {
if (editableNode != null) {
// special case for Mimetype - since this is a sub-property of the ContentData object
// we must extract it so it can be edited in the client, then we check for it later
// and create a new ContentData object to wrap it and it's associated URL
ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
if (content != null) {
this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
}
}
if (exception instanceof FileExistsException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
} else if (exception instanceof InvalidNodeRefException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
} else {
return super.formatErrorMessage(exception);
}
}
use of org.alfresco.service.cmr.model.FileExistsException in project alfresco-remote-api by Alfresco.
the class NodesImpl method makeFolders.
private NodeRef makeFolders(NodeRef parentNodeRef, List<String> pathElements) {
NodeRef currentParentRef = parentNodeRef;
// just loop and create if necessary
for (final String element : pathElements) {
final NodeRef contextNodeRef = currentParentRef;
// does it exist?
// Navigation should not check permissions
NodeRef nodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
return nodeService.getChildByName(contextNodeRef, ContentModel.ASSOC_CONTAINS, element);
}
}, AuthenticationUtil.getSystemUserName());
if (nodeRef == null) {
try {
// Checks for create permissions as the fileFolderService is a public service.
FileInfo createdFileInfo = fileFolderService.create(currentParentRef, element, ContentModel.TYPE_FOLDER);
currentParentRef = createdFileInfo.getNodeRef();
} catch (AccessDeniedException ade) {
throw new PermissionDeniedException(ade.getMessage());
} catch (FileExistsException fex) {
// Assume concurrency failure, so retry
throw new ConcurrencyFailureException(fex.getMessage());
}
} else if (!isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)) {
String parentName = (String) nodeService.getProperty(contextNodeRef, ContentModel.PROP_NAME);
throw new ConstraintViolatedException("Name [" + element + "] already exists in the target parent: " + parentName);
} else {
// it exists
currentParentRef = nodeRef;
}
}
return currentParentRef;
}
use of org.alfresco.service.cmr.model.FileExistsException in project alfresco-remote-api by Alfresco.
the class ADMRemoteStore method createDocuments.
/**
* Creates multiple XML documents encapsulated in a single one.
*
* @param res WebScriptResponse
* @param store String
* @param in XML document containing multiple document contents to write
*/
@Override
protected void createDocuments(WebScriptResponse res, String store, InputStream in) {
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document;
document = documentBuilder.parse(in);
Element docEl = document.getDocumentElement();
Transformer transformer = ADMRemoteStore.this.transformer.get();
for (Node n = docEl.getFirstChild(); n != null; n = n.getNextSibling()) {
if (!(n instanceof Element)) {
continue;
}
final String path = ((Element) n).getAttribute("path");
// Turn the first element child into a document
Document doc = documentBuilder.newDocument();
Node child;
for (child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof Element) {
doc.appendChild(doc.importNode(child, true));
break;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
transformer.transform(new DOMSource(doc), new StreamResult(out));
out.close();
writeDocument(path, new ByteArrayInputStream(out.toByteArray()));
}
} catch (AccessDeniedException ae) {
res.setStatus(Status.STATUS_UNAUTHORIZED);
throw ae;
} catch (FileExistsException feeErr) {
res.setStatus(Status.STATUS_CONFLICT);
throw feeErr;
} catch (Exception e) {
// various annoying checked SAX/IO exceptions related to XML processing can be thrown
// none of them should occur if the XML document is well formed
logger.error(e);
res.setStatus(Status.STATUS_INTERNAL_SERVER_ERROR);
throw new AlfrescoRuntimeException(e.getMessage(), e);
}
}
use of org.alfresco.service.cmr.model.FileExistsException in project records-management by Alfresco.
the class RM978Test method testCopyDocumentInFolderInRmSite.
public void testCopyDocumentInFolderInRmSite() {
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {
private NodeRef folder1;
private NodeRef document1;
private String document1Name = GUID.generate();
private NodeRef rmCategory;
private NodeRef rmFolder;
public void given() {
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
return null;
}
}, getAdminUserName());
}
public void when() throws FileExistsException, FileNotFoundException {
runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
filePlanPermissionService.setPermission(rmFolder, user, RMPermissionModel.FILING);
return null;
}
}, getAdminUserName());
fileFolderService.copy(document1, rmFolder, null);
}
});
}
use of org.alfresco.service.cmr.model.FileExistsException in project records-management by Alfresco.
the class RM978Test method testMoveFolderInFolderInRmSite.
public void testMoveFolderInFolderInRmSite() {
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {
private NodeRef folder1;
private NodeRef rmCategory;
private NodeRef rmFolder;
public void given() {
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
return null;
}
}, getAdminUserName());
}
public void when() throws FileExistsException, FileNotFoundException {
fileFolderService.move(folder1, rmFolder, GUID.generate());
}
});
}
Aggregations