06-23-2010 10:19 AM
07-14-2010 09:48 AM
07-14-2010 10:35 AM
07-15-2010 04:51 AM
07-15-2010 05:56 AM
07-15-2010 07:40 AM
07-15-2010 08:00 AM
FileInputStream fis =null;
RepositoryServiceSoapBindingStub repositoryService =null;
ContentServiceSoapBindingStub contentService =null;
AuthoringServiceSoapBindingStub authoringService = null;
try {
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home/app:dictionary/app:models" , Constants.ASSOC_CONTAINS, null);
repositoryService =WebServiceFactory.getRepositoryService();
contentService =WebServiceFactory.getContentService();
authoringService = WebServiceFactory.getAuthoringService();
Reference contentReference= null;
String ModelXmlFile = Path + FileName;
File modelFile = new File(ModelXmlFile);
NamedValue[] contentProps = new NamedValue[2];
NamedValue[] titledProps = new NamedValue[2];
CML cml = null;
Query query = null;
fis= new FileInputStream(ModelXmlFile);
byte[] bytes = ContentUtils.convertToByteArray(fis);
ContentFormat format = new ContentFormat("text/xml", "UTF-8");
companyHomeParent.setChildName("{http://www.alfresco.org/model/content/1.0}" + FileName);
contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, FileName);
//contentProps[1] = Utils.createNamedValue(ContentModel.PROP_MODEL_ACTIVE,"YES");
titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, FileName);
titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "Sample description.");
CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/app:company_home/app:dictionary/app:models/cm:" + ISO9075.encode(FileName) + "\"");
ResultSet rs =repositoryService.query(storeRef, query, false).getResultSet();
if(rs.getTotalRowCount() > 0) {
ResultSetRow[] rsRows = rs.getRows();
contentReference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
System.out.println("Removing file " + FileName); //show file name
//Reference reference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
cml = new CML();
Predicate predicate = new Predicate(new Reference[]{contentReference}, null, null);
CMLDelete delete = new CMLDelete(predicate);
cml.setDelete(new CMLDelete[] {delete});
repositoryService.update(cml);
CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);
/*NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants,newname)};
create.setProperty(properties);*/
cml = new CML();
cml.setCreate(new CMLCreate[] {create});
cml.setAddAspect(new CMLAddAspect[] {addAspect});
UpdateResult[] result = repositoryService.update(cml);
Reference content = result[0].getDestination();
contentService.write(content,Constants.PROP_CONTENT , bytes, format);
}
else{
CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);
cml = new CML();
cml.setCreate(new CMLCreate[] {create});
cml.setAddAspect(new CMLAddAspect[] {addAspect});
UpdateResult[] result = repositoryService.update(cml);
Reference content = result[0].getDestination();
contentService.write(content,Constants.PROP_CONTENT , bytes, format);
}
}catch(FileNotFoundException fnf) {
System.err.println("Exception is" +fnf);
}catch(RepositoryFault rf) {
System.err.println("Exception is" +rf);
}catch(AxisFault af) {
System.err.println("Exception is" +af);
}catch (Exception e) {
System.err.println("Exception is" +e);
}catch(OutOfMemoryError ome){
System.err.println("Exception is" +ome);
}
07-15-2010 09:07 AM
07-15-2010 09:11 AM
07-15-2010 09:20 AM
07-16-2010 02:18 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.