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

