workspace code

===================

            EPMWorkspace epmworkspace = null;
            EPMWorkspace aepmworkspace[] = WorkspaceUtilities.getWorkspacesForCurrentUser();
            if(aepmworkspace != null && aepmworkspace.length > 0)
                epmworkspace = aepmworkspace[0];
                
===================

	//Object aobj[] = GenericUtilities.getAssociated(epmDocIn);
	//if(aobj != null) {
	// for(int i = 0; i < aobj.length;)
	//PersistenceHelper.manager.delete((Persistable)aobj[i++]);
	//}

	//EPMWorkspace epmworkspace = (EPMWorkspace)getObject(getFormData().getProperty("checkoutFolder"));

	//EPMWorkspace epmworkspace = (EPMWorkspace)getContextObj();

	//EPMWorkspace act_ws = (EPMWorkspace)SessionContext.getContext().get("TEMP_ACTIVE_WS");
	//TypeInstance checkoutFolder;
	//wt.folder.Folder userCheckoutFolder = WorkInProgressHelper.service.getCheckoutFolder();

	//EPMBaselineHelper.service.add(act_ws, wtpAssoc5);
	//EPMBaselineHelper.service.add(act_ws, epmDocIn);

	//System.out.println( "userCheckoutFolder: "+userCheckoutFolder);

	//disassociate
	//GenericUtilities.disassociate(wtpAssoc5, epmDocIn);
	/*
	QueryResult qrBuild = PersistenceHelper.manager.navigate(wtpAssoc5, "buildSource", wt.epm.build.EPMBuildRule.class, false);

	EPMBuildRule aepmbuildrule[];
	aepmbuildrule = null;

	aepmbuildrule = new EPMBuildRule[qrBuild.size()];
	int i = 0;
	boolean flag = false;
	ObjectIdentifier objEpm = PersistenceHelper.getObjectIdentifier(epmDocIn);
	//wt.folder.Folder userCheckoutFolder = WorkInProgressHelper.service.getCheckoutFolder();

	Vector buildRuleLinks = new Vector();

	while(qrBuild.hasMoreElements()) {
		buildRuleLinks.addElement((EPMBuildRule)qrBuild.nextElement());
	}

	System.out.println( "buildRuleLinks.size(): "+buildRuleLinks.size());

	for(int v=0; v < buildRuleLinks.size(); v++) {
		System.out.println("EPMBuildRule Links that are being deleted are \t" + buildRuleLinks.elementAt(v));
		PersistenceServerHelper.manager.remove((EPMBuildRule)buildRuleLinks.elementAt(v));
	}
	*/

	/*
	while(qrBuild.hasMoreElements()) {
		EPMBuildRule epmBuildRule = (EPMBuildRule)qrBuild.nextElement();
		flag = PersistenceHelper.getObjectIdentifier(epmBuildRule.getBuildSource()).equals(objEpm);
		aepmbuildrule[i++] = epmBuildRule;
		//epmBuildRule = (BinaryLink)PersistenceHelper.manager.delete((EPMBuildRule)epmBuildRule);
		//epmBuildRule = (BinaryLink)PersistenceHelper.manager.delete((EPMBuildRule)epmBuildRule);
		//PersistenceHelper.manager.delete((Persistable)epmBuildRule);
		PersistenceHelper.manager.remove((EPMBuildRule)epmBuildRule);

		if(aepmbuildrule[i++] instanceof Persistable) {
			//PersistenceHelper.manager.delete((Persistable)aepmbuildrule[i++]);
		}
	}
	*/

	//System.out.println( "qrBuild.size(): "+qrBuild.size());
	//System.out.println( "flag: "+flag);

	//System.out.println( "EPM: "+epmDocIn.getNumber() + "|OID: "+oidepmDoc);
	//System.out.println( "WTPart Assoc ["+y+"]: "+wtpart.getNumber()+"|OID: "+oidWtp);
	//arraylistEpmLink.add(linkEpmStg);

===================

