Changeset 1103 for contrib/psync


Ignore:
Timestamp:
07/08/09 19:14:32 (15 years ago)
Author:
wmerlotto
Message:

Ticket #554 - Melhorias na sincronizacao de eventos, contatos e adaptacao para Funambol 7.0

Location:
contrib/psync
Files:
15 added
10 edited

Legend:

Unmodified
Added
Removed
  • contrib/psync/build/build.properties

    r1009 r1103  
    22 
    33# version dependant jar files 
    4 common-pim.jar=funambol-common-pim-6.0.3.jar 
     4common-pim.jar=pim-framework-7.0.6.jar 
    55 
    66psync.name=funambol-psync 
    7 psync.release.major=1 
     7psync.release.major=7 
    88psync.release.minor=0 
    9 psync.build.number=0 
     9psync.build.number=1 
  • contrib/psync/build/build.xml

    r1009 r1103  
    189189                <pathelement location="${dir.lib}/commons-codec-1.3.jar" /> 
    190190                <pathelement location="${dir.lib}/commons-lang-2.2.jar"  /> 
    191                 <pathelement location="${dir.lib}/funambol-framework.jar"/> 
    192                 <pathelement location="${dir.lib}/funambol-admin-dev.jar"/> 
     191                <pathelement location="${dir.lib}/ds-server-7.0.4.jar"/> 
     192                <pathelement location="${dir.lib}/core-framework-7.0.1.jar"/> 
     193                <pathelement location="${dir.lib}/server-framework-7.0.4.jar"/> 
     194                <pathelement location="${dir.lib}/admin-framework-7.0.0.jar"/> 
    193195                <pathelement location="${dir.lib}/joda-time-1.4.jar"     /> 
    194196                <pathelement location="${dir.lib}/${pim-common.lib}"     /> 
  • contrib/psync/src/main/java/br/com/prognus/psync/admin/PIMSyncSourceConfigPanel.java

    r1009 r1103  
    167167        /** 
    168168         * Set preferredSize of the panel 
    169          *  
     169         * 
    170170         * @return preferredSize of the panel 
    171171         */ 
     
    179179         * Checks if the values provided by the user are all valid. If they are, the 
    180180         * method ends regularly. 
    181          *  
     181         * 
    182182         * @throws IllegalArgumentException 
    183183         *             if name, uri, type or directory are empty (null or 
     
    236236        /** 
    237237         * Checks whether a SIF content type is selected. 
    238          *  
     238         * 
    239239         * @return true if in the combo box the selected string starts with "SIF" 
    240240         */ 
     
    249249        /** 
    250250         * Adds extra components just above the confirm button. 
    251          *  
     251         * 
    252252         * @param x 
    253253         *            horizontal position 
     
    268268        /** 
    269269         * Returns the panel name 
    270          *  
     270         * 
    271271         * @return the panel name 
    272272         */ 
     
    277277        /** 
    278278         * Returns the available types 
    279          *  
     279         * 
    280280         * @return the available types; 
    281281         */ 
     
    284284        /** 
    285285         * Returns the type to select based on the given syncsource 
    286          *  
     286         * 
    287287         * @return the type to select based on the given syncsource 
    288288         */ 
     
    292292         * Sets the source info of the given syncsource based on the given 
    293293         * selectedType 
    294          *  
     294         * 
    295295         * @param syncSource 
    296296         *            the source 
     
    305305        /** 
    306306         * Creates the panel's components and layout. 
    307          *  
     307         * 
    308308         * @todo adjust layout 
    309309         */ 
  • contrib/psync/src/main/java/br/com/prognus/psync/engine/source/PIMCalendarSyncSource.java

    r1009 r1103  
    7474        public void beginSync(SyncContext context) { 
    7575 
    76                 this.manager = new PIMCalendarManager(JNDI_DATA_SOURCE_NAME, context 
    77                                 .getPrincipal()); 
     76                try { 
     77                        this.manager = new PIMCalendarManager(JNDI_DATA_SOURCE_NAME, context.getPrincipal(), context.getSourceQuery()); 
     78                } catch (Exception e) { 
     79                        // TODO Auto-generated catch block 
     80                        e.printStackTrace(); 
     81                } 
    7882                super.manager = this.manager; 
    7983                super.beginSync(context); 
    8084        } 
     85 
     86 
    8187 
    8288        /** 
  • contrib/psync/src/main/java/br/com/prognus/psync/engine/source/PIMSyncSource.java

    r1009 r1103  
    106106                log.trace("PIMSyncSource beginSync start"); 
    107107 
     108                this.sourceQuery = context.getSourceQuery(); 
     109 
    108110                principal = context.getPrincipal(); 
    109111                userId = principal.getUsername(); 
     
    148150        /** 
    149151         * Gets the status of the SyncItem with the given key. 
    150          *  
     152         * 
    151153         * @param syncItemKey 
    152154         *            as a SyncItemKey object 
     
    214216        /** 
    215217         * Extracts the content from a syncItem. 
    216          *  
     218         * 
    217219         * @param syncItem 
    218220         * @return as a String object 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMCalendarDAO.java

    r1009 r1103  
    135135        private Sync4jPrincipal principal = null; 
    136136 
     137        private Boolean sourceQuery = false; 
     138        private Timestamp date1 = null; 
     139        private Timestamp date2 = null; 
     140 
    137141        /* 
    138142         * @see PIMEntityDAO#PIMEntityDAO(String, String) 
    139143         */ 
    140         public PIMCalendarDAO(String jndiDataSourceName, Sync4jPrincipal principal) { 
     144        public PIMCalendarDAO(String jndiDataSourceName, Sync4jPrincipal principal, String sourceQuery) throws Exception { 
    141145 
    142146                super(jndiDataSourceName, principal.getUsername()); 
    143147                log.info("\n\n=> Created new PIMCalendarDAO for data source " + jndiDataSourceName + " and user ID " + userId); 
    144148                this.principal = principal; 
     149 
     150                if(sourceQuery != null){ 
     151                        this.sourceQuery = true; 
     152                        findDates(sourceQuery); 
     153                } 
    145154        } 
    146155 
     
    178187                long id_cal  = 0; 
    179188 
     189                long datea1 = 0; 
     190                long datea2 = 0; 
     191                long dateb1 = 0; 
     192 
    180193                try { 
    181194 
     
    202215                        } 
    203216 
    204                         rp          = c.getRecurrencePattern(); // Recebe a repetição do alarme 
    205                         reminder    = c.getReminder(); // Recebe o alarme do evento 
    206                         body            = stringFrom(c.getDescription()); // Descricao completa do evento 
    207                         location        = stringFrom(c.getLocation()); // Localizacao do evento 
    208                         is_public       = (stringFrom(c.getAccessClass())).equals("2") ? "0" : "1"; // Evento particular ou publico 
    209                         subject         = stringFrom(c.getSummary()); // Titulo do evento 
    210                         category    = stringFrom(c.getCategories()); 
    211  
    212                         // Verifica o parametro uid necessario para o expresso 
    213                         ps = con.prepareStatement("select config_value from phpgw_config WHERE config_name = 'hostname' AND config_app = 'phpgwapi'"); 
    214                         rs = ps.executeQuery(); 
    215                         String uid = rs.next() ? ("-@" + rs.getString(1)) : ""; 
    216  
    217                         // Verifica a categoria do evento 
    218                         if(category != null && (!category.equals(""))){ 
    219                                 category = addCategory(category); 
    220                         } 
    221  
    222                         // Prepara os dados para inserir o evento no banco de dados 
    223                         ps = con.prepareStatement(SQL_INSERT_INTO_EXP_PIM_CALENDAR); 
    224                         ps.setString(1, uid); // -@hostname 
    225                         ps.setLong(2, Long.parseLong(userId)); // owner 
    226                         ps.setString(3, category); // category 
    227                         ps.setLong(4, new Long(Long.toString(dtstart.getTime()).substring(0, 10))); // datetime 
    228                         ps.setLong(5, new Long(Long.toString(lastUpdate.getTime()).substring(0, 10))); // mdatetime 
    229                         ps.setLong(6, new Long(Long.toString(dend.getTime()).substring(0, 10))); // edatetime 
    230                         ps.setString(7, (rp == null) ? "E" : "M"); // cal_type 
    231                         ps.setLong(8, Long.parseLong(is_public)); // is_plublic 
    232                         ps.setString(9, truncate(subject, SQL_SUBJECT_DIM)); // title 
    233                         ps.setString(10, truncate(body, SQL_BODY_DIM)); // body of event, a little description of it 
    234                         ps.setString(11, truncate(location, SQL_LOCATION_DIM)); // location of the event 
    235                         ps.setString(12, ""); // Participants outside 
    236                         ps.setLong(13, lastUpdate.getTime()); // last update 
    237                         ps.setString(14, String.valueOf(Def.PIM_STATE_NEW)); // status 
    238                         ps.executeUpdate(); 
    239  
    240                         // Verifica o id maximo do evento inserido 
    241                         ps = con.prepareStatement("select max(cal_id) from phpgw_cal limit 1"); 
    242                         rs = ps.executeQuery(); 
    243  
    244                         if (rs.next()) { 
    245                                 long id = rs.getInt(1); 
    246                                 id_cal = (id == 0) ? 1 : id; 
    247                         } 
    248  
    249                         cw.setId(Long.toString(id_cal)); 
    250  
    251                         ps = con.prepareStatement(SQL_INSERT_INTO_EXP_PIM_CALENDAR_USER); 
    252                         ps.setLong(1, id_cal); 
    253                         ps.setLong(2, Long.parseLong(userId)); // owner 
    254                         ps.executeUpdate(); 
    255  
    256                         // Evento com repetição 
    257                         if (rp != null) { 
    258                                 addRecurrencePattern(rp, id_cal, sd); 
    259                         } 
    260  
    261                         // Evento com Alarme 
    262                         if (reminder != null && reminder.isActive()) { 
    263                                 addReminder(reminder, id_cal); 
    264                         } 
    265  
    266                         con.commit(); 
    267                         con.setAutoCommit(true); 
     217//                      datea1 = this.date1.getTime(); // 23 
     218//                      datea2 = this.date2.getTime(); // 29 
     219//                      dateb1 = dtstart.getTime(); // 28 
     220// 
     221//                      if(dateb1 >= datea1 && dateb1 <= datea2){ 
     222 
     223                                rp          = c.getRecurrencePattern(); // Recebe a repetição do alarme 
     224                                reminder    = c.getReminder(); // Recebe o alarme do evento 
     225                                body            = stringFrom(c.getDescription()); // Descricao completa do evento 
     226                                location        = stringFrom(c.getLocation()); // Localizacao do evento 
     227                                is_public       = (stringFrom(c.getAccessClass())).equals("2") ? "0" : "1"; // Evento particular ou publico 
     228                                subject         = stringFrom(c.getSummary()); // Titulo do evento 
     229                                category    = stringFrom(c.getCategories()); 
     230 
     231                                // Verifica o parametro uid necessario para o expresso 
     232                                ps = con.prepareStatement("select config_value from phpgw_config WHERE config_name = 'hostname' AND config_app = 'phpgwapi'"); 
     233                                rs = ps.executeQuery(); 
     234                                String uid = rs.next() ? ("-@" + rs.getString(1)) : ""; 
     235 
     236                                // Verifica a categoria do evento 
     237                                if(category != null && (!category.equals(""))){ 
     238                                        category = addCategory(category); 
     239                                } 
     240 
     241                                // Prepara os dados para inserir o evento no banco de dados 
     242                                ps = con.prepareStatement(SQL_INSERT_INTO_EXP_PIM_CALENDAR); 
     243                                ps.setString(1, uid); // -@hostname 
     244                                ps.setLong(2, Long.parseLong(userId)); // owner 
     245                                ps.setString(3, category); // category 
     246                                ps.setLong(4, new Long(Long.toString(dtstart.getTime()).substring(0, 10))); // datetime 
     247                                ps.setLong(5, new Long(Long.toString(lastUpdate.getTime()).substring(0, 10))); // mdatetime 
     248                                ps.setLong(6, new Long(Long.toString(dend.getTime()).substring(0, 10))); // edatetime 
     249                                ps.setString(7, (rp == null) ? "E" : "M"); // cal_type 
     250                                ps.setLong(8, Long.parseLong(is_public)); // is_plublic 
     251                                ps.setString(9, truncate(subject, SQL_SUBJECT_DIM)); // title 
     252                                ps.setString(10, truncate(body, SQL_BODY_DIM)); // body of event, a little description of it 
     253                                ps.setString(11, truncate(location, SQL_LOCATION_DIM)); // location of the event 
     254                                ps.setString(12, ""); // Participants outside 
     255                                ps.setLong(13, lastUpdate.getTime()); // last update 
     256                                ps.setString(14, String.valueOf(Def.PIM_STATE_NEW)); // status 
     257                                ps.executeUpdate(); 
     258 
     259                                // Verifica o id maximo do evento inserido 
     260                                ps = con.prepareStatement("select max(cal_id) from phpgw_cal limit 1"); 
     261                                rs = ps.executeQuery(); 
     262 
     263                                if (rs.next()) { 
     264                                        long id = rs.getInt(1); 
     265                                        id_cal = (id == 0) ? 1 : id; 
     266                                } 
     267 
     268                                cw.setId(Long.toString(id_cal)); 
     269 
     270                                ps = con.prepareStatement(SQL_INSERT_INTO_EXP_PIM_CALENDAR_USER); 
     271                                ps.setLong(1, id_cal); 
     272                                ps.setLong(2, Long.parseLong(userId)); // owner 
     273                                ps.executeUpdate(); 
     274 
     275                                // Evento com repetição 
     276                                if (rp != null) { 
     277                                        addRecurrencePattern(rp, id_cal, sd); 
     278                                } 
     279 
     280                                // Evento com Alarme 
     281                                if (reminder != null && reminder.isActive()) { 
     282                                        addReminder(reminder, id_cal); 
     283                                } 
     284 
     285                                con.commit(); 
     286                                con.setAutoCommit(true); 
     287 
     288//                      } 
    268289 
    269290                } catch (Exception e) { 
    270                         throw new PIMDBAccessException("Error adding a calendar item: " 
    271                                         + e.getMessage()); 
     291                        throw new PIMDBAccessException("Error adding a calendar item: " + e.getMessage()); 
    272292                } finally { 
    273293                        DBTools.close(con, ps, rs); 
     
    810830                        dtStart = getDateFromString(stringFrom(c.getCalendarContent().getDtStart())); 
    811831                        dtEnd = getDateFromString(stringFrom(c.getCalendarContent().getDtEnd())); 
     832 
     833                        long hj = System.currentTimeMillis(); 
     834                        if(dtStart.getTime() > hj){ 
     835                                return twins; 
     836                        } 
    812837 
    813838                        StringBuffer sqlGetCalendarTwinList = new StringBuffer(SQL_GET_EXP_PIM_CALENDAR_ID_LIST_BY_USER); 
     
    14371462        } 
    14381463 
     1464        private void findDates(String source) throws Exception { 
     1465 
     1466                String aux = null; 
     1467                StringTokenizer tokens = null; 
     1468                String primeira = null; 
     1469                String segunda = null; 
     1470 
     1471                int i = 0; 
     1472                int j = 0; 
     1473 
     1474                java.util.Calendar calendar1 = null; 
     1475                java.util.Calendar calendar2 = null; 
     1476 
     1477                try { 
     1478 
     1479                        aux = source.substring(source.indexOf("(")+1, source.indexOf(")")); 
     1480                        tokens = new StringTokenizer(aux, ","); 
     1481 
     1482                        primeira = tokens.nextToken(); 
     1483                        segunda = tokens.nextToken(); 
     1484 
     1485                        i = Integer.parseInt(primeira); 
     1486                        j = Integer.parseInt(segunda); 
     1487 
     1488                        calendar1 = java.util.Calendar.getInstance(); 
     1489                        calendar2 = java.util.Calendar.getInstance(); 
     1490 
     1491                        calendar1.add(java.util.Calendar.DAY_OF_MONTH, i); 
     1492                        calendar2.add(java.util.Calendar.DAY_OF_MONTH, j); 
     1493 
     1494                        this.date1 = new Timestamp(calendar1.getTimeInMillis()); 
     1495                        this.date2 = new Timestamp(calendar2.getTimeInMillis()); 
     1496 
     1497                } catch (Exception e) { 
     1498                        throw new PIMDBAccessException("Error convert dates findDates  " + e.getMessage()); 
     1499                } 
     1500        } 
     1501 
    14391502} 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMContactDAO.java

    r1009 r1103  
    6868                        + "WHERE (id_owner = ?) " 
    6969                        + "AND ((given_names is null AND (?) = '') " 
    70                         + "OR (lower(given_names) = ?)) " 
     70                        + "OR (given_names = ?)) " 
    7171                        + "AND ((family_names is null AND (?) = '') " 
    72                         + "OR (lower(family_names) = ?)) "; 
     72                        + "OR (family_names = ?)) "; 
    7373 
    7474        private static final String SQL_INSERT_INTO_FNBL_PIM_CONTACT = "INSERT INTO phpgw_cc_contact " 
     
    10061006                        } 
    10071007 
    1008                         String fnSearch = (firstName.length() == 0 ? "<N/A>" : firstName 
    1009                                         .toLowerCase()); 
    1010                         String lnSearch = (lastName.length() == 0 ? "<N/A>" : lastName 
    1011                                         .toLowerCase()); 
     1008                        String fnSearch = (firstName.length() == 0 ? "<N/A>" : firstName); 
     1009                        String lnSearch = (lastName.length() == 0 ? "<N/A>" : lastName); 
    10121010                        StringBuilder sb = new StringBuilder(100); 
    10131011 
    1014                         sb.append("\n\nLooking for items having: ").append( 
    1015                                         "\n> first name   : '").append(fnSearch).append('\'') 
    1016                                         .append("\n> last  name   : '").append(lnSearch).append( 
    1017                                                         '\'').append("\n"); 
     1012                        sb.append("\n\nLooking for items having: ") 
     1013                          .append("\n> first name   : '") 
     1014                          .append(fnSearch).append('\'') 
     1015                          .append("\n> last  name   : '") 
     1016                          .append(lnSearch).append('\'').append("\n"); 
    10181017 
    10191018                        log.info(sb.toString()); 
     
    10221021                                        + SQL_ORDER_BY_ID); 
    10231022                        ps.setLong(1, Long.parseLong(userId)); 
    1024                         ps.setString(2, firstName.toLowerCase()); 
    1025                         ps.setString(3, firstName.toLowerCase()); 
    1026                         ps.setString(4, lastName.toLowerCase()); 
    1027                         ps.setString(5, lastName.toLowerCase()); 
     1023                        ps.setString(2, firstName); 
     1024                        ps.setString(3, firstName); 
     1025                        ps.setString(4, lastName); 
     1026                        ps.setString(5, lastName); 
    10281027                        rs = ps.executeQuery(); 
    10291028 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java

    r1009 r1103  
    7070         * Creates a new instance of PIMEntityDAO, ready to be linked to a given 
    7171         * DataSource. 
    72          *  
     72         * 
    7373         * @param jndiDataSourceName 
    7474         *            the jndiname of the datasource to use 
     
    197197         * Looks up the data source, making some guess attempts based on 
    198198         * jndiDataSourceName. 
    199          *  
     199         * 
    200200         * @throws Exception 
    201201         */ 
     
    216216         * Retrieves the UID list of the new items belonging to the user filtered 
    217217         * according to the given time interval. 
    218          *  
     218         * 
    219219         * @param since 
    220220         *            the earliest allowed last-update Timestamp 
     
    234234         * Retrieves the UID list of the deleted items belonging to the user 
    235235         * filtered according to the given time interval. 
    236          *  
     236         * 
    237237         * @param since 
    238238         *            the earliest allowed last-update Timestamp 
     
    252252         * Retrieves the UID list of the updated items belonging to the user 
    253253         * filtered according to the given time interval. 
    254          *  
     254         * 
    255255         * @param since 
    256256         *            the earliest allowed last-update Timestamp 
     
    273273         * Retrieves the UID list of the items belonging to the user filtered 
    274274         * according to the given time interval and status. 
    275          *  
     275         * 
    276276         * @param since 
    277277         *            the earliest allowed last-update Timestamp 
     
    289289        /** 
    290290         * Checks (safely) whether the property is unset. 
    291          *  
     291         * 
    292292         * @param property 
    293293         *            may be null 
    294294         * @return false only if the property value is a non-null, but possibly 
    295295         *         empty (""), string 
    296          *  
     296         * 
    297297         * @see PIMEntityDAO#stringFrom(Property) 
    298298         */ 
     
    304304        /** 
    305305         * Checks (safely) whether the property is unset or set to an empty string. 
    306          *  
     306         * 
    307307         * @param property 
    308308         *            may be null 
    309309         * @return false only if the property value is a non-null non-empty string 
    310          *  
     310         * 
    311311         * @see PIMEntityDAO#stringFrom(Property, boolean) 
    312312         */ 
     
    327327         * considered as an acceptable value for the property: in such a case, an 
    328328         * empty String object will be returned. 
    329          *  
     329         * 
    330330         * @param property 
    331331         *            may be null 
     
    349349         * stringFrom(..., false) will be considered as explicitly kept blank if its 
    350350         * value is "". This means that single field deletions can be made tunable. 
    351          *  
     351         * 
    352352         * @param property 
    353353         *            may be null 
     
    356356         *            null; otherwise, in such a case an empty String object will be 
    357357         *            returned 
    358          *  
     358         * 
    359359         * @return if existing (and not empty if emptyImpliesNull is true), the 
    360360         *         property value will be returned as a String object 
     
    380380        /** 
    381381         * Gets a substring in a safe way. 
    382          *  
     382         * 
    383383         * @param string 
    384384         *            may be null or longer than maxLength 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/manager/PIMCalendarManager.java

    r1009 r1103  
    4343 
    4444        /** 
     45         * @throws Exception 
    4546         * @see PIMEntityDAO#PIMEntityDAO(String, String) 
    4647         */ 
    47         public PIMCalendarManager(String jndiDataSourceName, 
    48                         Sync4jPrincipal principal) { 
     48        public PIMCalendarManager(String jndiDataSourceName, Sync4jPrincipal principal, String sourceQuery) { 
    4949 
    50                 this.dao = new PIMCalendarDAO(jndiDataSourceName, principal); 
     50                try { 
     51                        this.dao = new PIMCalendarDAO(jndiDataSourceName, principal, sourceQuery); 
     52                } catch (Exception e) { 
     53                } 
    5154                super.dao = this.dao; 
    5255 
     
    6063        /** 
    6164         * Updates a calendar. 
    62          *  
     65         * 
    6366         * @param uid 
    6467         *            the UID of the calendar 
  • contrib/psync/src/main/sql/postgresql/create_schema.sql

    r1009 r1103  
     1ALTER TABLE phpgw_cal ALTER title TYPE character varying(255); 
    12ALTER TABLE phpgw_cal ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar; 
    23ALTER TABLE phpgw_cal ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
     
    56ALTER TABLE phpgw_cc_contact ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
    67ALTER TABLE phpgw_cc_contact ADD COLUMN category character varying(20); 
     8 
Note: See TracChangeset for help on using the changeset viewer.