cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

how to add the parts to workspace through customozation

AR_9920456
14-Alexandrite

how to add the parts to workspace through customozation

first i tried to add the all associated  EPM from the BOM  to workspace, all epm get added in the workspace. Now i am trying to add the WTPart  to workspace. its not working.

 

this is the code how i added previously the epm to workspace

private void addToWorkspace(EPMDocument doc) {

try {

wt.fc.ReferenceFactory referencefactory = new wt.fc.ReferenceFactory();

wt.fc.WTReference wtreference = referencefactory.getReference(doc);

wt.epm.EPMDocument epm = (wt.epm.EPMDocument) wtreference.getObject();

 

wtreference = referencefactory.getReference("OR:wt.epm.workspaces.EPMWorkspace:1150900");

wt.epm.workspaces.EPMWorkspace workspace= (wt.epm.workspaces.EPMWorkspace) wtreference.getObject();

System.out.println("workspace-->"+workspace);

 

wt.epm.workspaces.EPMAsStoredConfigSpec asStored = wt.epm.workspaces.EPMAsStoredConfigSpec.newEPMAsStoredConfigSpec(epm);

wt.fc.QueryResult queryResult = wt.epm.structure.EPMStructureHelper.service.navigateReferencesToIteration(epm, null, true, asStored);

 

//To add to workspace, set some collection

wt.fc.collections.WTHashSet collection = new wt.fc.collections.WTHashSet();

collection.add(epm);

 

while (queryResult.hasMoreElements()) {

System.out.println("has more elements");

wt.epm.EPMDocument docs = (wt.epm.EPMDocument) queryResult.nextElement();

System.out.println("docs-->"+docs);

collection.add(docs);

}

// Add to workspace

wt.epm.workspaces.EPMWorkspaceHelper.manager.addToWorkspace(workspace, collection);

System.out.println("we executed add to workspace");

 

} catch (WTException | WTPropertyVetoException e) {

e.printStackTrace();

}

}

Now i am tying to add both parts and epm documents to the workspace.

private void addAllToWorkspace(WTPart part) throws WTException {

try {

// Add the part and its associated EPMDocument to the workspace

addToWorkspace(part);

 

EPMDocument associatedEPM = getAssociatedEPM(part);

if (associatedEPM != null) {

addToWorkspace(associatedEPM);

}

} catch (Exception e) {

e.printStackTrace();

throw new WTException("Error adding part and its related documents to the workspace: " + e.getMessage());

}

}

 

private void addToWorkspace(Object obj) throws WTException {

try {

wt.fc.ReferenceFactory referenceFactory = new wt.fc.ReferenceFactory();

wt.epm.workspaces.EPMWorkspace workspace = (wt.epm.workspaces.EPMWorkspace) referenceFactory

.getReference("OR:wt.epm.workspaces.EPMWorkspace:1150900").getObject();

 

wt.fc.collections.WTHashSet collection = new wt.fc.collections.WTHashSet();

 

if (obj instanceof EPMDocument) {

EPMDocument epmDoc = (EPMDocument) obj;

System.out.println("Adding EPMDocument to collection: " + epmDoc.getNumber());

collection.add(epmDoc);

 

// Get the EPMDocument configuration

wt.epm.workspaces.EPMAsStoredConfigSpec asStored = wt.epm.workspaces.EPMAsStoredConfigSpec.newEPMAsStoredConfigSpec(epmDoc);

wt.fc.QueryResult queryResult = wt.epm.structure.EPMStructureHelper.service.navigateReferencesToIteration(epmDoc, null, true, asStored);

 

while (queryResult.hasMoreElements()) {

EPMDocument referencedDoc = (EPMDocument) queryResult.nextElement();

System.out.println("Adding referenced EPMDocument to collection: " + referencedDoc.getNumber());

collection.add(referencedDoc);

}

} else if (obj instanceof WTPart) {

WTPart part = (WTPart) obj;

System.out.println("Adding WTPart to collection: " + part.getNumber());

collection.add(part);

 

}

 

// Add the collection to the workspace

wt.epm.workspaces.EPMWorkspaceHelper.manager.addToWorkspace(workspace, collection);

System.out.println("Added collection to workspace");

 

} catch (Exception e) {

e.printStackTrace();

throw new WTException("Error adding object to workspace: " + e.getMessage());

}

}

3 REPLIES 3

Hi @AR_9920456 

If you say it does not work, what does it mean ? 

Any errors are in the method server log? 

PetrH

AR_9920456
14-Alexandrite
(To:HelesicPetr)

it is not working as expected. I am able to add only the EPM Document not e parts.

Hi @AR_9920456 

What the e.printStackTrace(); says? You have not described the error what I was asking. 

PS: try to write just test function to add one WTPart to a workspace and play with it what is wrong.

PetrH 

Announcements

Top Tags