import wt.epm.workspaces.EPMWorkspace;
import wt.epm.workspaces.WorkspaceFolder;


 	public static EPMWorkspace findWsNo() throws WTException, WTPropertyVetoException {
 		WTPrincipal wtprincipal = SessionHelper.manager.getPrincipal();
 		QuerySpec queryspec = new QuerySpec(EPMWorkspace.class);
 		SearchCondition searchcondition = new SearchCondition(EPMWorkspace.class, "name", "=", "lj_temp");
 		queryspec.appendWhere(searchcondition, 0, -1);
 		queryspec.appendAnd();
 		SearchCondition searchcondition1 = new SearchCondition(EPMWorkspace.class, "principalReference.key.id", "=", PersistenceHelper.getObjectIdentifier(wtprincipal).getId());
 		queryspec.appendWhere(searchcondition1, 0, -1);
 		QueryResult queryresult = PersistenceHelper.manager.find(queryspec);

 		if(queryresult != null && queryresult.hasMoreElements()) {
 			epmws = (EPMWorkspace)queryresult.nextElement();
 			System.out.println( "epmws.toString(): "+ epmws.toString());
 			//QueryResult itemsqr = EPMBaselineHelper.service.getBaselineItems(epmws);
 			//System.out.println( "itemsqr.size(): "+ itemsqr.size());
 		}
 		return epmws;
	}


===================

         else if ( current instanceof EPMWorkspace ) {

            WTContainer owningContainer = ((EPMWorkspace)current).getContainer();
            if (!WTContainerHelper.isClassicContainer(owningContainer)) {
               continue;
            }
         }
         
   /**
    *  Retrieve the folder contents of the folder context object. If the current
    *  context object is not a folder, this method returns a null
    *  SortedEnumeration <BR>
    *  <BR>
    *  <B>Supported API: </B> false
    *
    *@return                  a SortedEnumeration of the contents associated with
    *      the folder context object, or null if the context object is not a
    *      folder
    *@exception  WTException  Description of the Exception
    */
   private SortedEnumeration retrieveFolderContents() throws WTException {
      SortedEnumeration sorted_results = null;

      if (getContextObj() instanceof Folder) {

         if (VERBOSE) {
            System.out.println("BasicTemplateProcessor.retrieveFolderContents()");
         }
         QueryResult result = FolderHelper.service.findFolderContents((Folder) getContextObj());
         if (result != null) {
            //dbhate : 13-May-2002 :
            //Disable Wildfire in stand-alone mode if the key 'com.ptc.windchill.cadx.standalone.enabled' is not set.
            //i.e. show the workspaces only if user agent is wildfire or above mentioned key is set
            boolean showWorkspaces = false;
            try {
               showWorkspaces = isWildfireEnabled();
            } catch (Exception e) {}
            ;
            if (showWorkspaces) {
               // if Folder has WORKSPACE role then replace folder object with workspace object
               Vector content = result.getObjectVectorIfc().getVector();
               for (int i = 0; i < content.size(); i++) {
                  if (content.elementAt(i) instanceof SubFolder) {
                     EPMWorkspace ws = null;
                     try {
                        QueryResult qr = PersistenceHelper.manager.navigate((SubFolder) content.elementAt(i),
                              WorkspaceFolder.WORKSPACE_ROLE,
                              WorkspaceFolder.class);
                        if (qr.hasMoreElements()) {
                           ws = (EPMWorkspace) qr.nextElement();
                        }
                     } catch (Exception e) {}
                     if (ws != null) {
                        content.setElementAt(ws, i);
                     }
                  }
               }
            }
            sorted_results = new SortedEnumeration(result.getEnumeration(),
                  new FolderCollationKeyFactory());
         }
      }
      return sorted_results;
   }



   public static boolean displayFolderObject( WTContainer container, WTObject obj)
        throws WTException
   {
       boolean retval = false;
       if (obj instanceof SubFolder ) {
           SubFolder folder = (SubFolder) obj;
           if ( WTContainerHelper.isContainedBy((WTContained)folder, WTContainerHelper.service.getClassicRef()) )
                   retval = true;
           if ( WTContainerHelper.isContainedBy((WTContained)folder, WTContainerHelper.service.getExchangeRef()) ) {
                EPMWorkspace ws = null;
                try {
                    QueryResult qr = PersistenceHelper.manager.navigate(folder,
                            WorkspaceFolder.WORKSPACE_ROLE,
                            WorkspaceFolder.class);
                    if (!qr.hasMoreElements()) {
                        retval = true;
                    }
                    else
                        retval = false;
                } catch (Exception e) {
                    retval = false;
                }
           }
       }
       else if ( WTContainerHelper.isContainedBy((WTContained)obj, WTContainerHelper.service.getClassicRef()) )
           retval = true;

       return retval;
   }


