Sei sulla pagina 1di 29

` Universita degli studi di Trieste ` Facolta di Ingegneria

Tesi di Laurea Triennale in

Ingegneria Informatica

AUTOMATIZZAZIONE DELLA COMPILAZIONE DI DOCUMENTI UTILIZZANDO GLI STRUMENTI DI GOOGLE DOCS

Relatore

Candidato

Chiar.mo Prof. Alberto BARTOLI

Tiziano CECCARINI

Anno Accademico 2010/2011

` Universita degli studi di Trieste ` Facolta di Ingegneria


Tesi di Laurea Triennale in

Ingegneria Informatica

AUTOMATIZZAZIONE DELLA COMPILAZIONE DI DOCUMENTI UTILIZZANDO GLI STRUMENTI DI GOOGLE DOCS

Relatore

Candidato

Chiar.mo Prof. Alberto BARTOLI

Tiziano CECCARINI

Anno Accademico 2010/2011

A Chiara e ai miei genitori

Indice
1 Introduzione 1.1 Obiettivo della tesi 1.2 Risultato della tesi 1.3 Motivazioni . . . . 1.4 Vincoli di progetto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5 5 6 6 7 7 7 8 8 9 12 12 12 15 16 16 17 18 18 18 18 18 19

2 Analisi 2.1 Google Documenti . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Situazione esistente . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Strumenti messi a disposizione da Google . . . . . . . . . . . . 3 Progettazione 3.1 Class diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Interfaccia 4.1 Finestra di login . . . . . 4.2 Form principale . . . . . 4.3 Barra di stato . . . . . . 4.4 Finestra informazioni . . 4.5 Finder . . . . . . . . . . 4.6 Requisiti dinstallazione

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

5 Implementazione 5.1 Utilizzo delle classi implementate 5.2 Developers Guide . . . . . . . . . 5.2.1 Introduction . . . . . . . . 5.2.2 Getting Started . . . . . . 5.2.3 Usage Examples . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

6 Conclusioni 26 6.1 Lavoro svolto . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.2 Sviluppi futuri . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1
1.1

Introduzione
Obiettivo della tesi

Scopo di questa tesi ` limplementazione di un sistema che automatizzi la e compilazione dei verbali di laurea. Attualmente gli studenti inseriscono tutti i dati richiesti relativi alla loro tesi di laurea (nome, cognome, relatore, corso di laurea, titolo tesi, link ai documenti della tesi, informazioni di contatto), tramite un form di archiviazione tesi, realizzato con Google Form. Si vuole creare unapplicazione che permetta di autocompletare il template del Verbale di Laurea, realizzato con Google Documenti, con i dati precedentemente inseriti nel Google Form dagli studenti.

1.2

Risultato della tesi

Il risultato di questa tesi ` unapplicazione stand alone chiamata Google e Merge. Dato un qualsiasi documento template e una tabella dati opportunamente compilata, Google Merge ` in grado di: e Creare documenti compilati e salvarli su Google Documenti; sul computer in formato ODT o PDF ; Inviare email con Oggetto e Corpo ssi con in allegato il documento personalizzato.

Figura 1: Interfaccia graca

1.3

Motivazioni

Si ` scelto di utilizzare il servizio gratuito Google Documenti, in quanto e permette di creare in modo veloce e intuitivo dei form per la raccolta dati (es: form archiviazione tesi). Google Documenti, il sistema di immissione dati nora utilizzato dagli studenti, non dispone delle funzionalit` di auto a completamento documenti e invio automatico del documento creato tramite e-mail. Al ne di non abbandonare del tutto lattuale sistema di raccolta dati e di colmare le funzionalit` richieste, ` stata sviluppata questa applicazione. a e

1.4

Vincoli di progetto

Sono stati imposti alcuni vincoli di progetto, che impongono di utilizzare: Gli strumenti messi a disposizione da Google; Il linguaggio Java; Lapplicativo stand alone. 6

Analisi

In questa fase si ` analizzata la situazione esistente, ossia in cosa consista il e servizio Google Documenti e quali siano gli strumenti messi a disposizione.

