Hello,
I'm working with VirtualDocuments. I don't know how to add and remove childs of a VirtualDocument using DFC 6.5. Can anyone help me with a sample code??
Thanks in advance
I've found a sample code for adding childs, but I don't know how to delete them with the child r_object_id...
protected void createVDM(IDfSession sess, String objId) throws IOException {
try { // Instantiate an IDfSysObject object root. IDfSysObject sysObjRoot = (IDfSysObject)sess.getObject(new DfId(objId));
// Before we begin, see if the root object is already checked out. if (sysObjRoot.isCheckedOut() && !sysObjRoot.isCheckedOutBy(sess.getLoginUserName())) { System.out.println("\nError: the root object is already checked out by someone else!"); } else { // Instantiate an IDfVirtualDocument from the root object. IDfVirtualDocument vDoc = sysObjRoot.asVirtualDocument("CURRENT", false);
// Instantiate an IDfVirtualDocument as the root node of the VDM. IDfVirtualDocumentNode rootNode = vDoc.getRootNode();
// Instantiate an IDfVirtualDocument which will be the tail node of VDM tree. IDfVirtualDocumentNode insertAfterNode = null;
// Checkout the root sysobject. sysObjRoot.checkout();
System.out.println("\nNow add child objects to the VDM...");
// Prompt the user for child objects and add them to the VDM. while (true) { // Obtain an object name from the user. String objName = DfExUtils.getInput("\nEnter a child object name, 'Q' to quit: "); if (objName.toUpperCase().equals("Q")) { break; }
// Get the object id from a given object name. String childObjId = DfExUtils.getObjectId(sess, objName); if (childObjId != null) { // Instantiate an IDfSysObject child object. IDfSysObject sysObjChild = (IDfSysObject)sess.getObject(new DfId(childObjId));
// Obtain the chronicle id of child (the root version of the object). IDfId chronIdChild = sysObjChild.getChronicleId();
// Add a node to the VDM - method args: // 1. the object that is the virtual document // 2. if null, the new node is placed as the first child of rootNode // 3. the chronicle id of child // 4. To early bind the component, specify the version label // 5. Set this to true if you want to set the follow_assembly attribute to true // for the component. // 6. Set this to true to use the version label IDfVirtualDocumentNode childNode = vDoc.addNode(rootNode, insertAfterNode, chronIdChild, "CURRENT", false, true); } }
// Ask the user for a target location for the new VDM. sysObjRoot.link(DfExUtils.getInput("\nEnter a Docbase location for the VDM (e.g. /Temp): "));
// Save the VDM - this will also handle the checkin. sysObjRoot.save();
System.out.println("\nVDM successfully created!"); } } catch (DfException dfe) { System.out.println("\nError: createVDM():" + dfe.toString()); } }
Code snippet to remove a child node from a Virtual Document
// Get virtual document. // IDfSysObject sysObjRoot = (IDfSysObject)sess.getObject(new DfId(objId))
IDfVirtualDocument sysVDoc = sysObjRoot.asVirtualDocument("CURRENT", false);
// Get the root node of the virtual document tree. // IDfVirtualDocumentNode rootNode = sysVDoc.getRootNode(); IDfSysObject rootObject = rootNode.getSelectedObject();
// Get the child count for the root node. // int origChildCnt = rootNode.getChildCount();
//Remove the child node from the root document
//For e.g., lets remove the last node ;
//Get the last child of the root node. // IDfVirtualDocumentNode nodeToRemove = rootNode.getChild(origChildCnt - 1);
// Checkout the root. // rootObject.checkout();
sysVDoc.removeNode(nodeToRemove);
// Checkin the root object. // IDfId oldId = rootObject.getObjectId(); IDfId newId = rootObject.checkin(false, "");
Thanks Rakesh,
there is any possibility to delete a child by his r_object_id, not by the position??
If you already know the object ID of the child, then you would need to alter the code as below. (I am assuming that you know thw object id of the Virtual Document root)
// Get virtual document. // IDfSysObject sysObjRoot = (IDfSysObject)sess.getObject(new DfId(objId)) //objId is the ID of the Virtual Doc root.
/// Get the child object/virtual document to remove IDfSysObject childObject = (IDfSysObject) m_session.getObject(childObjId);
if (childObject.isVirtualDocument()) { // To create virtual document from sys object do the following. IDfVirtualDocument virdoc = childObject.asVirtualDocument("", false);
IDfVirtualDocumentNode childVDocNode = childObject.getRootNode();
sysVDoc.removeNode(childVDocNode);
}
else
{
StringBuffer dqlBuffer = new StringBuffer(200); DfQuery query = new DfQuery();
dqlBuffer.append("select r_object_id from dmr_containment where parent_id = 'objId' and component_id = 'childObjId'");
query.setDQL(dqlBuffer.toString());
IDfCollection coll = query.execute(session, IDfQuery.READ_QUERY);
IDfId containId = null;
while (coll.next())
containId = new DfId(coll.getString(DfDocbaseConstants.R_OBJECT_ID));
sysObjRoot.removePart(containId,0,false);
Did the suggestion work?
I couldn't try it yet.
Thanks Rakesh
Hi,
Does any one have any idea about how to convert a Virtual Document into an assemly in D6.5. I have a requirement to convert virtual document to assembly.
Thank you..
/Ajosh
You can convert a Virtual Document to a snapshot (assembly) the following way.
void assembleVDOC( IDfSession sess, IDfId vdocID) throws DfException {
IDfSysObject objectToAssemble = (IDfSysObject)sess.getObject(vdocID);
IDfSysObject sysObject = (IDfSysObject)sess.newObject(objectToAssemble.getType().getName()); sysObject.setObjectName( "SNAP1");
sysObject.link(objectToAssemble.getFolderId(0).getId());
sysObject.setContentType(objectToAssemble.getContentType());
IDfVirtualDocument virtualDoc = objectToAssemble.asVirtualDocument( null, false);
// Build up the qualification to use StringBuffer qualificationBuffer = new StringBuffer(" dm_sysobject IN DOCUMENT ID('"); qualificationBuffer.append(objectToAssemble.getObjectId().getId()); qualificationBuffer.append("') DESCEND with any r_version_label='"); qualificationBuffer.append( virtualDoc.getRootNode().getLateBindingValue()); qualificationBuffer.append("' "); String qualification = qualificationBuffer.toString();
// Assemble the virtual document sysObject.save(); IDfCollection dfCollection = sysObject.assemble( objectToAssemble.getObjectId(), -1, qualification, null); // commit the assembly process dfCollection.next(); // close the implicit transaction dfCollection.close();
if (sysObject.isDirty()) sysObject.save();
m_assemblyId = sysObject.getObjectId();
Hi Rakesh,
I absolutely understand that i should create a new post for my query. but i think you may be able to help me. Please can you tell me what is the difference between IDfSysObject.removePart and IDfVirtualDocument.removeNode in case i want to delete a normal document and if i want to delete a virtual document which is a child.
Many thanks in advance.