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); }
WorkflowDescriptorImpl(WorkflowManagerImpl manager, String category, WorkflowDefinition definition, Document document) throws RepositoryException { this(manager, category, definition, document.getIdentity()); }
/** * 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))); }
protected void setBooleanProperty(String relPath, Boolean newValue) throws RepositoryException { if (hasNode()) { getCheckedOutNode().setProperty(relPath, newValue); } }
protected String[] getStringsProperty(String relPath) throws RepositoryException { String[] result = null; if (hasNode() && getNode().hasProperty(relPath)) { Value[] values = getNode().getProperty(relPath).getValues(); result = new String[values.length]; int i = 0; for (Value v : values) { result[i++] = v.getString(); } } return result; }
private Node getDocumentNode(Session session, Document document) { if (document == null || document.getIdentity() == null) { log.error("Cannot retrieve workflow for null document"); return null; } try { return document.getNode(session); } catch (ItemNotFoundException e) { log.error("Document not found {}", e.getMessage()); } catch (RepositoryException e) { log.error("Unexpected error {}", e.getMessage(), e); } return null; }
/** * Enabling package access * @return backing Node */ protected Node getNode() { return super.getNode(); }
protected void deleteDocument(Document document) throws RepositoryException { Node node = document.getCheckedOutNode(getWorkflowContext().getInternalWorkflowSession()); JcrUtils.ensureIsCheckedOut(node.getParent()); node.remove(); }
@Override public Object clone() throws CloneNotSupportedException { PublishableDocument clonedDocument = (PublishableDocument) super.clone(); clonedDocument.creationDate = creationDate; clonedDocument.createdBy = createdBy; clonedDocument.lastModificationDate = lastModificationDate; clonedDocument.lastModifiedBy = lastModifiedBy; clonedDocument.publicationDate = null; clonedDocument.availability = new String[0]; return clonedDocument; }
private String getReturnValue(Object returnObject) { if (returnObject == null) { return null; } if (returnObject instanceof Document) { Document document = (Document) returnObject; StringBuilder sb = new StringBuilder(); sb.append("document[uuid="); sb.append(document.getIdentity()); if (document.getIdentity() != null) { sb.append(",path='"); try { sb.append(document.getNode(session).getPath()); } catch (RepositoryException e) { sb.append("error:").append(e.getMessage()); } } sb.append("']"); return sb.toString(); } else { return returnObject.toString(); } }
/** * Enabling package access * @return backing Node */ protected Node getNode() { return super.getNode(); }
protected void setNodeProperty(String relPath, Node nodeValue) throws RepositoryException { if (hasNode()) { getCheckedOutNode().setProperty(relPath, nodeValue); } }
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 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; }
/** * Checks if specific privileges (e.g. hippo:editor) are granted to the current workflow context its * {@link WorkflowContext#getSubjectSession()} for a specific {@link org.hippoecm.repository.api.Document}. * <p> Implementation note: previously evaluated privileges are cached against the Document node's identifier * within the SCXMLWorkflowContext instance </p> * * @param document the document to check permission for * @param privileges the privileges (, separated) to check permission for * @return true if the current subject session has been granted all the specified privileges for the document node */ public final boolean isGranted(Document document, String privileges) { if (document == null) { return false; } return isGranted(document.getIdentity(), privileges); }
@Override public Object doExecute() throws WorkflowException, RepositoryException, RemoteException { if (getVariant() == null || !getVariant().hasNode() || getTarget() == null || getTarget().getIdentity() == null || getHistoric() == null) { throw new WorkflowException("Variant, target or date not provided"); } Node targetNode = getTarget().getNode(getWorkflowContext().getInternalWorkflowSession()); Node variantNode = getVariant().getNode(getWorkflowContext().getInternalWorkflowSession()); final Version version = lookupVersion(variantNode, getHistoric()); if (version != null) { clear(targetNode); restore(targetNode, version.getFrozenNode()); targetNode.save(); return new DocumentVariant(targetNode); } return null; }
public Document duplicate(Document offspring) throws WorkflowException, MappingException, RepositoryException, RemoteException { Node source = offspring.getNode(rootSession); return duplicate(source, COPY_OF +source.getName()); }
protected void setLongProperty(String relPath, Long newValue) throws RepositoryException { if (hasNode()) { getCheckedOutNode().setProperty(relPath, newValue); } }