Processing pagination in LinkedIn API - java

I'm trying to retrieve all of my network updates using the linkedin-j API. I can fetch the first 10 updates, but do not know how to retrieve any more.
The following code retrieves the first 10 updates:
Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.STATUS_UPDATE));
System.out.println("Total updates fetched:" + network.getUpdates().getTotal());
for (Update update : network.getUpdates().getUpdateList()) {
System.out.println("-------------------------------");
System.out.println(update.getUpdateKey() + ":" + update.getUpdateContent().getPerson().getFirstName() + " " + update.getUpdateContent().getPerson().getLastName() + "->" + update.getUpdateContent().getPerson().getCurrentStatus());
if (update.getUpdateComments() != null) {
System.out.println("Total comments fetched:" + update.getUpdateComments().getTotal());
for (UpdateComment comment : update.getUpdateComments().getUpdateCommentList()) {
System.out.println(comment.getPerson().getFirstName() + " " + comment.getPerson().getLastName() + "->" + comment.getComment());
}
}
}
There is another method called network.getUpdates().getStart(), but I don't know how to implement it. I've been at this for hours, and any advice would be appreciated.

If you would like to use pagination in linkedin-j, then you could use getNetworkUpdates(Set, int, int) along with network.getUpdates().getTotal().
public Network getNetworkUpdates(Set<NetworkUpdateType> updateTypes, int start, int count);

Related

Need to receive 200 recommendation from flight search using java code for loop map function in rest assured

I need to receive 300 recommendation in one short using for loop using my code.
Currently I can receive one to 10 recommendation response. But when i deal with 200 to 500 recommendations it's so hard for me to edit my code from 1 to 500. Instead I try to implement the for loop in my code but it's fails.
Below is my code.
Map<String, String> recommendations5 = response.jsonPath().getMap("recommendation[5]");
System.out.print("\n\n");
System.out.print(recommendations5.get("validatingAirlineName"));
System.out.print("\n\n");
System.out.println("adultBaseFare=" + recommendations5.get("adultBaseFare"));
System.out.println("adultTaxFare=" + recommendations5.get("adultTaxFare"));
System.out.println("Deeplink=" + recommendations5.get("Deeplink"));
System.out.println("marketingAirlineCodes=" + recommendations5.get("marketingAirlineCodes"));
System.out.println("validatingAirlineName=" + recommendations5.get("validatingAirlineName"));
System.out.println("totalBaseFare=" + recommendations5.get("totalBaseFare"));
System.out.println("totalFare=" + recommendations5.get("totalFare"));
System.out.println("validatingAirlineCode=" + recommendations5.get("validatingAirlineCode"));
System.out.println("validatingAirlineName=" + recommendations5.get("validatingAirlineName"));
Below is the my for loop logic but it fails.
My error:
Exception in thread "main" java.lang.IllegalArgumentException: The parameter "i" was used but not defined. Define parameters using the JsonPath.params(...) function
My for loop code:
for(int i=0;i<=jsonResponse.size();i++)
{
Map<String, String> recommendations5 = response.jsonPath().getMap("recommendation[i]");
System.out.print("\n\n");
System.out.print(recommendations5.get("validatingAirlineName"));
System.out.print("\n\n");
System.out.println("adultBaseFare=" + recommendations5.get("adultBaseFare"));
System.out.println("adultTaxFare=" + recommendations5.get("adultTaxFare"));
System.out.println("Deeplink=" + recommendations5.get("Deeplink"));
System.out.println("marketingAirlineCodes=" + recommendations5.get("marketingAirlineCodes"));
System.out.println("validatingAirlineName=" + recommendations5.get("validatingAirlineName"));
System.out.println("totalBaseFare=" + recommendations5.get("totalBaseFare"));
System.out.println("totalFare=" + recommendations5.get("totalFare"));
System.out.println("validatingAirlineCode=" + recommendations5.get("validatingAirlineCode"));
System.out.println("validatingAirlineName=" + recommendations5.get("validatingAirlineName"));
}
You need to replace the String i will the actually i int value
Map<String, String> recommendations5 = response.jsonPath().getMap("recommendation[" + i + "]");

Error converting Flink CEP table in Dataset<Row> object

