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

Priyan RockZ
  • 1,605
  • 7
  • 40
  • 68
  • 1
    What line is the exception triggering on? – Gagravarr Oct 09 '13 at 08: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 (https://wiki.alfresco.com/wiki/Repository_Web_Service) – alfrescian Oct 09 '13 at 12:07
  • 2
    consider to use REST or CMIS if possible - Alfresco CML is a little bit outdated – alfrescian Oct 09 '13 at 12:11
  • thanks Gagravarr & alfrescian :-) – Priyan RockZ Oct 10 '13 at 03:59

1 Answers1

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.

Tahir Malik
  • 6,623
  • 15
  • 22