2.1

Google Documenti

Google Documenti ` un servizio gratuito che mette a disposizione i seguenti e applicativi web-based: Word Processor; Foglio di calcolo; Strumenti per la creazione di presentazioni; Strumenti per la creazione di form. Inoltre permette agli utenti di creare e modicare documenti on-line mentre collaborano in tempo reale con altri utenti. Google Documenti, per la realizzazione dei servizi sopra elencati, sfrutta una tecnologia inizialmente realizzata dalla Tonic Systems.

2.2

Situazione esistente

La situazione di partenza prevede che ogni studente compili, in tutte le sue parti, il form di archiviazione tesi. Allinvio dello stesso i dati vengono immagazzinati in uno Spreadsheet Google associato al form. A ogni form inviato corrisponde una nuova riga nel foglio di calcolo.

Figura 2: Situazione Preesistente

2.3

Strumenti messi a disposizione da Google

Sono state utilizzate le seguenti API, messe a disposizione da Google, per lo sviluppo di questa applicazione: La Spreadsheets API; La Documents List API. La Spreadsheets API consente alle applicazioni client di accedere e modicare i dati immagazzinati nei fogli di calcolo presenti su Google Documenti. La Documents List API permette alle applicazioni client di accedere e modicare i dati immagazzinati in Google Documenti ma non di cercare, selezionare e modicare parti di un documento. Dallanalisi delle API ` emersa la mancanza di funzionalit` che, usando e a Google Documenti, permettano di eettuare la modica del documento template in base ai dati presenti in una tabella. Per personalizzare i documenti si ` perci` reso necessario scaricare una copia e o del template sul computer locale. I principali formati supportati da Google per lesportazione del template sono RTF, DOC, ODT e PDF. Si ` scelto di utilizzare il formato ODT (Open Document Format) di Open e Oce, per il quale esiste una libreria open source che consente la creazione e modica di questi le.

Progettazione

Lo use case diagram ` lo strumento utilizzato per la descrizione delle fune zionalit` oerte dal software dal punto di vista degli attori che interagiscono a con il sistema stesso.

Figura 3: Use case diagram 8

Nel caso in questione, lapplicativo permette allutente di unire il documento template alla tabella dati; entrambi sono archiviati on-line sul servizio Google Documenti. Sono state previste diverse modalit` di salvataggio dei le generati dallua nione tra template e tabella dati: Salvataggio on line su Google Documenti; Salvataggio su computer locale; Invio delle mail con allegato personalizzato.

3.1

Class diagram

Durante la fase di progettazione si ` voluto separare nettamente il codice che e esegue le funzionalit` richieste da quello che realizza la GUI (Graphical User a Interface). Tale scelta ` stata dettata dalla volont` di favorire quanto pi` possibile il e a u riutilizzo del codice gi` scritto. a Il progetto ` quindi composto da due package principali: e Il primo contiene le classi per la gestione del documento e laccesso ai dati denominato core; Il secondo comprende le classi per la gestione dellinterfaccia graca denominato gui. Del package core fanno parte inoltre altri quattro package che svolgono funzionalit` accessorie: a nder: Il package nder contiene tutte le classi che permettono di cercare documenti e cartelle allinterno dello spazio di Google documenti dedicato allutente. Si ` denita uninterfaccia Finder che ore e un modo duso comune a tutte le classi votate alla ricerca. mail: Il package mail contiene linterfaccia Mail che attribuisce alle classi dedicate allinvio di mail i metodi da implementare. Al momento unimplementazione dellinterfaccia Mail ` fatta dalla classe Googlee ` Mail, che si avvale dei server smtp messi a disposizione da GMail. E stato scelto di denire uninterfaccia per non dover modicare il codice delle classi nel caso in cui si utilizzino servizi e-mail diversi da quello di GMail usato al momento.

