Hi,
I upload a file "A01-200704.xls" unto space "/company_home/upload" through web service, this file can not be search by PATH:\"/app:company_home/cm:upload/cm:A01-200704.xls\". But if I upload this file through Add Content of Alfresco admin browser page, it can be searched, i think there should be some aspect or attribute lost when uploading file through web service, can somebody help ? Thanks a lot.
// Start the session
AuthenticationUtils.startSession("admin", "admin");
try{
String[] files = { "A01_200704.xls" };
// Create a reference to the parent where we want to create content
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home/cm:upload", Constants.ASSOC_CONTAINS, null);
RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
ContentServiceSoapBindingStub contentService =WebServiceFactory.getContentService();
NamedValue[] contentProps = new NamedValue[1];
NamedValue[] titledProps = new NamedValue[2];
CML cml = new CML();
Query query = new Query();
for(String fileName : files ){
// Assign name
companyHomeParent.setChildName("cm:" + fileName);
//
contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, fileName);
//Construct CML statement to add titled aspect
titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, fileName);
titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "Financial report through JobServer");
CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
//
query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/app:company_home/cm:upload/cm:" + fileName + "\"");
ResultSet rs =repositoryService.query(storeRef, query, false).getResultSet();
if(rs.getTotalRowCount() > 0){ //file already exist, then, delete it and create a new one
ResultSetRow[] rsRows = rs.getRows();
System.out.println("Removing file " + rsRows[0].getColumns(1).getValue()); //show file name
Reference reference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
CMLDelete delete = new CMLDelete(predicate);
cml.setDelete(new CMLDelete[] {delete});
repositoryService.update(cml);
}
System.out.println("Creating new content …");
//create content
// Construct CML statement to create content node
// Note: Assign "1" as a local id, so we can refer to it in subsequent
// CML statements within the same CML block
CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);
// Construct CML Block
cml = new CML();
cml.setCreate(new CMLCreate[] {create});
cml.setAddAspect(new CMLAddAspect[] {addAspect});
// Issue CML statement via Repository Web Service and retrieve result
// Note: Batching of multiple statements into a single web call
UpdateResult[] result = repositoryService.update(cml);
Reference content = result[0].getDestination();
// Write some content
//ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
FileInputStream is = new FileInputStream("E:/Uploads/Anytime/" + fileName);
byte[] bytes = ContentUtils.convertToByteArray(is);
ContentFormat format = new ContentFormat("application/vnd.excel", "UTF-8");
// Write the content
contentService.write(content, Constants.PROP_CONTENT, bytes, format);
}
}catch(Throwable e){
System.out.println(e.toString());
}finally{
// End the session
AuthenticationUtils.endSession();
//System.exit(0);
}