Posts

Showing posts from 2013

Upload files to application drive account via Picker API

Google Picker API enables to pick files from Google Drive account or upload files to Google Drive account. With few lines of javascript code one can create sofisticated file upload UI. How to include Google Picker <script src="http://www.google.com/jsapi></script> google.setOnLoadCallback(createPicker); google.load('picker', '1'); /** Create picker object. */ function createPicker() { // Use DocsUploadView to upload documents to Google Drive. var uploadView = new google.picker.DocsUploadView(); var picker = new google.picker.PickerBuilder(). addView(uploadView). setAppId("xxxxxxxxxxxxxxxxxx"). // setOAuthToken(ACCESS_TOKEN). setCallback(pickerCallback). build(); picker.setVisible(true); } /** A simple callback implementation. */ function pickerCallback(data) { if (data.action == google.picker.Action.PICKED) { var fileId = data.docs[0].id; alert('The user selecte

Access application Google Drive account from javascript without client side authorization dialog

Use case We want to create a regular Google Drive account owned by an application. The application enables users to upload or view files within that account. Since Google Drive API provides javascript library the goal is to use javascript for all the logic (upload and view files) with minimum engagement of server side processing. For the purpose of creating an application owned account Google provides two options: SERVICE ACCOUNT Application is authorized by .pk12 certificate; the drawback is that only the application can see documents it created - documents cannot be viewed for example through Google Drive UI. REGULAR GOOGLE ACCOUNT used by the application only This option is our choice because we want to access stored files using Google Drive UI too. More information about the two options is available in Google Drive SDK documentation . To access a Google account using Google API we have to ensure correct handling of authentication and authorization procedures - Google A

Hibernate schema export with Hibernate Validator constraints accepted and Spring configured persistence

What is the goal: using Spring Framework for configuration of persistence settings (JPA 2.0 with Hibernate provider) using the configuration for Hibernate schema export tool apply Hibernate Validator constraints to generated schema Spring persistence configuration // define datasource - hsqldb for testing purposes - it requires hsqldb to be on classpath EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase database = builder.setType(EmbeddedDatabaseType.HSQL).build(); // standard way how to configure persistence in Spring (usually included as a part of some configuration class) LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setPersistenceXmlLocation("classpath:example/path/to/persistence.xml"); lcemfb.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); lcemfb.setDataSource(database); lcemfb.afterPropertiesSet(); Create Hibernate configuration from Spring configured persistence Ej

Hibernate delete and update queries with joins

From Hibernate 4.1.9 manual - section about bulk update and deletes : No implicit or explicit joins can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins. Unsupported (implicit join) DELETE A a WHERE a.relation.property = "dummy"; A way to go DELETE A a WHERE a.relation.id IN (SELECT r.id FROM Relation r WHERE r.property = "dummy");