odt2pdf : Il package odt2pdf denisce linterfaccia PdfConverterConnector. Tale interfaccia ` stata denita per motivazioni analoghe a e quelle viste al punto precedente. Attualmente ` implementato un cone vertitore che richiede lavvio di Open Oce come servizio in locale denito dalla classe Odt2PdfConverter. exception: Il package exception contiene tutte i tipi deccezione che vengono generati dalle classi del package core. Al ne di non appesantire eccessivamente il diagramma, per ognuna delle classi sono stati omessi gli attributi, per la cui lettura si rimanda al codice sorgente e ai Java Docs scaricabili allindirizzo relativo al progetto: http: //thesisproject.cekanet.com/files/docs/ Per facilitarne la lettura, sono state inoltre omesse le classi contenute nel package excepion.

10

Figura 4: Diagramma delle classi 11

Interfaccia

Linterfaccia utente ` stata progettata per essere di semplice e immediato uso e per lutente. Si ` quindi deciso di creare una struttura a schede, ognuna delle e quali implementa un caso duso tra quelli disponibili. Al ne di semplicare lapprendimento dellinterfaccia allutilizzatore si ` adottato lo stesso layout e per tutte le schede.

4.1

Finestra di login

Allavvio dellapplicativo ` necessario autenticarsi al servizio Google Docue menti. A tal scopo viene automaticamente presentato un form per lautenticazione(username e password).

Figura 5: Login Window

4.2

Form principale

Nel form principale sono disponibili tre schede, una per ogni tipo di caso duso. 12

La prima permette di caricare i documenti personalizzati nella cartella outputFolder precedentemente creata dallutente su Google Documenti.

Figura 6: Scheda Google Merge La seconda permette di salvare i le di output, nel formato selezionato dallutilizzatore, su un percorso locale a scelta.

13

Figura 7: Scheda Local Merge La terza permette di inviare e-mail, con oggetto e corpo ssi e allegato personalizzato, a ogni persona presente nel foglio dati. Gli allegati possono essere le ODT o PDF. Qualora lutente scegliesse di non allegare nessun le, il programma rivestirebbe la funzione di mailing list. Nel campo opt mail address si possono inserire ulteriori destinatari a cui inviare il messaggio. A questi verr` recapitato un allegato senza pera sonalizzazione. Tale funzionalit` ` stata implementata per permettere ae di inviare e-mail di convocazione ai docenti.

14

Figura 8: Scheda Mail Merge

4.3

Barra di stato

Un volta avviato il processo di merge, la barra di stato indica lo stato corrente del programma. Le fasi possibili sono: Fetching: viene scaricato il le template e viene letta la tabella dati; Merging: vengono creati i documenti personalizzati mediante lunione del documento template e la tabella dati; Uploading/Sending: i documenti vengono salvati o inviati via mail.

Figura 9: Barra di stato

15

4.4

Finestra informazioni

Nella nestra informazioni ` possibile visualizzare: e la versione del programma (nella forma 1.versionePackageGUI.versionePackageCore); lautore; il sito di riferimento contenente le istruzioni duso; la licenza duso (Licenza MIT).

Figura 10: Finestra informazioni

4.5

Finder

Si ` sviluppata una dialog box denominata Finder per permettere allutente e di navigare tra i documenti e le cartelle immagazzinati nel suo account Google Documenti. Nella colonna di sinistra ` riportato lalbero delle cartelle, mentre e in quella di destra sono elencati i le contenuti nella cartella selezionata a sinistra. I le visualizzati sono ltrati per tipo. A titolo di esempio, se 16

si ` fatto click sul pulsante browse corrispondente alla data table, il nder e elencher` solo i documenti di tipo spreadsheet. a

Figura 11: Finder

4.6

Requisiti dinstallazione

