XPages REST viewJsonService - xpages

I'm using a viewJsonService from the XPages Extension Library to return data for an agGrid. The service is called using it's URL with a keys parameter to select the data returned. If the key doesn't exist in the view then I'm getting an error NotesException: CreateNavFromKey failed.
I'm working around this by checking the whether the key exists in the view and if it doesn't using a second REST service that just returns an empty JSON object.
But is there any way of trapping the error so that the viewJsonService returns an empty JSON object in this scenario?
This is running on Domino 10.0.1 FP1
UPDATE...
<xe:restService id="restService1" pathInfo="getContactsForInd">
<xe:this.service>
<xe:viewJsonService defaultColumns="true" viewName="vwContactsByInd" var="row" databaseName="#{javascript:sessionScope.DBPath}" searchMaxDocs="0" count="5">
<xe:this.keys><![CDATA[#{javascript:docInd.getItemValueString("IndKey");}]]></xe:this.keys>
</xe:viewJsonService>
</xe:this.service>
</xe:restService>

Related

xPages REST service to feed a Notes Calendar Store

I am trying to use RESTservice to get data from a resource reservation DB and provide a calendar with filter capability by resource name.
All run fine while I use the rest service without filter
<xe:restService id="restService2" pathInfo="/inoteslegacyjson">
<xe:this.service>
<xe:viewJsonLegacyService count="30000"
databaseName="${compositeData.databaseName}"
viewName="${compositeData.viewName}" defaultColumns="false"
var="entry" contentType="text/plain" compact="false">
<xp:this.columns>
<!-- Cal Date -->
<xe:restViewColumn name="$134"
columnName="StartDateTime">
</xe:restViewColumn>
<!-- Icon -->
<xe:restViewColumn name="$149" columnName="$149"></xe:restViewColumn>
<!-- Start Date -->
<xe:restViewColumn name="$144"
columnName="StartDateTime">
</xe:restViewColumn>
...
But when I put a search syntax like this:
<xe:this.search><![CDATA[#{javascript:
var isResourceFiltered:Boolean;
var strTmp:String=viewScope.resourceName;
isResourceFiltered=(strTmp.compareToIgnoreCase("All")!=0);
print ("Is result filtered:" + isResourceFiltered + ", filter: "+ strTmp);
if (!isResourceFiltered) {
return "";
}
return "ResourceName=" + viewScope.resourceName}]]></xe:this.search>
I cannot see any message in console about Print() and get some errors in page:
calendarDataStore: RequestError: Unable to load /admin/resource.nsf/ResourceCalendarFiltered.xsp/inoteslegacyjson status: 500
or error 400
How does can I filter a calendar view for resource name
(And how make a time slice to get only time period showed in the UI to avoid count="30000"?)
viewScope.resourceName may not be set early enough for it to be used. This could explain the lack of a print statement and the error 500 returned by the calendarDataStore.
Try adding some error handling to verify it's an issue with the component vs an error with your code.
XPages OpenLog Logger (or the corresponding code in OpenNTF Domino API) will catch uncaught exceptions and so would verify coding issues without needing try/catch blocks.
I did a Java Rest service and used FT Search to search between two date ranges. You could also work your search by resource name into that FT Search as well. In my case I did not use a view but did the lookup in Java and built the returned text in my code (to work with FullCalendar, a web based calendar). Works great and is fast.

Replace/Update a existing node value in groovy

Below is my sample xml.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header>
<MessageHeader xmlns:ns3="http://csi.cingular.com/CSI/Namespaces/Types/Public/CingularDataModel.xsd" xmlns:ns39="http://csi.cingular.com/CSI/Namespaces/Types/Public/MessageHeader.xsd">
<ns39:TrackingMessageHeader>
<ns3:infrastructureVersion>86</ns3:infrastructureVersion>
<ns3:version>222</ns3:version>
<ns3:messageId>146100035386400076</ns3:messageId>
<ns3:originatorId>PEEPS</ns3:originatorId>
<ns3:timeToLive>120000</ns3:timeToLive>
<ns3:dateTimeStamp>2016-04-18T20:16:19.387Z</ns3:dateTimeStamp>
</ns39:TrackingMessageHeader>
<ns39:SecurityMessageHeader>
<ns3:userName></ns3:userName>
<ns3:userPassword></ns3:userPassword>
</ns39:SecurityMessageHeader>
<ns39:SequenceMessageHeader>
<ns3:sequenceNumber>1</ns3:sequenceNumber>
<ns3:totalInSequence>1</ns3:totalInSequence>
</ns39:SequenceMessageHeader>
</MessageHeader> </SOAP-ENV:Header> <SOAP-ENV:Body>
<InquireEnterpriseOrderListRequest xmlns="http://csi.cingular.com/CSI/Namespaces/InquireEnterpriseOrderListRequest.xsd">
<SelectionCriteria>
<organizationId>214256542</organizationId>
</SelectionCriteria>
</InquireEnterpriseOrderListRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I want to replace "organizationId" this tag value with the value read from file and trigger it using testRunner.runTestStepByName("InquireEnterpriseOrderList") once the value is updated in the node.
Can any help in understanding how to update/replace node with new value and re-trigger the API to capture result for many inputs.
Here you what you need to do:
Read file extract the required value and store it at test case level custom property. Assuming that you are using groovy script test step to do this. So, add the below additional code:
//You assign value from your code, for now using dummy assignment
def requiredvalue = '123453'
//Store that value at test case level custom property, say ORGANIZATION_ID
context.testCase.setPropertyValue('ORGANIZATION_ID', requiredValue.toString())
Now, you do not need to update the request. Instead use, property expansion as below, so that SoapUI automatically takes care of the required value from proerties
<organizationId>${#TestCase#ORGANIZATION_ID}</organizationId>

How to verify if values are updated or not by API using groovy in soap ui

I am using soapui and groovy for api automation and assertion.
Have one API which updates user profile data. i.e update username,firstname,lastname etc.
What is best way to verify that if data is updated or not after run update api. In groovy is there any way by which I can store previous data from API response then run update api and again check response and finally compare previous response and latest one?
What I have tried it comparing values which I am going to sent via API and values which API returns. If both equal then assume that values update. But this seems not perfect way to check update function.
Define a test case level custom property, say DEPARTMENT_NAME and value as needed.
Add a Script Assertion for the same request test step with below script:
//Check if the response is received
assert context.response, 'Response is null or empty'
//Parse text to json
def json = new groovy.json.JsonSlurper().parseText(context.response)
log.info "Department name from response ${json.data.name}"
assert json.data.name == context.expand('${#TestCase#DEPARTMENT_NAME}'), 'Department name is not matched'
You may also edit the request, and add the value as ${#TestCase#DEPARTMENT_NAME} instead of current fixed value XAPIAS Department. So that you can just change the value of department name at test case level property, the same is sent in the request and the same is verified in the response.
Use JDBC teststep to run query directly into database:
Use Xpath assertion to Validate your Update API
Assertion 1
/Results/ResultSet[1]/Row[1]/FirstName
Expected result
Updated FirstName
Assertion 2
/Results/ResultSet[1]/Row[1]/LastName
Updated Last Name
In our project we do it in this way:
First we execute all the APIs.
Then we Validate all the new/updated data in database in DB Validation testcase.
Works well in highly integrated environment as well.

How RESTful count property actually work?

I tried to load ONE data column using RESTful viewItemFileService and use it in dojo filtering select control for selection. The total rows is 50,000 and seems that REST could not handle big data because I set count=1000000. If I set count=500, then it works but the rest of data after 500 not available for selection in dojo filtering control. I would like to see RESTful can load data per count size but it seems no doing that. My code as below. I must missing something.
<xe:restService id="restActivity" jsId="activityStore"
pathInfo="activities">
<xe:this.service>
<xe:viewItemFileService viewName="lkpActivities"
dojoType="dojo.data.ItemFileReadStore" var="rowActivity"
contentType="application/json" compact="true" systemColumns="4"
count="1000000">
<xe:this.columns>
<xe:restViewColumn columnName="Activity"
name="Activity">
</xe:restViewColumn>
</xe:this.columns>
</xe:viewItemFileService>
</xe:this.service>
</xe:restService>
<xe:djFilteringSelect id="djfsActivity"
promptMessage="Please type the first letter of intended activity"
invalidMessage="No activity found. Please type again"
searchAttr="Activity" labelAttr="Activity" store="activityStore"
pageSize="20">
</xe:djFilteringSelect>

Unable to reference a view in another database from XPiNC

I have a repeat where the value loops through documents in the current database, these documents contain a database and view name. The repeat then opens the database and view and retrieves data from within them:
var dbOther:NotesDatabase = session.getDatabase(null, doc.getItemValueString("Database"));
if(dbOther != null){
var lookupView:NotesView = dbOther.getView(doc.getItemValueString("ViewName"));
var viewNav:NotesViewNavigator = lookupView.createViewNavFromCategory(key);
}
This works fine on all browsers but if I view the xpage in the Notes Client I get the following error: Exception occurred calling method NotesDatabase.getView(string) null
I have tested that the dbOther variable is set by writing the Server and FilePath properties to a log. I checked that it could see the views by generating a loop using getViews and getAliases, again all view aliases were written to the log without an issue.
I have manually entered the view name in case the value was not being selected from the document correctly but received the same error.
Is there a way I can connect to a view in another database in XPiNC? I have found an XSnippet which allows you to dynamically add view data sources to your page, I think this may get around my problem but wanted to find out if there was an alternative solution before I re-write everything!
Try some of these other ways of getting a handle on a database:
This one uses "" instead of the null parameter to indicate current server:
var dbOther:NotesDatabase = session.getDatabase("", doc.getItemValueString("Database"))
This one uses database.getServer() instead of the null parameter:
var dbOther:NotesDatabase = session.getDatabase(database.getServer(), doc.getItemValueString("Database"))
This one uses sessionAsSigner to get access to the database (instead of using the credentials of the current user):
var dbOther:NotesDatabase = sessionAsSigner.getDatabase(database.getServer(), doc.getItemValueString("Database"))
Are you using a Lotus Notes 8.5.3 client?

Resources