SAPUI5 parameter transfer to web transaction - sapui5

I am trying to open a transaction through the SAPUI5 event (eg. list item click).
While opening that transaction, parameters from the selected list item element in the SAPUI5 will be sent to that transaction and will fill specific input fields in the transaction such as material number, plant and so on.
Questions:
First of all, what is the best way to navigate from SAPUI5 to sap-web-transactions?
Second, how do I navigate while sending parameters? (gateway I suppose but how)

The following is an example of opening a SAP Transaction via Webgui from a SAPUI5 button event, the event shows one of many ways to attach additional parameters to the url
var sURL = 'http://my_sap_server:8000/sap/bc/gui/sap/its/webgui?~transaction=SU01';
var oButton = new sap.ui.commons.Button("b1");
oButton.setText("DDIC"); //Call Transaction SU01 and pass username as param
oButton.attachPress(function() {
var newURL = sURL + ' USR02-BNAME=' + oButton.getText( );
window.open(newURL);
});

Without knowing anything about your systems and/or code, it really depends on your use case...
If you have a J2EE webserver such as SAP HANA Cloud Platform, you could use JCO API to perform the call server side, and use a REST service to make the request from your client UI
If you have SAP NetWeaver CE, you could use the CAF framework instead of JCO, and still use REST.
However, from your question I assume you have SAP Gateway at your disposal, so I would recommend reading this paper by Bertram Ganz on how to consume Gateway OData services http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d59930-791c-3010-2abd-ac7793ad6c57?QuickLink=index&overridelayout=true&59017145615734

Related

Customizing "PayPal" button for PayPal Marketplace (API)

I am developing my app with PayPal Marketplace API for the first time.
Among other steps, I need to customize a "PayPal checkout" button. I did this by following instructions on this page.
In function "payment" (see the original code segment below), I supposed to provide a call-back url for CREATE_URL:
// payment() is called when the button is clicked
payment: function() {
// Set up a url on your server to create the payment
var CREATE_URL = '/demo/checkout/api/paypal/order/create/';
// Make a call to your server to set up the payment
return paypal.request.post(CREATE_URL)
.then(function(res) {
return res.id;
});
}
By reading this, I am puzzled why the CREATE_URL value is not a fullpath url starting with "http" or "https"? I have the similar question for EXECUTE_URL in an ensuing segment of the html file.
What type of RequestBody should my REST controller expect?
What action should my app take at the url for "CREATE_URL"? My intuition is to call the Order API to create an order (among other things in my database). Is this correct?
I can address your questions one at a time:
By reading this, I am puzzled why the CREATE_URL value is not a fullpath url starting with "http" or "https"? I have the similar question for EXECUTE_URL in an ensuing segment of the html file.
You don't have to have a full path URL (known as absolute path) because the path that you provide for CREATE_URL is on your own server. So the code where you have your button is on a page like exampleButton.html and when you click the button, it takes you to a script, such as
var CREATE_URL = '/demo/checkout/api/paypal/order/create/';
which is an index page which will run the Create Order API method with the data that you pass. Here is another example implementing a payment button with checkout.js using a server side language.
What type of RequestBody should my REST controller expect?
Your request body will receive the payment data from the JavaScript data parameter, which should be JSON format. You then pass this to the server side when you receive the POST data.
An even simpler implementation is to use the client-side integration to create the order.
What action should my app take at the url for "CREATE_URL"? My intuition is to call the Order API to create an order (among other things in my database). Is this correct?
Your app should automatically run the create order method. This script works with JavaScript promises, so will wait for a response, like getting a successful authorization (or failure) from the customer before attempting to execute the payment.

How to construct client context in AEM by passing values from an external system?

Is there a way to construct the client context in AEM by using values passed by an external website? The external website sends the user information such as IP address, page data, geolocation, etc. I want to construct the ClientContext JSON without using CQ_Analytics.ClientContextMgr.init, as the information is from an external system.
For eg: We know the location of a visitor to our website. We want to pass this value to AEM and set the client context so that we can get the targeted content for this location.
Our end goal is to get something like this (but we are trying to achieve this without constructing the JSON by ourselves):
CQ_Analytics.ClientContextMgr.clientcontext = JSON.parse('{"profile":{"country":"US"}}');
Is there any Javascript APIs provided by AEM to construct the JSON?
You need to extend the client context using AEM documentation provided at:
Creating a Custom Context Store Component
Follow the instructions till the Initialization part where you will need to populate the data in the jsp file for your extension.
So in your case it would be something this:
if(!locstore){
locstore = CQ_Analytics.JSONPStore.registerNewInstance("<%= store %>",
"<%= jsonpurl %>",{});
}
Where jsonpurl will be the location of your service that provides the external data in json(p) format. This will initialise your store with the values you want and you won't need to worry about the manual json handcrafting.
Client context is constructed on client side using the JS library in AEM. You will need some binding parameters to connect your external data source to the current client context.
The detailed tutorial can be found here.