===================

	public static EPMWorkspace findEPMWorkspaceInProduct( String organizationName, String containerName, String userName, String workspaceName ) throws Exception {
		return findEPMWorkspace( organizationName, "wt.pdmlink.PDMLinkProduct", containerName, userName, workspaceName );
	}	// end findEPMWorkspaceInProduct

	public static EPMWorkspace findEPMWorkspaceInLibrary( String organizationName, String containerName, String userName, String workspaceName ) throws Exception {
		return findEPMWorkspace( organizationName, "wt.inf.library.WTLibrary", containerName, userName, workspaceName );
	}	// end findEPMWorkspaceInLibrary

	public static EPMWorkspace findEPMWorkspace( String organizationName, String containerType, String containerName, String userName, String workspaceName ) throws Exception {
//		EPMWorkspace workspace = null;
		// cerca container ref
		WTContainerRef containerRef = null;
		try {
			// wt.epm.workspaces.EPMWorkspace
			containerRef = WTContainerHelper.service.getByPath( "/wt.inf.container.OrgContainer=" + organizationName + "/" + containerType + "=" + containerName );
			if ( containerRef == null ) {
				msg.debug( true, "Errore: Container non valido " + containerName );
				return null;
			}
		}
		catch ( Exception ex ) {
			msg.debug( true, "ERRORE: durante la ricerca del container " + containerName + "[" + ex.getMessage() + "]" );
		}
		WTUser user = null;
		if ( userName != null && !userName.equals( "" ) ) {
			user = findWTUser( userName );
		}
		//
		WTSet set = EPMWorkspaceHelper.manager.getWorkspaces( user, containerRef );
		Iterator it = set.referenceIterator();
		while ( it.hasNext() ) {
			wt.fc.ObjectReference or = (wt.fc.ObjectReference)it.next();
			EPMWorkspace ws = (EPMWorkspace)or.getObject();
			if ( ws.getName().equalsIgnoreCase( workspaceName ) ) {
				return ws;
//				workspace = ws;
//				break;
			}
		}
//		if ( workspace == null ) {
//			msg.debug( true, "workspace " + workspaceName + " non trovato" );
//			return workspace;
//		}
//		msg.debug( "ws found =" + workspace.getName() + " - " + workspace.getDescription() );
		return null;
	}	// end findEPMWorkspace


===================


// ant -f bin/tools.xml class -Dclass.includes=ext/CheckedOutList_08.java
// java ext.CheckedOutList_08 %>D:\ptc\Windchill\src\ext\output\CheckedOutList_08_all-091814_01.txt
// java ext.CheckedOutList_08 012%>D:\ptc\Windchill\src\ext\output\CheckedOutList_08_012-092114_01.txt

package ext;

import java.util.*;
import java.rmi.RemoteException;
import java.io.*;

import wt.util.*;
import wt.fc.*;
import wt.vc.*;
import wt.vc.config.*;
import wt.vc.wip.*;
import wt.folder.*;

import wt.query.*;
import wt.epm.*;
import wt.epm.workspaces.*;
import wt.part.*;

import wt.enterprise.RevisionControlled;
import wt.ownership.*;

import wt.httpgw.GatewayAuthenticator;
import wt.method.RemoteMethodServer;
import com.ptc.windchill.cadx.common.util.AssociateUtilities;
import com.ptc.windchill.cadx.common.util.GenericUtilities;
import com.ptc.windchill.cadx.common.util.ObjectDependencyUtility;
import com.ptc.windchill.cadx.common.util.WorkspaceUtilities;
import com.ptc.windchill.cadx.common.util.*;

public class CheckedOutList_08 {

