Example usage for org.springframework.batch.item.file.transform DefaultFieldSet DefaultFieldSet

List of usage examples for org.springframework.batch.item.file.transform DefaultFieldSet DefaultFieldSet

Introduction

In this page you can find the example usage for org.springframework.batch.item.file.transform DefaultFieldSet DefaultFieldSet.

Prototype

public DefaultFieldSet(String[] tokens, String[] names) 

Source Link

Document

Create a FieldSet with named tokens.

Usage

From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java

@Test
public void test() {
    FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider();
    FieldSet aFieldSet = new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" },
            new String[] { "TypeDoc", "Montant", "Date" });
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet);
    assertNotNull(aResult);/*from w w  w  .  j av  a2  s  . c  o  m*/
    assertEquals("Facture", aResult.getValue("rec0_TypeDoc"));
    assertEquals("2222.22", aResult.getValue("rec0_Montant"));
    assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_Date"));
    assertFalse(aResult.hasValue("rec1_TypeDoc"));
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void test() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(2);
    aFieldSetList.add(new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" },
            new String[] { "TypeDoc", "Montant", "Date" }));
    aFieldSetList.add(new DefaultFieldSet(new String[] { "Avoir", "-333.00", "" },
            new String[] { "TypeDoc", "Montant", "Date" }));
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList);
    assertNotNull(aResult);//from ww  w.j a v a 2s .co  m
    assertEquals("Facture", aResult.getValue("rec0_TypeDoc"));
    assertEquals("2222.22", aResult.getValue("rec0_Montant"));
    assertEquals("2014-08-01T12:00:00.000", aResult.getValue("rec0_Date"));
    assertEquals("Avoir", aResult.getValue("rec1_TypeDoc"));
    assertEquals("-333.00", aResult.getValue("rec1_Montant"));
    assertEquals("", aResult.getValue("rec1_Date"));
    assertFalse(aResult.hasValue("rec2_TypeDoc"));
}

From source file:fr.acxio.tools.agia.transform.ListFieldSetToMapProcessorTest.java

@Test
public void test() throws Exception {
    ListFieldSetToMapProcessor aProcessor = new ListFieldSetToMapProcessor();

    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(2);
    aFieldSetList.add(new DefaultFieldSet(new String[] { "Facture", "2222.22", "2014-08-01T12:00:00.000" },
            new String[] { "TypeDoc", "Montant", "Date" }));
    aFieldSetList.add(new DefaultFieldSet(new String[] { "Avoir", "-333.00", "" },
            new String[] { "TypeDoc", "Montant", "Date" }));

    Map<String, Object> aResult = aProcessor.process(aFieldSetList);

    assertNotNull(aResult);/*w ww .  j  a  v  a 2s. c om*/
    assertEquals("Facture", aResult.get("rec0_TypeDoc"));
    assertEquals("2222.22", aResult.get("rec0_Montant"));
    assertEquals("2014-08-01T12:00:00.000", aResult.get("rec0_Date"));
    assertEquals("Avoir", aResult.get("rec1_TypeDoc"));
    assertEquals("-333.00", aResult.get("rec1_Montant"));
    assertEquals("", aResult.get("rec1_Date"));
    assertFalse(aResult.containsKey("rec2_TypeDoc"));
}

From source file:com.ifeng.computing.batch.job.reader.JsonLineTokenizer.java

@Override
public FieldSet tokenize(String line) {
    List<String> tokens = new ArrayList<>();

    try {/* w w  w . j  a  v a 2 s.com*/
        HashMap<String, Object> result = new ObjectMapper().readValue(line, HashMap.class);

        tokens.add((String) result.get("field1"));
        tokens.add((String) result.get("field2"));

    } catch (IOException e) {
        throw new RuntimeException("Unable to parse json: " + line);
    }

    return new DefaultFieldSet(tokens.toArray(new String[0]), new String[] { "field1", "field2" });
}

From source file:fr.acxio.tools.agia.item.MultiLineNodeListItemReaderTest.java

