[FAB-16607] Update FabCar to reflect CC updates

Node.js CC:
As a result of using the new protobufjs library, certain
external APIs have changed in the Node.js chaincode. The
samples need to be updated to use these new APIs.

Java CC:
As a result of moving to Java 11, we hit this issue:
https://github.com/gradle/gradle/issues/8286
The sample needs to be updated to specify the absolute
path to checkstyle's suppression.xml.

Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
Change-Id: I4db886b3feff46d165e05a7eda624230b65f9cbe
This commit is contained in:
Simon Stone 2019-09-18 09:52:00 +01:00
parent 3fad853c15
commit 521a7ffc4a
3 changed files with 24 additions and 50 deletions

View file

@ -30,7 +30,7 @@
<property name="fileExtensions" value="java, properties, xml"/> <property name="fileExtensions" value="java, properties, xml"/>
<module name="SuppressionFilter"> <module name="SuppressionFilter">
<property name="file" value="config/checkstyle/suppressions.xml"/> <property name="file" value="${config_loc}/suppressions.xml"/>
<property name="optional" value="false"/> <property name="optional" value="false"/>
</module> </module>

View file

@ -108,34 +108,21 @@ class FabCar extends Contract {
async queryAllCars(ctx) { async queryAllCars(ctx) {
const startKey = 'CAR0'; const startKey = 'CAR0';
const endKey = 'CAR999'; const endKey = 'CAR999';
const iterator = await ctx.stub.getStateByRange(startKey, endKey);
const allResults = []; const allResults = [];
while (true) { for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
const res = await iterator.next(); const strValue = Buffer.from(value).toString('utf8');
let record;
if (res.value && res.value.value.toString()) {
console.log(res.value.value.toString('utf8'));
const Key = res.value.key;
let Record;
try { try {
Record = JSON.parse(res.value.value.toString('utf8')); record = JSON.parse(strValue);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
Record = res.value.value.toString('utf8'); record = strValue;
} }
allResults.push({ Key, Record }); allResults.push({ Key: key, Record: record });
} }
if (res.done) {
console.log('end of data');
await iterator.close();
console.info(allResults); console.info(allResults);
return JSON.stringify(allResults); return JSON.stringify(allResults);
} }
}
}
async changeCarOwner(ctx, carNumber, newOwner) { async changeCarOwner(ctx, carNumber, newOwner) {
console.info('============= START : changeCarOwner ==========='); console.info('============= START : changeCarOwner ===========');

View file

@ -107,34 +107,21 @@ export class FabCar extends Contract {
public async queryAllCars(ctx: Context): Promise<string> { public async queryAllCars(ctx: Context): Promise<string> {
const startKey = 'CAR0'; const startKey = 'CAR0';
const endKey = 'CAR999'; const endKey = 'CAR999';
const iterator = await ctx.stub.getStateByRange(startKey, endKey);
const allResults = []; const allResults = [];
while (true) { for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
const res = await iterator.next(); const strValue = Buffer.from(value).toString('utf8');
let record;
if (res.value && res.value.value.toString()) {
console.log(res.value.value.toString('utf8'));
const Key = res.value.key;
let Record;
try { try {
Record = JSON.parse(res.value.value.toString('utf8')); record = JSON.parse(strValue);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
Record = res.value.value.toString('utf8'); record = strValue;
} }
allResults.push({ Key, Record }); allResults.push({ Key: key, Record: record });
} }
if (res.done) {
console.log('end of data');
await iterator.close();
console.info(allResults); console.info(allResults);
return JSON.stringify(allResults); return JSON.stringify(allResults);
} }
}
}
public async changeCarOwner(ctx: Context, carNumber: string, newOwner: string) { public async changeCarOwner(ctx: Context, carNumber: string, newOwner: string) {
console.info('============= START : changeCarOwner ==========='); console.info('============= START : changeCarOwner ===========');