Saturday, June 24, 2017

How to pass date type parameter in a restful service

In certain use case, we might need to pass date type parameter from service consumer to service provider.
But date as a object is not allowed to transfer via http.

The are only 2 additional steps to resolve this problem
1. at consumer side, convert the date object to long value
2. at provider side, convert the long value back to date object.

in Javascript / Play / SpringBoot consumer, convert the date object to long value

new Date().getTime();



in Play / SpringBoot provider, convert the long date value to date object.

new Date( dateValueInLong );




Done!!



Friday, June 23, 2017

Saving and Updating a document with json in MongoDB

In MongoDB, we can use the same save(DBObject document) to save or update a json into MongoDB.


String jsonString = "{'Page':1,'Fruits':['apple','peach','pear']}";  // some json string
DBObject dbObject = (DBObject)JSON.parse(jsonString);

MongoClient mongo = new MongoClient( Arrays.asList(new ServerAddress("localhost", 27017)) );
DB db = mongo.getDB("myDB");
DBCollection collection = db.getCollection("myCollection");
collection.save(dbObject);



the save(DBObject document) will identify if this is new document,
it will perform insert
otherwise it will perform update.


Done!!

Thursday, June 22, 2017

Quick Start Angular 2 module in Liferay

Platform:
Angular 2
Liferay 6.x, Liferay 7

Steps
1. download the sample project done by devsoftcz from github

2. extract the sample project, and change the project folder name.

3. open bnd.bnd, change the Bundle-SymbolicName to desired name

4. open package.json, change the "name" and "description" in the top part.

LinkWithin

Related Posts Plugin for WordPress, Blogger...