@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 } }
protected boolean checkUnrestricted(CoreSession session) { return session.getPrincipal().isAdministrator(); }
public void save(CoreSession session) { session.saveDocument(doc); }
/** * Constructs a {@link UnrestrictedSessionRunner} given an existing session (which may or may not be already * unrestricted). * <p> * Originating user is taken on given session. * * @param session the available session */ protected UnrestrictedSessionRunner(CoreSession session) { this.session = session; sessionIsAlreadyUnrestricted = checkUnrestricted(session); if (sessionIsAlreadyUnrestricted) { repositoryName = null; } else { repositoryName = session.getRepositoryName(); } NuxeoPrincipal pal = session.getPrincipal(); if (pal != null) { originatingUsername = pal.getName(); } }
if (!session.exists(ref)) { return this; return new InstanceRef(this, session.getPrincipal());
protected DocumentModel getDocumentationRoot(CoreSession session) { DocumentRef rootRef = new PathRef(Root_PATH + Root_NAME); if (session.exists(rootRef)) { return session.getDocument(rootRef); } UnrestrictedRootCreator creator = new UnrestrictedRootCreator(session); creator.runUnrestricted(); // flush caches session.save(); return session.getDocument(creator.getRootRef()); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel target) throws OperationException { resetSchemaProperties(target); if (saveDocument) { target = session.saveDocument(target); if (save) { session.save(); } } return target; } }
public DocumentModel getDocumentWithPath(String path) { if (StringUtils.isEmpty(path)) { return null; } return documentManager.getDocument(new PathRef(path)); }
protected DocumentModel getParentDocument(DocumentModel documentModel) { if (documentManager.hasPermission(documentModel.getParentRef(), SecurityConstants.READ)) { return documentManager.getDocument(documentModel.getParentRef()); } return null; }
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; }
protected DocumentModelList getChildrenFor(String containerId) throws NuxeoException { try { // don't use the query model: is deprecated & has a result size limitation too small return documentManager.query(String.format(QUERY_DOC_ORDERED_CHILDREN_QM, containerId), CST_MAX_RESULT_SET_SIZE); } catch (Exception e) { throw new NuxeoException(e); } }
@OperationMethod public DocumentModel run(DocumentModel doc) { try { session.orderBefore(doc.getParentRef(), doc.getName(), before != null ? before.getName() : null); session.save(); return session.getDocument(doc.getRef()); } catch (DocumentNotFoundException e) { throw new NuxeoException(NOT_SAME_FOLDER_ERROR_MSG); } }
public PublicationNode getToutaticeNodeByPath(String path) throws NuxeoException { DocumentRef docRef = new PathRef(path); if (coreSession.hasPermission(docRef, SecurityConstants.READ)) { return new ToutaticeCoreFolderPublicationNode(coreSession.getDocument(new PathRef(path)), getConfigName(), getSessionId(), factory); } else { return new VirtualCoreFolderPublicationNode(coreSession.getSessionId(), path, getConfigName(), sid, factory); } }
protected boolean cleanTrashPath(DocumentModel parent, String name) { Path checkedPath = new Path(parent.getPathAsString()).append(name); if (getSession().exists(new PathRef(checkedPath.toString()))) { DocumentModel model = getSession().getDocument(new PathRef(checkedPath.toString())); if (model != null && model.isTrashed()) { name = name + "." + System.currentTimeMillis(); getSession().move(model.getRef(), parent.getRef(), name); return true; } } return false; }
@POST @Consumes(MediaType.APPLICATION_JSON) public Response doPost(DocumentModel inputDoc) { CoreSession session = ctx.getCoreSession(); if (StringUtils.isBlank(inputDoc.getType()) || StringUtils.isBlank(inputDoc.getName())) { return Response.status(Status.BAD_REQUEST).entity("type or name property is missing").build(); } DocumentModel createdDoc = session.createDocumentModel(doc.getPathAsString(), inputDoc.getName(), inputDoc.getType()); DocumentModelJsonReader.applyPropertyValues(inputDoc, createdDoc); createdDoc = session.createDocument(createdDoc); session.save(); return Response.ok(createdDoc).status(Status.CREATED).build(); }
protected void notifyEvent(CoreSession session, String eventId, DocumentModel doc, boolean immediate) { DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), doc); ctx.setProperties(new HashMap<>(doc.getContextData())); ctx.setCategory(DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); ctx.setProperty(CoreEventConstants.REPOSITORY_NAME, session.getRepositoryName()); ctx.setProperty(CoreEventConstants.SESSION_ID, session.getSessionId()); Event event = ctx.newEvent(eventId); event.setInline(false); event.setImmediate(immediate); EventService eventService = Framework.getService(EventService.class); eventService.fireEvent(event); }
@Override @Begin(pageflow = "createWorkspace", nested = true) @Factory(value = "tmpWorkspace") public DocumentModel getTmpWorkspace() { if (tmpWorkspace == null) { tmpWorkspace = documentManager.createDocumentModel("Workspace"); } return tmpWorkspace; }
private boolean canDeleteComment(String author, DocumentModel document) { boolean canDelete = false; Principal user = session.getPrincipal(); if (user != null) { boolean isUserAuthor = user.getName().equals(author); boolean isUserAdmin = ((NuxeoPrincipal) user).isAdministrator(); boolean userHasAllRights = session.hasPermission(document.getRef(), SecurityConstants.EVERYTHING); canDelete = isUserAuthor || isUserAdmin || userHasAllRights; } return canDelete; }
protected void add(Statement statement) { DocumentModel rel = session.createDocumentModel(null, "relation", docType); rel = setRelationProperties(rel, statement); session.createDocument(rel); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentRef doc) { session.setLock(doc); return session.getDocument(doc); }