{
  "{d}test": {
    "{f}exportoptions.json": {
      "passwordStyle": "SKIP",
      "apiOptionStyle": "EMIT_ALL",
      "authTokenStyle": "SKIP_AUTO",
      "skipUrlFragmentWrapping": false,
      "libraryStyle": "EMIT_ALL",
      "schemaCacheStyle": "DO_NOT_EMIT",
      "filters": {
        "key": [
          "libraries"
        ]
      }
    },
    "{d}libraries": {
      "{f}ReadMe.md": "This folder contains definitions for libraries and whether they are used.\n",
      "{f}b2bB2B-1.0.json": {
        "name": "b2bB2B",
        "version": "1.0",
        "isUsedByProject": false,
        "title": "B2BLib",
        "description": "Various B2B services (invoked from JavaScript Logic)",
        "groupName": "newlib",
        "docsURL": "",
        "referenceURL": ""
      },
      "{f}b2bB2B-1.0.js": "var B2B = {};  // a common JavaScript technique to name-scope shared functions\n//TODO: employ arrow functions when fully supported by Nashorn\n\nB2B.transformToWebHook = function transformToWebHook(aLogicContext, aResourceName, aTargetUrl) {\n    aLogicContext.logDebug(\"*** B2B.transformToWebHook *** using: \" + aResourceName + \", to: \" + aTargetUrl);\n    var resourceURL = aTargetUrl; // \"http://localhost:8080/rest/default/b2bderbypavlov/v1/SalesReports\";\n\n    // custom resource provides name mapping\n    // readiness lab: uncomment this  =====>\n    // aLogicContext.logDebug(\"getting aLogicContext.getTableDefinition()\");\n    var metaTable = aLogicContext.getTableDefinition();\n    aLogicContext.logDebug(\"*** transformToWebHook ***  metaTable: \" + metaTable);\n    var options = {sysfilter: \"equal(OrderID:\" + aLogicContext.getCurrentState().OrderID + \")\"\n            ,\"sysfilter..SupplierAlert.Order_DetailsList.Product.Supplier\": \"equal(CompanyName: '\" + \"Pavlova, Ltd.\" + \"')\" };\n    var resourceGetResponse = SysUtility.getResource(aResourceName, options);  // FIXME\n\n    // system console output\n    aLogicContext.logDebug(\"B2B.transformToWebHook posting getResponse: \" + JSON.stringify(resourceGetResponse).substring(1, 20) + \"...\");\n    aLogicContext.logDebug(\"B2B.transformToWebHook to URL: \" + resourceURL);\n\n    if (resourceURL === null || resourceURL === \"\") {\n        out = java.lang.System.out;\n        out.println(\"WebHook URL is null/empty - this not posted:\\n\" + (JSON.stringify(resourceGetResponse)).substring(1, 4) + \"...\");\n    }\n    else {\n        var settings = { headers: { Authorization: \"CALiveAPICreator supplier:1\" }};  // FIXME\n        var postResponse = SysUtility.restPost(resourceURL, null, settings, resourceGetResponse);\n\n        // API Creator log output\n        // log.debug('ok, using re-usable solution');\n        if (JSON.parse(postResponse).statusCode !== 201) {\n            throw \"B2B.transformToWebHook unexpected post response: \" + postResponse;\n        }\n    }\n\n    return null;\n};\n\n\nB2B.sendToWebHook = function sendToWebHook(aPostRequest, aTargetUrl) {\n    resourceURL = aTargetUrl;\n    var tryIt = true;\n    if (tryIt === true) {\n        if (resourceURL === null || resourceURL === \"\") {\n            out = java.lang.System.out;\n            out.println(\"WebHook URL is null/empty - this not posted:\\n\" + (JSON.stringify(aPostRequest)).substring(1, 20) + \"...\");\n        }\n        else {\n            var settings = { headers: { Authorization: \"CALiveAPICreator supplier:1\" }};  // FIXME\n            var postResponse = SysUtility.restPost(resourceURL, null, settings, aPostRequest);\n\n            // API Creator log output\n            // log.debug('ok, using re-usable solution');\n            if (JSON.parse(postResponse).statusCode !== 201) {\n                throw \"B2B.sendToWebHook unexpected post response: \" + postResponse;\n            }\n        }\n    }\n    return null;\n};\n\n\n// you can save state in logicContext.userProperties, including complex objects such as Maps\n\nB2B.putPropertyMap = function putPropertyMap(logicContext, propertyName, key, value) {\n    var RestRequest = Java.type('com.kahuna.server.rest.RestRequest');\n    var req = RestRequest.getCurrentRestRequest();\n    logicContext.logDebug(\"*** B2B.putPropertyMap - propertyName: \" + propertyName + \", key: \" + key + \", value: \" + value + \", on req: \" + req);\n    var property = req.getUserProperties().get(propertyName);   // userProperties to maintain state in transaction\n    if (property === null) {\n        property = new java.util.HashMap();\n    }\n    property.put(key, value);\n    req.setUserProperty(propertyName, property);\n};\n\n\n//approach for global (static) properties (dynamic properties can be saved in req.getUserProperties().get)\n//(alternative: store them in a 1 row table, edit with Data Explorer, accessors here)\n\nB2B.supplierURL = function supplierURL(req) {\n    var resultURL = req.localFullBaseURL.replace(\"nw\",\"pavlov\");\n    out.println(\"B2B.supplierURL returns: \" + resultURL);\n    return resultURL;\n};\n\n\n//returns a sample order, for testing\n\nB2B.sampleOrder = function sampleOrder() {\n    var newPartnerOrderJson =\n    {\n        \"CustomerNumber\": \"VINET\",\n        \"Items\": [\n            {\n            \"Product\": {\n                \"ProductName\": \"Pavlova\"\n            },\n            \"Quantity\": 1\n            }, {\n                \"Product\": {\n                    \"ProductName\": \"Uncle Bob's Organic Dried Pears\"\n                },\n                \"Quantity\": 2\n            }, {\n                \"Product\": {\n                    \"ProductName\": \"Tofu\"\n                },\n                \"Quantity\": 3\n            }, {\n                \"Product\": {\n                    \"ProductName\": \"Ikura\"\n                },\n                \"Quantity\": 4\n            }, {\n                \"Product\": {\n                    \"ProductName\": \"Konbu\"\n                },\n                \"Quantity\": 5\n            }, {\n                \"Product\": {\n                    \"ProductName\": \"Alice Mutton\"\n                },\n                \"Quantity\": 1\n            }\n        ],\n        \"Shipper\": {\n            \"CompanyName\": \"Federal Shipping\"\n        }\n    };\n\n    return newPartnerOrderJson;\n};\n\n\n// send email\n\nB2B.sendEmail = function sendEmail() {\n    var result = {};\n    var msg = \"error\";\n    var configSetup = {\n        to: \"to\",\n        from: \"from\",\n        title: \"title\",\n        text: \"text\"\n    };\n\n    result.configure = function configure(myconfig) {\n        configSetup.to = myconfig.to || \"to\";\n        configSetup.from = myconfig.from || \"from\";\n        configSetup.title = myconfig.title || \"title\";\n        configSetup.text = myconfig.text || \"text\";\n    };\n\n    result.send = function send() {\n        try {\n            // call my mail interface here\n            msg = \"Send email (stub) title: \" + configSetup.title + \" to: \" + configSetup.to + \", from: \" + configSetup.from + \" body text: \" + configSetup.text;\n        }\n        catch (e) {\n            return e;\n        }\n        out.println(\"B2B.sendMail returns: \" + msg);\n        return msg;\n    };\n\n    return result;\n}\n\n\n// minor debug helper, to prevent NPE in logging anObject.toString\n// where anObject is null\n\nB2B.db = function db(anObject) {\n    var result = \"null\";\n    if (anObject !== null) {\n        result = anObject.toString();\n    }\n    return result;\n};\n\n\n// copies like-named attributes from logicContext's row -> targetRow,\n// ignoring attributes part of pKey\n\nB2B.copyAttributes = function copyAttributes(logicContext, targetRow) {\n\n    sourceRow = logicContext.getCurrentState();\n\n    var sourceMetaEntity = sourceRow.getMetaEntity();\n    var targetMetaEntity = targetRow.getMetaEntity();\n\n    logicContext.touch(targetRow);\n    var debugMoved = [];\n\n    for each (var eachProp in sourceMetaEntity.getProperties()) {\n      if ( eachProp.isAttribute() ) {\n        var targetMetaProp = targetMetaEntity.getPropertyByName(eachProp.name);\n        // NB: cannot use hasOwnProperty (Java obj, not JS)\n        if (null !== targetMetaProp) {\n            if (targetMetaProp.isInPrimaryKey() === true) {\n                // logicContext.logDebug(\"copyAttributes -  skipping eachProp since in pKey: \" + eachProp.name);\n            }\n            else {\n                var propValue = sourceRow[eachProp.name];\n                targetRow[eachProp.name] = propValue;\n                debugMoved.push(eachProp.name);\n            }\n        }\n        else {\n            // logicContext.logDebug(\"copyAttributes - skipping eachProp since not in target: \" + eachProp.name);\n        }\n      }\n    }\n    logicContext.logDebug(\"copyAttributes - moved: [\" + debugMoved + \"]\");\n    logicContext.update(targetRow);\n};\n"
    }
  }
}