List of usage examples for javax.transaction UserTransaction begin
void begin() throws NotSupportedException, SystemException;
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoDwsServiceHandler.java
/** * @see org.alfresco.module.vti.handler.DwsServiceHandler#removeDwsUser(java.lang.String, java.lang.String) *///from ww w . ja va 2 s . c o m public void removeDwsUser(String dwsUrl, String id) { FileInfo dwsInfo = pathHelper.resolvePathFileInfo(dwsUrl); if (dwsInfo == null) { throw new VtiHandlerException(VtiError.NOT_FOUND); } UserTransaction tx = transactionService.getUserTransaction(false); try { tx.begin(); doRemoveDwsUser(dwsInfo, id); tx.commit(); } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { //NOOP } if (e instanceof AccessDeniedException) { throw new VtiHandlerException(VtiError.NO_PERMISSIONS); } throw new VtiHandlerException(VtiError.NO_PERMISSIONS); } if (logger.isDebugEnabled()) { logger.debug( "User with name '" + id + "' was successfully removed from site: " + dwsInfo.getName() + "."); } }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * @see org.alfresco.module.vti.handler.MethodHandler#checkInDocument(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.Date, boolean) *///from w ww. j a va 2 s . com public DocMetaInfo checkInDocument(String serviceName, String documentName, String comment, boolean keepCheckedOut, Date timeCheckedout, boolean validateWelcomeNames) { // timeCheckedout ignored if (logger.isDebugEnabled()) { logger.debug("Checkin document: " + documentName + ". Site name: " + serviceName); } for (String urlPart : documentName.split("/")) { if (VtiUtils.hasIllegalCharacter(urlPart)) { throw new VtiHandlerException(VtiHandlerException.HAS_ILLEGAL_CHARACTERS); } } FileInfo fileFileInfo = getPathHelper().resolvePathFileInfo(serviceName + "/" + documentName); AlfrescoMethodHandler.assertValidFileInfo(fileFileInfo); AlfrescoMethodHandler.assertFile(fileFileInfo); FileInfo documentFileInfo = fileFileInfo; DocumentStatus documentStatus = getDocumentHelper().getDocumentStatus(documentFileInfo.getNodeRef()); // if document isn't checked out then throw exception if (VtiDocumentHelper.isCheckedout(documentStatus) == false) { if (logger.isDebugEnabled()) { logger.debug("Document is not checked out."); } throw new VtiHandlerException(VtiHandlerException.DOC_NOT_CHECKED_OUT); } // if document is checked out, but user isn't owner, then throw exception if (VtiDocumentHelper.isCheckoutOwner(documentStatus) == false) { if (logger.isDebugEnabled()) { logger.debug("Unable to perform check in. Not an owner!!!"); } throw new VtiHandlerException(VtiHandlerException.DOC_CHECKED_OUT); } UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); if (VtiDocumentHelper.isLongCheckedout(documentStatus)) { // long-term checkout Map<String, Serializable> props = new HashMap<String, Serializable>(1, 1.0f); props.put(Version.PROP_DESCRIPTION, comment); props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR); NodeRef resultNodeRef = getCheckOutCheckInService().checkin( getCheckOutCheckInService().getWorkingCopy(documentFileInfo.getNodeRef()), props, null, keepCheckedOut); documentFileInfo = getFileFolderService().getFileInfo(resultNodeRef); } else { // short-term checkout getLockService().unlock(documentFileInfo.getNodeRef()); documentFileInfo = getFileFolderService().getFileInfo(documentFileInfo.getNodeRef()); } tx.commit(); if (logger.isDebugEnabled()) { logger.debug("Document successfully checked in."); } } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { } throw VtiExceptionUtils.createRuntimeException(e); } DocMetaInfo docMetaInfo = new DocMetaInfo(false); docMetaInfo.setPath(documentName); setDocMetaInfo(documentFileInfo, docMetaInfo); return docMetaInfo; }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * @see org.alfresco.module.vti.handler.MethodHandler#createDirectory(java.lang.String, org.alfresco.module.vti.metadata.model.DocMetaInfo) *//*from ww w .j av a 2 s . c o m*/ public boolean createDirectory(String serviceName, DocMetaInfo dir) { if (logger.isDebugEnabled()) { logger.debug("Creating directory: '" + dir.getPath() + "' in site: " + serviceName); } for (String urlPart : dir.getPath().split("/")) { if (VtiUtils.hasIllegalCharacter(urlPart)) { throw new VtiHandlerException(VtiError.V_HAS_ILLEGAL_CHARACTERS); } } Pair<String, String> parentChildPaths = VtiPathHelper .splitPathParentChild(serviceName + "/" + dir.getPath()); String parentName = parentChildPaths.getFirst(); String childFolderName = parentChildPaths.getSecond(); if (childFolderName.length() == 0) { if (logger.isDebugEnabled()) { logger.debug("Invalid name for new directory. Name should not be empty."); } throw new VtiHandlerException(VtiError.V_BAD_URL); } FileInfo parentFileInfo = getPathHelper().resolvePathFileInfo(parentName); if (parentFileInfo == null) { if (logger.isDebugEnabled()) { logger.debug("Parent folder not exists."); } throw new VtiHandlerException(VtiHandlerException.PRIMARY_PARENT_NOT_EXIST); } AlfrescoMethodHandler.assertFolder(parentFileInfo); UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); getFileFolderService().create(parentFileInfo.getNodeRef(), childFolderName, ContentModel.TYPE_FOLDER); tx.commit(); if (logger.isDebugEnabled()) { logger.debug("Folder successfully was created."); } } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { } if (e instanceof FileExistsException) { throw new VtiHandlerException(VtiHandlerException.FOLDER_ALREADY_EXISTS); } throw VtiExceptionUtils.createRuntimeException(e); } return true; }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * @see org.alfresco.module.vti.handler.MethodHandler#moveDocument(java.lang.String, java.lang.String, java.lang.String, java.util.List, java.util.EnumSet, java.util.EnumSet, * boolean, boolean)// w ww . j a va2 s .c o m */ public DocsMetaInfo moveDocument(String serviceName, String oldURL, String newURL, List<String> urlList, EnumSet<RenameOption> renameOptionSet, EnumSet<PutOption> putOptionSet, boolean docopy, boolean validateWelcomeNames) { // urlList ignored // validateWelcomeNames ignored FileInfo sourceFileInfo = getPathHelper().resolvePathFileInfo(serviceName + "/" + oldURL); AlfrescoMethodHandler.assertValidFileInfo(sourceFileInfo); if (docopy == false) { if (sourceFileInfo.isFolder() == false) { AlfrescoMethodHandler.assertRemovableDocument( getDocumentHelper().getDocumentStatus(sourceFileInfo.getNodeRef())); } } for (String urlPart : newURL.split("/")) { if (VtiUtils.hasIllegalCharacter(urlPart)) { throw new VtiHandlerException(VtiHandlerException.HAS_ILLEGAL_CHARACTERS); } } Pair<String, String> parentChildPaths = VtiPathHelper.splitPathParentChild(serviceName + "/" + newURL); String destName = parentChildPaths.getSecond(); if (destName.length() == 0) { throw new VtiHandlerException(VtiError.V_BAD_URL); } UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); // determining existence of parent folder for newURL String parentPath = parentChildPaths.getFirst(); FileInfo destParentFolder = getPathHelper().resolvePathFileInfo(parentPath); if (destParentFolder == null) { // if "createdir" option presents then create only primary parent of new location if (putOptionSet.contains(PutOption.createdir) || renameOptionSet.contains(RenameOption.createdir)) { destParentFolder = createOnlyLastFolder(parentPath); } if (destParentFolder == null) { throw new VtiHandlerException(VtiHandlerException.PRIMARY_PARENT_NOT_EXIST); } } // determining existence of folder or file with newURL FileInfo destFileInfo = getPathHelper().resolvePathFileInfo(destParentFolder, destName); if (destFileInfo != null) { // if "overwrite" option presents then overwrite existing file or folder if (putOptionSet.contains(PutOption.overwrite)) { if (destFileInfo.isFolder() == false) { DocumentStatus destDocumentStatus = getDocumentHelper() .getDocumentStatus(destFileInfo.getNodeRef()); AlfrescoMethodHandler.assertRemovableDocument(destDocumentStatus); // if destination document is long-term checked out then delete working copy if (destDocumentStatus.equals(DocumentStatus.LONG_CHECKOUT_OWNER)) { NodeRef workingCopyNodeRef = getCheckOutCheckInService() .getWorkingCopy(destFileInfo.getNodeRef()); getFileFolderService().delete(workingCopyNodeRef); // beforeDeleteNode policy unlocks original node } } getFileFolderService().delete(destFileInfo.getNodeRef()); } else { throw new VtiHandlerException(VtiHandlerException.FILE_ALREADY_EXISTS); } } if (docopy) { if (logger.isDebugEnabled()) { logger.debug("Copy document: " + oldURL + " to new location: " + newURL + " in site: " + serviceName); } destFileInfo = getFileFolderService().copy(sourceFileInfo.getNodeRef(), destParentFolder.getNodeRef(), destName); } else { if (sourceFileInfo.isFolder() == false) { DocumentStatus sourceDocumentStatus = getDocumentHelper() .getDocumentStatus(sourceFileInfo.getNodeRef()); // if source document is long-term checked out then delete working copy if (sourceDocumentStatus.equals(DocumentStatus.LONG_CHECKOUT_OWNER)) { NodeRef workingCopyNodeRef = getCheckOutCheckInService() .getWorkingCopy(sourceFileInfo.getNodeRef()); getFileFolderService().delete(workingCopyNodeRef); // beforeDeleteNode policy unlocks original node } } NodeRef sourceParentRef = null; if (oldURL != null) { // current parent Pair<String, String> sourceParentPaths = VtiPathHelper .splitPathParentChild(serviceName + "/" + oldURL); String sourceParentPath = sourceParentPaths.getFirst(); FileInfo sourceParent = getPathHelper().resolvePathFileInfo(sourceParentPath); if (sourceParent != null) { sourceParentRef = sourceParent.getNodeRef(); } } if (logger.isDebugEnabled()) { logger.debug("Move document: " + oldURL + " to new location: " + newURL + " in site: " + serviceName); } destFileInfo = getFileFolderService().moveFrom(sourceFileInfo.getNodeRef(), sourceParentRef, destParentFolder.getNodeRef(), destName); } tx.commit(); DocMetaInfo docMetaInfo = new DocMetaInfo(destFileInfo.isFolder()); docMetaInfo.setPath(newURL); setDocMetaInfo(destFileInfo, docMetaInfo); DocsMetaInfo result = new DocsMetaInfo(); if (destFileInfo.isFolder()) { result.getFolderMetaInfoList().add(docMetaInfo); addFileFoldersRecursive(destFileInfo, result); } else { result.getFileMetaInfoList().add(docMetaInfo); } return result; } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { } if (e instanceof FileNotFoundException) { throw new VtiHandlerException(VtiError.V_BAD_URL); } if (e instanceof NodeLockedException) { // only if source or destination folder is locked throw new VtiHandlerException(VtiHandlerException.REMOVE_DIRECTORY); } throw VtiExceptionUtils.createRuntimeException(e); } }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * @see org.alfresco.module.vti.handler.MethodHandler#putDocument(java.lang.String, org.alfresco.module.vti.metadata.model.Document, java.util.EnumSet, java.lang.String, * boolean, boolean)/*from w w w . ja va 2 s . c o m*/ */ public DocMetaInfo putDocument(String serviceName, Document document, EnumSet<PutOption> putOptionSet, String comment, boolean keepCheckedOut, boolean validateWelcomeNames) { // keepCheckedOut ignored // validateWelcomeNames // 'atomic' put-option : ignored // 'checkin' put-option : ignored // 'checkout' put-option : ignored // 'createdir' put-option : implemented // 'edit' put-option : implemented // 'forceversions' put-option : ignored // 'migrationsemantics' put-option : ignored // 'noadd' put-option : ignored // 'overwrite' put-option : implemented // 'thicket' put-option : ignored if (logger.isDebugEnabled()) { logger.debug("Saving document: '" + document.getPath() + "' to the site: " + serviceName); } for (String urlPart : document.getPath().split("/")) { if (VtiUtils.hasIllegalCharacter(urlPart)) { throw new VtiHandlerException(VtiHandlerException.HAS_ILLEGAL_CHARACTERS); } } Pair<String, String> parentChildPaths = VtiPathHelper .splitPathParentChild(serviceName + "/" + document.getPath()); String documentName = parentChildPaths.getSecond(); if (documentName.length() == 0) { throw new VtiHandlerException(VtiError.V_BAD_URL); } FileInfo curDocumentFileInfo; // file info for document for put_document method UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); String parentPath = parentChildPaths.getFirst(); FileInfo parentFileInfo = getPathHelper().resolvePathFileInfo(parentPath); if (parentFileInfo == null) { if (putOptionSet.contains(PutOption.createdir)) { parentFileInfo = createOnlyLastFolder(parentPath); } if (parentFileInfo == null) { if (logger.isDebugEnabled()) { logger.debug("The folder where file should be placed not exists."); } throw new VtiHandlerException(VtiHandlerException.PRIMARY_PARENT_NOT_EXIST); } } DocumentStatus documentStatus = DocumentStatus.NORMAL; // default status for new document curDocumentFileInfo = getPathHelper().resolvePathFileInfo(parentFileInfo, documentName); boolean docExisted = curDocumentFileInfo != null; if (docExisted) { documentStatus = getDocumentHelper().getDocumentStatus(curDocumentFileInfo.getNodeRef()); if (documentStatus.equals(DocumentStatus.READONLY)) { // document is readonly throw new VtiHandlerException(VtiHandlerException.FILE_OPEN_FOR_WRITE); } if (VtiDocumentHelper.isCheckedout(documentStatus) && VtiDocumentHelper.isCheckoutOwner(documentStatus) == false) { // document already checked out by another user if (logger.isDebugEnabled()) { logger.debug("Document is checked out by another user"); } throw new VtiHandlerException(VtiHandlerException.DOC_CHECKED_OUT); } if (VtiDocumentHelper.isLongCheckedout(documentStatus)) { NodeRef workingCopyNodeRef = getCheckOutCheckInService() .getWorkingCopy(curDocumentFileInfo.getNodeRef()); curDocumentFileInfo = getFileFolderService().getFileInfo(workingCopyNodeRef); } if ((putOptionSet.contains(PutOption.overwrite) == false && putOptionSet.contains(PutOption.edit) == false) || (!getFileFolderService().isHidden(curDocumentFileInfo.getNodeRef()) && putOptionSet.contains(PutOption.edit) && VtiUtils.compare(curDocumentFileInfo.getModifiedDate(), document.getTimelastmodified()) == false)) { if (logger.isDebugEnabled()) { logger.debug("ModifiedDate for document on server = '" + VtiUtils.formatDate(curDocumentFileInfo.getModifiedDate()) + "', " + "ModifiedDate for client document = '" + document.getTimelastmodified() + "'"); } throw new VtiHandlerException(VtiHandlerException.FILE_ALREADY_EXISTS); } NodeRef existedNodeRef = curDocumentFileInfo.getNodeRef(); // ALF-17662, hidden node is the same as non-existed node for SPP if (getFileFolderService().isHidden(existedNodeRef)) { // make it visible for client getFileFolderService().setHidden(existedNodeRef, false); } } else { curDocumentFileInfo = getFileFolderService().create(parentFileInfo.getNodeRef(), documentName, ContentModel.TYPE_CONTENT); } NodeRef curDocumentNodeRef = curDocumentFileInfo.getNodeRef(); Map<String, Serializable> versionProps = Collections .<String, Serializable>singletonMap(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR); // If document already exist but is not versionable, we must version it so it is not lost. // The first version must be 1.0 rather than 0.1. if (docExisted) { if (getNodeService().hasAspect(curDocumentNodeRef, ContentModel.ASPECT_VERSIONABLE) == false) { versionService.createVersion(curDocumentNodeRef, versionProps); } versionProps = Collections.<String, Serializable>singletonMap(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR); } else { // The document is new: Set the author to the current user getNodeService().setProperty(curDocumentNodeRef, ContentModel.PROP_AUTHOR, getAuthenticationService().getCurrentUserName()); } ContentWriter writer = getContentService().getWriter(curDocumentNodeRef, ContentModel.PROP_CONTENT, true); String mimetype = getMimetypeService().guessMimetype(documentName); writer.setMimetype(mimetype); writer.putContent(document.getInputStream()); // Create new version (from SPP) after content is written. versionService.createVersion(curDocumentNodeRef, versionProps); tx.commit(); } catch (Throwable e) { try { // set the inputStream in null for correct answer from server document.setInputStream(null); tx.rollback(); } catch (Exception tex) { } throw VtiExceptionUtils.createRuntimeException(e); } // refresh file info for new document curDocumentFileInfo = getFileFolderService().getFileInfo(curDocumentFileInfo.getNodeRef()); DocMetaInfo result = new DocMetaInfo(false); result.setPath(document.getPath()); setDocMetaInfo(curDocumentFileInfo, result); return result; }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * @see org.alfresco.module.vti.handler.MethodHandler#removeDocuments(java.lang.String, java.util.List, java.util.List, boolean) */// ww w . j a va 2s . c om public DocsMetaInfo removeDocuments(String serviceName, List<String> urlList, List<Date> timeTokens, boolean validateWelcomeNames) { // timeTokens ignored // validateWelcomeNames ignored DocsMetaInfo docsMetaInfo = new DocsMetaInfo(); UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); for (String url : urlList) { if (logger.isDebugEnabled()) { logger.debug("Removing item: '" + url + "' from site: " + serviceName); } FileInfo fileInfo = getPathHelper().resolvePathFileInfo(serviceName + "/" + url); AlfrescoMethodHandler.assertValidFileInfo(fileInfo); DocMetaInfo docMetaInfo = new DocMetaInfo(fileInfo.isFolder()); docMetaInfo.setPath(url); setDocMetaInfo(fileInfo, docMetaInfo); if (fileInfo.isFolder()) { // add nested files and folders to meta info list addFileFoldersRecursive(fileInfo, docsMetaInfo); docsMetaInfo.getFolderMetaInfoList().add(docMetaInfo); } else { DocumentStatus documentStatus = getDocumentHelper().getDocumentStatus(fileInfo.getNodeRef()); AlfrescoMethodHandler.assertRemovableDocument(documentStatus); if (documentStatus.equals(DocumentStatus.LONG_CHECKOUT_OWNER)) { NodeRef workingCopyNodeRef = getCheckOutCheckInService() .getWorkingCopy(fileInfo.getNodeRef()); getFileFolderService().delete(workingCopyNodeRef); // beforeDeletePolicy unlocks original document } docsMetaInfo.getFileMetaInfoList().add(docMetaInfo); } getFileFolderService().delete(fileInfo.getNodeRef()); } tx.commit(); } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { } throw VtiExceptionUtils.createRuntimeException(e); } return docsMetaInfo; }
From source file:org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoMethodHandler.java
/** * Helper method for short-term or long-term checkouts * /* w w w . j av a2 s . c om*/ * @param documentFileInfo file info for document ({@link FileInfo}) * @param timeout timeout in minutes for short-term checkout, if equals 0, then uses long-term checkout * @return FileInfo checked out document file info */ public FileInfo checkout(FileInfo documentFileInfo, int timeout) { DocumentStatus documentStatus = getDocumentHelper().getDocumentStatus(documentFileInfo.getNodeRef()); if (documentStatus.equals(DocumentStatus.READONLY)) { // document is readonly if (logger.isDebugEnabled()) { logger.debug("Unable to perform checked out operation!!! Document is read only."); } throw new VtiHandlerException(VtiHandlerException.FILE_OPEN_FOR_WRITE); } if (VtiDocumentHelper.isCheckedout(documentStatus) && VtiDocumentHelper.isCheckoutOwner(documentStatus) == false) { // document already checked out by another user if (logger.isDebugEnabled()) { logger.debug("Unable to perform checked out operation!!! Document is already checked out."); } throw new VtiHandlerException(VtiHandlerException.DOC_CHECKED_OUT); } FileInfo checkedoutDocumentFileInfo; if (documentStatus.equals(DocumentStatus.LONG_CHECKOUT_OWNER) == false) { UserTransaction tx = getTransactionService().getUserTransaction(false); try { tx.begin(); if (timeout == 0) { NodeRef workingCopyNodeRef = getCheckOutCheckInService() .checkout(documentFileInfo.getNodeRef()); checkedoutDocumentFileInfo = getFileFolderService().getFileInfo(workingCopyNodeRef); if (logger.isDebugEnabled()) { logger.debug("Long-term checkout."); } } else { getLockService().lock(documentFileInfo.getNodeRef(), getUserName(), VtiUtils.toAlfrescoLockTimeout(timeout)); // refresh file info checkedoutDocumentFileInfo = getFileFolderService().getFileInfo(documentFileInfo.getNodeRef()); if (logger.isDebugEnabled()) { logger.debug("Short-term checkout."); } } tx.commit(); } catch (Throwable e) { try { tx.rollback(); } catch (Exception tex) { } throw VtiExceptionUtils.createRuntimeException(e); } } else { // document already checked out by same user, just returns file info for working copy checkedoutDocumentFileInfo = getFileFolderService() .getFileInfo(getCheckOutCheckInService().getWorkingCopy(documentFileInfo.getNodeRef())); } return checkedoutDocumentFileInfo; }
From source file:org.alfresco.module.vti.handler.alfresco.AlfrescoDwsServiceHandler.java
/** * @see org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoDwsServiceHandler#doUpdateDwsDataDelete(org.alfresco.module.vti.metadata.model.LinkBean, java.lang.String) *//*from w ww .ja v a2 s . co m*/ @Override protected void doUpdateDwsDataDelete(LinkBean linkBean, String dws) { NodeRef linksContainer = null; linksContainer = siteService.getContainer(dws, "links"); if (linksContainer == null) { throw new VtiHandlerException(VtiHandlerException.LIST_NOT_FOUND); } NodeRef linkRef = nodeService.getChildByName(linksContainer, ContentModel.ASSOC_CONTAINS, linkBean.getId()); if (linkRef == null) { throw new VtiHandlerException(VtiHandlerException.ITEM_NOT_FOUND); } UserTransaction tx = transactionService.getUserTransaction(false); try { tx.begin(); nodeService.deleteNode(linkRef); tx.commit(); } catch (Throwable t) { try { tx.rollback(); } catch (Exception e) { } if (t instanceof AccessDeniedException) { throw new VtiHandlerException(VtiHandlerException.NO_PERMISSIONS); } throw VtiExceptionUtils.createRuntimeException(t); } if (logger.isDebugEnabled()) { logger.debug("Link with name '" + linkBean.getDescription() + "' was deleted."); } }
From source file:org.alfresco.module.vti.handler.alfresco.AlfrescoDwsServiceHandler.java
/** * @see org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoDwsServiceHandler#doUpdateDwsDataNew(org.alfresco.module.vti.metadata.model.LinkBean, java.lang.String) *//* w w w . j a v a 2 s . c o m*/ protected LinkBean doUpdateDwsDataNew(LinkBean linkBean, String dws) { LinkBean result = null; NodeRef linksContainer = null; if (siteService.hasContainer(dws, "links")) { linksContainer = siteService.getContainer(dws, "links"); } else { linksContainer = siteService.createContainer(dws, "links", ContentModel.TYPE_FOLDER, null); } if (linksContainer == null) { throw new VtiHandlerException(VtiHandlerException.LIST_NOT_FOUND); } Map<QName, Serializable> props = new HashMap<QName, Serializable>(); String name = getUniqueName(linksContainer); props.put(ContentModel.PROP_NAME, name); props.put(PROP_LINK_URL, linkBean.getUrl()); props.put(PROP_LINK_TITLE, linkBean.getDescription()); props.put(PROP_LINK_DESCRIPTION, linkBean.getComments()); UserTransaction tx = transactionService.getUserTransaction(false); try { tx.begin(); ChildAssociationRef association = nodeService.createNode(linksContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), TYPE_LINK, props); ContentWriter writer = contentService.getWriter(association.getChildRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); String text = linkBean.getUrl(); writer.putContent(text); result = buildLinkBean(association.getChildRef()); tx.commit(); } catch (Exception e) { try { tx.rollback(); } catch (Exception tex) { } if (e instanceof AccessDeniedException) { throw new VtiHandlerException(VtiHandlerException.NO_PERMISSIONS); } throw VtiExceptionUtils.createRuntimeException(e); } if (logger.isDebugEnabled()) { logger.debug("Link with name '" + linkBean.getDescription() + "' was created."); } return result; }
From source file:org.alfresco.module.vti.handler.alfresco.AlfrescoDwsServiceHandler.java
/** * @see org.alfresco.module.vti.handler.alfresco.AbstractAlfrescoDwsServiceHandler#doUpdateDwsDataUpdate(org.alfresco.module.vti.metadata.model.LinkBean, java.lang.String) *//* www . j a v a2 s . c o m*/ protected void doUpdateDwsDataUpdate(LinkBean linkBean, String dws) { NodeRef linksContainer = null; linksContainer = siteService.getContainer(dws, "links"); if (linksContainer == null) { throw new VtiHandlerException(VtiHandlerException.LIST_NOT_FOUND); } NodeRef linkRef = nodeService.getChildByName(linksContainer, ContentModel.ASSOC_CONTAINS, linkBean.getId()); if (linkRef == null) { throw new VtiHandlerException(VtiHandlerException.ITEM_NOT_FOUND); } UserTransaction tx = transactionService.getUserTransaction(false); try { tx.begin(); nodeService.setProperty(linkRef, PROP_LINK_URL, linkBean.getUrl()); nodeService.setProperty(linkRef, PROP_LINK_TITLE, linkBean.getDescription()); nodeService.setProperty(linkRef, PROP_LINK_DESCRIPTION, linkBean.getComments()); ContentWriter writer = contentService.getWriter(linkRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); String text = linkBean.getUrl(); writer.putContent(text); tx.commit(); } catch (Throwable t) { try { tx.rollback(); } catch (Exception e) { } if (t instanceof AccessDeniedException) { throw new VtiHandlerException(VtiHandlerException.NO_PERMISSIONS); } throw VtiExceptionUtils.createRuntimeException(t); } if (logger.isDebugEnabled()) { logger.debug("Link with name '" + linkBean.getDescription() + "' was updated."); } }