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

We are happy to announce the new Windchill Customization board! Learn more.

Windchill API to check if a certain version of object is published or not and then publish

aachanta
13-Aquamarine

Windchill API to check if a certain version of object is published or not and then publish

Hi All,

 

can we know if there is any code or API to know certain version of object is published or not ? Or can we know if there is an API to know if the object is published or not so that we can then publish it ?

1 ACCEPTED SOLUTION

Accepted Solutions
BenPerry
13-Aquamarine
(To:aachanta)

@aachanta

Just wanted to clarify if you're talking about creating visualizations, or publishing using ESI.

 

Assuming you mean visualizations - yes, there is some API.  I have a method I created a while ago that runs in a workflow expression robot.  It calls the custom package/method.

 

The method returns true/false.  If it returns false, the method submits a publish job and the workflow routes to a timer robot.  If it returns true, then it continues.  There is also a custom logger in the example.  It isn't necessary.

 

    public static boolean representationCheck (WTChangeOrder2 co, boolean publish, int count) throws WTException {
    //checks to see if all of the Resulting objects are published. if they aren't published, it will submit publish jobs for them.
        boolean result = true;
        
        LOGGER.debug("WF Util: representationCheck: Calling ext.site.WorkflowUtils.representationCheck(), time #" + count + ", ECO# " + co.getNumber() + ", with publish mode = " + publish);
        try{
            // Get a list of the Resulting Objects of the Change Notice
            QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(co);
            
            // Loop through the Resulting Objects.
            while (qr.hasMoreElements()) {
                WTObject obj = (WTObject)qr.nextElement();
                
                // If the WTObject is an EPMDocument, check to see if it has a representation.
                if (obj instanceof EPMDocument) {
                    EPMDocument epmDoc = (EPMDocument)obj;
                    Representation rep = PublishUtils.getRepresentation((Representable) epmDoc);
                    LOGGER.debug("     \"" + epmDoc.getIdentity() + "\" representation: " + rep);
                    
                    // If there is no representation for the EPMDocument, then submit a publish job for one.
                    if (rep == null) {
                        result = false;
                        if (publish) {
                            String objRef = ObjectReference.newObjectReference(epmDoc).toString();
                            Publisher pub = new Publisher();
                            PublisherAction publisherAction = new PublisherAction();
                            publisherAction.addAction(PublisherAction.QUEUEPRIORITY, "H");
                            result = pub.doPublish(false, true, objRef, (EPMAsStoredConfigSpec)null, (EPMAsStoredConfigSpec)null, true, null, null, Publisher.EPM, publisherAction.toString(), 0);
                            LOGGER.debug("WF Util: representationCheck: Publish Job submitted for \"" + epmDoc.getIdentity() + "\"");
                        }
                    }
                }
            }
            LOGGER.debug("WF Util: representationCheck: Done with ext.site.WorkflowUtils.representationCheck().  All Resulting EPMDocs published? " + result);
            return result;
        }catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("WF Util: representationCheck error checking representations, please see MS logs for stack trace");
            return true;
        }
    }

 

View solution in original post

5 REPLIES 5
BenPerry
13-Aquamarine
(To:aachanta)

@aachanta

Just wanted to clarify if you're talking about creating visualizations, or publishing using ESI.

 

Assuming you mean visualizations - yes, there is some API.  I have a method I created a while ago that runs in a workflow expression robot.  It calls the custom package/method.

 

The method returns true/false.  If it returns false, the method submits a publish job and the workflow routes to a timer robot.  If it returns true, then it continues.  There is also a custom logger in the example.  It isn't necessary.

 

    public static boolean representationCheck (WTChangeOrder2 co, boolean publish, int count) throws WTException {
    //checks to see if all of the Resulting objects are published. if they aren't published, it will submit publish jobs for them.
        boolean result = true;
        
        LOGGER.debug("WF Util: representationCheck: Calling ext.site.WorkflowUtils.representationCheck(), time #" + count + ", ECO# " + co.getNumber() + ", with publish mode = " + publish);
        try{
            // Get a list of the Resulting Objects of the Change Notice
            QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(co);
            
            // Loop through the Resulting Objects.
            while (qr.hasMoreElements()) {
                WTObject obj = (WTObject)qr.nextElement();
                
                // If the WTObject is an EPMDocument, check to see if it has a representation.
                if (obj instanceof EPMDocument) {
                    EPMDocument epmDoc = (EPMDocument)obj;
                    Representation rep = PublishUtils.getRepresentation((Representable) epmDoc);
                    LOGGER.debug("     \"" + epmDoc.getIdentity() + "\" representation: " + rep);
                    
                    // If there is no representation for the EPMDocument, then submit a publish job for one.
                    if (rep == null) {
                        result = false;
                        if (publish) {
                            String objRef = ObjectReference.newObjectReference(epmDoc).toString();
                            Publisher pub = new Publisher();
                            PublisherAction publisherAction = new PublisherAction();
                            publisherAction.addAction(PublisherAction.QUEUEPRIORITY, "H");
                            result = pub.doPublish(false, true, objRef, (EPMAsStoredConfigSpec)null, (EPMAsStoredConfigSpec)null, true, null, null, Publisher.EPM, publisherAction.toString(), 0);
                            LOGGER.debug("WF Util: representationCheck: Publish Job submitted for \"" + epmDoc.getIdentity() + "\"");
                        }
                    }
                }
            }
            LOGGER.debug("WF Util: representationCheck: Done with ext.site.WorkflowUtils.representationCheck().  All Resulting EPMDocs published? " + result);
            return result;
        }catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("WF Util: representationCheck error checking representations, please see MS logs for stack trace");
            return true;
        }
    }

 

aachanta
13-Aquamarine
(To:BenPerry)

Hi Ben

 

@BenPerry 

 

Thanks for the input. This helps a lot. But then can you please confirm what if the publishing fails ?

 

Will it get republished again ? If yes is there any count or limit on sending to publishing again

BenPerry
13-Aquamarine
(To:aachanta)

The method returns a boolean.  So you can call the method in an Execute Expression robot or Conditional in the workflow.  Based on the result, you can route to a 5-min timer (if the result was false) or continue forward (if the result was true).

aachanta
13-Aquamarine
(To:BenPerry)

HI Ben / Graham

 

Thanks for the help

 

It worked

d_graham
17-Peridot
(To:aachanta)

Not sure if this got resolved but the way I handled this is to run code that gets the QueueEntry of the publishing job.

From there, every 30 seconds (can be whatever but 30 seconds seems to work well) I get the status.  If status is COMPLETED, NONEVENTFAILED or SEVERE I know the entry has finished.

Once finished I get the publishing job status. If it JOB SUCCESSFUL all is good. If it's not there's a problem and from there you can do whatever you want. Republish, send notification to user, whatever.

 

This seems to be a bombproof way of determining if the Representable was published successfully.

 

David

 

David

Top Tags