private Document createGalleryItem(final Node document) throws RepositoryException { final String primaryItemName = getPrimaryItemName(document); if (primaryItemName != null) { final Node primaryItem; if (!document.hasNode(primaryItemName)) { primaryItem = document.addNode(primaryItemName); } else { primaryItem = document.getNode(primaryItemName); } primaryItem.setProperty(JCR_DATA, ""); primaryItem.setProperty(JCR_MIME_TYPE, "application/octet-stream"); primaryItem.setProperty(JCR_LAST_MODIFIED, Calendar.getInstance()); } else { throw new ItemNotFoundException("No primary item definition found"); } rootSession.save(); return new Document(document); }
public Document copy(String relPath, String absPath, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { Node source = subject.getNode(relPath); if(!source.isNodeType(HippoNodeType.NT_DOCUMENT) && !source.isNodeType(NT_HANDLE)) { throw new MappingException("copied item is not a document"); } Node target = subject.getSession().getRootNode().getNode(absPath.substring(1, absPath.lastIndexOf('/'))); if(!target.isNodeType(HippoNodeType.NT_DOCUMENT)) { throw new MappingException("copied destination is not a document"); } return copyFrom(new Document(source), new Document(target), absPath.substring(absPath.lastIndexOf('/') + 1), arguments); } public Document copy(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
public Document move(String relPath, String absPath, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { Node source = subject.getNode(relPath); if(!source.isNodeType(HippoNodeType.NT_DOCUMENT) && !source.isNodeType(NT_HANDLE)) { throw new MappingException("copied item is not a document"); } Node target = subject.getSession().getRootNode().getNode(absPath.substring(1, absPath.lastIndexOf('/'))); if(!target.isNodeType(HippoNodeType.NT_DOCUMENT)) { throw new MappingException("copied destination is not a document"); } return moveFrom(new Document(source), new Document(target), absPath.substring(absPath.lastIndexOf('/') + 1), arguments); } public Document move(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments)
/** * Get the containing folder of a document. * * @param document either a document, a handle or a folder * @param session the session to use to get the containing folder for * @return the folder containing this document or the root document * @throws RepositoryException */ public static Document getContainingFolder(Document document, Session session) throws RepositoryException { return new Document(getContainingFolder(document.getNode(session))); }
public DefaultWorkflowImpl(WorkflowContext context, Session userSession, Session rootSession, Node subject) throws RepositoryException { this.context = context; this.document = new Document(subject); this.subject = rootSession.getNodeByIdentifier(subject.getIdentifier()); }
public Document getReference() throws RepositoryException { if (hasNode() && getNode().hasProperty(HippoStdPubWfNodeType.HIPPOSTDPUBWF_DOCUMENT)) { return new Document(getNode().getProperty(HippoStdPubWfNodeType.HIPPOSTDPUBWF_DOCUMENT).getNode()); } return null; } }
@Override protected Node doExecute(Node node) throws Exception { Node targetFolder = selectRandomDocumentFolderNode(node); if (targetFolder != null) { String newName = "document"; do { newName += random.nextInt(10); } while (targetFolder.hasNode(newName)); Node handle = node.getParent(); getDocumentWorkflow(handle).move(new Document(targetFolder), newName); node.getSession().refresh(false); } return targetFolder; }
public Document copyFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { if (targetName == null || targetName.equals("")) { throw new WorkflowException("No target name given"); } String path = subject.getPath().substring(1); Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path)); Node destination = targetFolder.getNode(rootSession); Node source = offspring.getNode(rootSession); if (folder.isSame(destination)) { //throw new WorkflowException("Cannot copy document to same folder, use duplicate instead"); return duplicate(source, targetName); } if (source.getAncestor(folder.getDepth()).isSame(folder)) { return ((EmbedWorkflow)workflowContext.getWorkflow("embedded", new Document(destination))).copyTo(new Document(subject), offspring, targetName, arguments); } return null; }
private Document getTranslatedVariant(final Document translatedDocument) throws RepositoryException { final Node translatedNode = translatedDocument.getNode(UserSession.get().getJcrSession()); if (translatedNode.isNodeType(NT_HANDLE)) { Node variant = null; for (Node node : new NodeIterable(translatedNode.getNodes(translatedNode.getName()))) { variant = node; final String state = JcrUtils.getStringProperty(translatedNode, HIPPOSTD_STATE, null); if (UNPUBLISHED.equals(state)) { break; } } return variant != null ? new Document(variant) : null; } return translatedDocument; }
public Document moveFrom(Document offspring, Document targetFolder, String targetName, Map<String,String> arguments) throws WorkflowException, MappingException, RepositoryException, RemoteException { String path = subject.getPath().substring(1); Node folder = (path.equals("") ? rootSession.getRootNode() : rootSession.getRootNode().getNode(path)); Node destination = targetFolder.getNode(rootSession); if (folder.isSame(destination)) { throw new WorkflowException("Cannot move document to same folder"); } Node source = offspring.getNode(rootSession); if (!folder.isCheckedOut()) { folder.checkout(); } if (source.getAncestor(folder.getDepth()).isSame(folder)) { ((EmbedWorkflow)workflowContext.getWorkflow("internal", new Document(destination))).moveTo(new Document(subject), offspring, targetName, arguments); } return null; }
@Override protected String execute(Workflow wf) throws Exception { Node document = getModel().getNode(); Node folder = destination != null ? destination.getChainedModel().getObject() : new JcrNodeModel("/").getNode(); String nodeName = document.getName(); DocumentWorkflow workflow = (DocumentWorkflow) wf; workflow.move(new Document(folder), nodeName); browseTo(new JcrNodeModel(folder.getPath() + "/" + nodeName)); return null; } });
public void copy(Document destination, String newName) throws MappingException, RemoteException, WorkflowException, RepositoryException { Document folder = new Document(getContainingFolder(subject)); Workflow workflow = getWorkflowContext().getWorkflow(getFolderWorkflowCategory(), destination); if(workflow instanceof EmbedWorkflow) ((EmbedWorkflow)workflow).copyTo(folder, document, newName, null); else throw new WorkflowException("cannot copy document which is not contained in a folder"); }
public void rename(String newName) throws WorkflowException, MappingException, RepositoryException, RemoteException { Document folder = new Document(getContainingFolder(subject)); Workflow workflow = getWorkflowContext().getWorkflow(getFolderWorkflowCategory(), folder); if (workflow instanceof FolderWorkflow) { ((FolderWorkflow)workflow).rename(document, newName); } else { throw new WorkflowException("cannot rename document which is not contained in a folder"); } }
public void delete() throws WorkflowException, MappingException, RepositoryException, RemoteException { Workflow workflow = getWorkflowContext().getWorkflow(getFolderWorkflowCategory(), new Document(getContainingFolder(subject))); if(workflow instanceof FolderWorkflow) { ((FolderWorkflow) workflow).delete(document); } else { throw new WorkflowException("Cannot delete document that is not contained in a folder"); } }
public void archive() throws WorkflowException, MappingException, RepositoryException, RemoteException { Document folder = new Document(getContainingFolder(subject)); Workflow workflow = getWorkflowContext().getWorkflow(getFolderWorkflowCategory(), folder); if (workflow instanceof FolderWorkflow) { ((FolderWorkflow)workflow).archive(document); } else { throw new WorkflowException("cannot archive document which is not contained in a folder"); } }
public void move(Document destination, String newName) throws MappingException, RemoteException, WorkflowException, RepositoryException { Document folder = new Document(getContainingFolder(subject)); Workflow workflow = getWorkflowContext().getWorkflow(getFolderWorkflowCategory(), folder); if(workflow instanceof FolderWorkflow) ((FolderWorkflow)workflow).move(document, destination, newName); else throw new WorkflowException("cannot move document which is not contained in a folder"); }
@Override public Object doExecute() throws WorkflowException, RepositoryException, RemoteException { if (getVariant() == null || !getVariant().hasNode()) { throw new WorkflowException("No variant provided"); } final Session workflowSession = getWorkflowContext().getInternalWorkflowSession(); Node targetNode = getVariant().getNode(workflowSession); // ensure no pending changes which would fail the checkin workflowSession.save(); return new Document(targetNode.checkin()); } }
@Override protected String execute(Workflow wf) throws Exception { JcrNodeModel folderModel = new JcrNodeModel("/"); if (destination != null) { folderModel = destination.getNodeModel(); } String nodeName = (((WorkflowDescriptorModel) getDefaultModel()).getNode()).getName(); FullReviewedActionsWorkflow workflow = (FullReviewedActionsWorkflow) wf; workflow.move(new Document(folderModel.getNode().getUUID()), nodeName); browseTo(new JcrNodeModel(folderModel.getItemModel().getPath() + "/" + nodeName)); return null; } });
@Override protected String execute(Workflow wf) throws Exception { Node folder = destination != null ? destination.getChainedModel().getObject() : new JcrNodeModel("/").getNode(); Node document = getModel().getNode(); String nodeName = getNodeNameCodec(document, folder).encode(name); DocumentWorkflow workflow = (DocumentWorkflow) wf; workflow.copy(new Document(folder), nodeName); JcrNodeModel resultModel = new JcrNodeModel(folder.getPath() + "/" + nodeName); Node result = resultModel.getNode(); WorkflowManager manager = UserSession.get().getWorkflowManager(); DefaultWorkflow defaultWorkflow = (DefaultWorkflow) manager.getWorkflow("core", result.getNode(nodeName)); defaultWorkflow.setDisplayName(getLocalizeCodec().encode(name)); browseTo(resultModel); return null; }
@Override public Object doExecute() throws WorkflowException, RepositoryException, RemoteException { if (getVariant() == null || !getVariant().hasNode() || getHistoric() == null) { throw new WorkflowException("No variant or date provided"); } Node variant = getVariant().getNode(getWorkflowContext().getInternalWorkflowSession()); final Version version = lookupVersion(variant, getHistoric()); if (version != null) { return new Document(version.getFrozenNode()); } return null; } }