Search This Blog

Sunday 27 April 2014

Quiz on MongoDB - Part-02

## Implementation Using JAVA DRIVER
 ======================================
@NOTE: new BasicDBObject() is same as '{}' in mongo shell...given you have a hands-on exp of querrying over mongo-shell ,Keeping this in mind will help a lot while writing Code for JAVA DRIVER to query mongoDB.

 #  Java Driver: Representing Documents
How would you create a document using the Java driver with this JSON structure:
{
   "_id" : "user1",
   "interests" : [ "basketball", "drumming"]
}

new HashMap().put("_id", "user1").put(Arrays.asList("basketball", "drumming"));
new BasicDBObject("_id", "user1").append("interests", "basketball", "drumming");
new DBObject("_id", "user1").append("interests", Arrays.asList("basketball", "drumming"));
new BasicDBObject("_id", "user1").append("interests", Arrays.asList("basketball", "drumming"));          [# CORRECT #]
 ------------------------------------------------------------------------------------------------------------
# Java Driver: Insert
Do you expect the second insert below to succeed?

        MongoClient client = new MongoClient();
        DB db = client.getDB("school");
        DBCollection people = db.getCollection("people");
        DBObject doc = new BasicDBObject("name", "Andrew Erlichson")
                .append("company", "10gen");
        try {
            people.insert(doc);      // first insert
            doc.removeField("_id");  // remove the "_id" field
            people.insert(doc);      // second insert
        } catch (Exception e) {
            e.printStackTrace();
        }

No, because the _id will be a duplicate in the collection
 No, because the removeField call will remove the entire document
 Yes, because the removeField call will remove the _id key added by the driver in the first insert                        [# CORRECT #]
 Yes, because the driver always adds a unique _id field on insert.
 ------------------------------------------------------------------------------------------------------------
#  Java Driver: find, findOne, count   : 'collection.find(), collection.findOne() , collection.count()'

 In the following code snippet:
        MongoClient client = new MongoClient();
        DB db = client.getDB("school");
        DBCollection people = db.getCollection("people");
        DBObject doc;
        xxxx
        System.out.println(doc);
Please enter the simplest one line of Java code that would be needed in place of xxxx to make it print one document from the people collection.
> doc = people.findOne(); [# ANSWER #]
------------------------------------------------------------------------------------------------------------
# Java Driver: Query Criteria
Given a collection of documents with two fields -- type and score -- what is the correct line of code to find all documents where type is "quiz" and score is greater than 20 and less than 90. Select all that apply.
scores.find(new BasicDBObject("score", new BasicDBObject("$gt", 20).append("$lt", 90));
scores.find(new BasicDBObject("type", "quiz").append("score", new BasicDBObject("$gt", 20).append("$lt", 90))) [# CORRECT #] 
scores.find(new BasicDBObject("type", "quiz").append("$gt", new BasicDBObject("score", 20)).append("$lt", new BasicDBObject("score", 90))) scores.find(QueryBuilder.start("type").is("quiz").and("score").greaterThan(20).lessThan(90).get()) [# CORRECT #]
------------------------------------------------------------------------------------------------------------

#  Java Driver: field Selection 
------------------------------------------------------------------------------------------------------------
# Java Driver: Dot Notation
In the following code snippet, what do you think will happen if there exists in the collection a document that matches the query but does not have a key called "media.url"?

DBObject findOneUrlByMediaType(DBCollection videos, String mediaType) {
    DBObject query = new BasicDBObject("media.type", mediaType);
    DBObject projection = new BasicDBObject("media.url", true);
       return videos.findOne(query, projection);
}

It will throw an exception
It will return an empty document
 It will return a document containing a single field containing the document's _id   [# CORRECT #]
 There is not enough information to know
------------------------------------------------------------------------------------------------------------
#  Java Driver: Sort, Skip and Limit
Supposed you had the following documents in a collection named things.
{ "_id" : 0, "value" : 10 }
{ "_id" : 1, "value" : 5 }
{ "_id" : 2, "value" : 7 }
{ "_id" : 3, "value" : 20 }

If you performed the following query in the Java driver:
collection.find().sort(new BasicDBObject("value", -1)).skip(2).limit(1);
which document would be returned?
The document with _id=0
The document with _id=1
 The document with _id=2
 The document with _id=3
-----------------------------------------------------------------------------------------------------------
#  Java Driver: Update and Remove
In the following code fragment, what is the Java expression in place of xxxx that will set the field "examiner" to the value "Jones" for the document with _id of 1. Please use the $set operator.

        # update using $set
        scores.update(new BasicDBObject("_id", 1), xxxx);

new BasicDBObject("$set",new BasicDBObject("examiner","Jones"))

-----------------------------------------------------------------------------------------------------------
# Java Driver -- findAndModify();

------------------------------------------------------------------------------------------------------------


## MongoDB Schema Design
=======================

What's the single most important factor in designing your application schema within MongoDB?
Making the design extensible.
 Making it easy to read by a human.
Matching the data access patterns of your application. [# CORRECT #]
 Keeping the data in third normal form.

 ----------------------------------------------------------------------------------------------------------
 Living Without Transactions
Which of the following operations operate atomically within a single document? Check all that apply.
Update [# CORRECT #]
findAndModify [# CORRECT #]
$addToSet(within an update)            [# CORRECT #]
$push within an update         [# CORRECT #]
------------------------------------------------------------------------------------------------------------
# One to One Relations
What's a good reason you might want to keep two documents that are related to each other one-to-one in separate collections? Check all that apply.
Because you want to allow atomic update of both documents at once.
 To reduce the working set size of your application. [# CORRECT #]
 To enforce foreign key constraints
 Because the combined size of the documents would be larger than 16MB [# CORRECT #]

 #  One to Many Relations
When is it recommended to represent a one to many relationship in multiple collections?
Always
Whenever the many is large
Whenever the many is actually few Never

------------------------------------------------------------------------------------------------------------
# Trees
Given the following typical document for a e-commerce category hierarchy collection called categories
{
  _id: 34,
  name : "Snorkeling",
  parent_id: 12,
  ancestors: [12, 35, 90]
}
Which query will find all descendants of the snorkeling category?
db.categories.find({ancestors:{'$in':[12,35,90]}})
db.categories.find({parent_id: 34})
 db.categories.find({_id:{'$in':[12,35,90]}})
 db.categories.find({ancestors:34}) [# CORRECT #]
-----------------------------------------------------------------------------------------------------------
#  Handling Blobs
Which of the following statements are true about GridFS?
GridFS stores large blobs in a single collection by breaking up the file into multiple pieces.
Each gridFS document is given a unique filename.
GridFS stores large blobs in two collections, one for metadata and one for the blob chunks.                            [# CORRECT #]
GridFS compresses your file on disk.

Wednesday 23 April 2014

Using DynamicQuery on multiples Entities in Liferay

Here's an example where i have used Dynamic Query to query two different Entities in Liferay .

Entity1 = ResourceBookingMapping
Entity1 = PromotionalItemsBooking
Also, see carefully the applicantsCriterion where lies the core-logic ..

Refer the complete code-extract below :
------------------------------------------------------------------------------------------------------------------------------------
List<ResourceBookingMapping> resourceBookingList = new ArrayList<ResourceBookingMapping>();
Criterion combineCriterion = null;
DynamicQuery query = DynamicQueryFactoryUtil.forClass(ResourceBookingMapping.class);
DynamicQuery applicantQuery = DynamicQueryFactoryUtil.forClass(PromotionalItemsBooking.class)
.setProjection(ProjectionFactoryUtil.property("referenceNo"))
.add(RestrictionsFactoryUtil.eq("userId", applicantId));
Criterion dateRangeCriterion = RestrictionsFactoryUtil.between("createDate",
                                                                                                new java.sql.Timestamp( date1.getTime()), 
                                                                                               new java.sql.Timestamp(date2.getTime()));
Criterion itemsCriterion = RestrictionsFactoryUtil.eq("itemId",itemId);
Criterion applicantsCriterion = PropertyFactoryUtil.forName("referenceNo").in(applicantQuery);
Criterion itemsUnionApplicantCriterion = RestrictionsFactoryUtil.and(itemsCriterion ,                                                                                                                                                                                                 applicantsCriterion);
if(applicantId>0 && itemId>0){
System.out.println(" Criterion -PromotionalItemsBooking :: itemId>0 && applicantId>0 ");
combineCriterion = RestrictionsFactoryUtil.and(dateRangeCriterion, itemsUnionApplicantCriterion);
}else if(applicantId>0){
System.out.println(" Criterion -PromotionalItemsBooking :: applicantId>0 ");
combineCriterion = RestrictionsFactoryUtil.and(applicantsCriterion, dateRangeCriterion);
query.add(combineCriterion);
}else if(itemId>0){
System.out.println(" Criterion -PromotionalItemsBooking :: itemId>0 ");
combineCriterion = RestrictionsFactoryUtil.and(itemsCriterion, dateRangeCriterion);
query.add(combineCriterion);
}else{
System.out.println(" Criterion -PromotionalItemsBooking :: only Date-Range Applicable ");
query.add(dateRangeCriterion);
}
resourceBookingList = ResourceBookingMappingLocalServiceUtil.dynamicQuery(query);
------------------------------------------------------------------------------------------------------------------------------------

Monday 14 April 2014

Quiz on MongoDB

[  $ ,^,$lt ,$gt,$lte,$gte, $or,$and,$regex ,$in ,$all, .DOT Notation]
cursor operators : .sort({name:-1}), .limit() ,  .skip()
.update() : [ $set , $inc]
----------------------------------------------------------------------------------------------------------
#Using $or
How would you find all documents in the scores collection where the score is less than 50 or greater than 90?
db.scores.find({$or:[{score:{$lt:50}},{score:{$gt:90}}]});
----------------------------------------------------------------------------------------------------------
What will the following query do?
db.scores.find( { score : { $gt : 50 }, score : { $lt : 60 } } );
Find all documents with score between 50 and 60
Find all documents with score greater than 50
Find all documents with score less than 60        [# CORRECT #]
None of the above
[## Q/A -REASON: being a JS Obj the first list of score will be replaced by the second @JS Promt...thus in order to achieve certain effect ,we could use $AND or $gt & $lt within the same inner query ,etc]
--------------------------------------------------------------------------------------------------------
#Querrying inside Array
Which of the following documents would be returned by this query?
db.products.find( { tags : "shiny" } );

{ _id : 42 , name : "Whizzy Wiz-o-matic", tags : [ "awesome", "shiny" , "green" ] } [# CORRECT #]
 { _id : 704 , name : "Fooey Foo-o-tron", tags : [ "blue", "mediocre" ] }
 { _id : 1040 , name : "Snappy Snap-o-lux", tags : "shiny" } [# CORRECT #]
 { _id : 12345 , name : "Quuxinator", tags : [ ] }
 ---------------------------------------------------------------------------------------------------------
 #Using $in & $all
 Which of the following documents matches this query?

db.users.find( { friends : { $all : [ "Joe" , "Bob" ] }, favorites : { $in : [ "running" , "pickles" ] } } )

{ name : "William" , friends : [ "Bob" , "Fred" ] , favorites : [ "hamburgers", "running" ] }
{ name : "Stephen" , friends : [ "Joe" , "Pete" ] , favorites : [ "pickles", "swimming" ] }
 { name : "Cliff" , friends : [ "Pete" , "Joe" , "Tom" , "Bob" ] , favorites : [ "pickles", "cycling" ] }[# CORRECT #]
 { name : "Harry" , friends : [ "Joe" , "Bob" ] , favorites : [ "hot dogs", "swimming" ] }
 -----------------------------------------------------------------------------------------------------------
#Querries with Dot[.] Notation
 Suppose a simple e-commerce product catalog called catalog with documents that look like this:

{ product : "Super Duper-o-phonic",
  price : 100000000000,
  reviews : [ { user : "fred", comment : "Great!" , rating : 5 },
              { user : "tom" , comment : "I agree with Fred, somewhat!" , rating : 4 } ],
  ... }
Write a query that finds all products that cost more than 10,000 and that have a rating of 5 or better..

 db.catalog.find({price:{$gt:10000},"reviews.rating":{$gte:5}}) [# ANSWER #]
 --------------------------------------------------------------------------------------------------------
 #Querying,Cursors
 Recall the documents in the scores collection:
{
"_id" : ObjectId("50844162cb4cf4564b4694f8"),
"student" : 0,
"type" : "exam",
"score" : 75
}
Write a query that retrieves exam -type documents, sorted by score in descending order, skipping the first 50 and showing only the next 20.

 db.scores.find({type:"exam"}).sort({score:-1}).skip(50).limit(20) [# ANSWER #]
 --------------------------------------------------------------------------------------------------------
 #Counting Results
 How would you count the documents in the scores collection where the type was "essay" and the score was greater than 90?
 db.scores.count({type:"essay",score:{$gt:90}})
  ----------------------------------------------------------------------------------
 #Updating wholesale Document
 Let's say you had a collection with the following document in it:
{ "_id" : "Texas", "population" : 2500000, "land_locked" : 1 }
and you issued the query:
db.foo.update({_id:"Texas"},{population:30000000})

{ "_id" : "Texas", "population" : 2500000, "land_locked" : 1 } 
{ "_id" : "Texas", "population" : 3000000, "land_locked" : 1 }
 { "_id" : "Texas", "population" : 30000000 } [# CORRECT #]
 { "_id" : ObjectId("507b7c601eb13126c9e3dcca"), "population" : 2500000 }  
  ----------------------------------------------------------------------------------
 .update() --$set
 For the users collection, the documents are of the form
{
"_id" : "myrnarackham",
"phone" : "301-512-7434",
"country" : "US"
}

Please set myrnarackham's country code to "RU" but leave the rest of the document (and the rest of the collection) unchanged. 
 > db.users.update({"_id" : "myrnarackham"},{$set:{"country":"RU"}}) [# ANSWER #]
   ----------------------------------------------------------------------------------
.update() --$unset
 Write an update query that will remove the "interests" field in the following document in the users collection.

    "_id" : "jimmy" , 
    "favorite_color" : "blue" , 
    "interests" : [ "debating" , "politics" ] 
}
 > db.users.update({"_id":"jimmy"},{$unset:{"interests":1}}) [# ANSWER #]
Further u can use the .find() mthd to verify the same 
> db.users.find({"_id" : "jimmy"})
{ "_id" : "jimmy", "favorite_color" : "blue" }
   ----------------------------------------------------------------------------------
 .update() -- USING $push, $pop, $pull, $pushAll ,$pullAll ,$addToSet
  db.array.update({"id:0"},{$push:{"a":55}})  [# INCORRECT #]
  db.array.update({"id":0},{$push:{a:55}})  [# CORRECT #]
-----------------------------------
 Suppose you have the following document in your friends collection:
{ _id : "Mike", interests : [ "chess", "botany" ] }

What will the result of the following updates be?
db.friends.update( { _id : "Mike" }, { $push : { interests : "skydiving" } } );
db.friends.update( { _id : "Mike" }, { $pop : { interests : -1 } } );
db.friends.update( { _id : "Mike" }, { $addToSet : { interests : "skydiving" } } );
db.friends.update( { _id : "Mike" }, { $pushAll: { interests : [ "skydiving" , "skiing" ] } } );

A> { _id : "Mike", interests : ["botany","skydiving","skydiving","skiing" ] } [# ANSWER #]
   ----------------------------------------------------------------------------------
#  .update() :-- Upserts {upsert:true}
upsert = update(if record foound) else insert the same [thts wht i make out of this.. ;-) ]
After performing the following update on an empty collection
db.foo.update({username:'bar'}, {'$set':{'interests':['cat', 'dog']}}, {upsert: true} );

What could be the state of the collection.
{ "_id" : ObjectId("507b78232e8dfde94c149949"), "interests" : [ "cat", "dog" ]}
 {"interests" : [ "cat", "dog" ], "username" : "bar" } 
 {} 
 { "_id" : ObjectId("507b78232e8dfde94c149949"), "interests" : [ "cat", "dog" ], "username" : "bar" } [# CORRECT #]
   ----------------------------------------------------------------------------------
 Multi-update  db.collection_name.update({},{$set:{}}{multi:true})
 Recall the schema of the scores collection:

{
"_id" : ObjectId("50844162cb4cf4564b4694f8"),
"student" : 0,
"type" : "exam",
"score" : 75
}
Give every document with a score less than 70 an extra 20 points.
> db.scores.update({score:{$lt:70}},{$inc:{score:20}},{multi:true}) [# ANSWER #]
   ----------------------------------------------------------------------------------
.remove()  works on any collection , similar to .find() method...ie unless you specify wch document to remove inside a collection it will remove all one-by-one..
 Recall the schema of the scores collection:
{
"_id" : ObjectId("50844162cb4cf4564b4694f8"),
"student" : 0,
"type" : "exam",
"score" : 75
}
Delete every document with a score of less than 60. 
 > db.scores.remove({score:{$lt:60}})
   ----------------------------------------------------------------------------------
# getLastError
 d.runCommand({getLastError:1}) --will let u know whether the last DB-Operation failed or ws successfull
   ----------------------------------------------------------------------------------

Wednesday 22 January 2014

org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embedded stylesheet instruction for file :


Recently i faced this Exception while working on a basic spring example...later to my surprize it turned out to be one stupid experience ;-) ...thus thought of sharing the same with an intent that it could save someone else's time...


org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embedded stylesheet instruction for file: file:/F:/Projects_Spring/demoProject_dec22/src/mySpring.xml at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:225) at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:186) at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:73)
Caused by: org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embedded stylesheet instruction for file: file:/F:/Projects_Spring/demoProject_dec22/src/mySpring.xml at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:214) ... 2 more



It's an Eclipse bug, I've noticed it too. Make sure that you're running the right Eclipse Runtime config (i.e. if you're clicking on the little green "Play" button on the top, thinking it will re-run the last (valid) Runtime you've ran, re-check (by clicking on the down arrow next to it) to make sure no new Runtime has been created).
What I've noticed it that even though I create a perfectlly valid run-time pointing to a Java main class and everyting, which I run a few times and all is ok, after a while, if I select an xml file (because I wanted to edit it for example) and then leave it selected as I click on my run button, Eclipse will create a new XSLT Transformation run time for that xml file and try to run it, failing with the exception you report. The solution is to erase that run time, make sure I have no xml file selected, and re-run the correct run time.

Tuesday 17 December 2013

Creating & Using a language.properties for your custom portlet





STEP:1 Create a Package named-'content' under the.. '/docroot/WEB-INF/src'
Note: Create a Package and not a folder. [i did that mistake for the first time ;-)]

STEP:2 now create a file named - '/content/language.properties' under the content folder created above..

STEP:3 now to recognize this file @ portlet-level you need to make an entry in the 'portlet.xml' file present under the -'/docroot/WEB-INF/portlet.xml'
Add the properties file entry in this file using the resource-bundle tag as following :-
--------------------------------------------------------------------
<resource-bundle>content.language</resource-bundle>

--------------------------------------------------------------------

Note: add this Tag @ following location for each portlet (that intends to use this language.properties file) in the portlet.xml:-
--------------------------------------------------------------------
<portlet>
    <portlet-name>portfolio</portlet-name>
    ...
   <resource-bundle>content.language</resource-bundle>
    <portlet-info>...</portlet-info>
    ...
</portlet>
--------------------------------------------------------------------
Note: Also , the correct entry format is : <resource-bundle>content.language</resource-bundle>
often mistaken with --
<resource-bundle>language</resource-bundle>  OR
<resource-bundle>language.properties</resource-bundle>  OR
<resource-bundle>content.language.properties</resource-bundle>

To populate a jQuery-DataTable by passing JSON Response(JSonArray) as parameter.

Recently, i came across a Reqirement where i need to populate datatable(i used jQuery-DataTable) by passing JSON array as input parameter.
For example , i had a JSON ajax call which returns me a JSON array data,i would like to populate datatable with this JSON array,
 i know i can do AJAX call from datatable itself, but i would like to explore this option of getting data first 
and then building table using this data..

[download link -- http://datatables.net/download/]
use the following link to download the all the required JS libs/files (probably you will get a complete JQuery Datatable project ..
and you need to extract the following files from the /js folder in there..)
- dataTables.js
- dataTables.min.js
Alongwith these you will be needing -
- jquery.js
- jquery-1.10.2.min.js    as well(download and include ,incase you haven't uptill now..)

Ok, so here the input Text in my 'jsp' which will invoke the ajax-call onKeyUp -
<input id="organizationName" name="organizationName" onkeyup="doSearchAjaxCall();" type="text" value="" />

here's the JavaScript function which is responsible for making the ajax call.....
----------------------------------------------------------------------------------------------
Also, before jumping to script keep note of the Portlet-URL(required for the ajax call) ,
i created a resourceURL (given below) which will hit the serveResource in my PortletClass ..(you may create as per your requirement)
-- -- -- -- -- -- -- -- -- -- -- -- -- --
<portlet:resourceURL var="searchRequestURL">
</portlet:resourceURL>
-- -- -- -- -- -- -- -- -- -- -- -- -- --
<script>
function doSearchAjaxCall() {
 // fetching various field params from the jsp..
var acbno = jQuery("#acbno").val();    
var orgName = jQuery("#organizationName").val();
var field = jQuery("#field").val();          

//dataType:'json',
Note: mentioning dataType in the ajax-call is note required ...only 'setContentType("application/json")' is enough [set in portlet class --see complete code below]
jQuery.ajax({
type: "POST",
url: "<%= searchRequestURL.toString() %>",
data:"acbno="+acbno+"&orgName="+orgName+"&field="+field,
error: function(data) {
alert(" inside error >>> "+data);
},
success: function(data) {
//var stringResponse = JSON.stringify(data);
Note: Dont make the Mistake of converting the data-array into string before passing into datatable - as it requires data-array in json form only..
//alert("data stringify = >>>> "+stringResponse);
// console.log("success data>>  "+data);
// pass the data-array obtained in success-fn to another js fn created -'loadDataTable()' which will futher //populate the Datatable..
loadDataTable(data);          // custom -function Call

}
});
 }

  function loadDataTable(data){

  // console.log("loadDataTable >>  "+data);
   $("#tableId1").dataTable().fnDestroy();
var oTable = $('#tableId1').dataTable({
"aaData" : data,
"aoColumns" : [
{"sTitle" : "SammNo" },
{ "sTitle" : "OrganizationName" },
{ "sTitle" : "Field" },
{"sTitle" : "Scope" }
]
});
}
// Also, you may add the ajax call on jQuery ready as well here...see explanation below >>>
</script>

Note: aaData - 
Note: aoColumns -
Note :    $("#tableId1").dataTable().fnDestroy();   ---bcz Datatables cannot be reinitialised hence, need to destroy the existing datatable before poputaing again for consecutive ajax call for same datatable..

----------------------------------------------------------------------------------------------
 Also, you may add the ajax call on jQuery ready as well Incase you want the datatable to be populated on page load as well...
 bcz above code will populate the datatable as & when the 'onkeyup()' function is called for the input-text -'organizationName'.
 ----------------------------------------------------------------------------------------------------
jQuery().ready(function(){

var acbno = jQuery("#acbno").val();
var orgName = jQuery("#organizationName").val();
var field = jQuery("#field").val();

    jQuery.ajax({
type: "POST",
url: "<%= searchRequestURL.toString() %>",
data:"acbno="+acbno+"&orgName="+orgName+"&field="+field,
error: function(data) {
alert(" inside error >>> "+data);

},
success: function(data) {

//console.log(" jQuery-ready >> success data>>  "+data);

loadDataTable(data);

}
});
});
------------------------------------------------------------------------------------------------------------


NOTE : STRICTLY AVOID USING 'console.log();' - This gives an error saying 'console is unDefined' in most of the IE version browsers. This error often breaks the complete JavaScript used ..In my case i wasn't able to display jQuery DataTables in IE whereas it was working  F9 in FF && Chrome..!!!
Though could use the same for debugging purpose OR incase the target browser for your application duznt includes IE (which is often not the case ) ;-)






Dynamically Creating a URL for a DLFileEntry or a File stored in Document & Media

Recently, i came across a requirement where i need to provide a view link to the various files stored in Liferay Document & Media.ie on click of these links the File(.pdf stored in our case) needs to open in a new Tab in Browser.
Hence, a url is required for that file :
I came to know that the complete URL formed is composed of the following components:
host+documents+groupId+folderId+fileTitle
where,
host - you can obtain as following- 'PortalUtil.getPortalURL(portletRequest)'
-will return something like this (http://localhost:8080/) incase of local machine..
documents - you can hardcode as this is hardly going to change in the D&M path..
groupId - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getGroupId()'
folderId - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getFolderId()'
fileTitle - you better fetch from the dlFileEntry Obj as - 'dlFileEntry.getTitle()'
- Note: Don't fetch 'dlFileEntry.getName()' instead of 'dlFileEntry.getTitle()'

Hence,
The complete url will look something like this:
 'http://localhost:8080/documents/10179/0/Flipkart-Induct-meet'

Here's how i formed this URl in my PortletClass:
------------------------------------------------------------------------------------------------------------
final String filePath_fromDM = "documents/"+dlFileEntry.getGroupId()+"/"+dlFileEntry.getFolderId()+"/"+dlFileEntry.getTitle();
System.out.println(">>>>>>  filePath_fromDM >>> = "+filePath_fromDM);
-will return something like this (documents/10179/0/Flipkart-Induct-meet) incase of local machine..

String completeFilePathUrl = StringPool.BLANK;
completeFilePathUrl = PortalUtil.getPortalURL(resourceRequest)+"/"+filePath_fromDM;
System.out.println(" >>> completeFilePathUrl () = "+completeFilePathUrl );
-will return something like this (http://localhost:8080/documents/10179/0/Flipkart-Induct-meet) incase of local machine..
------------------------------------------------------------------------------------------------------------

And, finally here how i formed a Link for this URL on click of which it will open the doc in a New-Tab..
String linkFormed = "<a href='"+scopeUrl+"' target='_blank'>View</a>" ;
Note: target="_Blank" is required only if you want to open the link in a new Browser Tab.
which you can pass in a response , use in a jsp , etc as per your requirement..