Commit 6e8ca3c5 authored by Anuj Gupta's avatar Anuj Gupta
Browse files

Merge branch 'ibm-open-issues-ctag-final' into 'master'

fix: IBM open issues ctag final

See merge request !136
parents cc64b65b 3d6b11f9
Pipeline #50570 passed with stages
in 12 minutes and 2 seconds
...@@ -18,14 +18,13 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -18,14 +18,13 @@ export class DatastoreDAO extends AbstractJournal {
public constructor(tenant: TenantModel) { public constructor(tenant: TenantModel) {
super(); super();
logger.info('In datastore.constructor.'); logger.info('In datastore.constructor.');
this.dataPartition = tenant.esd.indexOf('.') !== -1 ? tenant.esd.split('.')[0] : tenant.esd; this.dataPartition = tenant.gcpid;
} }
public async initDb(dataPartition: string) public async initDb(dataPartition: string)
{ {
logger.info('In datastore.initDb.'); logger.info('In datastore.initDb.');
const dbUrl = IbmConfig.DOC_DB_URL; const dbUrl = IbmConfig.DOC_DB_URL;
logger.debug(dbUrl);
const cloudantOb = cloudant(dbUrl); const cloudantOb = cloudant(dbUrl);
logger.info('DB initialized. cloudantOb-'); logger.info('DB initialized. cloudantOb-');
...@@ -84,23 +83,22 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -84,23 +83,22 @@ export class DatastoreDAO extends AbstractJournal {
await this.initDb(this.dataPartition); await this.initDb(this.dataPartition);
logger.info('Fetching document.'); logger.info('Fetching document.');
/// changed from entity.name to entity.key.name try{
await this.docDb.get(entity.key.name, { revs_info: true }, (err, existingDoc) => { const getResponse = await this.docDb.get(entity.key.name, { revs_info: true });
logger.info('Document exists in db.');
if (!err) {/// update record const existingDoc = getResponse;
logger.info('Document exists in db.'); const docTemp = JSON.parse(JSON.stringify(existingDoc));
const docTemp = JSON.parse(JSON.stringify(existingDoc)); /// have to add if condition. before that check the dataset object structure
/// have to add if condition. before that check the dataset object structure docTemp.ltag = entity.ltag;
docTemp.ltag = entity.ltag; if (entity.data.trusted)
if (entity.data.trusted) docTemp.trusted = entity.data.trusted;
docTemp.trusted = entity.data.trusted;
Object.assign(docTemp, entity.data);
Object.assign(docTemp, entity.data); logger.debug(docTemp);
logger.debug(docTemp); await this.docDb.insert(docTemp, entity.key.name);
this.docDb.insert(docTemp, entity.key.name); logger.info('Document updated.');
logger.info('Document updated.'); } catch(err){
} if(err.statusCode === 404)
else/// insert record
{ {
logger.info('Document does not exist. This will be a new document'); logger.info('Document does not exist. This will be a new document');
const customizedOb = {}; const customizedOb = {};
...@@ -110,13 +108,13 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -110,13 +108,13 @@ export class DatastoreDAO extends AbstractJournal {
for (const element in entity.data) { for (const element in entity.data) {
if (!((entity.key.kind === 'datasets' || entity.key.kind === 'seismicmeta') && element === '_id')) if (!((entity.key.kind === 'datasets' || entity.key.kind === 'seismicmeta') && element === '_id'))
if (!((entity.key.kind === 'datasets' || entity.key.kind === 'seismicmeta') && element === '_rev')) if (!((entity.key.kind === 'datasets' || entity.key.kind === 'seismicmeta') && element === '_rev'))
customizedOb[element] = entity.data[element]; customizedOb[element] = entity.data[element];
}; };
logger.debug(customizedOb); logger.debug(customizedOb);
this.docDb.insert(customizedOb, entity.key.name); await this.docDb.insert(customizedOb, entity.key.name);
logger.info('Document inserted.'); logger.info('Document inserted.');
} }
}); }
logger.info('Returning from datastore.save.'); logger.info('Returning from datastore.save.');
} }
...@@ -582,4 +580,4 @@ class QueryStatementBuilder { ...@@ -582,4 +580,4 @@ class QueryStatementBuilder {
logger.debug(selectorQuery); logger.debug(selectorQuery);
return selectorQuery; return selectorQuery;
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment