0
votes

I am trying to understand how MFP JSONStore & HTTP adapters work. I downloaded the source code here. I followed the steps to build the app. I also deployed this adapter here. But when I tried to push the dirty data to the adapter, I got noting there. The adapter still logs undefined.

Here is the push function code:

function pushToAdapter(){
    alert("pushToAdapter");
    try {
        WL.JSONStore.get(collectionName).push().then(function (res) {
            if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
                document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
            } else {
                document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
            }   
        }).fail(function (errorObject) {
            alert(errorObject.msg);
        });
    } catch (e) {
        alert("Failed To Push Documents to Adapter");
    }
}

& this is the adapter code:

function pushPeople(data) {
    MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
    MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
    return;
}

function addPerson(data) {
    MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
    MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
    return;
}

function removePerson(data) {
    MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
    MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
    return;
}

Please note that I am using a patched version of cordova-plugin-mfp-jsonstore. It is the same as this version except for lines 5238 (as follows):

resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure,  WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);
1
I have tried exactly the same steps and the application works as expected. Here is the link to my Android project with the patch (setting the header) applied. Note: Import the project as is into Android studio modify the server end point and run the project. Do not perform any cordova operation on the project which can be overwriting the patch applied. If you still face an issue you could share your project as well, i can take a look at it.S.A.Norton Stanley
It is the same. no data received in the adapter. here is what I get in the adapter: MFP.Logger I Adapter: JSONStoreAdapter, procedure: addPerson called. MFP.Logger I Got data from JSONStore to ADD: undefined I am wondering, where is the data get sent to the adapter? I mean invocationData.parameters(line 5224 in jsonstore.js) is never used anywhere!. Also resourceRequest.send() is parameterless!. May this be the cause for receiving nothing in the adapter?user1040987

1 Answers

2
votes

Looks like the parameters were not being passed as a part of the push request. You can use the jsonstore.js provided here and verify if it solves your problem. This will be officially released in the next iFix.