@Test public void mapToMappedRecord() throws Exception { Map<String, Object> functionMap = createFunctionMap(); MappedRecord record = mapper.mapFunctionMapValuesToMappedRecord("BAPI_NAME", recordFactory, functionMap); assertEquals("BAPI_NAME", record.getRecordName()); String importParam1 = (String) record.get("IMPORT_PARAM2"); assertEquals("importParam2", importParam1); int param3 = (Integer) record.get("IMPORT_PARAM3"); assertEquals(3, param3); MappedRecord importStruct = (MappedRecord) record.get("IMPORT_PARAM1"); assertEquals("IMPORT_PARAM1", importStruct.getRecordName()); assertEquals(1, importStruct.get("STRUCT_FIELD1")); assertEquals("structField2", importStruct.get("STRUCT_FIELD2")); assertThat(record.get("CHANGING_PARAM1")).isEqualTo("changingParam1"); assertThat(record.get("CHANGING_PARAM2")).isEqualTo(2); IndexedRecord tableParam1 = (IndexedRecord) record.get("TABLE_PARAM1"); assertEquals("TABLE_PARAM1", tableParam1.getRecordName()); MappedRecord row1 = (MappedRecord) tableParam1.get(0); assertEquals("tableField1", row1.get("TABLE_FIELD1")); assertEquals(new Date(1), row1.get("TABLE_FIELD2")); assertEquals(1, row1.get("TABLE_FIELD3")); MappedRecord row2 = (MappedRecord) tableParam1.get(1); assertEquals("tableField2", row2.get("TABLE_FIELD1")); assertEquals(new Date(2), row2.get("TABLE_FIELD2")); assertEquals(2, row2.get("TABLE_FIELD3")); }
@SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } }
JCAMapper { @SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } } }
JCAMapper { @SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } }  }
JCAMapper { @SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } }  MappedRecord mapFunctionMapValuesToMappedRecord(final String bapiName,
                                                           final RecordFactory recordFactory,
                                                           final Map<String, Object> functionMap); void mapRecordToFunctionMap(final Map<String, Object> functionMap,
                                       final Map<String, Object> resultRecordMap,
                                       final BapiMapping bapiMapping); }
JCAMapper { @SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } }  MappedRecord mapFunctionMapValuesToMappedRecord(final String bapiName,
                                                           final RecordFactory recordFactory,
                                                           final Map<String, Object> functionMap); void mapRecordToFunctionMap(final Map<String, Object> functionMap,
                                       final Map<String, Object> resultRecordMap,
                                       final BapiMapping bapiMapping);  }