anyone knows? On Thu, Jul 19, 2012 at 5:48 PM, Roy Liu <liuchua...@gmail.com> wrote:
> Hi, > > When I use Transformer to handle files, I always get NULL with > row.get(columnName). > anyone knows? > > -------------- > The following file is *data-config.xml* > > <dataConfig> > <dataSource type="JdbcDataSource" > name="ds" > driver="oracle.jdbc.driver.OracleDriver" > url="jdbc:oracle:thin:@10.1.1.1:1521:sid" > user="username" > password="pwd" > /> > <document name="BS_REPORT"> > > <entity name="report" pk="ID" > query="select a.objid as ID from DOCGENERAL a where > a.objid=14154965"> > > <field column="ID" name="id" /> > > *<entity name="attachment" * > * query="select docid as ID, name as filename, > storepath as filepath from attachment where docid=${report.ID}" * > * transformer="com.bs.solr.BSFileTransformer" >* > * <field column="ID" name="bs_attachment_id" />* > * <field column="filename" name="bs_attachment_name" />* > * <field column="filepath" name="bs_attachment" isfile="true"/>* > * </entity>* > > </entity> > > </document> > </dataConfig> > > > public class *BSFileTransformer *extends Transformer { > private static Log LOGGER = LogFactory.getLog(BSFileTransformer.class); > @Override > public Object transformRow(Map<String, Object> row, Context context) { > // row.get("filename") is always null,but row.get("id") is > OK. > S*ystem.out.println("==============filename:"+row.get("filename"));* > > List<Map<String, String>> fields = context.getAllEntityFields(); > > String id = null; // Entity ID > String fileName = "NONAME"; > for (Map<String, String> field : fields) { > String name = field.get("name"); > System.out.println("----name:" + name); > if ("bs_attachment_id".equals(name)) { > String columnName = field.get("column"); > id = String.valueOf(row.get(columnName)); > } > if ("bs_attachment_name".equals(name)) { > String columnName = field.get("column"); > fileName = (String) row.get(columnName); > } > String isFile = field.get("isfile"); > if ("true".equals(isFile)) { > String columnName = field.get("column"); > String filePath = (String) row.get(columnName); > > try { > System.out.println("----fileName:"+ fileName+",filePath: " + filePath); > if(filePath != null){ > File file = new File(filePath); > InputStream inputStream = new FileInputStream(file); > Tika tika = new Tika(); > String text = tika.parseToString(inputStream); > row.put(columnName, text); > } > LOGGER.info("Processed File OK! Entity: " + fileName + ", ID: " +id); > } catch (IOException ioe) { > LOGGER.error(ioe.getMessage()); > row.put(columnName, ""); > } catch (TikaException e) { > LOGGER.error("Parse File Error:" + id + ", Error:" > + e.getMessage()); > row.put(columnName, ""); > } > } > } > return row; > } > } >