12-30-2010 03:31 PM
Reference baseFolder = createSpace("Testing Space");
Reference insideFolder = createSpace(baseFolder, "inside-test");
protected static Reference createSpace(String spacename) throws Exception
{
Reference space = null;
// Create the space if it is not already existent
try {
//Therefore a reference to the maybe not existent space is required
System.out.println("Entering space " + spacename);
space = new Reference(STORE, null, getCompanyHome().getPath() + "/cm:" + normilizeNodeName(spacename));
getRepositoryService().get(new Predicate(new Reference[]{space}, STORE, null));
}
catch (Exception e1)
{
System.out.println("The space named " + spacename + " does not exist. Creating it.");
ParentReference companyHome = getCompanyHome();
// Set Company Home as the parent space
companyHome.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", companyHome, 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) {
System.err.println("Can not create the space.");
throw e2;
}
}
return space;
}
protected static 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:" + normilizeNodeName(spacename));
WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{space}, STORE, null));
System.out.println("What the hell");
}
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) {
System.err.println("Can not create the space.");
throw e2;
}
}
return space;
}
protected static ParentReference ReferenceToParent(Reference spaceref)
{
ParentReference parent = new ParentReference();
parent.setStore(STORE);
parent.setPath(spaceref.getPath());
parent.setUuid(spaceref.getUuid());
parent.setAssociationType(Constants.ASSOC_CONTAINS);
return parent;
}
//Blanks are allowed in space names but not in paths. Because the path should depend on the name we need a version of the name which contains no blanks
protected static String normilizeNodeName(String name)
{
return name.replace(" ","_");
}
protected static RepositoryServiceSoapBindingStub getRepositoryService()
{
return WebServiceFactory.getRepositoryService();
}
protected static ContentServiceSoapBindingStub getContentService()
{
return WebServiceFactory.getContentService();
}
protected static ParentReference getCompanyHome()
{
ParentReference companyHomeParent = new ParentReference(STORE, null, "/app:company_home", Constants.ASSOC_CONTAINS, null);
return companyHomeParent;
}
12-31-2010 03:49 AM
…
String spaceName = "Testing Space";
Reference baseFolder = createSpace(spaceName);
…
Node[] nodeArray = getRepositoryService().get(new Predicate(new Reference[] { space }, WORKSPACE_STORE, null));
space = nodeArray[0].getReference();
UpdateResult[] results = getRepositoryService().update(cml);
space = results[0].getDestination();
space = new Reference(STORE, null, getCompanyHome().getPath() + "/cm:" + ISO9075.encode(spacename));
When you create a space name do not use ISO9075!
02-10-2011 04:47 PM
02-11-2011 03:20 AM
space = new Reference(STORE, null, getCompanyHome().getPath() + "/cm:" + ISO9075.encode(spacename));
When you create a space name do not use ISO9075!
02-11-2011 09:35 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.