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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

JSP Page to Set State

breed
12-Amethyst

JSP Page to Set State

I am working on an administrative JSP page that would allow me to Set-State on wtdocuments and/or epmdocuments. I am using the Search-Objects webject to search for and get the information about the documents but, I cannot find a webect that allows me to set-state. Would anyone know how this could be accomplished in a JSP page? Is this something I would need to create a java class to handle? I have limited exposure to java so I would like to stick with the JSP if possible. Here is the search page I have currently. I would like to have the button that is clicked submit the request to the server for the state change.

search1.jpg

<%@page language="java" session="false"%>
<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie" %>

<html>
<head>


<title>WindSearch3.0</title>

<body>

</head>
<body>
<h2> Info*Engine JSP Test Page</h2>
<%
String where = request.getParameter ("where");
if ( where == null )
where = "()";
else if( where != null )
where= "(name='*" + where + "*')";
String wherevalue = request.getParameter ("where");
%>

<div class="main">
<h1>WindENG Search 3.0</h1>
<form action="aindex.jsp" method="POST">
Search: <input type="text" name="where" value="<%=wherevalue%>">
<input type="submit" value="Search">
<link rel="stylesheet" type="text/css" href="jsp.css">

<p><b>
Searching with where clause <%= where%>.
</b></p>

<ie:webject name="Search-Objects" type="OBJ">
       <ie:param name="INSTANCE" data="com.ptc.net.HostID.Windchill"/>
       <ie:param name="TYPE" data="wt.epm.EPMDocument"/>
       <ie:param name="VERSION" data="LATEST"/>
       <ie:param name="ITERATION" data="LATEST"/>
       <ie:param name="WHERE" data="<%=where%>"/>
       <ie:param name="WHERE" data="(state.state='Released')" />
    <ie:param name="ATTRIBUTE" data="CADName,name,state.state,versionInfo.identifier.versionId,obid" delim=","/>
       <ie:param name="GROUP_OUT" data="epmdocument"/>
</ie:webject>

<br>
<table border="1" cellpadding="2"
        <tr>
                <td>All<INPUT type=checkbox onclick="selectAll(this)" value=checkbox name=allcheckbox></td>
                <td>CADname</td><td>name</td><td>state.state</td><td>versionInfo.identifer.verisonID</td><td>OBID</dt>
        </tr>

    <ie:forEach groupIn="epmdocument" groupOut="row">
        <tr>
            <td><input value=" " type="checkbox"></td>
                <td><ie:getValue name="CADName"/></td>
                <td><ie:getValue name="name"/></td>
                <td><ie:getValue name="state.state"/></td>
                <td><ie:getValue name="versionInfo.identifier.versionId"/></td>
                <td><ie:getValue name="obid"/></td>
                <td><input type="submit" value="In Work"></td>
                <td><input type="submit" value="Preproduction"></td>
                <td><input type="submit" value="Released"></td>
                <td><input type="submit" value="Obsolete"></td>
        </tr>
    </ie:forEach>
</table>

</body>
</html>

ACCEPTED SOLUTION

Accepted Solutions
BineshKumar1
13-Aquamarine
(To:breed)

Not sure we can do this using webjects. But for the Java API you can do something like below and is fairly easy

try {

  System.out.println("Entered SetState Method");

  ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.epm.EPMDocument:30651355012");

  EPMDocument cadDoc = (EPMDocument) PersistenceHelper.manager.refresh(oid);

  System.out.println("Number: " +cadDoc.getNumber());

  LifeCycleHelper.service.setLifeCycleState ((LifeCycleManaged) cadDoc, State.toState ("WIP"));

  PersistenceHelper.manager.refresh ((Persistable) cadDoc, true, true);

  System.out.println("State of the document: " +cadDoc.getLifeCycleState());

     }

  catch(WTException e)

  {

  e.printStackTrace();

  }

Thank you

Binesh Kumar

Medtronic - MITG

View solution in original post

9 REPLIES 9
BineshKumar1
13-Aquamarine
(To:breed)

