//#import $owl_mall_u:services/modelService.jsx
//#import $owl_backend_session:services/modelService.jsx
//#import $owl_orgs:services/modelService.jsx
//#import $owl_roles:services/modelService.jsx
//#import session.js

function main(){
    var isid = SessionService.getSessionId(request);

    var rorg = getRequestOrg();
    if(rorg){
        var ret = {
            state: 'ok',
            org:rorg
        }
        out.print(JSON.stringify(ret));
        return;
    }
    else{
        var sessionId = 'owl_backend_session_' + isid;
        var session = owl_backend_sessionService.get(sessionId);
        var orgId = session.orgId;
        var org = owl_orgsService.get(orgId);
        var ret = {
            state: 'ok',
            org:org
        }
        out.print(JSON.stringify(ret));
        return;
    }



}
main();

function getRequestOrg(){
    if(!$body){
        return null;
    }
    var params = JSON.parse($body);
    var rorgId = params.rorgId;
    var org = owl_orgsService.get(rorgId);
    return org;
}