I've created an BatchTableEnviroment in Apache Flink and created a Table object where I loaded data in. Now I want to search for some patterns. I'm doing this with the Detecting patterns in Tables CEP library. The task of the query below is to find the longest period of a mGroup for which the avgResult did not go below a certain threshold. Where a mGroup is a Integer value like 100, 200, 300 etc. Avgresult is double value. When I compile the query part I dont get any error. I get the error when I convert the Table to a DataSet<row>. Below the query u can see the error message.
ExecutionEnvironment fbEnv = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = BatchTableEnvironment.create(fbEnv);
Table trendTable = tableEnv.sqlQuery(
" SELECT * " +
" FROM tableAvg " +
" MATCH_RECOGNIZE(" +
" PARTITION BY mType " +
" ORDER BY mGroup " +
" MEASURES " +
" FIRST(A.mGroup) as startGr, " +
" LAST(A.mGroup) as endGr, " +
" A.avgResult as avgRes" +
" ONE ROW PER MATCH " +
" AFTER MATCH SKIP PAST LAST ROW " +
" PATTERN (A+ B) " +
" DEFINE " +
" A AS A.avgResult < 50 " +
") "
);
tableEnv.registerTable("TrendTable", trendTable);
DataSet<Row> result = tableEnv.toDataSet(trendTable, Row.class);
/////////////////////ERROR MESSAGE BELOW
Exception in thread "main" org.apache.flink.table.api.TableException: Cannot generate a valid execution plan for the given query:
FlinkLogicalMatch(partition=[[$1]], order=[[2]], outputFields=[[mType, startGr, endGr, avgRes]], allRows=[false], after=[FLAG(SKIP PAST LAST ROW)], pattern=[(PATTERN_QUANTIFIER(_UTF-16LE'A', 1, -1, false), _UTF-16LE'B')], isStrictStarts=[false], isStrictEnds=[false], subsets=[[]], patternDefinitions=[[<(PREV(A.$0, 0), 50)]], inputFields=[[sumResult, mType, EXPR$2]])
FlinkLogicalSort(sort0=[$2], dir0=[ASC])
FlinkLogicalCalc(expr#0..5=[{inputs}], expr#6=[/($t2, $t3)], expr#7=[99], expr#8=[>($t5, $t7)], sumResult=[$t6], mType=[$t1], EXPR$2=[$t4], $condition=[$t8])
FlinkLogicalAggregate(group=[{0, 1}], agg#0=[SUM($2)], agg#1=[SUM($3)], agg#2=[MAX($4)], agg#3=[COUNT()])
FlinkLogicalCalc(expr#0..2=[{inputs}], expr#3=[1], expr#4=[-($t0, $t3)], expr#5=[100], expr#6=[/($t4, $t5)], expr#7=[1.0:DECIMAL(2, 1)], $f0=[$t6], mType=[$t1], mValue=[$t2], $f3=[$t7], mID=[$t0])
FlinkLogicalTableSourceScan(table=[[default_catalog, default_database, H]], fields=[mID, dateTime, mValue, unixDateTime, mType], source=[CsvTableSource(read fields: mID, mType, mValue)])
This exception indicates that the query uses an unsupported SQL feature.
Please check the documentation for the set of currently supported SQL features.
at org.apache.flink.table.plan.Optimizer.runVolcanoPlanner(Optimizer.scala:245)
at org.apache.flink.table.plan.Optimizer.optimizePhysicalPlan(Optimizer.scala:170)
at org.apache.flink.table.plan.BatchOptimizer.optimize(BatchOptimizer.scala:57)
at org.apache.flink.table.api.internal.BatchTableEnvImpl.translate(BatchTableEnvImpl.scala:280)
at org.apache.flink.table.api.java.internal.BatchTableEnvironmentImpl.toDataSet(BatchTableEnvironmentImpl.scala:71)
at StreamTableEnv.main(StreamTableEnv.java:169)
The CEP library and MATCH_RECOGNIZE only work on top of the streaming API (and not batch), meaning that you need to use a StreamTableEnvironment rather than a BatchTableEnviroment.

Consecutive log prints - only the first printed (no visible error)

I have this code fragment in my java class:
catch (AuthenticationFailedException afe) {
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + "E-Mail " + protocol + encStr + " login failed on " + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer());
IlientConf.logger.error("[" + accountID + "," + emailConf.getIncomingUser() + "#" + emailConf.getIncomingMailServer() + "] " + afe.getMessage());
IlientConf.logger.debug("Email integration AuthenticationFailedException", afe);
return false;
}
IlientConf.logger is a log4j logger.
The actual log that is printed contains only the first line. This is it:
[someuser,sapunlock#someuser.com#outlook.office365.com] E-Mail pop3
(SSL) login failed on sapunlock#someuser.com#outlook.office365.com
The second and the third log statements are lost somehow.
I really need the stack trace of the error, but I can't get it.
No other related error is shown in the log.
Please help me understand what the reason for this is.
P.S.: Of course I can change the log statements to show this better, but this is deployed at a customers environment and needs to be solved before the next version.

Grouping duplicates till a specific count

I have a number of xml's that come in haphazardly that contain a Ocount, and Lnumber, as well as other data. I have created a class to get that data.
My problem is that how can I group xml's that have the same Lnumber(string), until it reaches the Ocount(int). (the xmls that have the same lnumber has the same Ocount). And eventually send out a email telling with xmls has been processed.
String readLine = FileHandler.checkListFile(sh.getShipmentHeader().getBillToCustomer());
if (!readLine.isEmpty())
{
int orderCount = 0;
int index = readLine.indexOf(";") + 1;
String customerName = readLine.substring(index, readLine.indexOf(";", index)).trim();
index = readLine.indexOf(";", index) + 1;
String to = readLine.substring(index, readLine.length()).trim();
if (!billMap.containsKey(sh.getShipmentHeader().getBillToCustomer()))
{
billMap.put(sh.getShipmentHeader().getBillToCustomer(), 1);
orderCount = 1;
}
else
{
billMap.put(sh.getShipmentHeader().getBillToCustomer(), ((int) billMap.get(sh.getShipmentHeader().getBillToCustomer())) + 1);
orderCount = (int) billMap.get(sh.getShipmentHeader().getBillToCustomer());
}
outboundMessage += sh.getShipmentHeader().getOrderNumber() + li ;
logger.info("On-Demand Outbound Export Info: " + orderCount + " processed out of " + sh.getShipmentHeader().getOrderCount() +
" for " + customerName);
if (orderCount == sh.getShipmentHeader().getOrderCount())
{
Email email = new Email();
billMap.remove(sh.getShipmentHeader().getBillToCustomer());
outboundMessage += li + "Total of #"+ sh.getShipmentHeader().getOrderCount() + " orders processed for "+ customerName + li ;
logger.info("On-Demand Email sent for " + customerName);
System.out.println(outboundMessage);
email.outboundEmail("TEST: Orders for " + customerName + " complete", outboundMessage, to);
outboundMessage = "";
email = null;
}}
I been working on this for days, where am I going wrong.
It seems like you are having difficulty obtaining information from xmls. I suggest using XStream [1]. It is capable of serialising objects to xml and back. By using XStream, you can get an Object from the xml and compare variables (Lnumber and Ocount) easily.
If you insist using this code, I suggest adding comments to notify us what you are doing, but if want an easier alternative to work with xml files using java, I highly suggest using XStream as a solution.
[1] http://x-stream.github.io/

Java vs. Net HTTP Client Performance

We call a webservice from our C# app which takes about 300ms using WCF (BasicHttpBinding). We noticed that the same SOAP call does only take about 30ms when sending it from SOAP UI.
Now we also implemented a test accessing the webservice via a basic WebClient in order to make sure that the DeSer-part of the WCf is not the reason for this additional delay. When using the WebClient class the call takes about 300ms as well.
Any ideas on why Java compared to C# is about 10x faster in this regard? Is there some kind of tweaking possible on the .NET side of things?
private void Button_Click(object sender, RoutedEventArgs e)
{
executeTest(() =>
{
var resultObj = client.getNextSeqNr(new WcfClient()
{
domain = "?",
hostname = "?",
ipaddress = "?",
loginVersion = "?",
processId = "?",
program = "?",
userId = "?",
userIdPw = "?",
userName = "?"
}, "?", "?");
});
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
executeTest(()=>
{
webClient.Proxy = null;
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
webClient.Headers.Add("Content-Type", "application/xml");
webClient.Encoding = Encoding.UTF8;
var data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"SomeNamespace\">" +
" <soapenv:Header/>" +
" <soapenv:Body>" +
" <ser:getNextSeqNr>" +
" <!--Optional:-->" +
" <clientInfo>" +
" <!--Optional:-->" +
" <domain>?</domain>" +
" <!--Optional:-->" +
" <hostname>?</hostname>" +
" <!--Optional:-->" +
" <ipaddress>?</ipaddress>" +
" <!--Optional:-->" +
" <loginVersion>?</loginVersion>" +
" <!--Optional:-->" +
" <processId>?</processId>" +
" <!--Optional:-->" +
" <program>?</program>" +
" <!--Optional:-->" +
" <userId>*</userId>" +
" <!--Optional:-->" +
" <userIdPw>?</userIdPw>" +
" <!--Optional:-->" +
" <userName>?</userName>" +
" </clientInfo>" +
" <!--Optional:-->" +
" <name>?</name>" +
" <!--Optional:-->" +
" <schema>?</schema>" +
" </ser:getNextSeqNr>" +
" </soapenv:Body>" +
"</soapenv:Envelope>";
string result = webClient.UploadString("http://server:8080/service", "POST", data);
});
}
Am I missing something here? Any idea would be helpful... ;-)
Kind regards,
Sebastian
I just found the reason for this.
It's the 100-Expect Continue HTTP Header and the corresponding implementation in .NET. The .NET client wait 350ms as default on the server. This causes the delays. Java seems to have other default values here...
Just add the following line of code very early in your code:
System.Net.ServicePointManager.Expect100Continue = false;
Cheers!

Categories

Resources