星期四, 1月 27, 2011

[Alfresco] Peer-Association 範例

BaseWebServiceSystemTest.java 
使用foundation api範例



// setup user avatar association
if (this.photoRef != null){
                List<AssociationRef> refs = this.getNodeService().getTargetAssocs(personRef, ContentModel.ASSOC_AVATAR);
                // remove old association if it exists
                if (refs.size() == 1)
                {
                    NodeRef existingRef = refs.get(0).getTargetRef();
                    this.getNodeService().removeAssociation(
                            personRef, existingRef, ContentModel.ASSOC_AVATAR);
                }
                // setup new association
                this.getNodeService().createAssociation(personRef, this.photoRef, ContentModel.ASSOC_AVATAR);
}

DictionaryWebService.java
使用webservice api範例
// Create test content
ParentReference contentParentRef = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}testContent");
NamedValue[] contentProperties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, CONTENT_NAME, null)};
CMLCreate createContent = new CMLCreate("testContent", contentParentRef, null, null, null, Constants.TYPE_CONTENT, contentProperties);
            
ParentReference contentParentRef2 = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}testContent2");
NamedValue[] contentProperties2 = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, CONTENT_NAME_2, null)};
CMLCreate createContent2 = new CMLCreate("testContent2", contentParentRef2, null, null, null, Constants.TYPE_CONTENT, contentProperties2);
            
// Create test folder
ParentReference folderParentRef = new ParentReference(BaseWebServiceSystemTest.store, BaseWebServiceSystemTest.rootReference.getUuid(), null, Constants.ASSOC_CHILDREN, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}testFolder");            
NamedValue[] folderProperties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, FOLDER_NAME, null)};
CMLCreate createFolder = new CMLCreate("testFolder", folderParentRef, null, null, null, Constants.TYPE_FOLDER, folderProperties);
            
// Create an associatin between the content
CMLAddAspect cmlAddAspect = new CMLAddAspect("{http://www.alfresco.org/model/content/1.0}attachable", null, null, "testContent");
CMLCreateAssociation createAssoc = new CMLCreateAssociation(null, "testContent", null, "testContent2", Constants.createQNameString(
Constants.NAMESPACE_CONTENT_MODEL, "attachments"));
            
CML cml = new CML();
cml.setCreate(new CMLCreate[]{createContent, createContent2, createFolder});
cml.setAddAspect(new CMLAddAspect[]{cmlAddAspect});
cml.setCreateAssociation(new CMLCreateAssociation[]{createAssoc});
            
UpdateResult[] updateResult = this.repositoryService.update(cml);

沒有留言:

張貼留言

留個話吧:)