Prospettiva Nevski

Nevsky Avenue (Russian: Не́вский проспе́кт, tr. Nevsky Prospekt, IPA: [ˈnʲefskʲɪj prɐˈspʲekt]) is the main street in the city of St. Petersburg, Russia. Planned by Peter the Great as beginning of the road to Novgorod and Moscow, the avenue runs from the Admiralty to the Moscow Railway Station and, after making a turn at Vosstaniya Square, to the Alexander Nevsky Lavra. [wiki]

Inspirational Quotes from Sir Alex Ferguson

This is a really interesting post

My favorite quote is:

I’ve never played for a draw in my life

And Don’t Forget To Add Some “Fergie Time”

Results pagination with MongoDB and Java

To implement the MongoDB results pagination in Java, there are few parameters that need to be collected:

1) the order of results (ascending / descending)
2) the field used to order the results
3) the number of element and the page selected
4) the field and the value used to filter the results

As well as the results of query, the method needs to return the total number of elements. All returned elements will be saved in a HashMap.

HashMap<String, Object> resultMap = new HashMap<String, Object>();
 
Direction direction = Sort.DEFAULT_DIRECTION;
if (sortDirection > 0) {
	direction = Sort.Direction.ASC;
} else { 
	direction = Sort.Direction.DESC;
}
 
List

If a pagination is required, skip and limit are used

if (pageSize > 0) {
	query.skip((pageNum - 1 ) * pageSize);
	query.limit(pageSize);
}
 
if ( sortField != null && !sortField.equals("") ) {				
	query.with(new Sort(direction, sortField));
}
 
results = mongoTemplate.find(query, Object.class);

If a pagination is required, queryCounter (basically a version of query without pagination an limit) is used to calculate the total number of results. Of course, if pagination is not required, is possible to use directly the size of results.

if ( pageSize > 0 ) {
	resultMap.put("RESULT_SIZE", (int) mongoTemplate.count(queryCounter, Object.class));
} else {
	// If pagination is not required, the query is not re-executed
	resultMap.put("RESULT_SIZE", results.size());
}

mongoTemplate is a spring bean defined in this way on context configuration:

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"  c:mongo-ref="mongo" c:databaseName="${mongo.db.name}">
	<property name="writeConcern" value="SAFE" />
</bean>
Tagged ,

MongoDB query with logical and condition in Java

Suppose you need to apply some filters to your MongoDB query, for example to extract some _ids that match a regex condition. This is the way to do that:

Query query;
query.addCriteria(Criteria.where("_id").in(IDs).and(query_field).regex(".*" + query_value + ".*", "i"));

In this example I used the Query (see here) and Criteria (see here) classes

And, this is the query you can use in mongoDB (Robomongo* or command line):

Query: { 
	"_id" : { "$in" : [ "ID1" , "ID2" , "ID3" ]} , 
	"detail.medicationBrandName" : { "$regex" : ".*x.*" , "$options" : "i"}}, 
	Fields: null, Sort: { "medicationGenericName" : -1}
}

*Robomongo: is a shell-centric cross-platform open source MongoDB management tool (i.e. Admin GUI). Robomongo embeds the same JavaScript engine that powers MongoDB’s mongo shell. You can download it here.

Tagged , ,

Puff the magic dragon

Puff the Magic Dragon is a song written by Leonard Lipton and Peter Yarrow, and made popular by Yarrow’s group Peter, Paul and Mary in a 1963 recording.

Speculation about drug references []
After the song’s initial success, speculation arose — as early as a 1964 article in Newsweek — that the song contained veiled references to smoking marijuana.[5] The word “paper” in the name of Puff’s human friend (Jackie Paper) was said to be a reference to rolling papers, and the word “dragon” was interpreted as “draggin’,” i.e. inhaling smoke; similarly, the name “Puff” was alleged to be a reference to taking a “puff” on a joint. The supposition was claimed to be common knowledge in a letter by a member of the public to The New York Times in 1984.[6]
The authors of the song have repeatedly rejected this urban legend and have strongly and consistently denied that they intended any references to drug use.[7] Peter Yarrow has frequently explained that “Puff” is about the hardships of growing older and has no relationship to drug-taking.[8][9] He has also said of the song that it “never had any meaning other than the obvious one” and is about the “loss of innocence in children”.[10]
In 1976, Yarrow’s bandmate Paul Stookey of Peter, Paul and Mary also upheld the song’s innocence. He recorded a version of the song at the Sydney Opera House in March 1976,[11] in which he set up a fictitious trial scene. The Prosecutor accused the song of being about marijuana, but Puff and Jackie protested. The judge finally leaves the case to the jury (the Opera House audience) and says if they will sing along with the song, it will be acquitted. The audience joins in with Stookey, and at the end of their sing-along, the judge declares “case dismissed.”

Oh, yes.. sure… they didn’t get anything.

LinkedIn recommendation

I was thinking about a recommendation on LinkedIn. My concern is about this question: how To Get Great LinkedIn Recommendations and, in particular when. As a freelancer with a big customer is really important to have an exit strategy to prevent a regrettable situation so, I was thinking to ask to some recommendation on LinkedIn. This professional social network is starting to be a good starting point to find new business partners and, of course, a recommendation that offer specific results or tell a story of transformation about your professional experience should be a great way to improve your profile.

I read a lot of blogs but I found this one really interesting linkedin-recommendations

Tagged

Partita IVA ben visibile in home page

L’Agenzia delle Entrate ha sentito la necessità di ribadire e precisare quanto già previsto dal comma 1 dell’art.35 del DPR 633/72, diramando la risoluzione n. 60 datata 16 maggio 2006, recante: “Indicazione numero partita IVA nel sito web – articolo 35, comma 1, del D.P.R. n. 633 del 1972”.
Esso deve essere sempre indicato nelle dichiarazioni, nella home page dell’eventuale sito web ed in ogni altro documento destinato all’ufficio stesso.
[…Con il provvedimento in esame l’Agenzia delle Entrate precisa quanto segue:L’obbligo di indicazione del numero di partita IVA nel sito web rileva per tutti i soggetti passivi IVA, a prescindere dalle concrete modalità di esercizio dell’attività.
Di conseguenza, quando un soggetto IVA dispone di un sito web relativo all’attività esercitata, quand’anche utilizzato solamente per scopi pubblicitari, lo stesso è tenuto ad indicare il numero di partita IVA…]

dataSource: The name of the property, following JavaBean naming conventions.

Suppose you defined TemplateDao Spring bean in this way:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">	
	<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>	
	<property name="url"><value>jdbc:mysql://${mysql.hostname}:${mysql.port}/${mysql.db}</value></property>
	<property name="username"><value>${mysql.user}</value></property>
	<property name="password"><value>${mysql.password}</value></property>
</bean>	
 
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<property name="dataSource" ref="dataSource"/>
</bean> 
 
<bean id="TemplateRequestDao" class="com.afm.admin.dao.mysql.TemplateDaoMySql">
	<property name="dataSource" ref="dataSource" />
</bean>

and you get this error message: The name of the property, following JavaBean naming conventions. The reason is probably you forgot to extend your implementation class:

public class TemplateDaoMySql extends JdbcDaoSupport implements TemplateDao {
 
	@Override
	public List<TemplateRequest> getTemplateRequest(UserProfile userProfile) {
		// TODO Auto-generated method stub
		return null;
	}
 
}

Time lost to fix this issue: more or less 1 hour. Image the how many I was frustrated when I discovered what was the problem.

Tagged , ,