protected void add(Statement statement) { DocumentModel rel = session.createDocumentModel(null, "relation", docType); rel = setRelationProperties(rel, statement); session.createDocument(rel); }
@Override protected DocumentModel execute(CoreSession session, DocumentModel document, Properties properties, boolean save) throws NuxeoException, IOException { DocumentHelper.setProperties(session, document, properties); return session.createDocument(document); }
@Override public void populate(CoreSession session) { DocumentModel doc = session.createDocumentModel("/", "default-domain", "Domain"); doc.setProperty("dublincore", "title", "Domain"); doc = session.createDocument(doc); doc = session.createDocumentModel("/default-domain/", "workspaces", "WorkspaceRoot"); doc.setProperty("dublincore", "title", "Workspaces"); doc = session.createDocument(doc); doc = session.createDocumentModel("/default-domain/", "sections", "SectionRoot"); doc.setProperty("dublincore", "title", "Workspaces"); doc = session.createDocument(doc); doc = session.createDocumentModel("/default-domain/", "templates", "TemplateRoot"); doc.setProperty("dublincore", "title", "Templates"); doc.setProperty("dublincore", "description", "Root of workspaces templates"); doc = session.createDocument(doc); doc = session.createDocumentModel("/default-domain/workspaces", "test", "Workspace"); doc.setProperty("dublincore", "title", "workspace"); doc = session.createDocument(doc); }
@OperationMethod public BusinessAdapter run(BusinessAdapter input) { DocumentModel document = input.getDocument(); // TODO the code intends to copy to a new document with parentPath+name but it's buggy and does not do that // TODO currently we just create a placeless document with an random name // TODO use createDocumentModel instead of document to fix // createDocumentModel.copyContent(document); document = session.createDocument(document); return document.getAdapter(input.getClass()); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws IOException { if (name == null) { name = "Untitled"; } DocumentModel newDoc = session.createDocumentModel(doc.getPathAsString(), name, type); if (content != null) { DocumentHelper.setProperties(session, newDoc, content); } return session.createDocument(newDoc); }
@POST @Path("{adapterName}/{docName}") public Object doPutAdapter(@PathParam("adapterName") String adapterName, @PathParam("docName") String docName, BusinessAdapter input) { DocumentModel document = input.getDocument(); DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel parentDoc = dobj.getDocument(); document.setPathInfo(parentDoc.getPathAsString(), docName); CoreSession session = ctx.getCoreSession(); document = session.createDocument(document); session.save(); BusinessAdapter adapter = document.getAdapter(input.getClass()); return new DefaultJsonAdapter(adapter); }
@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(); }
@Override public void populate(CoreSession session) { super.populate(session); DocumentModel doc = session.createDocumentModel("/", "testBlob", "File"); doc.setPropertyValue("file:content", (Serializable) Blobs.createBlob("one")); session.createDocument(doc); File docFile = FileUtils.getResourceFileFromContext("hello.doc"); DocumentModel doc2 = session.createDocumentModel("/", "testBlob2", "File"); doc2.setPropertyValue("file:content", new FileBlob(docFile)); session.createDocument(doc2); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } }
private void createChildren(CoreSession s, DocumentModel p, int depth) { if (depth > 0) { for (int i = 0; i < SIZE; i++) { s.createDocument(s.createDocumentModel(p.getPathAsString(), p.getName() + "file" + i, "File")); s.createDocument(s.createDocumentModel(p.getPathAsString(), p.getName() + "note" + i, "Note")); DocumentModel child = s.createDocumentModel(p.getPathAsString(), p.getName() + "doc" + i, "ComplexDoc"); child.setPropertyValue("dc:modified", new Date()); child.setPropertyValue("dc:nature", "article"); child.setPropertyValue("dc:contributors", new String[] { "bob", "Administrator" }); child = s.createDocument(child); s.createProxy(child.getRef(), p.getRef()); DocumentModel folder = s.createDocumentModel(p.getPathAsString(), p.getName() + "folder" + i, "Folder"); folder = s.createDocument(folder); createChildren(s, folder, depth - 1); } } } }
public static synchronized DocumentModel getOrCreate(CoreSession session, String rootPath, String id, String folderType) { String path = String.format("%s/%s", rootPath, id); DocumentRef pathRef = new PathRef(path); boolean exists = session.exists(pathRef); if (exists) { DocumentModel existing = session.getDocument(pathRef); if (!existing.isTrashed()) { return existing; } } // create it DocumentModel newDocument = session.createDocumentModel(rootPath, IdUtils.generateId(id, "-", true, 24), folderType); newDocument.setPropertyValue(TITLE_PROPERTY_NAME, id); newDocument = session.createDocument(newDocument); return newDocument; }
protected static DocumentModel createUserWorkspaceDomain( CoreSession unrestrictedSession, String domainName) throws ClientException { DocumentModel doc = unrestrictedSession.createDocumentModel("/",domainName, "Domain"); doc.setProperty("dublincore", "title", domainName); doc.setProperty("dublincore", "description", ""); doc = unrestrictedSession.createDocument(doc); ACP acp = new ACPImpl(); ACE denyEverything = new ACE(SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false); ACL acl = new ACLImpl(); acl.setACEs(new ACE[] { denyEverything }); acp.addACL(acl); doc.setACP(acp, true); return doc; }
@Override public DocumentModel createFolder(String parentPath, String name) { DocumentModel parent = resolveLocation(parentPath); if (!parent.isFolder()) { throw new NuxeoException("Can not create a child in a non folderish node"); } String targetType = "Folder"; if ("WorkspaceRoot".equals(parent.getType())) { targetType = "Workspace"; } // name = cleanName(name); cleanTrashPath(parent, name); DocumentModel folder = getSession().createDocumentModel(parent.getPathAsString(), name, targetType); folder.setPropertyValue("dc:title", name); folder = getSession().createDocument(folder); return folder; }
protected static String getRootPath(CoreSession session, String basePath, String suffix) { PathRef rootRef = new PathRef(basePath); if (session.exists(rootRef)) { Path path = new Path(basePath).append(suffix); rootRef = new PathRef(path.toString()); if (session.exists(rootRef)) { return path.toString(); } else { DocumentModel root = session.createDocumentModel("Folder"); root.setPathInfo(basePath, suffix); root = session.createDocument(root); return root.getPathAsString(); } } return null; }
/** * Finds the first domain by name, and creates under it the root container for the structure containing the route * instances. */ protected DocumentModel createDocumentRoutesStructure(String routeStructureDocType, String id, CoreSession session) { DocumentModel root = session.createDocumentModel(session.getRootDocument().getPathAsString(), id, routeStructureDocType); root.setPropertyValue(DC_TITLE, routeStructureDocType); root = session.createDocument(root); ACP acp = session.getACP(root.getRef()); ACL acl = acp.getOrCreateACL(ACL.LOCAL_ACL); acl.addAll(getACEs()); session.setACP(root.getRef(), acp, true); return root; }
@Override public void run() { DocumentModel root = session.createDocumentModel(Root_PATH, Root_NAME, "Folder"); root.setProperty("dublincore", "title", Root_NAME); root = session.createDocument(root); ACL acl = new ACLImpl(); acl.add(new ACE(Write_Grp, "Write", true)); acl.add(new ACE(Read_Grp, "Read", true)); ACP acp = root.getACP(); acp.addACL(acl); session.setACP(root.getRef(), acp, true); rootRef = root.getRef(); // flush caches session.save(); }
@Override public void run() { DocumentRef pathRef = new PathRef(parentPath); if (session.exists(pathRef)) { taskRootDoc = session.getDocument(pathRef); } else { Path path = new Path(parentPath); taskRootDoc = session.createDocumentModel(path.removeLastSegments(1).toString(), path.lastSegment(), TaskConstants.TASK_ROOT_TYPE_NAME); taskRootDoc = session.createDocument(taskRootDoc); ACP acp = taskRootDoc.getACP(); ACL acl = acp.getOrCreateACL(ACL.LOCAL_ACL); acl.add(new ACE("Everyone", "Everything", false)); taskRootDoc.setACP(acp, true); taskRootDoc = session.saveDocument(taskRootDoc); } }
@Override public void run() { DocumentModel root = session.createDocumentModel(parentPath, name, "Workspace"); root.setProperty("dublincore", "title", name); root = session.createDocument(root); if (setAcl) { ACL acl = new ACLImpl(); acl.add(new ACE(Write_Grp, "Write", true)); acl.add(new ACE(Read_Grp, "Read", true)); ACP acp = root.getACP(); acp.addACL(acl); session.setACP(root.getRef(), acp, true); } rootRef = root.getRef(); // flush caches session.save(); }
@Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getAncestorRef(session, docModel); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(s, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }
public void createContentStructure(DocumentModel eventDoc) { initSession(eventDoc); if (eventDoc.isVersion() || !isTargetEmpty(eventDoc)) { return; } setAcl(acl, eventDoc.getRef()); for (TemplateItemDescriptor item : template) { String itemPath = eventDoc.getPathAsString(); if (item.getPath() != null) { itemPath += "/" + item.getPath(); } DocumentModel newChild = session.createDocumentModel(itemPath, item.getId(), item.getTypeName()); newChild.setProperty("dublincore", "title", item.getTitle()); newChild.setProperty("dublincore", "description", item.getDescription()); setProperties(item.getProperties(), newChild); newChild = session.createDocument(newChild); setAcl(item.getAcl(), newChild.getRef()); } }
public static ServiceInfoDocAdapter create(ServiceInfo si, CoreSession session, String containerPath) { DocumentModel doc = session.createDocumentModel(TYPE_NAME); String name = computeDocumentName("service-" + si.getId()); String targetPath = new Path(containerPath).append(name).toString(); boolean exist = false; if (session.exists(new PathRef(targetPath))) { exist = true; doc = session.getDocument(new PathRef(targetPath)); } doc.setPathInfo(containerPath, name); doc.setPropertyValue("dc:title", si.getId()); doc.setPropertyValue(PROP_CLASS_NAME, si.getId()); doc.setPropertyValue(PROP_COMPONENT_ID, si.getComponentId()); doc.setPropertyValue(PROP_OVERRIDEN, si.isOverriden()); if (exist) { doc = session.saveDocument(doc); } else { doc = session.createDocument(doc); } return new ServiceInfoDocAdapter(doc); }