2015年1月26日 星期一

2015年1月22日 星期四

[Java Groovy] Convert Array or Object to String

def numbers = [0, 1, 2, 3, 4, 5] as Integer[]
assert '0 x 1 x 2 x 3 x 4 x 5' == numbers.join(' x ')

def objects = [new URL('http://www.mrhaki.com'), 'mrhaki', new Expando(name: 'mrhaki'), new Date(109, 10, 10)]
assert 'http://www.mrhaki.com,mrhaki,{name=mrhaki},Tue Nov 10 00:00:00 UTC 2009' == objects.join(',')

http://mrhaki.blogspot.hk/2009/10/groovy-goodness-join-elements-to-string.html

2015年1月14日 星期三

[Spring] [MongoDB] MongoDB Collection Event Listener

Event Listeners:

  • onBeforeConvert(E document)
  • onAfterConvert(DbObject dbo, E document)
  • onBeforeSave(E document)
  • onAfterSave( E collection, DbObject dbo)
  • ...

How to Use:

Step 1: Write Java class

Step 2: Register Event Listener in Spring XML



http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/

http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/

http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html

[MongoDB] ObjectId to Timestamp Converter

Test data (ObjectId): 54b37110f441a40ce4239497

Return (ISO Timestamp): 2015-01-12T07:00:32.000Z

* Note that _id stores the timestamp to second only, no millisecond value stored :(

http://steveridout.github.io/mongo-object-time/

[JPA] @transient

transient : passing with time; remaining in a place only a brief of time
http://www.thefreedictionary.com/transient

@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation

2015年1月13日 星期二

2015年1月8日 星期四

[Spring Security] Get Current User

To get the current authentication:

Method 1
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      String name = auth.getName(); //get logged in username
 Method 2
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String name = user.getUsername(); //get logged in username

http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/

2015年1月6日 星期二

[Spring Security] About CSRF

What is CSRF?
Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.


For Spring Security, notice that one description says:
" If you were not using Spring MVC taglibs or Thymeleaf, you can access the CsrfToken on the ServletRequest using the attribute _csrf. "

[康復路] 試完又試

見了醫生,因為血色素又變低了,醫生想檢查是否「缺鐵」為成因,檢查又檢查…… 感覺有些麻煩……又抽血,又要留樣本…… 令我回想起當日入院的時光,因為一些原因,留樣本只需留一次,免卻留三次的麻煩;現在每天都要留一次,連續三天。每天早上就要跑醫院一趟再上班。 幸好也完成了。 第二次抽血...