As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
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); }