javax.resource.cci.MappedRecord Java Examples

The following examples show how to use javax.resource.cci.MappedRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCAMapper.java    From hibersap with Apache License 2.0 6 votes vote down vote up
public MappedRecord mapFunctionMapValuesToMappedRecord(final String bapiName,
                                                       final RecordFactory recordFactory,
                                                       final Map<String, Object> functionMap) throws ResourceException {
    LOG.debug("mapFunctionMapValuesToMappedRecord() functionMap=" + functionMap);

    MappedRecord mappedInputRecord = recordFactory.createMappedRecord(bapiName);

    final Map<String, Object> importMap = UnsafeCastHelper.castToMap(functionMap.get(BapiConstants.IMPORT));
    mapToMappedRecord(recordFactory, mappedInputRecord, importMap);

    final Map<String, Object> changingMap = UnsafeCastHelper.castToMap(functionMap.get(BapiConstants.CHANGING));
    mapToMappedRecord(recordFactory, mappedInputRecord, changingMap);

    final Map<String, Object> tableMap = UnsafeCastHelper.castToMap(functionMap.get(TABLE));
    mapToMappedRecord(recordFactory, mappedInputRecord, tableMap);

    LOG.debug("mapFunctionMapValuesToMappedRecord() record=" + mappedInputRecord);

    return mappedInputRecord;
}
 
Example #2
Source File: JCAConnection.java    From hibersap with Apache License 2.0 6 votes vote down vote up
public void execute(final BapiMapping bapiMapping, final Map<String, Object> functionMap) {
    Record result;

    try {
        MappedRecord mappedInputRecord = mapper.mapFunctionMapValuesToMappedRecord(bapiMapping.getBapiName(), recordFactory,
                functionMap);

        LOG.debug("JCA Execute: " + bapiMapping.getBapiName() + ", arguments= " + functionMap + "\ninputRecord = "
                + mappedInputRecord);

        result = connectionProvider.getConnection().createInteraction().execute(null, mappedInputRecord);

        LOG.debug("JCA Execute: " + bapiMapping.getBapiName() + ", result = " + result);

        final Map<String, Object> resultMap = UnsafeCastHelper.castToMap(result);
        mapper.mapRecordToFunctionMap(functionMap, resultMap, bapiMapping);
    } catch (final ResourceException e) {
        throw new HibersapException("Error executing function module " + bapiMapping.getBapiName(), e);
    }
}
 
Example #3
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCreateMappedRecord() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	MappedRecord mappedRecord = mock(MappedRecord.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(recordFactory.createMappedRecord("name")).willReturn(mappedRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.createMappedRecord("name");

	verify(recordFactory).createMappedRecord("name");
}
 
Example #4
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCreateMappedRecord() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	MappedRecord mappedRecord = mock(MappedRecord.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(recordFactory.createMappedRecord("name")).willReturn(mappedRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.createMappedRecord("name");

	verify(recordFactory).createMappedRecord("name");
}
 
Example #5
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateMappedRecord() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	MappedRecord mappedRecord = mock(MappedRecord.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(recordFactory.createMappedRecord("name")).willReturn(mappedRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.createMappedRecord("name");

	verify(recordFactory).createMappedRecord("name");
}
 
Example #6
Source File: JCAMapper.java    From hibersap with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void appendToRecord(final Record record, final String fieldName, final Object value) {
    if (record instanceof IndexedRecord) {
        ((IndexedRecord) record).add(value);
    } else {
        ((MappedRecord) record).put(fieldName, value);
    }
}
 
Example #7
Source File: JCAMapper.java    From hibersap with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example #8
Source File: JCAMapperTest.java    From hibersap with Apache License 2.0 5 votes vote down vote up
@Test
public void mapToMappedRecord()
        throws Exception {
    // map
    Map<String, Object> functionMap = createFunctionMap();
    MappedRecord record = mapper.mapFunctionMapValuesToMappedRecord("BAPI_NAME", recordFactory, functionMap);

    assertEquals("BAPI_NAME", record.getRecordName());

    // check import parameters
    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"));

    // check changing parameters
    assertThat(record.get("CHANGING_PARAM1")).isEqualTo("changingParam1");
    assertThat(record.get("CHANGING_PARAM2")).isEqualTo(2);

    // check table parameters
    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"));
}
 
Example #9
Source File: NotSupportedRecordFactory.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public MappedRecord createMappedRecord(String name) throws ResourceException {
	throw new NotSupportedException("The RecordFactory facility is not supported by the connector");
}
 
Example #10
Source File: NotSupportedRecordFactory.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public MappedRecord createMappedRecord(String name) throws ResourceException {
	throw new NotSupportedException("The RecordFactory facility is not supported by the connector");
}
 
Example #11
Source File: NotSupportedRecordFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MappedRecord createMappedRecord(String name) throws ResourceException {
	throw new NotSupportedException("The RecordFactory facility is not supported by the connector");
}
 
Example #12
Source File: NotSupportedRecordFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public MappedRecord createMappedRecord(String name) throws ResourceException {
	throw new NotSupportedException("The RecordFactory facility is not supported by the connector");
}
 
Example #13
Source File: JCAMapper.java    From hibersap with Apache License 2.0 4 votes vote down vote up
public void mapRecordToFunctionMap(final Map<String, Object> functionMap,
                                   final Map<String, Object> resultRecordMap,
                                   final BapiMapping bapiMapping) {
    LOG.debug("mapRecordToFunctionMap() recordMap=" + resultRecordMap);

    for (final Entry<String, Object> entry : resultRecordMap.entrySet()) {
        final Object recordValue = entry.getValue();
        final String recordKey = entry.getKey();

        if (recordValue != null) {
            LOG.debug("mapping " + recordValue.getClass().getName() + ": " + recordKey + "=" + recordValue);
        }

        if (recordValue instanceof IndexedRecord) {
            // Table parameter
            final IndexedRecord indexedResultRecord = (IndexedRecord) recordValue;
            List<Map<String, Object>> table = new ArrayList<>();

            for (Object object : indexedResultRecord) {
                MappedRecord mr = (MappedRecord) object;
                final Map<String, Object> line = new HashMap<>();

                @SuppressWarnings("unchecked")
                Set<String> keys = mr.keySet();

                for (String key : keys) {
                    line.put(key, mr.get(key));
                }
                table.add(line);
            }

            Map<String, Object> tables = UnsafeCastHelper.castToMap(functionMap.get(TABLE));
            tables.put(indexedResultRecord.getRecordName(), table);
        } else {
            // Simple parameter or structure parameter (the latter is a MappedRecord which luckily implements Map)
            String parameterType = getParameterType(recordKey, bapiMapping);
            if (isNotBlank(parameterType)) {
                Map<String, Object> export = UnsafeCastHelper.castToMap(functionMap.get(parameterType));
                export.put(recordKey, recordValue);
            } else {
                LOG.debug("Skipping unmapped parameter: " + recordKey);
            }
        }
    }
    LOG.debug("mapRecordToFunctionMap() functionMap=" + functionMap);
}
 
Example #14
Source File: JCAMapperTest.java    From hibersap with Apache License 2.0 4 votes vote down vote up
@Override
public MappedRecord answer(InvocationOnMock invocation) {
    String name = invocation.getArgument(0);
    return new MyMappedRecord(name);
}
 
Example #15
Source File: HelloWorldRecordFactoryImpl.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
/**
 * @see RecordFactory#createMappedRecord(String)
 */
public MappedRecord createMappedRecord(String recordName)
	throws ResourceException {

	throw new NotSupportedException(MAPPED_RECORD_NOT_SUPPORTED_ERROR);
}