How to define the SAP mandant/client number in an SAPUI5 application running inside Eclipse WebApp preview?

With the Eclipse development tools for SAPUI5 it is possible to run a SAPUI5 app in WebApp preview mode. It's working fine expect one point.
The client data used in OData service is always "100" by default.
I assume the used client is the one used for repository setup.
But for testing I have to use a different client (200) because of maintained test data.
Since SAPUI5 1.26.9 and corresponding development tools it seems to work, defining a default client at SAP NetWeaver Gateway but after an upgrade to 1.28.x most of the time client 100 is used.
Now I am searching the documentation for that problem but can't find anything. One problem of course would be to that the search term "client" will not help at all.
I would also aviod to hard code any client number somewhere because at the real system the logged in client will be used automatically.
But in the WebApp preview I will not be asked for a client.
Maybe this is the wrong place to ask this question? In that case I will delete it.
Can you have a parameter in the URL and link that to retrieving your serviceUrl?
Maybe you can have a URL parameter and based on that you can 2 service URL's one with hard-coded value of client 200 and other without anything.
You can retrieve the parameter:
jQuery.sap.getUriParameters().get("test-mode") === "true";
To hard code the client in OData service definition:
var sUrl = "proxy/protocol/server:port/pathToService?sap-client=600";
var oModel = new sap.ui.model.odata.ODataModel(sUrl,true)
You could use the sap-client GET-parameter. This one will be passed to your application automatically when you used the SAP Portal or SAPGUI.
ODataModel passes it to data-service with its own.
When you call your model object, you can pass some header variables to 'point' to the right sap client.
// Set the client header variable
var oHeaders = {'sap-client': '120'};
var bCSRF = "true";
var oModel = sap.ui.model.odata.ODataModel(serviceURL, true, "user", "pass", oHeaders, bCSRF, false, false, "", false);
sap.ui.getCore().getModel(oModel, 'gAppModel')
You can test which header variables you need using a REST client like Postman.
The details of the OData constructor can be found in the API - UI5 OData Model

Jira calls external REST Service

My Problem: I want to introduce a new field in JIRA with status information from external REST Service (response is json).
Plan: Every Jira issue has a input field with some reference string. Behind this field there should be a panel, what should display informations from the external REST call (parsing response JSON is required).
Can someone give me some good info pages, how to tell JIRA to call external REST Service?
If you don't want to build it see:
nFeed
HTTP Feed Custom Field
If you want to build it yourself then start by following this tutorial on Creating a custom field type which is to more or less store a basic String within the database. (This would be the reference string)
You then have two options, the first is within the JiraCustomField class override the getVelocityParameters which was taken from How to call a java method from velocity Atlassian Answers question.
Then create a method (fetchValueFromWebService(String val)) that you would call that would contain code to query the REST Service based off the fields value that would be passed in from the velocity template. (E.g. $instance.fetchValueFromWebService($value))
To perform the actual web service call you can use any library you want, just see the Managing Dependencies documentation so it gets included in the plugin. (For example using the Jira Jersey version see this)
Your other option would be to within the view-basictext.vm have it use javascript and perform an AJAX to the web service by calling a function in your own JS file and dump that into a span that you have defined: (See Including Javascript and CSS resources)
<span id="webServiceValue"></span>
<script type="text/javascript">
fetchValueFromWebService($value);
</script>
You would however need to ensure that the webservice has Cross-origin resource sharing (CORS) enabled if you go the AJAX route.

Securing REST Service using a simple Token

I have a drop-down in my application for which i populate the data using an Ajax call as shown below. This works fine and my Web API URL is "http://example.com/Service.svc/json/getairports"
$(function () {
$.getJSON("http://example.com/Service.svc/json/getairports", {}, function (data) {
$("#airport-departure-modal, #destination-airport-modal").html("")
$.each(data, function (index, element) {
$("#airport-departure-modal, #destination-airport-modal").append("<option id=" + element["AirportCode"] + ">" + element["AirportName"] + "</option>");
});
});
});
But my worry is security since anyone can view this URL using view source or developer tools. So i wanted to bring in a token and pass it to the service like "http://example.com/Service.svc/json/getairports?token=SECUREKEY" but i wonder how this can solve the problem since secure key also visible in the view source. So my question is how can i keep the secure key invisible in the client side or dynamically passed only when the ajax call is initiated?
Just for information, i will be using HTTPS in production so that sniffing over the wire is taken care. Also not that, this service is going to be used only within the same application though Web API service might be hosted on a separate node.
Kindly advise if there might be some alternative but simple solution for the above scenario. i am aware of other advanced mechanisms such as OAuth,HMAC, Amazon S3, etc. But i just want to have a simple solution.
What exactly are you trying to solve? Do you want to prevent a user from calling your API programmatically? If your browser can get something, so can a user with the power of view-source - so that's a fruitless effort. Really though, it sounds like you want to prevent CSRF.
This answer should be helpful.