AnsweredAssumed Answered

Secondary parent

Question asked by tfornoville on Aug 8, 2007
I changed the FirstFoundationClient in the 2.0.1 distribution to create 2 spaces and then add content making one space the primary parent and the other a secondary parent.

Here's the code

AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
authenticationService.authenticate("admin", "admin".toCharArray());

SearchService searchService = serviceRegistry.getSearchService();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\"");
      NodeRef companyHome = resultSet.getNodeRef(0);

FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
FileInfo primary = fileFolderService.create(companyHome, "primary", ContentModel.TYPE_FOLDER);
FileInfo second = fileFolderService.create(companyHome, "second", ContentModel.TYPE_FOLDER);


//
// create new content node
//

// assign name
String name = "Foundation API sample (" + System.currentTimeMillis() + ")";
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, name);

// create content node
NodeService nodeService = serviceRegistry.getNodeService();
ChildAssociationRef association = nodeService.createNode(primary.getNodeRef(),
      ContentModel.ASSOC_CONTAINS,
      QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
ContentModel.TYPE_CONTENT,
contentProps);
NodeRef content = association.getChildRef();

// add titled aspect (for Web Client display)
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
titledProps.put(ContentModel.PROP_TITLE, name);
titledProps.put(ContentModel.PROP_DESCRIPTION, name);
nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);

//
// write some content to new node
//

ContentService contentService = serviceRegistry.getContentService();
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
String text = "The quick brown fox jumps over the lazy dog";
writer.putContent(text);

//add secondary parent
nodeService.addChild(second.getNodeRef(), content, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS);

This all works fine but is there a way to delete the content from the secondary parent while leaving it under the primary USING THE WEBCLIENT?
Another option would be to use a link but then the reverse problem arises: the link remains even when the content is deleted (resulting in a rather ugly exception when trying to follow the link).

All feedback appreciated.

Outcomes