6
Points
Questions
0
Answers
1
-
Hi
You can try following code .
This will update manufacturer Parts with every value provided in Excel file even Empty value.
Thanks,
Purushottam
package com.lattice.Agile; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.agile.api.AgileSessionFactory; import com.agile.api.IAgileSession; import com.agile.api.IImportManager; public class Test { public static void main(String args[]) { String srcFilePath="C:/Users/purushottam.khatal/Desktop/template.xls"; String srcFileType="ExcelFile"; // Null implies loading the default mapping String mappingPath="C:/Users/purushottam.khatal/Desktop/TDR-TT_MAP.xml"; // Null implies do not transform String transformPath=null; String [] operations=new String[]{"manufacturerParts"}; List options=new ArrayList(); options.add("BusinessRuleOptions|ChangeMode=Authoring"); options.add("BusinessRuleOptions|BehaviorUponNonExistingObjects=Reject"); try { System.out.println("start"); //s1.append(System.getProperty("java.version")); HashMap params = new HashMap(); params.put(AgileSessionFactory.USERNAME, "username_here"); params.put(AgileSessionFactory.PASSWORD, "password_here"); AgileSessionFactory sesion_factory = AgileSessionFactory.getInstance("http://instance:port/Agile"); System.out.println("tryin to create session"); IAgileSession session = sesion_factory.createSession(params); //Session Created IImportManager imgr = (IImportManager)session.getManager(IImportManager.class); byte[] logData=null; logData=imgr.importData(stream2byte(new FileInputStream(srcFilePath)), srcFileType, convertFiletoStream(mappingPath), null, operations, options); byte buf[]=new byte[1024*4]; File log_file = new File("log.xml"); OutputStream os = new FileOutputStream(log_file); os.write(logData); os.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("out of try block"); } private static byte[] convertFiletoStream(String path) throws IOException{ if(path==null || path.equals("")) return null; return stream2byte(new FileInputStream(path)); } private static byte[] stream2byte(InputStream stream) throws IOException { ByteArrayOutputStream outStream=new ByteArrayOutputStream(); byte buf[]=new byte[1024*4]; int n=0; while((n=stream.read(buf))!=-1){ outStream.write(buf, 0, n); } byte[] data=outStream.toByteArray(); outStream.close(); return data; } }
- 2858 views
- 8 answers
- 0 votes