Search code examples
jcrhippocms

Hippo cms add content to repository


This time I'm trying add a values to repository using component. I don't have problem with reading.

Currently, I'm trying add the city to the repository

My code:

Session session = this.getPersistableSession(request);
HippoBean siteBaseBean = request.getRequestContext().getSiteContentBaseBean();
HippoBean hippoFolder = siteBaseBean.getBean("city"); 
Node node = hippoFolder.getNode();

String path = node.getPath(); // it's working "/content/documents/myhippoproject/city"

node.addNode("4","hippo:handle");
session.save();

after this code nothing happened. I tried also:

node.addNode("4",HippoNodeType.HIPPO_NODE);

No errors and node.


Solution

  • ok, I found a solution.

    Session session = this.getPersistableSession(request);
        HippoBean siteBaseBean = request.getRequestContext().getSiteContentBaseBean();
    HippoBean hippoFolder = siteBaseBean.getBean("city"); 
        Node node = hippoFolder.getNode();
    
    HippoRepository repository = HippoRepositoryFactory.getHippoRepository("vm://");
                Session session2 = repository.login("admin", "admin".toCharArray());
    
    
                HstRequestContext requestContext = request.getRequestContext();
                WorkflowPersistenceManager wpm = null;
                wpm = getWorkflowPersistenceManager(session2);
                wpm.setWorkflowCallbackHandler(new BaseWorkflowCallbackHandler<DocumentWorkflow>() {
                    public void processWorkflow(DocumentWorkflow wf) throws Exception {
                        wf.requestPublication();
                    }
                });
    String name = "12";
    
    wpm.createAndReturn(node.getPath(), "myhippoproject:City", name, false);
    
    City city = (City) wpm.getObject(node.getPath() + "/" + name);
                    wpm.update(city);
                    session2.save();