protected boolean hasPermission(CoreSession session, DocumentModel doc, Set<String> permissions, boolean required) { for (String permission : permissions) { if ((required && !session.hasPermission(doc.getRef(), permission)) || (!required && session.hasPermission(doc.getRef(), permission))) { return false; } } return true; }
public DocumentTreeIterator(CoreSession session, DocumentModel root, boolean excludeRoot) { this.root = root; this.session = session; if (excludeRoot) { sequence = session.getChildrenIterator(root.getRef(), null, null, null); } else { sequence = new OneDocSequence(root); } }
@Override public DocumentModel next() { // satisfy iterator contract - throw an exception if no more elements to // iterate if (!hasNext()) { throw new NoSuchElementException("no more documents to iterate over"); } // we have a non empty sequence to iterate over DocumentModel doc = sequence.next(); if (doc.isFolder()) { // TODO: load children after the document was traversed // update the sequence queue with children from this folder queue.add(session.getChildrenIterator(doc.getRef(), null, null, null)); } return doc; }
@Override public <T extends LocalConfiguration> T getConfiguration(Class<T> configurationClass, String configurationFacet, DocumentModel currentDoc) { if (currentDoc == null || currentDoc.getRef() == null) { return null; T localConfiguration = session.adaptFirstMatchingDocumentWithFacet(currentDoc.getRef(), configurationFacet, configurationClass); if (localConfiguration == null) { break; parentRef = parentDoc.getRef(); if (parentRef == null) { break;
public DocumentLocationImpl(DocumentModel doc) { serverName = doc.getRepositoryName(); docRef = doc.getRef(); String id = doc.getId(); if (id != null) { docIdRef = new IdRef(id); } else { docIdRef = null; } String path = doc.getPathAsString(); if (path != null) { docPathRef = new PathRef(path); } else { docPathRef = null; } }
/** * @since 5.4 */ @Override public DocumentModel getSourceDocument(DocumentModel document) { return documentManager.getSourceDocument(document.getRef()); }
@Override public String getCurrentDocumentFullUrl() { if (currentDocument == null) { log.error("current document is null"); return null; } return DocumentLocator.getFullDocumentUrl(getCurrentServerLocation(), currentDocument.getRef()); }
@Override public Object getAdaptedValue(OperationContext ctx, Object objectToAdapt) throws TypeAdaptException { DocumentRefList docs = new DocumentRefListImpl(); docs.add(((DocumentModel) objectToAdapt).getRef()); return docs; }
/** * Checks if current user has given permission * on current document. * * @param permission * @return true if current user has given permission * on current document */ public boolean hasPermission(String permission){ DocumentModel currentDoc = navigationContext.getCurrentDocument(); return documentManager.hasPermission(currentDoc.getRef(), permission); }
public boolean getCanEdit() { if (documentsListsManager.isWorkingListEmpty(CURRENT_DOCUMENT_SELECTION)) { return false; } List<DocumentModel> docs = documentsListsManager.getWorkingList(CURRENT_DOCUMENT_SELECTION); for (DocumentModel doc : docs) { if (!documentManager.hasPermission(doc.getRef(), SecurityConstants.WRITE)) { return false; } } return true; }
public String getCurrentLifeCycleState() throws NuxeoException { try { DocumentModel currDoc = getCurrentDocument(); return documentManager.getCurrentLifeCycleState(currDoc.getRef()); } catch (NuxeoException e) { throw new ClientRuntimeException(e); } }
protected DocumentModel getParentDocument(CoreSession session, DocumentModel doc) { DocumentModel parent; if (session.exists(doc.getRef())) { parent = session.getParentDocument(doc.getRef()); } else { Path parentPath = doc.getPath().removeLastSegments(1); parent = session.getDocument(new PathRef(parentPath.toString())); } return parent; }
@Path("{label}") public DocumentObject getVersion(@PathParam("label") String label) { DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel doc = dobj.getDocument(); List<VersionModel> versions = dobj.getCoreSession().getVersionsForDocument(doc.getRef()); for (VersionModel v : versions) { if (label.equals(v.getLabel())) { return dobj.newDocument(dobj.getCoreSession().getDocumentWithVersion(doc.getRef(), v)); } } throw new WebResourceNotFoundException("No such version " + label + " for document" + getTarget().getPath()); }
@Override @Observer(EventNames.BEFORE_DOCUMENT_CHANGED) public void followTransition(DocumentModel changedDocument) { String transitionToFollow = (String) changedDocument.getContextData(LIFE_CYCLE_TRANSITION_KEY); if (transitionToFollow != null) { documentManager.followTransition(changedDocument.getRef(), transitionToFollow); documentManager.save(); } }
/** * Checks the selected document in, with the selected version. */ @Override public String checkIn() { DocumentModel currentDocument = navigationContext.getCurrentDocument(); documentManager.checkIn(currentDocument.getRef(), null, null); retrieveVersions(); return navigationContext.getActionResult(currentDocument, UserAction.AFTER_EDIT); }
protected String moveToBottom(DocumentModel container, String documentsListName) { DocumentRef containerRef = container.getRef(); DocumentModel selectedDocument = documentsListsManager.getWorkingList(documentsListName).get(0); documentManager.orderBefore(containerRef, selectedDocument.getName(), null); documentManager.save(); notifyChildrenChanged(container); addFacesMessage("feedback.order.movedToBottom"); return null; }
@DELETE public Object removeLock() { try { DocumentModel doc = getTarget().getAdapter(DocumentModel.class); ctx.getCoreSession().removeLock(doc.getRef()); doc.refresh(); return null; // TODO } catch (NuxeoException e) { e.addInfo("Failed to unlock document"); throw e; } }