@Test
public void testRead() throws Exception {
    MultiLineNodeListItemReader aReader = new MultiLineNodeListItemReader();

    ItemReader<FieldSet> aDelegate = mock(FieldSetItemReader.class);

    when(aDelegate.read()).thenReturn(/*from ww  w. j  a  va2  s  .com*/
            new DefaultFieldSet(new String[] { "Type1", "123" }, new String[] { "Type", "Value" }),
            new DefaultFieldSet(new String[] { "Type2", "ABC", "2014-08-14" },
                    new String[] { "Type", "Value1", "Value2" }),
            new DefaultFieldSet(new String[] { "Type1", "345" }, new String[] { "Type", "Value" }),
            new DefaultFieldSet(new String[] { "Type2", "DEF", "2014-08-13" },
                    new String[] { "Type", "Value1", "Value2" }),
            new DefaultFieldSet(new String[] { "Type3", "789GHI", null },
                    new String[] { "Type", "Value1", "Value2" }),
            null);

    aReader.setDelegate(aDelegate);
    aReader.setNewRecordCondition("@{#next == null or #next['Type'].equals('Type1')}");

    aReader.open(new ExecutionContext());
    List<FieldSet> aRecord1 = aReader.read();
    List<FieldSet> aRecord2 = aReader.read();
    List<FieldSet> aRecord3 = aReader.read();
    aReader.close();

    assertNotNull(aRecord1);
    assertNotNull(aRecord2);
    assertNull(aRecord3);
    assertEquals(2, aRecord1.size());
    assertEquals(3, aRecord2.size());
    assertEquals("123", aRecord1.get(0).getValues()[1]);
    assertEquals("ABC", aRecord1.get(1).getValues()[1]);
    assertEquals("345", aRecord2.get(0).getValues()[1]);
    assertEquals("DEF", aRecord2.get(1).getValues()[1]);
    assertEquals("789GHI", aRecord2.get(2).getValues()[1]);
}

From source file:fr.acxio.tools.agia.item.database.FieldSetSqlParameterSourceProviderTest.java

@Test
public void testEmpty() {
    FieldSetSqlParameterSourceProvider aProvider = new FieldSetSqlParameterSourceProvider();
    FieldSet aFieldSet = new DefaultFieldSet(new String[] {}, new String[] {});
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSet);
    assertNotNull(aResult);/*from  www.j  a  v a2  s  .com*/
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.ConfigurationTest.java

@Test
public void testSimpleNodeFactory() throws Exception {
    StandardEvaluationContext aContext = new StandardEvaluationContext();
    FieldSet aData = new DefaultFieldSet(new String[] { "V1", "V2", "V3" }, new String[] { "C1", "C2", "C3" });
    aContext.setVariable("in", aData.getProperties());
    NodeList aNodeList = defaultNodeFactory.getNodes(aContext);
    assertNotNull(aNodeList);/*from  ww w . j  ava  2s  .  com*/
    assertEquals(5, aNodeList.size());
}

From source file:fr.acxio.tools.agia.transform.ListFieldSetToMapProcessorTest.java

@Test
public void testEmptyFieldSet() throws Exception {
    ListFieldSetToMapProcessor aProcessor = new ListFieldSetToMapProcessor();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    aFieldSetList.add(new DefaultFieldSet(new String[] {}, new String[] {}));
    Map<String, Object> aResult = aProcessor.process(aFieldSetList);
    assertNotNull(aResult);//from  w ww  . ja  va 2 s  .c o  m
    assertFalse(aResult.containsKey("rec0_TypeDoc"));
}

From source file:fr.acxio.tools.agia.alfresco.ListFieldSetToNodeProcessorTest.java

@Test
public void testSingleFolder() throws Exception {
    ListFieldSetToNodeProcessor aProcessor = createSimpleProcessor();

    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    aFieldSetList.add(new DefaultFieldSet(new String[] { "test" }, new String[] { "name" }));
    NodeList aResult = aProcessor.process(aFieldSetList);
    assertNotNull(aResult);/*  ww w .  ja  v a  2 s  . c om*/
    assertEquals(1, aResult.size());
    assertEquals("/cm:test", aResult.get(0).getPath());
}

From source file:fr.acxio.tools.agia.item.database.ListFieldSetSqlParameterSourceProviderTest.java

@Test
public void testEmptyFieldSet() {
    ListFieldSetSqlParameterSourceProvider aProvider = new ListFieldSetSqlParameterSourceProvider();
    List<FieldSet> aFieldSetList = new ArrayList<FieldSet>(1);
    aFieldSetList.add(new DefaultFieldSet(new String[] {}, new String[] {}));
    SqlParameterSource aResult = aProvider.createSqlParameterSource(aFieldSetList);
    assertNotNull(aResult);//from www  .ja  v  a2  s.  com
    assertFalse(aResult.hasValue("rec0_TypeDoc"));
}