Skip to main content
12-Amethyst
March 27, 2024
Solved

How to handle master object creation while creating multiple versions of an object

  • March 27, 2024
  • 2 replies
  • 2764 views

I have a scenario,

consider I am creating the following objects using Windchill Custom API loader.

EPMDocument -

xyz.prt, versions A.1,B.1,C.1

WTPart - 

abc, versions A.1,B.1,C.1

I use the below static methods to initialize the objects.

EPMDocument.newEPMDocument(docNumber, docName, authoringApp, docType, cadName) for epmdocument

WTPart.newWTPart(number,name) for wtpart

 

My question:

First, when A.1 instance is created, i believe the API also creates its master object in the background.

What happens when i move to B.1 creation, with same API code?

will it attempt re-creation of master object (or)override  existing master object during B.1 and C.1?

 

 

 

 

Best answer by Fadel

@NP_10570407  try something like below to create a cad in a given version  :

*/
ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.epm.EPMDocument:169864");
EPMDocument epm = (EPMDocument) PersistenceHelper.manager.refresh(oid);

String version = "D";
MultilevelSeries mls = MultilevelSeries.newMultilevelSeries("wt.vc.VersionIdentifier", version);
VersionIdentifier vid = VersionIdentifier.newVersionIdentifier(mls);

WTKeyedHashMap rev_map = new WTKeyedHashMap();
ReviseOptions rev_opts = new ReviseOptions(epm);
// comment the line below if you want to use the next revision in the serie
rev_opts.document.versionId = vid;
rev_map.put( epm, rev_opts);
EPMDocumentHelper.service.reviseAll(rev_map);

 

2 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
March 28, 2024

Hi @NP_10570407 

I would say test it, you will see.

Please can you also share the result of your test? That we can discus it. 

PetrH

PetrH
12-Amethyst
March 28, 2024

Hi @HelesicPetr ,

 

I have tested and end up with uniqueness exception as mentioned by @Fadel 

NP_10570407_0-1711631577827.png

 

Fadel
23-Emerald I
March 28, 2024

I would join Petr to test it , theoretically I would expect that you get 

wt.pom.UniquenessException: EPMDocument - xxxx is not unique

Buiꓘa
HelesicPetr
22-Sapphire II
22-Sapphire II
March 28, 2024

@Fadel 

And thanks that @NP_10570407 needs to find another way how to store new version to the system.

For example create a new revision on the existing object, with correct revision label etc.  

PetrH

PetrH
12-Amethyst
March 28, 2024

@Fadel  Thanks for sharing the code snippet. my scenario is different. I have to bulk load(create) objects based on input csv file. csv can have entries for more revisions/versions of same object. my method code below(sorry for long thread):

 