Not sure we can do this using webjects. But for the Java API you can do something like below and is fairly easy

try {

  System.out.println("Entered SetState Method");

  ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.epm.EPMDocument:30651355012");

  EPMDocument cadDoc = (EPMDocument) PersistenceHelper.manager.refresh(oid);

  System.out.println("Number: " +cadDoc.getNumber());

  LifeCycleHelper.service.setLifeCycleState ((LifeCycleManaged) cadDoc, State.toState ("WIP"));

  PersistenceHelper.manager.refresh ((Persistable) cadDoc, true, true);

  System.out.println("State of the document: " +cadDoc.getLifeCycleState());

     }

  catch(WTException e)

  {

  e.printStackTrace();

  }

Thank you

Binesh Kumar

Medtronic - MITG

breed
12-Amethyst
(To:BineshKumar1)

Thanks, I will give that a try.

Do you know if the ObjectIdentifier would be the same thing as the obid I show in the screenshot? Or would I need to parse that out of the obid?

BineshKumar1
13-Aquamarine
(To:breed)

You need to parse it to ObjectID

ReferenceFactory rf = new ReferenceFactory();

  WTReference ref = rf.getReference("VR:wt.epm.EPMDocument:30651331163");

  Persistable persistable = ref.getObject();

  System.out.println("Entered SetState Method");

  System.out.println("Object Id : " +ref.getObject());

  EPMDocument cadDoc = (EPMDocument)persistable;

  System.out.println("Number: " +cadDoc.getNumber());

  LifeCycleHelper.service.setLifeCycleState ((LifeCycleManaged) cadDoc, State.toState ("WIP"));

Thank you,

Binesh Kumar

Medtronic - MITG

Darrell
13-Aquamarine
(To:breed)

If you still want to use a JSP page for this, you can add the java code inside the jsp as I've done in the attached example for renaming EPM Docs.

breed
12-Amethyst
(To:Darrell)

Thanks for sharing that code it is really helpful! Time to play around with it...

breed
12-Amethyst
(To:breed)

Thanks, I think this is going to work for me, I did have one other question you have a State object that is not instantiated in that snippet of code how did you create that object. Sorry my Java coding is limited.

breed
12-Amethyst
(To:breed)

Thanks Binesh Kumar‌ I got it working now. It is a special use case but others may find it interesting so I am posting the code here. I created two JSP pages a start page and a results page. A new search can be started from the search page. I have not cleaned up the code and added all the error handling I need but this gives you a starting point. Disclaimer this is just some sample code and is not ready for production, use at your own risk.

Here is the start page starteng.jsp

<html>

<head>

<link rel="stylesheet" type="text/css" href="jsp.css">

<title>Engineering Set State App</title>

</head>

<body>

<div class="main">

    <div class="logo">

        <img src="image.jpg" alt="setstate logo" style="width:auto;height:60px;">&nbsp&nbsp&nbsp&nbsp<img src="image2.jpg" alt="setstate logo" style="width:auto;height:45px;">

    </div>

    <div class="searchbox">

        <form id="form" action="engineering.jsp?" method="POST">

        <input class="submit-textbox" type="text" name="where">&nbsp<input class="submit-button" type="submit" value="Search">

        </form>

    </div>

</div>

</body>

</html>

Here is the results page engineering.jsp:

<%@ page language="java" session="false" %>
<%@ taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="com.jbtc.*" %>
<%@ page import="java.util.regex.*" %>
<%@ page import="java.util.Pattern.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.net.URL" %>
<%@ page import="wt.method.RemoteMethodServer" %>
<%@ page import="wt.util.WTException" %>
<%@ page import="wt.epm.EPMDocument" %>
<%@ page import="wt.doc.WTDocument" %>
<%@ page import="wt.fc.ObjectIdentifier" %>
<%@ page import="wt.fc.Persistable" %>
<%@ page import="wt.fc.PersistenceHelper" %>
<%@ page import="wt.lifecycle.LifeCycleHelper" %>
<%@ page import="wt.lifecycle.State" %>
<%@ page import="wt.lifecycle.LifeCycleManaged" %>

