use of org.alfresco.service.cmr.repository.NodeService 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.repository.NodeService 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.repository.NodeService 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;
}
}
use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.
the class ExecuteScriptCommand method execute.
/**
* @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
*/
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
// get the target Script node for the command
NodeRef scriptRef = (NodeRef) properties.get(PROP_SCRIPT);
if (scriptRef == null) {
throw new IllegalArgumentException("Unable to execute ExecuteScriptCommand - mandatory parameter not supplied: " + PROP_SCRIPT);
}
NodeRef personRef = (NodeRef) properties.get(PROP_USERPERSON);
if (personRef == null) {
throw new IllegalArgumentException("Unable to execute ExecuteScriptCommand - mandatory parameter not supplied: " + PROP_USERPERSON);
}
// get the optional document and space context ref
NodeService nodeService = serviceRegistry.getNodeService();
NodeRef docRef = (NodeRef) properties.get(PROP_DOCUMENT);
NodeRef spaceRef = null;
if (docRef != null) {
spaceRef = nodeService.getPrimaryParent(docRef).getParentRef();
}
// build the model needed to execute the script
Map<String, Object> model = serviceRegistry.getScriptService().buildDefaultModel(personRef, new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId()), (NodeRef) nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER), scriptRef, docRef, spaceRef);
// add the url arguments map
model.put("args", properties.get(PROP_ARGS));
// execute the script and return the result
return serviceRegistry.getScriptService().executeScript(scriptRef, null, model);
}
use of org.alfresco.service.cmr.repository.NodeService in project acs-community-packaging by Alfresco.
the class BaseAssociationEditor method encodeBegin.
/**
* @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
*/
public void encodeBegin(FacesContext context) throws IOException {
if (isRendered() == false) {
return;
}
// reset the highlighted row flag
this.highlightedRow = false;
ResponseWriter out = context.getResponseWriter();
// get the child associations currently on the node and any that have been added
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
// show the editable association component
AssociationDefinition assocDef = getAssociationDefinition(context);
if (assocDef == null) {
logger.warn("Failed to find association definition for association '" + associationName + "'");
// add an error message as the property is not defined in the data dictionary
String msg = MessageFormat.format(Application.getMessage(context, MSG_ERROR_ASSOC), new Object[] { this.associationName });
Utils.addErrorMessage(msg);
} else {
String targetType = assocDef.getTargetClass().getName().toString();
boolean allowMany = assocDef.isTargetMany();
populateAssocationMaps((Node) getValue(), nodeService);
if (isDisabled()) {
// show the current list of associations in a read-only form
renderReadOnlyAssociations(context, out, nodeService);
} else {
// start outer table
out.write("<table border='0' cellspacing='4' cellpadding='0' class='multiValueSelector'>");
if (allowMany) {
out.write("<tr><td colspan='2'>1. ");
out.write(getSelectItemsMsg());
out.write("</td></tr>");
// show the search field
renderSearchField(context, out);
// show available options for this association
renderAvailableOptions(context, out, nodeService, targetType, allowMany);
// add the Add to List button
out.write("<tr><td colspan='2'>2. <input type='submit' value='");
out.write(Application.getMessage(context, MSG_ADD_TO_LIST_BUTTON));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, Integer.toString(ACTION_ADD)));
out.write("\"/>");
// add some padding
out.write("<tr><td height='6'></td></tr>");
out.write("<tr><td colspan='2'>");
out.write(getSelectedItemsMsg());
out.write("</td></tr>");
// show all the current associations
out.write("<tr><td colspan='2'><table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>");
out.write("<tr><td colspan='2' class='selectedItemsHeader'>");
out.write(Application.getMessage(context, "name"));
out.write("</td></tr>");
renderExistingAssociations(context, out, nodeService, allowMany);
out.write("</table></td></tr>");
} else {
if (this.showAvailable) {
out.write("<tr><td colspan='2'>1. ");
out.write(getSelectItemMsg());
out.write("</td></tr>");
// show the search field
renderSearchField(context, out);
// show available options for this association
renderAvailableOptions(context, out, nodeService, targetType, allowMany);
// add the ok and cancel buttons
out.write("<tr><td colspan='2' align='right'><input type='submit' value='");
out.write(Application.getMessage(context, MSG_OK));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, Integer.toString(ACTION_SET)));
out.write("\"/> <input type='submit' value='");
out.write(Application.getMessage(context, MSG_CANCEL));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, Integer.toString(ACTION_CANCEL)));
out.write("\"/></td></tr>");
} else {
// show the select button if required
if ((allowMany == false && this.originalAssocs.size() == 0 && this.added.size() == 0) || (allowMany == false && this.originalAssocs.size() == 1 && this.removed.size() == 1 && this.added.size() == 0)) {
out.write("<tr><td><input type='submit' value='");
out.write(Application.getMessage(context, MSG_SELECT_BUTTON));
out.write("' onclick=\"");
out.write(generateFormSubmit(context, Integer.toString(ACTION_SELECT)));
out.write("\"/></td></tr>");
} else {
// show the current association
renderExistingAssociations(context, out, nodeService, allowMany);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("number original = " + this.originalAssocs.size());
logger.debug("number added = " + this.added.size());
logger.debug("number removed = " + this.removed.size());
}
// close table
out.write("</table>");
// output a hidden field containing the current value
out.write("<input type='hidden' id='");
out.write(this.getClientId(context));
out.write("_current_value");
out.write("' name='");
out.write(this.getClientId(context));
out.write("_current_value");
out.write("' value='");
// if the current state will leave the node without any associations
// do not set a value for the hidden field
int numberAssocs = (this.originalAssocs.size() + this.added.size()) - this.removed.size();
if (numberAssocs > 0) {
out.write(Integer.toString(numberAssocs));
}
out.write("' />");
}
}
}
Aggregations