	public static void findNo(String objNo) throws WTException, WTPropertyVetoException {
		configSpec = new LatestConfigSpec();

		QuerySpec qs = new QuerySpec(EPMDocument.class);
		qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NUMBER,SearchCondition.LIKE,objNo));
		//qs.appendAnd();
		//qs.appendWhere(new SearchCondition(EPMDocument.class, "iterationInfo.latest", "TRUE"));

		//qs = configSpec.appendSearchCriteria(qs);
		QueryResult qr = PersistenceHelper.manager.find(qs);
		//qr = configSpec.process(qr);

		while (qr.hasMoreElements()) {
			epm = null;
			epm = (EPMDocument)qr.nextElement();
			String epmTyp = epm.getDocType().toString();

			if(WorkInProgressHelper.isCheckedOut(epm)) {
				if(epm instanceof Workable && WorkInProgressHelper.isWorkingCopy((Workable)epm)) {
					//System.out.println(epm.getOwnership().getOwner().getDisplayName());
					EPMWorkspace ws = getWSFromFolder(WorkspaceUtilities.getCheckoutFolder(epm));
					//System.out.println( ws.getName());

					//Folder wsFolder = WorkspaceUtilities.getCheckoutFolder(epm);
					//System.out.println( "wsFolder: "+wsFolder);

					String modDate = String.valueOf(epm.getModifyTimestamp());
					//System.out.println( "modDate: "+modDate);

					System.out.println( epm.getNumber()+"|"+epm.getName()+"|"+epm.getVersionIdentifier().getValue()+"."+epm.getIterationIdentifier().getValue()+"|"+epmTyp+"|"+epm.getOwnership().getOwner().getDisplayName()+"|"+modDate);
					//System.out.println( epm.getNumber()+"|"+epm.getName()+"|"+epm.getVersionIdentifier().getValue()+"."+epm.getIterationIdentifier().getValue()+"|"+epmTyp+"|"+epm.getOwnership().getOwner().getDisplayName()+"|"+modDate+"|"+ws.getName());
				}
			}
		}

		//System.out.println( "\n============\nWTPARTS\n============\n");

		QuerySpec qs2 = new QuerySpec(WTPart.class);
		qs2.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,objNo));
		//qs2.appendAnd();
		//qs2.appendWhere(new SearchCondition(WTPart.class, "iterationInfo.latest", "TRUE"));

		//qs2 = configSpec.appendSearchCriteria(qs2);
		QueryResult qr2 = PersistenceHelper.manager.find(qs2);
		//qr2 = configSpec.process(qr2);

		while (qr2.hasMoreElements()) {
			wtp = null;
			wtp = (WTPart)qr2.nextElement();

			if(WorkInProgressHelper.isCheckedOut(wtp)) {
				if(wtp instanceof Workable && WorkInProgressHelper.isWorkingCopy((Workable)wtp)) {
					//EPMWorkspace ws2 = getWSFromFolder(WorkspaceUtilities.getCheckoutFolder(wtp));
					//Folder wsFolder2 = WorkspaceUtilities.getCheckoutFolder(wtp);

					//if(wtp instanceof Foldered)
						//System.out.println( "wtp instanceof Foldered");

					Folder fold1 = FolderHelper.getFolder((Foldered)wtp);
					//System.out.println( "fold1: "+fold1);

					//Folder wsFolder3 = WorkspaceUtilities.getCheckoutFolder(fold1);
					//System.out.println( "wsFolder3: "+wsFolder3);

					//wt.epm.workspaces.EPMWorkspace epmworkspace = WorkspaceUtilities.getCheckoutWorkspace(wtp);
					//System.out.println( "epmworkspace: "+epmworkspace);

					//System.out.println( "wsFolder2: "+wsFolder2);

					//QueryResult queryresult = PersistenceHelper.manager.navigate(fold1, "workspace", wt.epm.workspaces.WorkspaceFolder.class);
					//System.out.println( "queryresult.size(): "+queryresult.size());

					//wt.epm.workspaces.EPMWorkspace epmworkspace2 = ObjectDependencyUtility.getCheckoutWorkspace(wtp);
					//System.out.println( "epmworkspace2: "+epmworkspace2);

					//boolean flag1 = wt.sandbox.SandboxHelper.isCheckedOutToSandbox(wtp);
					//boolean flag2 = wt.sandbox.SandboxHelper.isSandboxWorkingCopyNoDBHack(wtp);

					//System.out.println( "flag1: "+flag1);
					//System.out.println( "flag2: "+flag2);

					String modDate2 = String.valueOf(wtp.getModifyTimestamp());
					//System.out.println( wtp.getNumber()+"|"+wtp.getName()+"|"+wtp.getVersionIdentifier().getValue()+"."+wtp.getIterationIdentifier().getValue()+"|WTPART"+"|"+wtp.getOwnership().getOwner().getDisplayName()+"|"+ws2.getName()+"|"+modDate2);
					System.out.println( wtp.getNumber()+"|"+wtp.getName()+"|"+wtp.getVersionIdentifier().getValue()+"."+wtp.getIterationIdentifier().getValue()+"|WTPART"+"|"+wtp.getOwnership().getOwner().getDisplayName()+"|"+modDate2+"|"+fold1.getName());
					//System.out.println( ws2.getName());

					//System.out.println( wtp.getNumber()+"|"+wtp.getName()+"|"+wtp.getVersionIdentifier().getValue()+"."+wtp.getIterationIdentifier().getValue()+"|WTPART"+"|"+wtp.getOwnership().getOwner().getDisplayName());
				}
			}
		}
	}

	public static EPMWorkspace getWSFromFolder(Folder folder) {
		EPMWorkspace ws = null;
		try {
			//QueryResult qr = PersistenceHelper.manager.navigate(folder, "workspace", wt.epm.workspaces.WorkspaceFolder.class);
			QueryResult qr = PersistenceHelper.manager.navigate((SubFolder)folder, "workspace", wt.epm.workspaces.WorkspaceFolder.class);
			if(qr.hasMoreElements())
				ws = (EPMWorkspace)qr.nextElement();
		}
		catch(Exception e) { }
		return ws;
	}

	public static void main(String[] args) {
		RemoteMethodServer rms = RemoteMethodServer.getDefault();
		GatewayAuthenticator auth = new GatewayAuthenticator();
		auth.setRemoteUser("wcadmin");
		rms.setAuthenticator(auth);

		try {
			if(args.length < 1) {
				System.out.println(Usage);
				System.exit(0);
			}
			else {
				findNo(args[0].toUpperCase());
				System.exit(0);
			}
		}
		catch(WTException wtee) { System.out.println( "\tFAILED = WTException: "+wtee.toString()+"\n"); }
		catch(WTPropertyVetoException wtpe) { System.out.println( "\tFAILED = WTPropertyVetoException: "+wtpe.toString()+"\n"); }
		finally { System.exit(0); }
	}

	public static String Usage = "\nUsage:\n\njava "+
	"ext.CheckedOutList %<epmdoc search string>%\n\n"+
	"1st Argument = <epmdoc query>. Should include % where % = * = wild card.\n";

	static String epmNo;
	static EPMDocument epm, epmWC;
	static WTPart wtpAssoc, wtp;
	static ConfigSpec configSpec;
}