<ie:webject name="Get-Properties" type="MGT">
    <ie:param name="ATTRIBUTE" data="wt.federation.ie.VMName"/>
    <ie:param name="GROUP_OUT" data="properties"/>
</ie:webject>
<html>
<head>
<title>Engineering Set State App</title>
<link rel="stylesheet" type="text/css" href="jsp.css">
</head>
<body>
<%
String searchTerm = request.getParameter ("where");
String obid = request.getParameter("obid");
String newState = request.getParameter("state");
String obidSplit = "fail";
String newObid = null;
if(obid != null && !obid.isEmpty()){
        Pattern p = Pattern.compile("[^:]*:([^:]*:[^-]*)");
        Matcher m = p.matcher(obid);
        if(m.find()){
            obidSplit = m.group(1);
        }
        if(obidSplit != null && !obidSplit.isEmpty()){
            String itemID = obidSplit;
            int lastIndex = itemID.lastIndexOf(":");
            newObid = itemID.substring(0, lastIndex);
        }
        if(newObid.startsWith("wt.doc.WTDocument")){
            try{
                ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier(newObid);
                WTDocument cadDoc = (WTDocument) PersistenceHelper.manager.refresh(oid);
                LifeCycleHelper.service.setLifeCycleState((LifeCycleManaged) cadDoc, State.toState(newState));
                PersistenceHelper.manager.refresh((Persistable) cadDoc, true, true);
            }catch(WTException e) {
                e.printStackTrace();
                System.out.println("<h1>ERROR!</h1>");
            }
        }
        if(newObid.startsWith("wt.epm.EPMDocument")){
            try{
                //System.out.println("<p>Entered setstate method</p>");
                ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier(newObid);
                //System.out.println("<p>created oid</p>");
                EPMDocument cadDoc = (EPMDocument) PersistenceHelper.manager.refresh(oid);
                //System.out.println("<p>Number: " +cadDoc.getNumber() + "</p>");
                LifeCycleHelper.service.setLifeCycleState((LifeCycleManaged) cadDoc, State.toState(newState));
                PersistenceHelper.manager.refresh((Persistable) cadDoc, true, true);
                //System.out.println("<p>State of the Document: " +cadDoc.getLifeCycleState() +"</p>");
                }catch(WTException e) {
                    e.printStackTrace();
                    System.out.println("<h1>ERROR!</h1>");
                }
        }
    }
%>
<%
String where = request.getParameter ("where");
if ( where == null )
where = "()";
else if( where != null )
where= "(name='*" + where + "*')";
String wherevalue = request.getParameter ("where");
%>

<div class="main">
    <div class="logo">
        <img src="JBT_White.jpg" alt="setstate logo" style="width:auto;height:60px;">&nbsp&nbsp&nbsp&nbsp<img src="setstate.jpg" alt="setstate logo" style="width:auto;height:45px;">
    </div>
    <div class="searchbox">
        <form action="engineering.jsp" method="post">
            <input type="hidden" name="obid" value="" />
            <input type="hidden" name="state" value="" />
            <input class="submit-textbox" type="text" name="where" value="<%=wherevalue%>">&nbsp<input class="submit-button" type="submit" value="Search">
        </form>
    </div>
