I have created a RESTful webservice and this webservice uses a mysql database. This was done following a howto using the Netbeans IDE.
All is working fine except for one little thing.
There is one table that is set as a 'time' type (default values 00:00:00) but for some reason when i access the wadl i get to see:
<time>1970-01-01T17:00:00+01:00</time>
I am not a very good Java programmer but i saw in the source of the webservice that Netbeans made this:
public void setDate(Date time) {
this.time = time;
}
How do i change this to just the time value? Are there standard classes that i can use?
[edit]
I am running a glassfish server where i deployed a Netbeans generated war file.
The tutorial to generate a RESTful webservice using Netbeans and mysql
(netbeans.org/kb/docs/websvc/rest.html#entities-and-services)
In the database, the time value is usually just stored as a long value ignoring the date part, which results in that when it's converted to a date, the date value is the unix epoch value (i.e. 0).
So i'm not sure that this is an issue, just convert it back to a Date on the receiving end and you'll have a date with the time properly set.
EDIT:
I suppose you have a transfer object of some sort where you define this "time" parameter? Or are you using hibernate or similar objects as the output to your rest xml generator?
If so, have you tried changing the data type from Date to Time?
Another way would be to change the type to String and in the setDate method use SimpleDateFormat to get a string on the exact form you want.
The types exposed by the RESTful web service are defined in the class YourTableFacadeREST. Try to modify the returned type of the corresponding method in that class.
EDITED
The problem is that the above idea will not work when the exposed object is more complex and your date is only "a part" of that object. Probably the best solution is to handle the conversion with the code reading the object.
If your goal is just to display these data (i.e. for requests of type GET) you may try with a view. I have never done Jersey RESTful web services on a view, but it should work for the GET side. Your View should display the original table with the datetime field converted to date. See here the syntax for creating a view in MySql:
http://dev.mysql.com/doc/refman/5.0/en/create-view.html
Related
I want to use Tarantool database for logging user activity.
Are there any out of the box solutions to create web dashboard with nice charts based on the collected data?
A long time ago, using an old-old version of tarantool I've created a draft of tarbon - time-series database, with carbon-cache identical interface.
Since that time the protocol have changed, but the generic idea still the same: use spaces to store data, compact data organization and correct indexes to access spaces as time-series rows and lua for preparing resulting jsons.
That solution was perfect in performance (either on reads or on writes), but that old version lacks disk storage and without disk I was very limited to metrics capacity.
Tarantool has embedded lua language so u could generate json from your data and use any charting library. For example D3.js has method to load json directly from url.
d3.json(url[, callback])
Creates a request for the JSON file at the specified url with the mime type "application/json". If a callback is specified, the request is immediately issued with the GET method, and the callback will be invoked asynchronously when the file is loaded or the request fails; the callback is invoked with two arguments: the error, if any, and the parsed JSON. The parsed JSON is undefined if an error occurs. If no callback is specified, the returned request can be issued using xhr.get or similar, and handled using xhr.on.
You also could look at c3.js simple facade for d3
I am trying to save a date into meteor mongodb my challenge is as follows:
1) if i use new Date() it creates a date object in mongo DB however it saves the time as local time as javascript Date() this always comes with a timezone +0x:hours based on browser local timezone. When i retrieve this it causes havoc as i am assuming everything in my db is UTC.
2) I want to use moment js library which is great because it can represent dates in UTC properly but my challenge is how do i get mongo db to accept a moment time? The minute i use moment.format() it saves it as a string!
So how can i send a date to a mongodb insert command with a date object that is in UTC? string just dont work :(
Any help would be appreciated.
Thanks
I think everything you need to know about both of these questions can be found here and here.
TLDR:
If you directly insert/update from the client you will store a timestamp based on the user's clock. It will still be stored as UTC, but you may or may not want to trust that the time is correct. I strongly suggest using a method for any db modifications which involve time so that the server's version of time will always be used.
Moment objects are not serializable to a format compatible with mongodb. Use a date object and format it on the client.
The problem with saving dates on the client is that each client can have a different time zone, or even wrong time set. Thus the only solution is to have the date set on the server. Using a method for each insert / update is not an elegant solution.
A common practice is to modify the document inside allow or deny callback:
Messages.allow({
insert: function(userId, doc) {
...
doc.timestamp = new Date();
return true;
},
});
That way you ensure all documents have a compatible timestamp, and you can use usual db methods on the client.
The Meteor community recently started an extensive document about how to use dates and times. You'll find a lot of useful information there, in addition to David Weldon's links:
https://meteor.hackpad.com/Meteor-Cookbook-Using-Dates-and-Times-qSQCGFc06gH
However, in particular I recommend using https://github.com/mizzao/meteor-timesync when security is not a concern. It allows you to client-locally obtain an accurate server time even if the client's clock is way off, without a round-trip to the server. This can be useful for all kinds of reasons - in my apps, I universally just use server-relative time and don't care about what the client's time is at all.
I am stuck with date-time equality in breezejs.
What I want to do is query data and return only the latest records that changed since my last sync.
...
query = query.where('ModifiedDateTime', '>=', lastSyncDate);
The ModifiedDateTime is a DateTime type on the dB side, and the lastSyncDate is the datetime of last sync from new Date(Date.now())
This works for the day but not for the time, what I wanted to do is call the getTime() function to get an integer to compare like described here: Beware equality tests but I can't figure out how to do it in the where clause?
Something like
query = query.where(ModifiedDateTime.getTime(), '>=', lastSyncDate.getTime());
But obviously this is not possible, is there another way to do it?
Browser DateTime is unlikely to be the same as server DateTime in the real world. I think you need a way to get the server sync DateTime from the server and use that in your request. A recommendation on how to proceed depends much on how you define lastSyncDateTime and perhaps your willingness to supplement the client/server protocol to include sync DateTime in the server response AND dig that out on the client so you can use it in a query. The tools are there but there is nothing native in Breeze to support this.
You might have a good feature request here for out-of-the-box breeze Web API protocol enhancement. You might suggest that we extend that protocol to include the server DateTime in the response (e.g. in a custom header) AND make that available to the breeze application developer as one of the properties of the query (and save) result.
But getting ahead of myself. First step is to explain what your need for this is and how you use it.
Right now I am working on a project to fetch data from a SharePoint list using SOAP API. I tried and successfully fetches the complete list, but now I want to fetch some specific data that is updated after a specific date.
Is this possible to fetch such data using SOAP query. I can see last update filed when I view single item at the bottom. Is this some how possible to use that filed?
Yes you can use the Web Services to do lot of things just like filtering a list result. I don't know which language you use, but with JavaScript you can look at these two frameworks that should help you:
http://aymkdn.github.io/SharepointPlus/ : easy way to create your queries (I created it)
http://spservices.codeplex.com/ : the most popular framework but less easy to use (it's my point of view)
You can also look at the documentation on MSDN (the param to use is query): http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx
At last found the answer,
The last update date and time can be retrieved from the list column "Modified".
The soap response will have the value in the attribute "ows_Modified".
Muhammad Usman
I'm connecting to a third-party web service to retrieve rows from the underlying database. I can optionally pass a parameter like this:
http://server.com/resource?createdAfter=[yyyy-MM-dd hh:ss]
to get only the rows created after a given date.
This means I have to store the current timestamp (using #[function:datestamp:...], no problem) in one message scope and then retrieve it in another.
It also implies the timestamp should be preserved in case of an outage.
Obviously, I could use a subflow containing a file endpoint, saving in a designated file on a path. But, intuitively, based on my (very!) limited experience, it feels hackish.
What's the correct idiom to solve this?
Thanks!
The Object Store Module is designed just for that: to allow you to save bits of information from your flows.
See:
http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html
https://github.com/mulesoft/mule-module-objectstore/