09-16-2010 08:11 AM
public static Reference createFolder(String folderName) throws RepositoryFault, RemoteException {
RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
String currentPath = getCompanyHome().getPath();
String newPath = currentPath.concat("/cm:").concat(folderName);
Reference folder = getCompanyHome();
folder.setPath(newPath);
try {
Node[] nodeFolder = repoService.get(new Predicate(new Reference[] { folder }, getStore(), null));
folder = nodeFolder[0].getReference();
if (log.isDebugEnabled()) {
log.debug("createFolder, la cartella [" + folderName + "] esiste già");
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("createFolder, la cartella [" + folderName + "] NON esiste, procedo nella sua creazione");
}
ParentReference parent = new ParentReference(getStore(), null, ConfigManager.getInstance().getConfigValue("alfresco.percorso.company.home"), Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, folderName));
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, folderName) };
CMLCreate cmlCreate = new CMLCreate(folderName, parent, null, null, null, Constants.TYPE_FOLDER, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[] { cmlCreate });
UpdateResult[] updateResults = repoService.update(cml);
folder = updateResults[0].getDestination();
}
return folder;
}
09-16-2010 09:14 AM
private static String findFolderOrContent(Reference root, String toSearch) {
String idReference = null;
RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
try {
QueryResult results = repoService.queryChildren(root);
ResultSetRow[] rows = results.getResultSet().getRows();
ResultSetRow currentRow;
NamedValue[] colums;
String currentName;
String currentValue;
for (int i = 0; i < rows.length; i++) {
currentRow = rows[i];
colums = currentRow.getColumns();
for (int y = 0; y < colums.length; y++) {
currentName = colums[y].getName();
if (currentName.equals(Constants.PROP_NAME)) {
currentValue = colums[y].getValue();
if (currentValue.equals(toSearch)) {
log.info("findFolderOrContent, [" + toSearch + "] trovato");
log.info("findFolderOrContent, id [" + currentRow.getNode().getId() + "]");
idReference = currentRow.getNode().getId();
}
}
}
}
} catch (RepositoryFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return idReference;
}
public static Reference createOrGetId(String name) throws RepositoryFault, RemoteException {
Reference folder = getCompanyHome();
try {
String idFind = findFolderOrContent(folder, name);
if (idFind != null) {
if (log.isDebugEnabled()) {
log.debug("createOrGetId, la cartella [" + name + "] esiste già");
}
folder = new Reference(getStore(), idFind, null);
}
else {
if (log.isDebugEnabled()) {
log.debug("createOrGetId, la cartella [" + name + "] NON esiste, procedo nella sua creazione");
}
RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
String currentPath = getCompanyHome().getPath();
String newPath = currentPath.concat("/cm:").concat(name);
folder.setPath(newPath);
ParentReference parent = new ParentReference(getStore(), null, ConfigManager.getInstance().getConfigValue("alfresco.percorso.company.home"), Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, name));
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, name) };
CMLCreate cmlCreate = new CMLCreate(name, parent, null, null, null, Constants.TYPE_FOLDER, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[] { cmlCreate });
UpdateResult[] updateResults = repoService.update(cml);
folder = updateResults[0].getDestination();
}
} catch (Exception e) {
log.error("createOrGetId, Exception ", e);
}
log.info("createOrGetId, id [" + folder.getUuid() + "]");
return folder;
}
09-16-2010 09:56 AM
09-16-2010 10:22 AM
An elaborated guess: try endoding your paths using helper class org.alfresco.webservice.util.ISO9075#encode()
HTH
Gyro
new Reference(getStore(), id, null);
but I can't retrive the path.09-16-2010 10:35 AM
Other question, if I want to retrive the reference from id, how I can do?
I try with this codebut I can't retrive the path.new Reference(getStore(), id, null);
Store spacesStore = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
…
Reference companyHome = new Reference(spacesStore, folderId, null);
09-16-2010 10:39 AM
Store spacesStore = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
07-05-2011 04:46 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.