0
"java.lang.IllegalStateException: Failed to resolve to a single NodeRef with parameters (store=workspace:SpacesStore uuid=null path=/app:company_home/cm:DCSL_DOCS/cm:Scanned_Docs), found 0 nodes."

above shows my erro. here is my source code which tries to create space in alfresco

protected Reference createSpace(Reference parentref, String spacename) throws Exception {
    Reference space = null;
    ParentReference parent = ReferenceToParent(parentref);
    try {
        System.out.println("Entering space:" + spacename+":");
        space = new Reference(STORE, null, parent.getPath() + "/cm:" + ISO9075.encode(spacename));
        WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{space}, STORE, null));
    } catch (Exception e1) {
        System.out.println("The space named " + spacename + " does not exist. Creating it.");
       parent.setChildName(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, normilizeNodeName(spacename)));
        //Set the space's property name
        NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, spacename)};
        // Create the space using CML (Content Manipulation Language)
        CMLCreate create = new CMLCreate("1", parent, null, null, null, Constants.TYPE_FOLDER, properties);
        CML cml = new CML();
        cml.setCreate(new CMLCreate[]{create});

        //Execute the CML create statement
        try {
            getRepositoryService().update(cml);
        } catch (Exception e2) {
            e2.printStackTrace();
            System.err.println("Can not create the space.");
            throw e2;
        }
    }
    return space;
}

Please help me to sort out this issue. thanks

4
  • 1
    What line is the exception triggering on? Commented Oct 9, 2013 at 8:58
  • 1
    you cannot create a NodeRef aka Reference using the path. this line does not work: space = new Reference(STORE, null, parent.getPath() + "/cm:" + ISO9075.encode(spacename)); use RepositoryService.queryChildren(...) or RepositoryService.query(...) to check if your space exists (wiki.alfresco.com/wiki/Repository_Web_Service) Commented Oct 9, 2013 at 12:07
  • 2
    consider to use REST or CMIS if possible - Alfresco CML is a little bit outdated Commented Oct 9, 2013 at 12:11
  • thanks Gagravarr & alfrescian :-) Commented Oct 10, 2013 at 3:59

1 Answer 1

2

Use this one instead:

ParentReference parentReference = new ParentReference(STORE, null, parent.getPath() + "/cm:" + ISO9075.encode(spacename), Constants.ASSOC_CONTAINS, Constants.ASSOC_CONTAINS);

Check the sample in your Alfresco SDK: samples\WebServiceSamples\source\org\alfresco\sample\webservice\CMLUpdates.java

In this sample it gets the parent ref with path, and creates an extra file in the folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.