Per il funzionamento ` necessario che la macchina virtuale Oracle Java 1.6 e sia installata. Per permettere loutput dei le PDF ` necessario che Open Oce 3.2.1. sia e installato e avviato come servizio. Il programma viene fornito con uno script per ambiente Windows che individua la macchina virtuale java, avvia Open Oce come servizio ed esegue il programma. Per eseguire il programma senza eccezioni ` necessario che lutente abbia e precedentemente creato nel suo account una sola cartella chiamata GoogleMerge contenente: il documento template; lo spreadsheet dati; 17

una cartella chiamata outputFolder. Le parole da sostituire nel documento di template devono essere messe tra i simboli minore e maggiore (<parola>). La tabella dati deve contenere due colonne: una colonna chiamata processingstatus che indica quali righe debbano essere prese in considerazione per lelaborazione; una colonna chiamata MailAddress che indica a quale indirizzo inviare le e-mail. Il binario del programma viene fornito in un unico le jar contenente, oltre al programma stesso, tutte le API ad esso correlate.

Implementazione

In questo capitolo viene descritta limplementazione dellapplicativo. Il codice dello stesso ` stato scritto per intero dal laureando, eccezion fatta per e le librerie (importate da terze parti) e per il codice generato automaticamente dallIDE per la realizzazione dellinterfaccia graca. Per la descrizione dellimplementazione delle singole funzionalit` si rimanda a ai commenti presenti nel codice sorgente o alla guida dello sviluppatore messa a disposizione da Google.

5.1

Utilizzo delle classi implementate

Si passa allanalisi dettagliata dellutilizzo delle classi implementate allinterno del package core. A tale scopo viene di seguito riportata la guida dello sviluppatore scritta interamente dal laureando in lingua inglese.

5.2
5.2.1

Developers Guide
Introduction

This guide provides examples of using GoogleMerge CoreFramework library. 5.2.2 Getting Started

Here is what you need to start: Googlemerge CoreFramework library 18

Installed software: 1. Oracle Java 1.6 2. OpenOce 3.2.1 started as service (for pdf conversion) Dependencies: 1. Apache common IO 1.4 2. Apache Xerces 2.10.0 3. Google Gdata 1.41.3 4. Google Guava r06 5. OpenOce odfdom 0.8.6 6. Oracle javamail 1.4.3 7. ArtOfSolving jodConverter 2.2.2 (for pdf conversion) You can download these libraries from CoreFramework download zone. Before you start, visit http://tinyurl.com/5snx3z4 to take a look to data spreadsheet and template document examples to understand how to make them. 5.2.3 Usage Examples

Browsing les and folders on Google Docs account. You will need several imports to run the following Browsing examples: Please note: Some types allowed by Google are: spreadsheet, document, folder, form, presentation.
import com . g o o g l e . gdata . c l i e n t . d o c s . D o c s S e r v i c e ; import com . g o o g l e . gdata . u t i l . A u t h e n t i c a t i o n E x c e p t i o n ; import import import import import import com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . thesisproject thesisproject thesisproject thesisproject thesisproject thesisproject . . . . . . core core core core core core . . . . . . finder finder finder finder finder finder . FindAll ; . Finder ; . Result ; . Search ; . FindFolderContent ; . FindSharedRootFolder ;

import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . ;

For all the examples a Google client login is required. To use client login invoke setUserCredentials() method of DocsService.
D o c s S e r v i c e g o o g l e C l i e n t = new D o c s S e r v i c e ( A p p C o n f i g u r a t i o n . companyName ) ; try { g o o g l e C l i e n t . s e t U s e r C r e d e n t i a l s ( username@gmail . com , password ) ; } catch ( A u t h e n t i c a t i o n E x c e p t i o n e ) {

19

System . out . p r i n t l n ( I n c o r r e c t username o r password ) ; System . e x i t ( 1) ; }

The following example lists all the documents for the authenticated user:
F i n d e r f = new F i n d A l l ( g o o g l e C l i e n t ) ; L i s t <R e s u l t > r e s u l t s = f . g e t R e s u l t s ( ) ;

The following example lists all the documents with given type for the authenticated user:
F i n d e r f = new F i n d A l l ( g o o g l e C l i e n t , document ) ; L i s t <R e s u l t > r e s u l t s= f . g e t R e s u l t s ( ) ;

The following example looks for documents with keyword in the document title:
F i n d e r f = new S e a r c h ( g o o g l e C l i e n t , keyword ) ; L i s t <R e s u l t > r e s u l t s = f . g e t R e s u l t s ( ) ;

The following example looks for spreadsheet type documents with keyword in the document title:
F i n d e r f = new S e a r c h ( g o o g l e C l i e n t , s p r e a d s h e e t , keyword ) ; L i s t <R e s u l t > r e s u l t s = f . g e t R e s u l t s ( ) ;

The following example lists the content of a googleFolder:


F i n d e r f = new F i n d F o l d e r C o n t e n t ( g o o g l e C l i e n t , f o l d e r R e s o u r c e I D ) ; L i s t <R e s u l t > r e s u l t s = f . g e t R e s u l t s ( ) ;

The following example lists the specied type content of the given Google Folder:
F i n d e r f = new F i n d F o l d e r C o n t e n t ( g o o g l e C l i e n t , f o l d e r R e s o u r c e I D , spreadsheet ) ; L i s t <R e s u l t > r e s u l t s = f . g e t R e s u l t s ( ) ;

The following example lists root shared folders:


L i s t <R e s u l t > r e s u l t s = F i n d S h a r e d R o o t F o l d e r . f i n d S h a r e d R o o t F o l d e r ( googleClient ) ;

Paging through results By default classes that implement Finder interfaces return, with getResults() method, the rst 100 results. This saves bandwidth and improves performance. The following example shows how to retrieve the rest of the results.

20

Finder f ; L i s t <R e s u l t > r e s u l t s ; f = new F i n d A l l ( g o o g l e C l i e n t ) ; results = f . getResults () ; f o r ( i n t i =0; i <r e s u l t s . s i z e ( ) ; i ++) System . out . p r i n t l n ( r e s u l t s . g e t ( i ) ) ; while ( f . h a s M o r e R e s u l t s ( ) ) { r e s u l t s = f . getMoreResults () ; f o r ( i n t i =0; i <r e s u l t s . s i z e ( ) ; i ++) System . out . p r i n t l n ( r e s u l t s . g e t ( i ) ) ; }

Merging You will need these imports to run the following Merging examples:
import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . m a i l . GoogleMail ; import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . m a i l . Mail ; import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . o d t 2 p d f . Odt2PdfConverter ; import import import import import com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . thesisproject thesisproject thesisproject thesisproject thesisproject . . . . . core core core core core . P a ra m e t e r s ; . LocalMerge ; . EMailMerge ; . GDocumentMerge ; . PrintableData ;

To merge Google Document template and Google spreadsheet data table, rst you have to read data table and then perform merge.
/ F i r s t s e t up p a r a m e t e r s / P a r a m e t e r s p a r a m e t e r s = new P a r a m e t e r s ( ) ; p a r a m e t e r s . setGoogleUsername ( username@gmail . com ) ; p a r a m e t e r s . s e t G o o g l e P a s s w o r d ( password ) ; parameters . setDataTableResourceId ( dataTableResourceID ) ; parameters . setOutputFolderResourceId ( googleOutputFolderResourceID ) ; parameters . setTemplateResourceId ( templateresourceID ) ; p a r a m e t e r s . setMessageBody ( Message body ) ; p a r a m e t e r s . s e t M e s s a g e S u b j e c t ( Message S u b j e c t ) ; / Reads Google d a t a s p r e a d s h e e t / P r i n t a b l e D a t a pd = new P r i n t a b l e D a t a ( p a r a m e t e r s ) ;

The following example merges and then saves the merged documents to the GoogleDocs folder specied in parameters:
GDocumentMerge gdm = new GDocumentMerge ( p a r a m e t e r s , pd . g e t P r i n t a b l e R e c o r d s ( ) ) ; gdm . s t a r t M e r g e ( ) ; gdm . uploadODTGeneratedFiles ( ) ;

The following example merges and then save the merged documents to a local folder in odt format:
LocalMerge lm = new LocalMerge ( p a r a m e t e r s , pd . g e t P r i n t a b l e R e c o r d s ( ) ) ; lm . s t a r t M e r g e ( ) ;

21

lm . saveODTGeneratedFiles ( /home/ u s e r / f o l d e r T o S a v e ) ;

The following example merges and then sends an email message for each line of the data table; mail subject and body are the same for all email sent and dened in parameters. Destination address is the value contained in the MailAddress column of the data table (in each line there must be only one well-formed email address). Any class that implements com.cekanet.thesisproject.core.mail.Mail can be used to send emails. For your commodity, CoreFramework has already dened a mail sender that uses Gmail.
Mail m a i l S e r v i c e = new GoogleMail ( p a r a m e t e r s . getGoogleUsername ( ) , p a r a m e t e r s . getGooglePassword ( ) ) ; EMailMerge emm = new EMailMerge ( p a r a m e t e r s , pd . g e t P r i n t a b l e R e c o r d s ( ) , mailService ) ; / Sends t h e a t t a c h m e n t i n ODT f o r m a t / emm. sendODTGeneratedFiles ( ) ; / Sends w i t h o u t any a t t a c h m e n t / emm. sendAlone ( ) ;

Generate PDF Any Class that implements com.cekanet.thesisproject.core.odt2pdf. PdfConverterConnector can be used as odt to pdf format converter. For your commodity CoreFramework has already an odt to pdf converter wrote in com.cekanet.thesisproject.core.odt2pdf.Odt2PdfConverter class that implements PdfConverterConnector. This converter uses Open Ofce 3.2.1 running as service to convert. In the following examples OpenOce is already started as service. Sending an email with PDF le attached:
Mail m a i l S e r v i c e = new GoogleMail ( p a r a m e t e r s . getGoogleUsername ( ) , p a r a m e t e r s . getGooglePassword ( ) ) ; EMailMerge emm = new EMailMerge ( p a r a m e t e r s , pd . g e t P r i n t a b l e R e c o r d s ( ) , mailService ) ; / I n i t i a l i z e o b j e c t and open t h e c o n n e c t i o n t o O p e n O f f i c e s e r v i c e . / Odt2PdfConverter p d f C o n v e r t e r = new Odt2PdfConverter ( ) ; emm. sendPDFGeneratedFiles ( p d f C o n v e r t e r ) ; pdfConverter . disconnect () ;

The following example merges and then saves documents to a local folder in pdf format:
LocalMerge lm = new LocalMerge ( p , pd . g e t P r i n t a b l e R e c o r d s ( ) ) ; lm . s t a r t M e r g e ( ) ; / I n i t i a l i z e o b j e c t and open t h e c o n n e c t i o n t o O p e n O f f i c e s e r v i c e . / Odt2PdfConverter p d f C o n v e r t e r = new Odt2PdfConverter ( ) ; lm . s av e P D F G e n e r a t e d F i l e s ( /home/ u s e r / f o l d e r T o S a v e , p d f C o n v e r t e r ) ; pdfConverter . disconnect () ;

22

Putting all work together The following example is inspired by GoogleMerge GUI application. To make it work, you have to create a GoogleDocs Folder GoogleMerge with this content: Spreadsheet named data containing data table. Template Document named template Output folder named outputFolder. Google Docs allows to create more les with the same name. The example throws a FrameWorkException if there is a duplicate of any le or folder requested (including GoogleMerge folder).
/ This i s a s i m p l e example how t o u s e GooogleMerge CoreFramework API . For s i m p l i c i t y t h i s code h a n d l e o n l y t h e f i s t 100 r e s u l t s o f each s e a r c h . @author T i z i a n o C e c c a r i n i /

import j a v a . u t i l . L i s t ; import com . g o o g l e . gdata . c l i e n t . d o c s . D o c s S e r v i c e ; import com . g o o g l e . gdata . u t i l . A u t h e n t i c a t i o n E x c e p t i o n ;

import import import import import import import import

com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t . com . c e k a n e t .

thesisproject thesisproject thesisproject thesisproject thesisproject thesisproject thesisproject thesisproject

. . . . . . . .

core core core core core core core core

. . . .

finder finder finder finder

. Finder ; . Result ; . Search ; . FindFolderContent ;

. P a ra m e t e r s ; . LocalMerge ; . PrintableData ; . AppConfiguration ;

import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . e x c e p t i o n . WorkingFolderNotFoundException ; import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . e x c e p t i o n . M i s c o n f i g u r a t i o n E x c e p t i o n ; import com . c e k a n e t . t h e s i s p r o j e c t . c o r e . e x c e p t i o n . FrameworkException ; public c l a s s Main { public s t a t i c void main ( S t r i n g [ ] a r g s ) { Parameters parameters ; p a r a m e t e r s = new P a r a m e t e r s ( ) ; p a r a m e t e r s . setGoogleUsername ( u s e r @ g m a i l . com ) ; p a r a m e t e r s . s e t G o o g l e P a s s w o r d ( password ) ; D o c s S e r v i c e g o o g l e C l i e n t = new D o c s S e r v i c e ( A p p C o n f i g u r a t i o n . companyName ) ; try { g o o g l e C l i e n t . s e t U s e r C r e d e n t i a l s ( p a r a m e t e r s . getGoogleUsername ( ) , parameters . getGooglePassword ( ) ) ; } catch ( A u t h e n t i c a t i o n E x c e p t i o n e ) {

23

System . out . p r i n t l n ( I n c o r r e c t username o r password ) ; System . e x i t ( 1) ; } try { Finder f ; L i s t <R e s u l t > r e s u l t s ; / Looking up D e f a u l t Google Docs F o l d e r . I f e x i s t more o c c u r e n c e of directory name a WorkingFolderNotFoundException i s thrown / f = new S e a r c h ( g o o g l e C l i e n t , f o l d e r , A p p C o n f i g u r a t i o n . defaultWorkingFolder ) ; results = f . getResults () ; i f ( r e s u l t s . s i z e ( ) >= 1 ) { i n t g o o g l e M e r g e O c c u r e n c e s =0; f o r ( i n t i =0; i <r e s u l t s . s i z e ( ) ; i ++) i f ( r e s u l t s . g e t ( i ) . g e t T i t l e ( ) . e q u a l s ( GoogleMerge ) ) { parameters . setWorkingFolderResourceId ( r e s u l t s . get ( i ) . getResourceId () ) ; g o o g l e M e r g e O c c u r e n c e s ++; i f ( googleMergeOccurences > 1) throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Too + A p p C o n f i g u r a t i o n . d e f a u l t W o r k i n g F o l d e r+ f o l d e r s ! \ n Only one must be p r e s e n t ! ) ; } } else throw new WorkingFolderNotFoundException ( ) ; / L i s t w o r k i n g f o l d e r c o n t e n t . I f a working f i l e e x i s t d u p l i c a t e a MisconfigurationException i s thrown / f = new F i n d F o l d e r C o n t e n t ( g o o g l e C l i e n t , p a r a m e t e r s . getWorkingFolderResourceId ( ) ) ; results = f . getResults () ; i n t d a t a O c c u r e n c e s =0; i n t f o l d e r O c c u r e n c e s =0; i n t t e m p l a t e O c c u r e n c e s =0; f o r ( i n t i =0 ; i <r e s u l t s . s i z e ( ) ; i ++){ i f ( r e s u l t s . get ( i ) . g e t T i t l e ( ) . equals ( AppConfiguration . defaultDataTableName ) ) i f ( r e s u l t s . g e t ( i ) . getType ( ) . e q u a l s ( s p r e a d s h e e t ) | | r e s u l t s . g e t ( i ) . getType ( ) . e q u a l s ( form ) ) { d a t a O c c u r e n c e s ++; parameters . setDataTableResourceId ( r e s u l t s . get ( i ) . getResourceId () ) ; } i f ( r e s u l t s . get ( i ) . g e t T i t l e ( ) . equals ( AppConfiguration . defaultOutputFolderName ) ) i f ( r e s u l t s . g e t ( i ) . getType ( ) . e q u a l s ( f o l d e r ) ) { f o l d e r O c c u r e n c e s ++; parameters . setOutputFolderResourceId ( r e s u l t s . get ( i ) . getResourceId () ) ; } i f ( r e s u l t s . get ( i ) . g e t T i t l e ( ) . equals ( AppConfiguration . defaultTemplateTableName ) ) i f ( r e s u l t s . g e t ( i ) . getType ( ) . e q u a l s ( document ) ) { t e m p l a t e O c c u r e n c e s ++; parameters . setTemplateResourceId ( r e s u l t s . get ( i ) . getResourceId () ) ; } }

24

i f ( d a t a O c c u r e n c e s == 0 ) { throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Cannot f i n d + A p p C o n f i g u r a t i o n . defaultDataTableName+ t a b l e . \ n Cannot l o a d program ) ; } i f ( t e m p l a t e O c c u r e n c e s ==0){ throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Cannot f i n d + A p p C o n f i g u r a t i o n . defaultTemplateTableName+ document . \ n Cannot l o a d program ) ; } i f ( f o l d e r O c c u r e n c e s == 0 ) { throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Cannot f i n d + A p p C o n f i g u r a t i o n . defaultOutputFolderName+ f o l d e r . \ n Cannot l o a d program ) ; } i f ( dataOccurences > 1) { throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Too +A p p C o n f i g u r a t i o n . defaultDataTableName+ t a b l e s . \ n Cannot l o a d program ) ; } i f ( templateOccurences > 1) { throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Too +A p p C o n f i g u r a t i o n . defaultTemplateTableName+ documents . \ n Cannot l o a d program ) ; } i f ( folderOccurences > 1) { throw new M i s c o n f i g u r a t i o n E x c e p t i o n ( Too +A p p C o n f i g u r a t i o n . defaultOutputFolderName+ f o l d e r s . \ n Cannot l o a d program ) ; } /Do merge / / r e a d d a t a s p r e a d s h e e t / P r i n t a b l e D a t a pd = new P r i n t a b l e D a t a ( p a r a m e t e r s ) ; LocalMerge lm = new LocalMerge ( p a r a m e t e r s , pd . g e t P r i n t a b l e R e c o r d s () ) ; /Do merge / lm . s t a r t M e r g e ( ) ; / Save f i l e s / lm . saveODTGeneratedFiles ( /home/ u s e r / f o l d e r T o S a v e ) ;

} catch ( FrameworkException e ) { System . e r r . p r i n t l n ( ERROR ! ) ; System . e r r . p r i n t l n ( e . g e t M e s s a g e ( ) ) ; System . e x i t ( 1) ; } } }

25

Conclusioni

I risultati ottenuti soddisfano appieno gli obiettivi ssati allinizio della tesi. Il software rispetta tutti i vincoli di progetto e implementa in maniera eciente le varie funzionalit` richieste. a A supporto del programma ` stato inoltre creato il sito web (http://thesisproject. e cekanet.com) contenente: le informazioni relative alle modalit` duso; a il codice sorgente; la guida dello sviluppatore.

6.1

Lavoro svolto

Vengono di seguito riportati alcuni indici atti a quanticare il lavoro svolto: PackageCore: Classi: 40 Righe di codice: 3030 Package Gui: Classi: 13 Righe di codice: 2877 Generazione del JavaDoc relativo al package core.

6.2

Sviluppi futuri

Il software ` stato a oggi utilizzato per alcune sessioni di laurea raggiungendo e gli obiettivi pressati. Data la recente introduzione da parte di Google di nuove API, e in base allesperienza fatta, levoluzione futura sar` un applicativo integrato direttamente a nel servizio Google Documenti tramite tecnologia Google Apps Script.

26

Potrebbero piacerti anche