Skip to content

Commit

Permalink
- fixed bug (cache_resource, parse for object)
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTKETI committed Jul 15, 2022
1 parent c21a53b commit 7d00eaf
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 84 deletions.
21 changes: 19 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,10 @@ function lookup_retrieve(request, response, callback) {
if (code === '200') {
var resultObj = request.targetObject[Object.keys(request.targetObject)[0]];

if(!resultObj.hasOwnProperty('acpi')) {
resultObj.acpi = [];
}

tr.check(request, (code) => {
if (code === '200') {
if (resultObj.ty == 2) {
Expand Down Expand Up @@ -1207,10 +1211,13 @@ function get_resource_from_url(connection, ri, sri, option, callback) {
if(cache_resource_url.hasOwnProperty(ri + '/la')) {

ty = cache_resource_url[ri + '/la'].ty;
targetObject[responder.typeRsrc[ty]] = cache_resource_url[ri + '/la'];
targetObject = {};
targetObject[responder.typeRsrc[ty]] = JSON.parse(JSON.stringify(cache_resource_url[ri + '/la']));
rootnm = Object.keys(targetObject)[0];
makeObject(targetObject[rootnm]);

console.log(targetObject);

callback(targetObject, 200);
}
else {
Expand All @@ -1221,11 +1228,21 @@ function get_resource_from_url(connection, ri, sri, option, callback) {
console.timeEnd(la_id);
if (code === '200') {
if (latestObj.length == 1) {
cache_resource_url[latestObj[0].pi + '/la'] = latestObj[0];

console.log(latestObj);

let strLatestObj = JSON.stringify(latestObj[0]).replace('RowDataPacket ', '');

latestObj[0] = JSON.parse(strLatestObj);
console.log(latestObj);

targetObject = {};
targetObject[responder.typeRsrc[latestObj[0].ty]] = latestObj[0];
makeObject(targetObject[Object.keys(targetObject)[0]]);

cache_resource_url[latestObj[0].pi + '/la'] = targetObject[Object.keys(targetObject)[0]];
console.log(cache_resource_url);

callback(targetObject);
}
else {
Expand Down
171 changes: 89 additions & 82 deletions mobius/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1546,18 +1546,25 @@ global.makeObject = function (obj) {
}
else {
if(attr == 'subl') {
if((obj[attr] == null) || (attr == '')) {
if((obj[attr] == null) || (obj[attr] == '')) {
obj[attr] = '[]';
}
}

if (attr == 'aa' || attr == 'at' || attr == 'lbl' || attr == 'srt' || attr == 'nu' || attr == 'acpi' || attr == 'poa' || attr == 'enc'
|| attr == 'bn' || attr == 'pv' || attr == 'pvs' || attr == 'mid' || attr == 'uds' || attr == 'cas' || attr == 'macp'
|| attr == 'rels' || attr == 'rqps' || attr == 'rsps' || attr == 'srv' || attr == 'mi' || attr == 'subl') {
var obj_type = getType(obj[attr]);
if (obj_type === 'string_object') {
try {
console.log(attr);
if((obj[attr] == null) || (obj[attr] == '')) {
obj[attr] = '[]';
}

obj[attr] = JSON.parse(obj[attr]);
}
catch (e) {
console.log(e.message);
}
}
else if (attr == 'trqp') {
var trqp_type = getType(obj.trqp);
Expand Down Expand Up @@ -1798,55 +1805,55 @@ function update_action(request, response, callback) {
}
else if (ty == '9') {
db_sql.update_grp(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '10') {
db_sql.update_lcp(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '13') {
if (responder.mgoType[resource_Obj[rootnm].mgd] == rootnm) {
if (resource_Obj[rootnm].mgd == 1001) {
db_sql.update_fwr(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (resource_Obj[rootnm].mgd == 1006) {
db_sql.update_bat(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (resource_Obj[rootnm].mgd == 1007) {
db_sql.update_dvi(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (resource_Obj[rootnm].mgd == 1008) {
db_sql.update_dvc(request.db_connection, resource_Obj[rootnm].lt, JSON.stringify(resource_Obj[rootnm].acpi), resource_Obj[rootnm].et, resource_Obj[rootnm].st, JSON.stringify(resource_Obj[rootnm].lbl),
Expand All @@ -1863,13 +1870,13 @@ function update_action(request, response, callback) {
}
else if (resource_Obj[rootnm].mgd == 1009) {
db_sql.update_rbo(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else {
callback('400-53');
Expand Down Expand Up @@ -1976,23 +1983,23 @@ function update_action(request, response, callback) {
}
else if (ty == '14') {
db_sql.update_nod(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '16') {
db_sql.update_csr(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '23') {
db_sql.update_sub(request.db_connection, resource_Obj[rootnm], function (err, results) {
Expand Down Expand Up @@ -2024,35 +2031,35 @@ function update_action(request, response, callback) {
}
else if (ty == '24') {
db_sql.update_smd(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '29') {
db_sql.update_ts(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
check_TS(resource_Obj[rootnm].ri, function (rsc, res_Obj) {
});
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
check_TS(resource_Obj[rootnm].ri, function (rsc, res_Obj) {
});
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '27') {
db_sql.update_mms(request.db_connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
if (!err) {
callback('200');
}
else {
callback('500-1');
}
});
}
else if (ty == '38') { // transactionMgmt
if (resource_Obj[rootnm].tctl == tctl_v.LOCK && (resource_Obj[rootnm].tst == tst_v.INITIAL)) { // LOCK
Expand Down

0 comments on commit 7d00eaf

Please sign in to comment.