public EPMDocument createNewEPMDocument(String number,String version,HashMap<String,String> paramHashMap) throws WTException {
        String str1 = CLASSNAME + ".createNewDocument: ";
        System.out.println("Entering... " + str1);
        
        EPMDocument localEPMDocument = null;
        try {
            
            String strName = paramHashMap.get("NAME");
            String strObjNumber = number;
            String desc = paramHashMap.get("DESCRIPTION");
            String c_org_name = paramHashMap.get("CONTAINER_ORGANIZATION_NAME");
            String cont = paramHashMap.get("CONTAINER");
            String c_type = paramHashMap.get("CONTAINERTYPE");
            String strEPMAuthtype = paramHashMap.get("AUTHORINGAPPTYPE"); ////e.g. value is 'PROE'
            String strEPMApptype = paramHashMap.get("EPMAPPLICATIONTYPE"); //e.g. value is 'EPM'
            String strEPMDoctype = paramHashMap.get("EPMDOCTYPE"); // e.g. value is 'CADCOMPONENT'
            String strCADName = paramHashMap.get("CADNAME");
            String strSeries = paramHashMap.get("SERIES");
            String strTypedef = paramHashMap.get("TYPEDEF");
            String[] res = version.split("[.]", 0);
            System.out.println("rev>"+res[0]);
            System.out.println("iter>"+res[1]);
            String strRevision = res[0];
            String strIteration = res[1];
            String strFolderPath = paramHashMap.get("FOLDERPATH");
            String strLCTemplate = paramHashMap.get("LIFECYCLETEMPLATE");
            String strState = paramHashMap.get("STATE");
            String strCreator = paramHashMap.get("CREATOR");
            String strModifier = paramHashMap.get("MODIFIER");
           // String tempNo = "";
              
            EPMAuthoringAppType localEPMAuthoringAppType = EPMAuthoringAppType
                    .toEPMAuthoringAppType(strEPMAuthtype);
            EPMApplicationType localEPMApplicationType = EPMApplicationType
                    .toEPMApplicationType(strEPMApptype);
            EPMDocumentType localEPMDocumentType = EPMDocumentType.toEPMDocumentType(strEPMDoctype);
            EPMContextHelper.setApplication(localEPMApplicationType);
            
            localEPMDocument = EPMDocument.newEPMDocument();
 
            TypeIdentifier ti = TypeHelper.getTypeIdentifier(strTypedef);
            WCTypeIdentifier wti = (WCTypeIdentifier) ti;
            TypeDefinitionReference tdr = TypedUtility.getTypeDefinitionReference(wti.getTypename());
            localEPMDocument.setTypeDefinitionReference(tdr);
            
            localEPMDocument.setName(strName);
            localEPMDocument.setNumber(strObjNumber);
            
            EPMDocumentMaster localEPMDocumentMaster = (EPMDocumentMaster) localEPMDocument.getMaster();
            
            localEPMDocumentMaster.setSeries(strSeries);
            
            if (localEPMDocumentMaster != null) {
                if (localEPMDocumentMaster.getDocType() != null) {
                    localEPMDocument.setDocType(localEPMDocumentMaster.getDocType());
                } else {
                    localEPMDocumentMaster.setDocType(localEPMDocumentType);
                }
                
                if (localEPMDocumentMaster.getOwnerApplication() == null) {
                    localEPMDocumentMaster.setOwnerApplication(localEPMApplicationType);
                }
                if (localEPMDocumentMaster.getAuthoringApplication() == null) {
                    localEPMDocumentMaster.setAuthoringApplication(localEPMAuthoringAppType);
                }
                if (strCADName != null) {
                    localEPMDocumentMaster.setCADName(strCADName);
                } else {
                    localEPMDocumentMaster.setCADName(strCADName);
                }
                
            } else {
            System.out.println("createNewEPMDocument EPMDocNumber: " + strObjNumber
                        + "   ===> Master is null. Error Setting EPMDocumentMaster!!");
                
                return null;
            }
            localEPMDocumentMaster.setDocSubType(EPMDocSubType.getEPMDocSubTypeDefault());
            localEPMDocument.setContainer(CommonUtilities.getContainer(cont));
            if (desc != null) {
                localEPMDocument.setDescription(desc);
            }
                 
            WTOrganization localWTOrganization = CommonUtilities.getWTOrganizationByName(c_org_name);
            if (localWTOrganization == null) {
                throw new WTException("Organization \"" + c_org_name + "\" does not exist.");
            }
            localEPMDocument.setOrganization(localWTOrganization);
                       
            System.out.println("Setting the Version and Iteration");
            
            //System.out.println("Setting Type for EPMDocument...");
           // localEPMDocument = (EPMDocument) setType(paramHashtable, localEPMDocument);
            MultilevelSeries mls = MultilevelSeries.newMultilevelSeries("wt.vc.VersionIdentifier", strRevision);
VersionIdentifier versionId = VersionIdentifier.newVersionIdentifier(mls);
 
            VersionControlHelper.setVersionIdentifier((Versioned)localEPMDocument, versionId);
            
            // set folder
            Folder folder = FolderHelper.service.getFolder(strFolderPath,
                    WTContainerRef.newWTContainerRef(CommonUtilities.getContainer(cont)));
            FolderHelper.assignFolder(localEPMDocument, folder);
            //FolderHelper.assignLocation(localEPMDocument, localFolder); ANOTHER API TO SET FOLDER
            
            // set lifecycle
            LifeCycleTemplate lct = LifeCycleHelper.service.getLifeCycleTemplate(strLCTemplate,
                    WTContainerRef.newWTContainerRef(CommonUtilities.getContainer(cont)));
            LifeCycleHelper.setLifeCycle(localEPMDocument, lct);
            
            localEPMDocument = (EPMDocument) LifeCycleServerHelper.setState(localEPMDocument, State.toState(strState));
              
            CommonUtilities.setCreator((Iterated)localEPMDocument,strCreator);
            CommonUtilities.setModifier((Iterated)localEPMDocument,strModifier);
             
          /*  TypeInstanceIdentifier localTypeInstanceIdentifier = TypeIdentifierUtility
                    .getTypeInstanceIdentifier(localEPMDocument);
            
            TypeInstance localTypeInstance = TypeInstanceFactory.newTypeInstance(localTypeInstanceIdentifier);
            
            TypeInstanceUtility.populateMissingTypeContent(localTypeInstance, null);*/
            localEPMDocument.setPlaceHolder(false);
            
            localEPMDocument = (EPMDocument) PersistenceHelper.manager.store(localEPMDocument);
            
            Series ser = Series.newSeries("wt.vc.IterationIdentifier", strIteration);
            IterationIdentifier iterationId = IterationIdentifier.newIterationIdentifier(ser);
            
            VersionControlHelper.setIterationIdentifier((Iterated)localEPMDocument, iterationId);
            
            System.out.println("Exiting... " + str1);
        } catch (NoSuchElementException localNoSuchElementException) {
        System.out.println(localNoSuchElementException);
            throw new WTException(localNoSuchElementException.getMessage());
        } catch (WTPropertyVetoException localWTPropertyVetoException) {
        System.out.println(localWTPropertyVetoException);
            throw new WTException(localWTPropertyVetoException.getMessage());
        }
        return localEPMDocument;
    }