How to get the Date/time for an Event I retrieve ?
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("username#gmail.com", "pwd");
URL feedUrl = new URL("https://www.google.com/calendar/feeds/username#gmail.com/public/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setFullTextQuery("Query");
CalendarEventFeed myResultsFeed = myService.query(myQuery,
CalendarEventFeed.class);
for (int i=0; i < myResultsFeed.getEntries().size(); i++)
{
CalendarEventEntry firstMatchEntry = (CalendarEventEntry) myResultsFeed.getEntries().get(i);
String myEntryTitle = firstMatchEntry.getTitle().getPlainText();
System.out.println(myEntryTitle + " " + firstMatchEntry.getPlainTextContent());
System.out.println(""+firstMatchEntry.getAuthors().get(0).getEmail());
System.out.println(""+firstMatchEntry.getPublished());
System.out.println(""+firstMatchEntry.getHtmlLink().getHref());
System.out.println(""+firstMatchEntry.getStatus().getValue());
}
I couldn't find a way to get any more useful info from a CalendarEventEntry.
LE: problem solved; after seeing this:
http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents
I got to this:
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());
Good thing the examples are different depending on language.
Problem solved; after seeing this:
http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents
I got to this:
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());
Related
I made two RestController apis. On response of second api I wanted first api's response (which is a json response), so I tried to use HttpServletResponse.redirect. I also set required content type to it. But on second api response I got Unsupported Media Type Content type 'null' not supported.
first API
#GetMapping(value="checkStatus/{msisdn}",consumes=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CoreResponseHandler> fetchOcsByDate2(#PathVariable(value="msisdn",required=true)String msisdn){
long l_time_start = System.currentTimeMillis();
List<Object[]> list = repository.getSingleCallDetail(msisdn);
if(list==null || list.size()==0) {
System.out.println("NO RECORD FOUND");
}
JSONObject objMain = new JSONObject();
for(Object[] objArr: list) {
JSONObject obj = new JSONObject();
String msisdn_ = objArr[0]==null?null:objArr[0].toString();
String songId = objArr[1]==null?null:objArr[1].toString();
String songName = objArr[2]==null?null:objArr[2].toString();
String status = objArr[3]==null?null:objArr[3].toString();
String lang = objArr[4]==null?null:objArr[4].toString();
String startDate = objArr[5]==null?null:objArr[5].toString();
objMain.put("status", status);
objMain.put("language", lang);
obj.put("id", songId);
obj.put("msisdn", msisdn);
obj.put("songName", songName);
objMain.put("subscription", obj);
}
long l_time_end = System.currentTimeMillis();
long l_diff = l_time_end-l_time_start;
if(list!=null && list.size()>0) {
return new ResponseEntity<CoreResponseHandler>(new SuccessResponseBeanRefined(HttpStatus.OK, ResponseStatusEnum.SUCCESSFUL, ApplicationResponse.SUCCESSFUL, objMain,l_diff+" ms"),HttpStatus.OK);
}
if(list==null || list.size()==0) {
return new ResponseEntity<CoreResponseHandler>(new SuccessResponseBeanRefined(HttpStatus.NOT_FOUND, ResponseStatusEnum.FAILED, ApplicationResponse.Failed, "not found",l_diff+" ms"),HttpStatus.NOT_FOUND);
}
return new ResponseEntity<CoreResponseHandler>(new SuccessResponseBeanRefined(HttpStatus.BAD_REQUEST, ResponseStatusEnum.FAILED, ApplicationResponse.Failed," > Bad request",l_diff+" ms"),HttpStatus.BAD_REQUEST);
}
no problem in output. ran smooth
second API
#GetMapping(value="verifyOtp/{msisdn}/{otp}",consumes=MediaType.APPLICATION_JSON_VALUE)
public void verifyOtp(#PathVariable(value="msisdn",required=true)String msisdn,
#PathVariable(value="otp",required=true)String otp,HttpServletResponse response) throws Exception{
long l_time_start = System.currentTimeMillis();
long l_time_end = System.currentTimeMillis();
long l_diff = l_time_end-l_time_start;
List<Object[]> list = repository.verifyOtp(msisdn,otp);
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
if(list!=null && list.size()>0) {
for(Object[] obj:list) {
String strDate = obj[3]==null?null:obj[3].toString();
Date dtDb = sdf.parse(strDate);
Date dtNow = new Date();
String strDtNow = sdf.format(dtNow);
dtNow = sdf.parse(strDtNow);
long ldtDb = dtDb.getTime();
long ldtNow = dtNow.getTime();
if(ldtDb>ldtNow) {
System.out.println("success within time");
int ii = repository.updateIsActive(msisdn);
response.setContentType("application/json");
response.sendRedirect("http://localhost:9393/crbt/api/subscriber/ivr/checkStatus/"+msisdn);
}
else {
System.out.println("failure time over!");
}
}
}
else {
}
}
second Api Response in postman
What I expected was first API's response. But its giving me some 415 content type error
How can I get first API's success json response from second api's response.. I even tried org.springframework.http.HttpHeaders but couldn't get desired output. What changes I had to do in order to get first Api's response in my second api response.
I have a strange feeling answering your questions, because I dislike the solution I'll provided. But it might help, so I'll give a try.
Basically, your Controller are just Spring beans, which means you can do is having a dependency, and second controller will call first controller. This will also change your method verifyOtp to make it change the return type.
Something like that:
...
#Autowired
private FirstController firstController;
...
#GetMapping(value="verifyOtp/{msisdn}/{otp}",consumes=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CoreResponseHandler> verifyOtp(#PathVariable(value="msisdn",required=true)String msisdn,
#PathVariable(value="otp",required=true)String otp,HttpServletResponse response) throws Exception{
long l_time_start = System.currentTimeMillis();
long l_time_end = System.currentTimeMillis();
long l_diff = l_time_end-l_time_start;
List<Object[]> list = repository.verifyOtp(msisdn,otp);
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
if(list!=null && list.size()>0) {
for(Object[] obj:list) {
String strDate = obj[3]==null?null:obj[3].toString();
Date dtDb = sdf.parse(strDate);
Date dtNow = new Date();
String strDtNow = sdf.format(dtNow);
dtNow = sdf.parse(strDtNow);
long ldtDb = dtDb.getTime();
long ldtNow = dtNow.getTime();
if(ldtDb>ldtNow) {
System.out.println("success within time");
int ii = repository.updateIsActive(msisdn);
return firstController.fetchOcsByDate2(msidn);
}
else {
System.out.println("failure time over!");
return null;
}
}
}
else {
return null;
}
}
I think you are trying to achieve something uncommon, and to avoid having this dependency between controller, consider:
Change your use case. Make the second controller returning a HttpStatus.OK, and make the client do the next call to the first controller
Create a service in charge of loading the msidn, which will avoid duplicate code, and keep you in a more standard position to make our evolutions.
The issue occurred due to GetMapping .
#GetMapping(value="checkStatus/{msisdn}",consumes=MediaType.APPLICATION_JSON_VALUE)
replace with below in first Api:
#GetMapping(value="checkStatus/{msisdn}")
I'm trying to use the ical4j library to find the current event (or at least events occurring today) in an ical file that contains recurring events. I've managed to build and print all events in the calendar but I have been getting
java.lang.IllegalArgumentException: Range start must be before range end
at runtime. This is strange because my period rule clearly starts before it ends. I have done a lot of reading and trying different things but I'm clueless. Here's the gist of what I'm trying to achieve:
private class CurrentShow extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
//params come from execute() call, params[0] is url
InputStream is = null;
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
try {
is = new URL(urls[0]).openStream();
CalendarBuilder builder = new CalendarBuilder();
try {
calendar = builder.build(is);
} catch (Exception e) {
}
for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
Component component = (Component) i.next();
System.out.println("Component [" + component.getName() + "]");
for (Iterator j = component.getProperties().iterator(); j.hasNext(); ) {
Property property = (Property) j.next();
System.out.println("Property [" + property.getName() + ", " + property.getValue() + "]");
}
}
java.util.Calendar today = java.util.Calendar.getInstance();
today.set(java.util.Calendar.HOUR_OF_DAY, 0);
today.clear(java.util.Calendar.MINUTE);
today.clear(java.util.Calendar.SECOND);
// create a period starting now with a duration of one (1) day..
Period period = new Period(new DateTime(today.getTime()), new Dur(1, 0, 0, 0));
Filter filter = new Filter(new Rule[] {new PeriodRule(period)}, Filter.MATCH_ALL);
Collection eventsToday = filter.filter(calendar.getComponents(Component.VEVENT));
Any help would be appreciated. Thanks.
I have been trying to get my android code to print to a new Brother Printer but
I keep getting ERROR_WRONG_LABEL.
I also get the information:
D/Brother Print SDK: no such enum object for the id: -1
This is my code:
public void printLabel() {
Printer myPrinter = new Printer();
PrinterInfo myPrinterInfo = new PrinterInfo();
try {
myPrinterInfo.printerModel = PrinterInfo.Model.QL_710W;
myPrinterInfo.ipAddress = "12.1.3.45";//not real ip
myPrinterInfo.macAddress = "";
myPrinterInfo.port = PrinterInfo.Port.NET;
myPrinterInfo.paperSize = PrinterInfo.PaperSize.A7;
myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
myPrinterInfo.numberOfCopies = 1;
LabelInfo mLabelInfo = new LabelInfo();
mLabelInfo.labelNameIndex = 5;
mLabelInfo.isAutoCut = true;
mLabelInfo.isEndCut = true;
mLabelInfo.isHalfCut = false;
mLabelInfo.isSpecialTape = false;
myPrinter.setPrinterInfo(myPrinterInfo);
myPrinter.setLabelInfo(mLabelInfo);
//File downloadFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
Log.i("HEYYYY", "startCommunication = " + myPrinter.startCommunication());
Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_overflow);
PrinterStatus printerStatus = myPrinter.printImage(map);
Log.i("HEYYYY", "errorCode-11 = " + printerStatus.errorCode);
Log.i("HEYYYY", "labelWidth = " + myPrinter.getLabelParam().labelWidth);
Log.i("HEYYYY", "paperWidth = " + myPrinter.getLabelParam().paperWidth);
Log.i("HEYYYY", "labelNameIndex " + mLabelInfo.labelNameIndex);
Log.i("HEYYYY", "printers " + myPrinter.getNetPrinters("QL-710W"));
Log.i("Label-id", myPrinter.getPrinterStatus().labelId + "");
myPrinter.endCommunication();
} catch(Exception e){
e.printStackTrace();
}
}
Whenever I put the mac address which I got from the printer page, the error code changes to
ERROR_NOT_MATCH_ADDRESS.
But without it(setting it to an empty string or commenting it out), it changes to
ERROR_WRONG_LABEL.
What is wrong with this code, please?
UPDATE:
I inserted the correct mac id and now the error code is
ERROR_WRONG_LABEL
what do I do?
After reading through the manual that came with it, I discovered that the ERROR_WRONG_LABEL code occurs due to wrong labelNameIndex or wrong paperSize.
I set the labelNameIndex value to 15 and, voila it worked.
I feel anyone facing this problems should try out various values for the labelNameIndex.
Thanks.
I am attempting to get the items and some of the related information from a Purchase Order with SuiteTalk. I am able to get the desired Purchase Orders with TransactionSearch using the following in Scala:
val transactionSearch = new TransactionSearch
val search = new TransactionSearchBasic
...
search.setLastModifiedDate(searchLastModified) //Gets POs modified in the last 10 minutes
transactionSearch.setBasic(search)
val result = port.search(transactionSearch)
I am able to cast each result to a record as an instance of the PurchaseOrder class.
if (result.getStatus().isIsSuccess()) {
println("Transactions: " + result.getTotalRecords)
for (i <- 0 until result.getTotalRecords) {
try {
val record = result.getRecordList.getRecord.get(i).asInstanceOf[PurchaseOrder]
record.get<...>
}
catch {...}
}
}
From here I am able to use the getters to access the individual fields, except for the ItemList.
I can see in the NetSuite web interface that there are items attached to the Purchase Orders. However using getItemList on the result record is always returning a null response.
Any thoughts?
I think you have not used search preferences and that is why you are not able to fetch purchase order line items. You will have to use following search preferences in your code -
SearchPreferences prefrence = new SearchPreferences();
prefrence.bodyFieldsOnly = false;
_service.searchPreferences = prefrence;
Following is working example using above preferences -
private void SearchPurchaseOrderByID(string strPurchaseOrderId)
{
TransactionSearch tranSearch = new TransactionSearch();
TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic();
RecordRef poRef = new RecordRef();
poRef.internalId = strPurchaseOrderId;
poRef.type = RecordType.purchaseOrder;
poRef.typeSpecified = true;
RecordRef[] poRefs = new RecordRef[1];
poRefs[0] = poRef;
SearchMultiSelectField poID = new SearchMultiSelectField();
poID.searchValue = poRefs;
poID.#operator = SearchMultiSelectFieldOperator.anyOf;
poID.operatorSpecified = true;
tranSearchBasic.internalId = poID;
tranSearch.basic = tranSearchBasic;
InitService();
SearchResult results = _service.search(tranSearch);
if (results.status.isSuccess && results.status.isSuccessSpecified)
{
Record[] poRecords = results.recordList;
PurchaseOrder purchaseOrder = (PurchaseOrder)poRecords[0];
PurchaseOrderItemList poItemList = purchaseOrder.itemList;
PurchaseOrderItem[] poItems = poItemList.item;
if (poItems != null && poItems.Length > 0)
{
for (var i = 0; i < poItems.Length; i++)
{
Console.WriteLine("Item Line On PO = " + poItems[i].line);
Console.WriteLine("Item Quantity = " + poItems[i].quantity);
Console.WriteLine("Item Descrition = " + poItems[i].description);
}
}
}
}
I have successfully created calendar entries using the Java .jar files for Google Calendar API. They always go into the "Rifle" calendar even though I have the calendars shown below. I need to know how to specify the calendar that entry falls under. For example, where would I specify "Meetings" or "Shotgun"
I'm not seeing anything or any examples of how to specify a particular calendar.
public void create() {
try {
CalendarService myService = new CalendarService("My Service");
myService.setUserCredentials("mycalendar", "mypassword");
URL postUrl = new URL("http://www.google.com/calendar/feeds/myurl#junk.com/private/full");
CalendarEventEntry myEntry = new CalendarEventEntry();
//myEntry.setIcalUID("Rec Fire");
DateTime startTime = DateTime.parseDateTime("2014-06-22T09:00:00");
DateTime endTime = DateTime.parseDateTime("2014-06-22T13:00:00");
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);
Where eventLocation = new Where();
eventLocation.setLabel("R-4");
eventLocation.setValueString("value string");
eventLocation.setRel("REL");
myEntry.addLocation(eventLocation);
EventWho eventWho = new EventWho();
eventWho.setAttendeeStatus("attendee status");
eventWho.setAttendeeType("Meetings");
eventWho.setValueString("who value string");
eventWho.setEmail("myemailt#email.com");
eventWho.setRel("who rel");
myEntry.addParticipant(eventWho);
myEntry.setTitle(new PlainTextConstruct("R-4 Rifles Only"));
myEntry.setContent(new PlainTextConstruct("Paragraph HURST MULLINS"));
CalendarEventEntry insertedEntry = myService.insert(postUrl, myEntry);
} catch (Exception e) {
e.printStackTrace();
}
I figured this out. First you have to get the IDs of your secondary calendars
public void retrieve() {
try {
CalendarService myService = new CalendarService("QuanticoShootingclub");
myService.setUserCredentials("calendar#quanticoshootingclub.com", "washington13");
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/owncalendars/full");
CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
System.out.println("Your calendars:");
System.out.println();
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEntry entry = resultFeed.getEntries().get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
System.out.println("\t\t" + entry.getId());
}
} catch (Exception e) {
e.printStackTrace();
}
}
You can also do this by goign to your Google Calendar on the web. Click the drop-down and then Calendar Settings > Calendar Address: (Calendar ID: #group.calendar.google.com)
Then, when you're creating the new calendar entry, you substitute this ID for the primary ID.
NOTE: From the original code
URL postUrl = new URL("http://www.google.com/calendar/feeds/***<secondary calendar ID>***/private/full");