===================

            if(nmoid.getRef() instanceof EPMWorkspace)
            {
                EPMWorkspace epmworkspace = (EPMWorkspace)nmoid.getRef();
                Folder folder = getPartOrDocTargetFolderFromWorkspace(nmcommandbean, epmworkspace);
                if(folder != null)
                {
                    log.debug("Using folder from workspace");
                    obj = folder;
                } else
                {
                    log.debug("folder from workspace is null");
                }
            }
            
===================
    public EPMWorkspace getWorkspace()
        throws WTException
    {
        if(ws == null && getWsName() != null)
            ws = WorkspaceUtilities.getEPMWorkspaceByName(getWsName(), SessionHelper.manager.getPrincipal());
        return ws;
    }

===================

configSpecs.getConfigSpecs(wt/epm/EPMDocument)

            List list = navigationcriteria.getConfigSpecs();
            if(list == null || list.isEmpty())
                break label0;
            Iterator iterator = list.iterator();
            Object aobj[];
            do
            {
                if(!iterator.hasNext())
                    break label0;
                ConfigSpec configspec = (ConfigSpec)iterator.next();
                aobj = CollectionSrvHelper.getWorkspaceByConfigSpec(configspec);
            } while(aobj[0] == null);
            ws = (EPMWorkspace)aobj[0];
            if(container == null)
                container = (WTContainer)aobj[1];
===================

         //Object[] epmspaces = com.ptc.windchill.cadx.common.util.WorkspaceUtilities.getWorkspacesForCurrentUser();

                    Folder folder = FolderHelper.getFolder((Foldered)getContextObj());
                    workspace = WorkspaceUtilities.getWorkspace(folder.getName());

===================

            WTReference wtreference = rf.getReference(s1);
            epmworkspace = (EPMWorkspace)wtreference.getObject();
            
===================

===================

===================

===================

===================


===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================

===================
