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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

i want to pass the zip file from my custom class to ImportContainerTemplateFormProcessor.java

RaikarRaghu
6-Contributor

i want to pass the zip file from my custom class to ImportContainerTemplateFormProcessor.java

By default at time of import the product template through UI it will call ImportContainerTemplateFormProcessor.java. 

So i am trying load the template through automatically,  i wrote a code it will fetch the .zip after that it has to call ImportContainerTemplateFormProcessor.java with the  .zip file paramater.

 

this is the code.

note : i am unable to pass the .zip file 

 

import com.ptc.core.components.beans.ObjectBean;

import com.ptc.core.components.forms.FormProcessingStatus;

import com.ptc.core.components.forms.FormResult;

import com.ptc.netmarkets.util.beans.NmCommandBean;

import com.ptc.windchill.principal.template.processor.ImportContainerTemplateFormProcessor;

import wt.log4j.LogR;

import wt.util.WTException;

import org.apache.logging.log4j.Logger;

 

import java.io.File;

import java.util.HashMap;

import java.util.List;

import java.util.ArrayList;

public class CustomTemplateImporter {

private static final Logger log = LogR.getLogger(CustomTemplateImporter.class.getName());

private static final String ZIP_FILE_PATH = "D:\\ptc\\Windchill_12.1\\Windchill\\loadFiles\\sup_product\\original_SAL_generated_template.zip";

 

public static void main(String[] args) {

File zipFile = new File(ZIP_FILE_PATH);

 

if (!zipFile.exists()) {

System.err.println("File not found: " + ZIP_FILE_PATH);

System.exit(1);

}

 

try {

NmCommandBean commandBean = new NmCommandBean();

 

commandBean.setTextParameter("file", ZIP_FILE_PATH); //

 

HashMap<String, Object> fileUploadMap = new HashMap<>();

fileUploadMap.put("file", zipFile);

commandBean.getMap().put("fileUploadMap", fileUploadMap);

 

// Set the required view attribute directly (mocking the request if necessary)

commandBean.setAttribute("view", "mockView");

List<ObjectBean> objectBeans = new ArrayList<>();

 

ImportContainerTemplateFormProcessor processor = new ImportContainerTemplateFormProcessor();

FormResult result = processor.doOperation(commandBean, objectBeans);

 

if (result.getStatus() == FormProcessingStatus.SUCCESS) {

System.out.println("Template imported successfully.");

} else {

System.err.println("Template import failed.");

}

} catch (WTException e) {

log.error("An error occurred during template import", e);

} catch (Exception e) {

log.error("An error occurred while setting parameters", e);

}

}

}

5 REPLIES 5
AndrewK
Community Manager
(To:RaikarRaghu)

Hi RaikarRaghu

Thank you for your question. 


I’d like to recommend bringing more details and context to your initial inquiry. It also helps to have screenshots to better understand what you are trying to do in your process. This will increase your chances to receive meaningful help from other Community members. 

RaikarRaghu
6-Contributor
(To:AndrewK)

Hello @AndrewK 

 

I am trying to load the product template from loadfile utility,

use case :

Step 1: i just export the product template as zip file, from the zip do unzip, we will get the xml file.

Step 2: for the validation purpose, i import that xml file manually from the windchill UI import action, it successfully loaded.

RaikarRaghu_1-1718363765174.png

Step 3: I deleted that template which i created in Step 2, and i tried to load that the xml file through load from file utility 

command : windchill wt.load.LoadFromFile -d D:\ptc\Windchill_12.1\Windchill\loadFiles\Testing\sup_product\SAL.xml -u wcadmin -p wcadmin -CONT_PATH \"/wt.inf.container.OrgContainer=PTC\"

errror: wt.pdmlink.PDMLinkProduct  cannot cast to wt.inf.container.OrgContainer

 

[Note :By default at time of importing the product template through windchill UI action it will call ImportContainerTemplateFormProcessor.java ]

 

Step 4: Now i am trying to pass that xml file from my custom java file [above code] to ImportContainerTemplateFormProcessor.java,   CustomTemplateImporter class  will fetch the .zip after that it has to call ImportContainerTemplateFormProcessor.java with the  .zip file paramater.

 . 

i am facing an issue, i am unable to pass that .zip file to the ImportContainerTemplateFormProcessor class. 

 

 

Hi @RaikarRaghu 

I tried it by my self with OOTB export and it seams that the XML is not suitable to be loaded by load from file utility

Sorry about that.

Try to find OOTB loadable example of templates that are loaded during installation. 

they exists in the Windchill location somewhere try to find it and check how the source xml file looks like. 

PetrH

Hello 

I tried to load by removing the ACL defined in the template, template successfully created. But i don't know why it is not creating with ACL.

 

Regards

Raghavendra

Hi @RaikarRaghu 

because it is not defined correctly for loadfromfile function.

PetrH

Top Tags