</div>
    <ie:webject name="Search-Objects" type="OBJ">
           <ie:param name="INSTANCE" data="$(properties[0]wt.federation.ie.VMName[0])"/>
           <%-- <ie:param name="INSTANCE" data="com.jbtc.net.mad1wc-prod01.Windchill"/> --%>
           <ie:param name="TYPE" data="wt.epm.EPMDocument"/>
           <ie:param name="VERSION" data="LATEST"/>
           <ie:param name="ITERATION" data="ALL"/>
           <ie:param name="WHERE" data="<%=where%>"/>
           <ie:param name="WHERE" data="state.state='*'" />
        <ie:param name="ATTRIBUTE" data="CADName,name,state.state,versionInfo.identifier.versionId,iteration,obid" delim=","/>
           <ie:param name="GROUP_OUT" data="epmdocument"/>
    </ie:webject>
    <ie:webject name="Search-Objects" type="OBJ">
           <ie:param name="INSTANCE" data="$(properties[0]wt.federation.ie.VMName[0])"/>
            <ie:param name="TYPE" data="wt.doc.WTDocument"/>
            <ie:param name="VERSION" data="LATEST"/>
            <ie:param name="ITERATION" data="All"/>
            <ie:param name="WHERE" data="<%=where%>"/>
      <ie:param name="WHERE" data="(state.state='*')"/>
            <ie:param name="ATTRIBUTE" data="name,state.state,versionInfo.identifier.versionId,iteration,obid" delim=","/>
            <ie:param name="GROUP_OUT" data="pdfdocument"/>
    </ie:webject>
    <ie:webject name="Merge-Groups" type="GRP">
        <ie:param name="CASE_IGNORE" data="true"/>
        <ie:param name="CLASS" data="class"/>
        <ie:param name="COMPARISON" data="ALPHA"/>
        <ie:param name="GROUP_IN" data="epmdocument"/>
        <ie:param name="GROUP_IN" data="pdfdocument"/>
        <ie:param name="GROUP_OUT" data="outdata"/>
        <ie:param name="SORTBY" data="name"/>
        <ie:param name="SORTED" data="ASC"/>
    </ie:webject>
<div class="atable">
    <br />
    <table id="items">
            <tr>
                    <th>File Name</th><th>Windchill Name</th><th>Current State</th><th>Rev</th><th></th><th></th><th></th><th></th><th></th>
            </tr>
        <ie:forEach groupIn="outdata" groupOut="row">
            <tr>
                    <td><ie:getValue name="CADName"/></td>
                    <td><ie:getValue name="name"/></td>
                    <td><ie:getValue name="state.state"/></td>
                    <td><ie:getValue name="versionInfo.identifier.versionId"/></td>
                    <td><ie:getValue name="Iteration"/></td>
                    <td class="nospacing">
                            <form method="post">
                                <input type="hidden" name="where" value="<%=wherevalue%>" />
                                <input type="hidden" name="obid" value="<ie:getValue name="obid" />" />
                                <input type="hidden" name="state" value="INWORK" />
                                <input type="hidden" name="usedobid" value="<%=newObid%>" />
                                <button class="setstate-button" type="submit" class="button">In Work</button>
                            </form>
                    </td>
                    <td class="nospacing">
                            <form method="post">
                                <input type="hidden" name="where" value="<%=wherevalue%>" />
                                <input type="hidden" name="obid" value="<ie:getValue name="obid" />" />
                                <input type="hidden" name="state" value="PREPRODUCTION" />
                                <button class="setstate-button" type="submit" class="button">Preproduction</button>
                            </form>
                    </td>
                    <td class="nospacing">
                            <form method="post">
                                <input type="hidden" name="where" value="<%=wherevalue%>" />
                                <input type="hidden" name="obid" value="<ie:getValue name="obid" />" />
                                <input type="hidden" name="state" value="RELEASED" />
                                <button class="setstate-button" type="submit" class="button">Released</button>
                            </form>
                    </td>
                    <td class="nospacing">
                            <form method="post">
                                <input type="hidden" name="where" value="<%=wherevalue%>" />
                                <input type="hidden" name="obid" value="<ie:getValue name="obid" />" />
                                <input type="hidden" name="state" value="OBSOLETE" />
                                <button class="setstate-button" type="submit" class="button">Obsolete</button>
                            </form>
                    </td>
            </tr>
        </ie:forEach>
    </table>
    <br />
</div>
</form>
</body>
</html>

Hope this is helpful.

BineshKumar1
13-Aquamarine
(To:breed)

Thanks Brian. This is great

breed
12-Amethyst
(To:BineshKumar1)

Thanks, could not have done it without your help!

Announcements


Top Tags