0

我正在使用带有 mfp cli 的 jsonStore 插件。

我已经确认插件已安装已安装。调用任何其他 WL。api 在我的项目中工作

但是当我运行此代码时,我收到一条错误消息:

PERSISTANT_STORE_NOT_OPEN

(function () {
'use strict';

angular
    .module('app')
    .run(appRun);

appRun.$inject = [ '$ionicPlatform', '$rootScope','MFPClientPromise', '$state', 'signinService', 'errorToastService', '$ionicHistory' ];

window.Messages = {
    // Add here your messages for the default language.
    // Generate a similar file with a language suffix containing the translated messages.
    // key1 : message1,
};

window.wlInitOptions = {
    // Options to initialize with the WL.Client object.
    // For initialization options please refer to IBM MobileFirst Platform Foundation Knowledge Center.
};

window.MFPClientDefer = angular.injector(['ng']).get('$q').defer();
window.wlCommonInit = window.MFPClientDefer.resolve;
window.MFPClientDefer.promise.then(function wlCommonInit(){
    // Common initialization code goes here or use the angular service MFPClientPromise
    console.log('MobileFirst Client SDK Initilized');
    mfpMagicPreviewSetup();
});

function appRun($ionicPlatform, $rootScope, MFPClientPromise, $state, signinService, errorToastService, $ionicHistory){
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
            cordova.plugins.Keyboard.disableScroll(true);

        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }

        //android backbutton handling
        $ionicPlatform.registerBackButtonAction(function (event) {
            event.preventDefault();
            //if ($ionicHistory.currentStateName === 'app.capture-check'){
            //    event.preventDefault();
            //} else {
            //    $ionicHistory.goBack();
            //}
        }, 100);

        MFPClientPromise.then(function(){
            WL.Logger.ctx({pkg: 'io.ionic'}).debug('mfp and ionic are ready, safe to use WL.* APIs');

            //get the devices ID
            var deviceId = WL.Device.getID({
                onSuccess: function (response) {
                    console.log('Device ID: ' + response.deviceID);
                    return response.deviceID
                },
                onFailure: function () { console.log("didn't get deviceId") }
            });

            //get the devices network info
            var networkInfo = WL.Device.getNetworkInfo(function (response) {
                console.log('network info: ' + angular.toJson(response));
                return response;
            });


            $rootScope.busyInd = new WL.BusyIndicator ({text: "Please wait..."});

            //auth challenge handler
            $rootScope.challengeHandler = WL.Client.createChallengeHandler("KMF_AuthenticatorRealm");

            $rootScope.challengeHandler.isCustomResponse = function(response) {

                console.log("Inside isCustomResponse:   ", response );

                if (!response || !response.responseJSON) {
                    return false;
                }

                if (response.responseJSON.authStatus) {

                    console.log("Inside isCustomResponse return true? :   ", response.responseJSON.authStatus );
                    return true;
                } else {
                    return false;
                }
            };

            $rootScope.challengeHandler.logger = WL.Logger.create({pkg:"challengeHandler"});

            $rootScope.challengeHandler.handleChallenge = function(challenge) {
                console.log("handle challenge in challenge handler", challenge);
                var authStatus = challenge.responseJSON.authStatus;

                var challengeUsername = signinService.username;
                var challengePassword = signinService.password;

                $rootScope.ctok = challenge.responseJSON.ctok;
                signinService.disclosure = challenge.responseJSON.disclosure;
                signinService.challenge = challenge.responseJSON.challenge;
                signinService.depositor = challenge.responseJSON.depositor;
                signinService.reviewer = challenge.responseJSON.reviewer;
                signinService.reportviewer = challenge.responseJSON.reportviewer;
                signinService.question = challenge.responseJSON.question;

                this.logger.info("handleChallenge :: authStatus :: " + authStatus);

                if (authStatus == "credentialsRequired") {

                    //if not at signin state, go there
                    if(!$state.includes('signin')){
                        $state.go('signin');
                    }

                    //jsonStore
                    var collections = {
                        forensics: {
                            searchFields: {userId: 'string'}
                        }
                    };

                    WL.JSONStore.init(collections);

                    WL.JSONStore.get('forensics').findAll()
                        .then(
                        function(reponse){
                            console.log(reponse);
                        })
                        .fail(function(error){
                            console.log(error);
                        });

                    var reqURL = '/my_custom_auth_request_url';
                    var options = {};
                    options.parameters = {
                        username : challengeUsername,
                        password : challengePassword,
                        tfaMobileToken: "",
                        serialNumber: "uniqueFromDevice0001",
                        userAgent: "KTT RDC v1.0",
                        remoteAddress: "111.222.333.444",
                        macAddress: "",
                        mobileDeviceId: "some-sort-of-GUID", // deviceId,
                        carrier:  "cricket",//networkInfo.carrierName,
                        mitekDeviceInfo: "",
                        requiredServerAction: "mlogon",
                        disclosureResult: null,
                        verifySecQuestionId: null,
                        verifySecAnswer: null
                    };
                    options.headers = {};
                    $rootScope.challengeHandler.submitLoginForm(reqURL, options, $rootScope.challengeHandler.submitLoginFormCallback);
                }
                else if (authStatus == "UserCredentialsFailed") {
                    $rootScope.busyInd.hide();
                    errorToastService.errorToast(authStatus);

                }
                else if (authStatus == "disclosureChallenge") {
                    $rootScope.busyInd.hide();
                    $ionicHistory.clearCache();
                    $ionicHistory.nextViewOptions({
                        disableBack: true
                    });
                    $state.go('terms');

                }
                else if (authStatus == "questionChallenge") {
                    $rootScope.busyInd.hide();
                    $ionicHistory.clearCache();
                    $ionicHistory.nextViewOptions({
                        disableBack: true
                    });
                    $state.go('securityQuestions');

                }
                else if (authStatus == "complete"){
                    $rootScope.busyInd.hide();
                    console.log("handle challenge in challenge handler", challenge);
                    $rootScope.challengeHandler.submitSuccess();
                }
                else if (authStatus == "UserCredentialsFailed"){
                    console.log("handle challenge in challenge handler", challenge);
                    //signinService.signout().then(function () {
                    //    $rootScope.busyInd.hide();
                    //    console.log('after signout(): ' + angular.toJson(signinService));
                    //    $state.go('signin');
                    //});
                }
            };

            $rootScope.challengeHandler.handleFailure = function(data){
                $rootScope.busyInd.hide();
                console.log("handle Failure in challenge handler", data);
                errorToastService.errorToast(data.error);
            };

            $rootScope.challengeHandler.submitLoginFormCallback = function(response) {

                console.log("submitLoginFormCallBack response:   ", response );

                var isLoginFormResponse = $rootScope.challengeHandler.isCustomResponse(response);//.responseJSON.WL-Authentication-Failure.KMF_AuthenticatorRealm);
                if (isLoginFormResponse){
                    console.log("submitLoginFormCallBack isLoginFormResponse:   " + isLoginFormResponse );
                    $rootScope.challengeHandler.handleChallenge(response);
                }
            };

        });

        //listen for state change errors
        $rootScope.$on('$stateChangeError',
            function(event, toState, toParams, fromState, fromParams, error){
                console.log('STATE CHANGE ERROR: Event:' + angular.toJson(event) + ' toState:'
                    + angular.toJson(toState) + ' toParams:' + angular.toJson(toParams) + ' fromState:'
                    + angular.toJson(fromState) + ' fromParams:' + angular.toJson(fromParams) + ' Error:' + error);
            });
    });
}

function mfpMagicPreviewSetup(){
    var platform;
    //nothing to see here :-), just some magic to make ionic work with mfp preview, similar to ionic serve --lab
    if(WL.StaticAppProps.ENVIRONMENT === 'preview'){
        //running mfp preview (MBS or browser)
        platform = WL.StaticAppProps.PREVIEW_ENVIRONMENT === 'android' ? 'android' : 'ios';
        if(location.href.indexOf('?ionicplatform='+platform) < 0){
            location.replace(location.pathname+'?ionicplatform='+platform);
        }
    }
}
}
})();
4

1 回答 1

0

JSONStore 是异步的

既然你有:

//jsonStore
var collections = {
    forensics: {
        searchFields: {userId: 'string'}
    }
};

WL.JSONStore.init(collections);

WL.JSONStore.get('forensics').findAll()
    .then(
        function(reponse){
            console.log(reponse);
    })
    .fail(function(error){
            console.log(error);
     });

在您尝试对 JSONStore 中的对象执行 findAll 之前,您不能保证您的 JSONStore 将被初始化。

于 2016-04-07T16:59:45.930 回答