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

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

NP_10570407
11-Garnet

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

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?

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
Fadel
22-Sapphire II
(To:HelesicPetr)

@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);

 

Fede

View solution in original post

9 REPLIES 9

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

Hi @HelesicPetr ,

 

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

NP_10570407_0-1711631577827.png

 

Fadel
22-Sapphire II
(To:NP_10570407)

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

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

Fede
HelesicPetr
22-Sapphire I
(To:Fadel)

@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

Fadel
22-Sapphire II
(To:HelesicPetr)

@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);

 

Fede

@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;
    }

 

Hi @NP_10570407 

So if you load more revisions you have two options

 

First load all data from CSV and then check if there are different revisions and work with it.

 

Second you can react to the exception and try to revise the existing object to the revision you need by code and set the attributes from your CSV as you need.

 

PetrH

Thanks a ton to both @HelesicPetr and @Fadel for your valuable inputs. it helped me to resolve the uniqueness error.

You guys are great.

@HelesicPetr & @Fadel 

My loader read the input values from a csv file and create the epmdocuments accordingly.

In csv file, i have entries to create two revisions of same object back to back. for e.g., 

NP_10570407_1-1711631998024.png

 

A.1 created successfully, while creating the same B.1 using same API, it fails with uniqueness

Announcements

Top Tags