@Override public boolean hasNext() { if (next != null) { return true; } // this could be optimized to retrieve batches of documents instead of // one at a time; this would need to call SQLSession.getDocumentsById // through a new CoreSession API (or improve getDocuments) for (;;) { if (!it.hasNext()) { return false; } String id = it.next(); IdRef idRef = new IdRef(id); if (!session.exists(idRef)) { continue; } DocumentModel doc; doc = session.getDocument(idRef); if (accept(doc)) { next = doc; return true; } // continue } }
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; } }
@Override public DocumentRef getRef() { return id == null ? null : new IdRef(id); }
protected TemplateMappingRemover(CoreSession session, String uid, String type2Remove) { super(session); targetRef = new IdRef(uid); this.type2Remove = type2Remove; }
@Override public void setDocument(Document document) { this.document = document; id = document.getRootElement().attributeValue(ExportConstants.ID_ATTR); String repName = document.getRootElement().attributeValue(ExportConstants.REP_NAME); srcLocation = new DocumentLocationImpl(repName, new IdRef(id)); }
protected void reinitLifecycle(List<String> docIds, CoreSession session) { for (String docId : docIds) { session.reinitLifeCycleState(new IdRef(docId)); } }
@Override public boolean canUntag(CoreSession session, String docId, String label) { return session.hasPermission(new IdRef(docId), SecurityConstants.WRITE); }
protected void removeDocument(CoreSession session, String docId) { try { session.removeDocument(new IdRef(docId)); } catch (DocumentNotFoundException e) { // ignore document that was already removed, or whose type is unknown return; } }
public DocumentModel getDocumentWithId(String id) { if (StringUtils.isEmpty(id)) { return null; } return documentManager.getDocument(new IdRef(id)); }
@Override public void deleteTask(CoreSession coreSession, String taskId) { final DocumentRef docRef = new IdRef(taskId); UnrestrictedSessionRunner runner = new UnrestrictedSessionRunner(coreSession) { @Override public void run() { session.removeDocument(docRef); } }; runner.runUnrestricted(); }
@Override public Set<String> doGetTags(CoreSession session, String docId) { DocumentRef docRef = new IdRef(docId); if (!session.exists(docRef)) { return Collections.emptySet(); } DocumentModel docModel = session.getDocument(docRef); List<Map<String, Serializable>> tags = getTags(docModel); return tags.stream().map(t -> (String) t.get(LABEL_PROPERTY)).collect(Collectors.toSet()); }
@Override public DocumentModel getTargetDocumentModel(Task task, CoreSession coreSession) { try { // TODO handle while target documents from task return coreSession.getDocument(new IdRef(task.getTargetDocumentsIds().get(0))); } catch (DocumentNotFoundException e) { return null; } }
public String getLogoURLFromDocRef(String docRef) { if (documentManager == null) { return DEFAULT_LOGO; } DocumentRef ref = new IdRef(docRef); try { DocumentModel doc = documentManager.getDocument(ref); return getLogoURL(doc); } catch (DocumentNotFoundException e) { log.error(e, e); return DEFAULT_LOGO; } }
@Override public String navigateToId(String documentId) { if (documentManager == null) { throw new IllegalStateException("documentManager not initialized"); } DocumentRef docRef = new IdRef(documentId); final DocumentModel doc = documentManager.getDocument(docRef); return navigateToDocument(doc, "view"); }
public boolean getDocumentExistsAndIsVisibleWithId(String id) { if (StringUtils.isEmpty(id)) { return false; } IdRef ref = new IdRef(id); return documentManager.exists(ref) && documentManager.hasPermission(ref, SecurityConstants.READ); }
@Override public List<DocumentRef> getVersionsRefs(DocumentRef docRef) { Document doc = resolveReference(docRef); checkPermission(doc, READ_VERSION); List<String> ids = doc.getVersionsIds(); List<DocumentRef> refs = new ArrayList<>(ids.size()); for (String id : ids) { refs.add(new IdRef(id)); } return refs; }
public DocumentModel getSelectedCollection() { if (selectedCollection == null && StringUtils.isNotBlank(selectedCollectionUid) && !isCreateNewCollection()) { try { final CoreSession session = (CoreSession) Component.getInstance("documentManager", true); selectedCollection = session.getDocument(new IdRef(selectedCollectionUid)); } catch (DocumentNotFoundException e) { log.error("Cannot fetch collection"); } } return selectedCollection; }
private DocumentModel getDocument() { if (docRef == null) { return navigationContext.getCurrentDocument(); } else { return documentManager.getDocument(new IdRef(docRef)); } }
public void addBlobs(String[] inDocIDs, String inXPath, CoreSession inSession) { for (String id : inDocIDs) { DocumentModel doc = inSession.getDocument(new IdRef(id)); addBlob(doc, inXPath); } }