Changeset 1545 for contrib/psync


Ignore:
Timestamp:
10/28/09 20:58:21 (15 years ago)
Author:
wmerlotto
Message:

Ticket #693 - Incrementado a sincronizacao de contatos, integracao com maven e codigo de autenticacao no LDAP.

Location:
contrib/psync
Files:
19 added
7 edited

Legend:

Unmodified
Added
Removed
  • contrib/psync/src/main/bean/psync/calendar/VEventSource.xml

    r1009 r1545  
    1 <?xml version="1.0" encoding="UTF-8"?> 
    2 <java version="1.4.0" class="java.beans.XMLDecoder"> 
    3  <object class="br.com.prognus.psync.engine.source.PIMCalendarSyncSource"> 
    4  <void property="name"> 
    5    <string>calendario</string> 
    6  </void> 
    7  <void property="sourceURI"> 
    8    <string>calendario</string> 
    9  </void> 
    10  <void property="entityType"> 
    11    <class>com.funambol.common.pim.calendar.Event</class> 
    12  </void> 
    13  <void property="info"> 
    14    <object class="com.funambol.framework.engine.source.SyncSourceInfo"> 
    15      <void property="supportedTypes"> 
    16      <array class="com.funambol.framework.engine.source.ContentType" length="2"> 
    17       <void index="0"> 
    18        <object class="com.funambol.framework.engine.source.ContentType"> 
    19         <void property="type"> 
    20          <string>text/x-vcalendar</string> 
    21         </void> 
    22         <void property="version"> 
    23          <string>1.0</string> 
    24         </void> 
    25        </object> 
    26       </void> 
    27       <void index="1"> 
    28        <object class="com.funambol.framework.engine.source.ContentType"> 
    29         <void property="type"> 
    30          <string>text/calendar</string> 
    31         </void> 
    32         <void property="version"> 
    33          <string>2.0</string> 
    34         </void> 
    35        </object> 
    36       </void> 
    37      </array> 
    38      </void>  <!-- supportedTypes --> 
    39      <void property="preferred"> 
    40        <int>0</int> 
    41      </void> 
    42    </object> 
    43  </void> <!-- info --> 
    44  </object> 
    45 </java> 
  • contrib/psync/src/main/bean/psync/contact/VCardSource.xml

    r1009 r1545  
    1 <?xml version="1.0" encoding="UTF-8"?> 
    2 <java version="1.4.0" class="java.beans.XMLDecoder"> 
    3  <object class="br.com.prognus.psync.engine.source.PIMContactSyncSource"> 
    4  <void property="name"> 
    5    <string>catalogo</string> 
    6  </void> 
    7  <void property="sourceURI"> 
    8    <string>catalogo</string> 
    9  </void> 
    10  <void property="info"> 
    11    <object class="com.funambol.framework.engine.source.SyncSourceInfo"> 
    12      <void property="supportedTypes"> 
    13        <array class="com.funambol.framework.engine.source.ContentType" length="1"> 
    14          <void index="0"> 
    15            <object class="com.funambol.framework.engine.source.ContentType"> 
    16              <void property="type"> 
    17                <string>text/x-vcard</string> 
    18              </void> 
    19              <void property="version"> 
    20                <string>2.1</string> 
    21              </void> 
    22            </object> 
    23          </void> 
    24        </array> 
    25      </void>  <!-- supportedTypes --> 
    26      <void property="preferred"> 
    27        <int>0</int> 
    28      </void> 
    29    </object> 
    30  </void> <!-- info --> 
    31  </object> 
    32 </java> 
  • contrib/psync/src/main/java/br/com/prognus/psync/engine/source/PIMCalendarSyncSource.java

    r1103 r1545  
    7777                        this.manager = new PIMCalendarManager(JNDI_DATA_SOURCE_NAME, context.getPrincipal(), context.getSourceQuery()); 
    7878                } catch (Exception e) { 
    79                         // TODO Auto-generated catch block 
    8079                        e.printStackTrace(); 
    8180                } 
     
    453452        private String hackFix(String text) { 
    454453 
    455                 String result, head, title, clas, description, tail, new_title; 
    456                 int p_categories, p_classes, p_location, p_dstart, values1, values2, op1, op2, op3, op4, op5, op6, op7, op8, qt1, qt2; 
    457  
    458                 qt1 = 0; 
    459                 qt2 = 0; 
    460  
    461                 // Pega as posicoes das tags 
    462                 p_categories = text.indexOf("CATEGORIES"); 
    463                 p_classes = text.indexOf("CLASS"); 
    464  
    465                 p_location = text.indexOf("LOCATION"); 
    466                 p_dstart = text.indexOf("DTSTART"); 
    467  
    468                 // Pega as posicoes das varias formas da tag SUMMARY 
    469                 op1 = text.indexOf("SUMMARY:"); 
    470                 op2 = text.indexOf("SUMMARY;CHARSET=UTF-8:"); 
    471                 op3 = text.indexOf("SUMMARY;ENCODING=QUOTED-PRINTABLE:"); 
    472                 op4 = text.indexOf("SUMMARY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:"); 
    473  
    474                 // Pega as posicoes das varias formas da tag DESCRIPTION 
    475                 op5 = text.indexOf("DESCRIPTION:"); 
    476                 op6 = text.indexOf("DESCRIPTION;CHARSET=UTF-8:"); 
    477                 op7 = text.indexOf("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:"); 
    478                 op8 = text.indexOf("DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:"); 
    479  
    480                 qt1 += (op1 == -1) ? 0 : op1 + 8; 
    481                 qt1 += (op2 == -1) ? 0 : op2 + 22; 
    482                 qt1 += (op3 == -1) ? 0 : op3 + 34; 
    483                 qt1 += (op4 == -1) ? 0 : op4 + 48; 
    484  
    485                 qt2 += (op5 == -1) ? 0 : op5 + 12; 
    486                 qt2 += (op6 == -1) ? 0 : op6 + 26; 
    487                 qt2 += (op7 == -1) ? 0 : op7 + 38; 
    488                 qt2 += (op8 == -1) ? 0 : op8 + 52; 
    489  
    490                 values1 = (p_categories == -1) ? p_classes : p_categories; 
    491                 values2 = (p_location == -1) ? p_dstart : p_location; 
    492  
    493                 head = text.substring(0, qt1); 
    494                 title = text.substring(qt1, values1); 
    495                 clas = text.substring(values1, qt2); 
    496                 description = text.substring(qt2, values2); 
    497                 tail = text.substring(values2); 
    498  
    499                 new_title = title.replaceAll("\r\n ", " "); 
    500  
    501                 // Retira os enters no final do titulo 
    502                 int title_t, title_bl; 
    503  
    504                 while(true){ 
    505                         title_t = new_title.length(); 
    506                         title_bl = new_title.lastIndexOf("=0D=0A=\r\n"); 
    507  
    508                         if(title_bl != -1 && title_t == title_bl + 11){ 
    509                                 new_title = new_title.substring(0, title_bl) + "\r\n"; 
    510                         } else { 
    511                                 break; 
    512                         } 
    513                 } 
    514  
    515                 // Retira os enters no final da descricao 
    516                 int description_t, description_bl; 
    517  
    518                 while(true){ 
    519                         description_t = description.length(); 
    520                         description_bl = description.lastIndexOf("=0D=0A=\r\n"); 
    521  
    522                         if(description_bl != -1 && description_t == description_bl + 11){ 
    523                                 description = description.substring(0, description_bl) + "\r\n"; 
    524                         } else { 
    525                                 break; 
    526                         } 
    527                 } 
    528  
    529                 result = head + new_title + clas + description + tail; 
    530  
    531                 return result; 
     454                try { 
     455                 
     456                        String result, head, title, clas, description, tail, new_title; 
     457                        int p_categories, p_classes, p_location, p_dstart, values1, values2, op1, op2, op3, op4, op5, op6, op7, op8, qt1, qt2; 
     458         
     459                        qt1 = 0; 
     460                        qt2 = 0; 
     461         
     462                        // Pega as posicoes das tags 
     463                        p_categories = text.indexOf("CATEGORIES"); 
     464                        p_classes = text.indexOf("CLASS"); 
     465         
     466                        p_location = text.indexOf("LOCATION"); 
     467                        p_dstart = text.indexOf("DTSTART"); 
     468         
     469                        // Pega as posicoes das varias formas da tag SUMMARY 
     470                        op1 = text.indexOf("SUMMARY:"); 
     471                        op2 = text.indexOf("SUMMARY;CHARSET=UTF-8:"); 
     472                        op3 = text.indexOf("SUMMARY;ENCODING=QUOTED-PRINTABLE:"); 
     473                        op4 = text.indexOf("SUMMARY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:"); 
     474         
     475                        // Pega as posicoes das varias formas da tag DESCRIPTION 
     476                        op5 = text.indexOf("DESCRIPTION:"); 
     477                        op6 = text.indexOf("DESCRIPTION;CHARSET=UTF-8:"); 
     478                        op7 = text.indexOf("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:"); 
     479                        op8 = text.indexOf("DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:"); 
     480         
     481                        qt1 += (op1 == -1) ? 0 : op1 + 8; 
     482                        qt1 += (op2 == -1) ? 0 : op2 + 22; 
     483                        qt1 += (op3 == -1) ? 0 : op3 + 34; 
     484                        qt1 += (op4 == -1) ? 0 : op4 + 48; 
     485         
     486                        qt2 += (op5 == -1) ? 0 : op5 + 12; 
     487                        qt2 += (op6 == -1) ? 0 : op6 + 26; 
     488                        qt2 += (op7 == -1) ? 0 : op7 + 38; 
     489                        qt2 += (op8 == -1) ? 0 : op8 + 52; 
     490         
     491                        values1 = (p_categories == -1) ? p_classes : p_categories; 
     492                        values2 = (p_location == -1) ? p_dstart : p_location; 
     493         
     494                        head = text.substring(0, qt1); 
     495                        title = text.substring(qt1, values1); 
     496                        clas = text.substring(values1, qt2); 
     497                        description = text.substring(qt2, values2); 
     498                        tail = text.substring(values2); 
     499         
     500                        new_title = title.replaceAll("\r\n ", " "); 
     501         
     502                        // Retira os enters no final do titulo 
     503                        int title_t, title_bl; 
     504         
     505                        while(true){ 
     506                                title_t = new_title.length(); 
     507                                title_bl = new_title.lastIndexOf("=0D=0A=\r\n"); 
     508         
     509                                if(title_bl != -1 && title_t == title_bl + 11){ 
     510                                        new_title = new_title.substring(0, title_bl) + "\r\n"; 
     511                                } else { 
     512                                        break; 
     513                                } 
     514                        } 
     515         
     516                        // Retira os enters no final da descricao 
     517                        int description_t, description_bl; 
     518         
     519                        while(true){ 
     520                                description_t = description.length(); 
     521                                description_bl = description.lastIndexOf("=0D=0A=\r\n"); 
     522         
     523                                if(description_bl != -1 && description_t == description_bl + 11){ 
     524                                        description = description.substring(0, description_bl) + "\r\n"; 
     525                                } else { 
     526                                        break; 
     527                                } 
     528                        } 
     529         
     530                        result = head + new_title + clas + description + tail; 
     531 
     532                        return result; 
     533                }catch (Exception e) { 
     534                        if (log.isTraceEnabled()) { 
     535                                log.trace(e); 
     536                        } 
     537                        return text; 
     538                } 
    532539        } 
    533540 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMContactDAO.java

    r1103 r1545  
    3232import br.com.prognus.psync.exception.PIMDBAccessException; 
    3333import br.com.prognus.psync.items.model.ContactWrapper; 
     34import br.com.prognus.psync.util.Country; 
    3435import br.com.prognus.psync.util.Def; 
    35  
     36import br.com.prognus.psync.util.TypeAddress; 
     37 
     38import com.funambol.common.pim.common.Property; 
     39import com.funambol.common.pim.contact.Address; 
    3640import com.funambol.common.pim.contact.BusinessDetail; 
    3741import com.funambol.common.pim.contact.Contact; 
    3842import com.funambol.common.pim.contact.Email; 
    3943import com.funambol.common.pim.contact.Name; 
     44import com.funambol.common.pim.contact.Note; 
    4045import com.funambol.common.pim.contact.PersonalDetail; 
    4146import com.funambol.common.pim.contact.Phone; 
     47import com.funambol.common.pim.contact.Photo; 
    4248import com.funambol.framework.security.Sync4jPrincipal; 
    4349import com.funambol.framework.server.store.NotFoundException; 
     
    5561                        + "WHERE id_owner = ?"; 
    5662 
    57         private static final String SQL_GET_CONTACT_BY_ID_USER = "SELECT id_contact, id_owner, last_update, last_status, given_names, family_names, birthdate, category FROM phpgw_cc_contact WHERE id_contact = ? AND id_owner = ? LIMIT 1"; 
     63        private static final String SQL_GET_CONTACT_BY_ID_USER = "SELECT id_contact, id_owner, last_update, last_status, given_names, family_names, birthdate, category, photo, notes, alias FROM phpgw_cc_contact WHERE id_contact = ? AND id_owner = ? LIMIT 1"; 
    5864 
    5965        private static final String SQL_GET_CONTACT_ITEM_BY_ID = "SELECT connection_name, connection_value, id_typeof_contact_connection FROM phpgw_cc_connections AS CO LEFT JOIN phpgw_cc_contact_conns AS CC ON CO.id_connection = CC.id_connection WHERE id_contact = ?"; 
     
    7379 
    7480        private static final String SQL_INSERT_INTO_FNBL_PIM_CONTACT = "INSERT INTO phpgw_cc_contact " 
    75                         + "(id_contact, id_owner, id_status, given_names, family_names, names_ordered, birthdate, category, last_update, last_status ) " 
    76                         + "VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; 
     81                        + "(id_contact, id_owner, id_status, given_names, family_names, names_ordered, birthdate, category, photo, notes, alias, last_update, last_status ) " 
     82                        + "VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; 
    7783 
    7884        private static final String SQL_INSERT_INTO_CONTACT_ITEM = "INSERT INTO phpgw_cc_connections " 
     
    8793 
    8894        private static final String SQL_UPDATE_FNBL_PIM_CONTACT_END = " WHERE id_contact = ? AND id_owner = ? "; 
    89  
     95         
     96         
     97        private static final String SQL_GET_CONTACT_ADDRESS_ITEM = " select ad.complement, ad.address1, ad.postal_code, ca.id_typeof_contact_address, city_name, state_name, cy.id_country from phpgw_cc_addresses AS ad JOIN phpgw_cc_contact_addrs AS ca ON ad.id_address=ca.id_address, phpgw_cc_city AS cy JOIN phpgw_cc_state AS st ON cy.id_state=st.id_state where cy.id_city=ad.id_city and ad.id_address in (select min(ca.id_address) from phpgw_cc_contact AS cc JOIN phpgw_cc_contact_addrs AS ca ON cc.id_contact=ca.id_contact JOIN phpgw_cc_addresses AS ad ON ca.id_address=ad.id_address where cc.id_contact = ? AND cc.id_owner = ? and ca.id_typeof_contact_address = ? )"; 
     98 
     99        private static final String SQL_GET_STATE_ITEM = "SELECT id_state, id_country, state_name, state_symbol FROM phpgw_cc_state "; 
     100         
     101        private static final String SQL_GET_CITY_ITEM = "SELECT id_city, id_state, id_country, city_timezone, city_geo_location, city_name FROM phpgw_cc_city "; 
     102 
     103        private static final String SQL_INSERT_STATE = "INSERT INTO phpgw_cc_state(id_state, id_country, state_name, state_symbol) VALUES (?, ?, ?, ?)"; 
     104         
     105        private static final String SQL_INSERT_CITY = "INSERT INTO phpgw_cc_city(id_city, id_state, id_country, city_timezone, city_geo_location, city_name) VALUES (?, ?, ?, ?, ?, ?)"; 
     106         
     107        private static final String SQL_INSERT_ADDRESS = "INSERT INTO phpgw_cc_addresses(id_address, id_city, id_state, id_country, address1, complement, postal_code, address_is_default) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; 
     108         
     109        private static final String SQL_INSERT_CONTACT_ADDRESS = "INSERT INTO phpgw_cc_contact_addrs(id_contact, id_address, id_typeof_contact_address) VALUES (?, ?, ?)"; 
     110 
     111        private static final int SQL_ADDRESS_DIM = 60; 
     112         
     113        private static final String SQL_ID_MAX_ADDRESS = "select max(id_address) FROM phpgw_cc_addresses"; 
     114         
     115        private static final String SQL_ID_MAX_STATE = "select max(id_state) FROM phpgw_cc_state"; 
     116         
     117        private static final String SQL_ID_MAX_CITY = "select max(id_city) FROM phpgw_cc_city"; 
     118         
    90119        private static final String SQL_EQUALS_QUESTIONMARK = " = ?"; 
    91120 
     
    111140 
    112141        protected static final String SQL_FIELD_CATEGORY = "category"; 
     142         
     143        protected static final String SQL_FIELD_PHOTO = "photo"; 
     144         
     145        protected static final String SQL_FIELD_NOTES = "notes"; 
    113146 
    114147        protected static final int SQL_FIRSTNAME_DIM = 49; 
     
    121154 
    122155        protected static final int SQL_CATEGORY_DIM = 20; 
     156         
     157        protected static final int SQL_NICK_DIM = 30; 
    123158 
    124159        protected static final String TYPE_EMAIL_1_ADDRESS = "Principal"; 
     
    159194 
    160195        protected static final String SQL_FIELD_ITEM_TYPE = "id_typeof_contact_connection"; 
     196         
     197        protected static final String SQL_FIELD_TYPEOF = "id_typeof_contact_address"; 
     198         
     199        protected static final String SQL_FIELD_COMPLEMENT = "complement"; 
     200         
     201        protected static final String SQL_FIELD_ADDRESS1 = "address1"; 
     202                 
     203        protected static final String SQL_FIELD_POSTALCODE = "postal_code"; 
     204         
     205        protected static final String SQL_FIELD_CITY_NAME = "city_name"; 
     206         
     207        protected static final String SQL_FIELD_STATE_NAME = "state_name"; 
     208         
     209        protected static final String SQL_FIELD_COUNTRY_ID = "id_country"; 
     210         
     211        protected static final String SQL_FIELD_STATE_ID = "id_state"; 
     212         
     213        protected static final String SQL_FIELD_CITY_ID = "id_city"; 
    161214 
    162215        private Sync4jPrincipal principal = null; 
     
    193246         * @see ContactWrapper 
    194247         */ 
     248        @SuppressWarnings("unchecked") 
    195249        public void addItem(ContactWrapper cw) throws PIMDBAccessException { 
    196250 
     
    223277                StringBuffer fullName = null; 
    224278                Date anniversary = null; 
     279                byte[] imagePhoto = null; 
     280                String note = null; 
     281                String alias = null; 
    225282 
    226283                try { 
     
    232289                        Timestamp lastUpdate = cw.getLastUpdate(); 
    233290 
     291                        try { 
     292                                List<Note> notes = c.getNotes(); 
     293                                int i = notes.size() - 1; 
     294                                note = notes.get(i).getPropertyValueAsString(); 
     295                        } catch (Exception e) { 
     296//                              log.error(e.getMessage(),e); 
     297                        } 
     298                        if(note==null) { 
     299                                note=""; 
     300                        } 
     301                         
    234302                        personalDetail = c.getPersonalDetail(); 
    235303                        businessDetail = c.getBusinessDetail(); 
     
    244312                                birthday = personalDetail.getBirthday(); 
    245313                                category = stringFrom(c.getCategories()); 
     314                                imagePhoto = personalDetail.getPhotoObject().getImage(); 
    246315                        } 
    247316 
     
    254323                                firstName = stringFrom(name.getFirstName()); 
    255324                                lastName = stringFrom(name.getLastName()); 
     325                                alias = stringFrom(name.getNickname()); 
    256326                        } 
    257327 
     
    297367                        ps.setDate(7, anniversary); // birthdate 
    298368                        ps.setString(8, truncate(category, SQL_CATEGORY_DIM)); // category 
    299                         ps.setLong(9, lastUpdate.getTime()); // last_update 
    300                         ps.setString(10, String.valueOf(Def.PIM_STATE_NEW)); // last_status 
     369                        ps.setBytes(9, imagePhoto); // photo 
     370                        ps.setString(10, note); // note 
     371                        ps.setString(11, truncate(alias, SQL_NICK_DIM)); // alias 
     372                        ps.setLong(12, lastUpdate.getTime()); // last_update 
     373                        ps.setString(13, String.valueOf(Def.PIM_STATE_NEW)); // last_status 
    301374                        ps.executeUpdate(); 
    302375 
     
    483556                String category = null; 
    484557                Date anniversary = null; 
     558                byte[] imagePhoto = null; 
     559                String note = null; 
     560                String alias = null; 
     561                Address persoAddress = null; 
     562                Address businAddress = null; 
    485563 
    486564                try { 
     
    495573                        Contact c = cw.getContact(); 
    496574 
     575                        try { 
     576                                List<Note> notes = c.getNotes(); 
     577                                int i = notes.size() - 1; 
     578                                note = notes.get(i).getPropertyValueAsString(); 
     579                        } catch (Exception e) { 
     580//                              log.error(e.getMessage(),e); 
     581                        } 
     582                        if(note==null) { 
     583                                note=""; 
     584                        } 
     585                         
    497586                        personalDetail = c.getPersonalDetail(); 
    498587                        businessDetail = c.getBusinessDetail(); 
     
    505594                                birthday = personalDetail.getBirthday(); 
    506595                                category = stringFrom(c.getCategories()); 
     596                                imagePhoto = personalDetail.getPhotoObject().getImage(); 
     597                                persoAddress = personalDetail.getAddress(); 
    507598                        } 
    508599 
     
    510601                                emails.addAll(businessDetail.getEmails()); 
    511602                                phones.addAll(businessDetail.getPhones()); 
     603                                businAddress = businessDetail.getAddress(); 
    512604                        } 
    513605 
     
    515607                                firstName = stringFrom(name.getFirstName()); 
    516608                                lastName = stringFrom(name.getLastName()); 
     609                                alias = stringFrom(name.getNickname()); 
    517610                        } 
    518611 
     
    525618                        if (category != null && category.length() > SQL_CATEGORY_DIM) { 
    526619                                category = category.substring(0, SQL_CATEGORY_DIM); 
     620                        } 
     621                        if (alias != null && alias.length() > SQL_NICK_DIM) { 
     622                                alias = alias.substring(0, SQL_NICK_DIM); 
    527623                        } 
    528624 
     
    563659                        queryUpdateFunPimContact.append(SQL_FIELD_CATEGORY 
    564660                                        + SQL_EQUALS_QUESTIONMARK_COMMA); 
     661                        queryUpdateFunPimContact.append(SQL_FIELD_PHOTO 
     662                                        + SQL_EQUALS_QUESTIONMARK_COMMA); 
     663                        queryUpdateFunPimContact.append(SQL_FIELD_NOTES 
     664                                        + SQL_EQUALS_QUESTIONMARK_COMMA); 
     665                        queryUpdateFunPimContact.append(SQL_FIELD_NICK 
     666                                        + SQL_EQUALS_QUESTIONMARK_COMMA); 
    565667                        queryUpdateFunPimContact 
    566668                                        .append(SQL_FIELD_STATUS + SQL_EQUALS_QUESTIONMARK 
     
    575677                        ps.setDate(5, anniversary); // birthdate 
    576678                        ps.setString(6, category); // category 
    577                         ps.setString(7, String.valueOf(Def.PIM_STATE_UPDATED)); // last_status 
    578                         ps.setLong(8, id_contact); // id_contact 
    579                         ps.setLong(9, Long.parseLong(userId)); // id_owner 
     679                        ps.setBytes(7, imagePhoto); // photo 
     680                        ps.setString(8, note); // notes 
     681                        ps.setString(9, alias); // alias 
     682                        ps.setString(10, String.valueOf(Def.PIM_STATE_UPDATED)); // last_status 
     683                        ps.setLong(11, id_contact); // id_contact 
     684                        ps.setLong(12, Long.parseLong(userId)); // id_owner 
    580685                        ps.executeUpdate(); 
    581686 
     
    730835                        } 
    731836 
     837                         
     838                        // endereco 
     839                        boolean syncAddress = true; 
     840                        if(syncAddress) { 
     841                        // Apaga os contatos na tabela phpgw_cc_addresses 
     842                        ps = con 
     843                                        .prepareStatement("DELETE FROM phpgw_cc_addresses WHERE id_address IN (SELECT id_address FROM phpgw_cc_contact_addrs WHERE id_contact = ?)"); 
     844                        ps.setLong(1, id_contact); 
     845                        ps.executeUpdate(); 
     846                 
     847                        // Apaga os contatos na tabela phpgw_cc_contact_addrs 
     848                        ps = con 
     849                                        .prepareStatement("DELETE FROM phpgw_cc_contact_addrs WHERE id_contact = ?"); 
     850                        ps.setLong(1, id_contact); 
     851                        ps.executeUpdate(); 
     852                         
     853                        // Para cadas tipo de endereco RESIDENCIAL | COMERCIAL 
     854                        for (TypeAddress typeAddress: TypeAddress.values()) { 
     855                                 
     856                                Address address = null; 
     857                                boolean defaultAddress = false; 
     858                                 
     859                                // se ambos sao nulos não faz nada aqui 
     860                                if (persoAddress == null && businAddress == null) { 
     861                                        break; 
     862                                } 
     863                                 
     864                                if (typeAddress.equals(TypeAddress.RESIDENCIAL)) { 
     865                                        address=persoAddress; 
     866                                        defaultAddress = true; 
     867                                } else if (typeAddress.equals(TypeAddress.COMERCIAL)) { 
     868                                        address=businAddress; 
     869                                } 
     870                                 
     871                                // Pula para o proximo 
     872                                if(address == null) { 
     873                                        continue; 
     874                                } 
     875                                 
     876                                String addressValue = address.getStreet().getPropertyValueAsString(); 
     877                                addressValue  = truncate(addressValue, SQL_ADDRESS_DIM); 
     878         
     879                                if (addressValue != null && addressValue.length() != 0) { 
     880 
     881                                        // Verifica o id maximo da tabela phpgw_cc_addresses 
     882                                        ps = con.prepareStatement(SQL_ID_MAX_ADDRESS); 
     883                                        rs = ps.executeQuery(); 
     884                                        long id_address = 0; 
     885                                         
     886                                        if (rs.next()) { 
     887                                                long id = rs.getInt(1); 
     888                                                id_address = (id == 0) ? 1 : ++id; 
     889                                        } 
     890 
     891                                        // Insere o endereco do contato na tabela 
     892                                        String idCountry; 
     893                                        try { 
     894                                                idCountry = Country.getCountryByName(address 
     895                                                                .getCountry().getPropertyValueAsString()).getCode(); 
     896                                        } catch (Exception e) { 
     897                                                idCountry = "BR"; 
     898                                        } 
     899                                        long idState = searchStateId(con, address.getState().getPropertyValueAsString(), idCountry); 
     900                                        long idCity = searchCityId(con, address.getCity().getPropertyValueAsString(), idState, idCountry); 
     901                                         
     902                                        ps = con.prepareStatement(SQL_INSERT_ADDRESS); 
     903                                        ps.setLong(1, id_address); 
     904                                        ps.setLong(2, idCity); 
     905                                        ps.setLong(3, idState); 
     906                                        ps.setString(4, idCountry); 
     907                                        ps.setString(5, addressValue); 
     908                                        ps.setString(6, address.getExtendedAddress().getPropertyValueAsString()); 
     909                                        ps.setString(7, address.getPostalCode().getPropertyValueAsString()); 
     910                                        ps.setBoolean(8, defaultAddress); 
     911                                        ps.executeUpdate(); 
     912 
     913                                        ps = con.prepareStatement(SQL_INSERT_CONTACT_ADDRESS); 
     914                                        ps.setLong(1, id_contact); 
     915                                        ps.setLong(2, id_address); 
     916                                        ps.setInt(3, typeAddress.getId()); 
     917                                        ps.executeUpdate(); 
     918                                } 
     919                        } 
     920                        } 
    732921                        con.commit(); 
    733922                        con.setAutoCommit(true); 
     
    743932 
    744933                return Long.toString(id_contact); 
     934        } 
     935 
     936 
     937        private long searchStateId(Connection con, String stateName, String idCountry) throws Exception { 
     938                 
     939                PreparedStatement ps = null; 
     940                ResultSet rs = null; 
     941                long stateId = 0; 
     942                 
     943                try { 
     944                        String SQL_GET_STATE = SQL_GET_STATE_ITEM + " where upper(" 
     945                                        + SQL_FIELD_STATE_NAME + ")" + SQL_EQUALS_QUESTIONMARK 
     946                                        + " and " + SQL_FIELD_COUNTRY_ID + SQL_EQUALS_QUESTIONMARK; 
     947                        ps = con.prepareStatement(SQL_GET_STATE); 
     948                        ps.setString(1, stateName.toUpperCase()); 
     949                        ps.setString(2, idCountry); 
     950                        rs = ps.executeQuery(); 
     951                        if (rs.next()) { 
     952                                stateId = rs.getInt(SQL_FIELD_STATE_ID); 
     953                                return stateId; 
     954                        } 
     955                } catch (Exception e) { 
     956                        e.printStackTrace(); 
     957                } 
     958                 
     959                ps = con.prepareStatement(SQL_ID_MAX_STATE); 
     960                rs = ps.executeQuery(); 
     961                 
     962                if (rs.next()) { 
     963                        long id = rs.getInt(1); 
     964                        stateId = (id == 0) ? 1 : ++id; 
     965                } 
     966                else { 
     967                        return 0; 
     968                } 
     969                 
     970                ps = con.prepareStatement(SQL_INSERT_STATE); 
     971                ps.setLong(1, stateId); 
     972                ps.setString(2, idCountry); 
     973                ps.setString(3, stateName); 
     974                ps.setString(4, stateName.substring(0, 2)); 
     975                if(ps.executeUpdate() > 0) { 
     976                        return stateId; 
     977                } 
     978                 
     979                return 0; 
     980        } 
     981 
     982        private long searchCityId(Connection con, String cityName, long idState, String idCountry) throws Exception { 
     983                 
     984                PreparedStatement ps = null; 
     985                ResultSet rs = null; 
     986                long cityId = 0; 
     987                 
     988                try { 
     989                        String SQL_GET_CITY = SQL_GET_CITY_ITEM + " where " 
     990                                        + SQL_FIELD_STATE_ID + SQL_EQUALS_QUESTIONMARK + " and " 
     991                                        + SQL_FIELD_COUNTRY_ID + SQL_EQUALS_QUESTIONMARK 
     992                                        + " and upper(" + SQL_FIELD_CITY_NAME + ")" 
     993                                        + SQL_EQUALS_QUESTIONMARK; 
     994                        ps = con.prepareStatement(SQL_GET_CITY); 
     995                        ps.setLong(1, idState); 
     996                        ps.setString(2, idCountry); 
     997                        ps.setString(3, cityName.toUpperCase()); 
     998                        rs = ps.executeQuery(); 
     999                        if (rs.next()) { 
     1000                                cityId = rs.getInt(SQL_FIELD_CITY_ID); 
     1001                                return cityId; 
     1002                        } 
     1003                } catch (Exception e) { 
     1004                        e.printStackTrace(); 
     1005                } 
     1006                ps = con.prepareStatement(SQL_ID_MAX_CITY); 
     1007                rs = ps.executeQuery(); 
     1008                 
     1009                if (rs.next()) { 
     1010                        long id = rs.getInt(1); 
     1011                        cityId = (id == 0) ? 1 : ++id; 
     1012                } 
     1013                else { 
     1014                        return 0; 
     1015                } 
     1016                 
     1017                ps = con.prepareStatement(SQL_INSERT_CITY); 
     1018                ps.setLong(1, cityId); 
     1019                ps.setLong(2, idState); 
     1020                ps.setString(3, idCountry); 
     1021                ps.setNull(4, 0); 
     1022                ps.setString(5, null); 
     1023                ps.setString(6, cityName); 
     1024                if(ps.executeUpdate() > 0) { 
     1025                        return cityId; 
     1026                } 
     1027                 
     1028                return 0; 
    7451029        } 
    7461030 
     
    9541238                                                                .getSQLState()); 
    9551239                        } 
     1240                         
     1241                        try { 
     1242                                ps = con.prepareStatement(SQL_GET_CONTACT_ADDRESS_ITEM); 
     1243                                ps.setLong(1, Long.parseLong(uid)); 
     1244                                ps.setLong(2, Long.parseLong(userId)); 
     1245                                ps.setInt(3, TypeAddress.RESIDENCIAL.getId()); 
     1246                                rs = ps.executeQuery(); 
     1247                                 
     1248                                Address address = c.getContact().getPersonalDetail().getAddress(); 
     1249                                addAddress(address, rs); 
     1250                        } catch (Exception e) { 
     1251                                throw new SQLException("\nError while adding personal address information"); 
     1252                        } 
     1253 
     1254                        try { 
     1255                                ps = con.prepareStatement(SQL_GET_CONTACT_ADDRESS_ITEM); 
     1256                                ps.setLong(1, Long.parseLong(uid)); 
     1257                                ps.setLong(2, Long.parseLong(userId)); 
     1258                                ps.setInt(3, TypeAddress.COMERCIAL.getId()); 
     1259                                rs = ps.executeQuery(); 
     1260                                 
     1261                                Address address = c.getContact().getBusinessDetail().getAddress(); 
     1262                                addAddress(address, rs); 
     1263                        } catch (Exception e) { 
     1264                                throw new SQLException("\nError while adding business address information"); 
     1265                        } 
    9561266 
    9571267                } catch (Exception e) { 
     
    9631273 
    9641274                return c; 
     1275        } 
     1276         
     1277         
     1278        private static void addAddress(Address address, ResultSet rs) throws Exception { 
     1279                 
     1280                ResultSetMetaData rsmd = rs.getMetaData(); 
     1281 
     1282                String column = null; 
     1283                int columnCount = 0; 
     1284                 
     1285                while (rs.next()) { 
     1286 
     1287                        columnCount = rsmd.getColumnCount(); 
     1288                         
     1289                        if (rs.getString(SQL_FIELD_ADDRESS1)==null || (rs.getString(SQL_FIELD_ADDRESS1)!=null && "".equals(rs.getString(SQL_FIELD_ADDRESS1).trim()))) { 
     1290                                break; 
     1291                        } 
     1292 
     1293                        for (int i = 1; i <= columnCount; ++i) { 
     1294 
     1295                                column = rsmd.getColumnName(i); 
     1296                                if (SQL_FIELD_TYPEOF.equalsIgnoreCase(column)) { 
     1297                                        continue; 
     1298                                } else if (SQL_FIELD_COMPLEMENT.equalsIgnoreCase(column)) { 
     1299                                        address.getExtendedAddress().setPropertyValue(rs.getString(i)); 
     1300                                } else if (SQL_FIELD_ADDRESS1.equalsIgnoreCase(column)) { 
     1301                                        address.getStreet().setPropertyValue(rs.getString(i)); 
     1302                                } else if (SQL_FIELD_POSTALCODE.equalsIgnoreCase(column)) { 
     1303                                        address.getPostalCode().setPropertyValue(rs.getString(i)); 
     1304                                } else if (SQL_FIELD_CITY_NAME.equalsIgnoreCase(column)) { 
     1305                                        address.getCity().setPropertyValue(rs.getString(i)); 
     1306                                } else if (SQL_FIELD_STATE_NAME.equalsIgnoreCase(column)) { 
     1307                                        address.getState().setPropertyValue(rs.getString(i)); 
     1308                                } else if (SQL_FIELD_COUNTRY_ID.equalsIgnoreCase(column)) { 
     1309                                        Country country = Country.getCountryByCode(rs.getString(i)); 
     1310                                        address.getCountry().setPropertyValue(country.getName()); 
     1311                                } else { 
     1312                                        throw new SQLException("\n=> Unhandled column: " + column); 
     1313                                } 
     1314                                 
     1315                        }                
     1316                } 
    9651317        } 
    9661318 
     
    11691521                        } else if (SQL_FIELD_CATEGORY.equalsIgnoreCase(column)) { 
    11701522                                c.getCategories().setPropertyValue(rs.getString(i)); 
     1523                        } else if (SQL_FIELD_PHOTO.equalsIgnoreCase(column)) { 
     1524                                if(c.getPersonalDetail()==null) { 
     1525                                        PersonalDetail pd = new PersonalDetail(); 
     1526                                        c.setPersonalDetail(pd); 
     1527                                } 
     1528                                Photo photo = new Photo(); 
     1529                                photo.setImage(rs.getBytes(i)); 
     1530                                c.getPersonalDetail().setPhotoObject(photo); 
     1531                        } else if (SQL_FIELD_NOTES.equalsIgnoreCase(column)) { 
     1532                                 
     1533                                try { 
     1534                                        if(rs.getString(i) != null) { 
     1535                                                if (c.getNotes() == null 
     1536                                                                || (c.getNotes() != null && c.getNotes().size() != 1) 
     1537                                                                || (c.getNotes() != null 
     1538                                                                                && c.getNotes().size() == 1 && c.getNotes() 
     1539                                                                                .get(0) == null)) { 
     1540                                                        List<Note> l = new ArrayList<Note>(1); 
     1541                                                        l.add(new Note()); 
     1542                                                        c.setNotes(l); 
     1543                                                } 
     1544                                                Note n = (Note) c.getNotes().get(0); 
     1545                                                n.setPropertyValue(rs.getString(i)); 
     1546                                                n.setPropertyType("Body"); // HARD CODE 
     1547                                        } 
     1548                                } catch (Exception e) { 
     1549                                        log.error(e.getMessage(),e); 
     1550                                } 
     1551 
     1552                        } else if (SQL_FIELD_NICK.equalsIgnoreCase(column)) { 
     1553                                c.getName().getNickname().setPropertyValue(rs.getString(i)); 
    11711554                        } else { 
    11721555                                throw new SQLException("\n=> Unhandled column: " + column); 
  • contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java

    r1103 r1545  
    2323import java.sql.ResultSet; 
    2424import java.sql.Timestamp; 
    25 import java.util.Enumeration; 
    26 import java.util.Iterator; 
     25import java.util.Hashtable; 
    2726import java.util.List; 
    2827 
     28import javax.naming.Context; 
     29import javax.naming.NamingEnumeration; 
    2930import javax.naming.NamingException; 
     31import javax.naming.directory.DirContext; 
     32import javax.naming.directory.InitialDirContext; 
     33import javax.naming.directory.SearchControls; 
     34import javax.naming.directory.SearchResult; 
    3035import javax.sql.DataSource; 
    3136 
     
    3843import com.funambol.framework.tools.DBTools; 
    3944import com.funambol.framework.tools.DataSourceTools; 
    40 import com.novell.ldap.LDAPAttribute; 
    41 import com.novell.ldap.LDAPAttributeSet; 
    42 import com.novell.ldap.LDAPConnection; 
    43 import com.novell.ldap.LDAPEntry; 
    44 import com.novell.ldap.LDAPException; 
    45 import com.novell.ldap.LDAPSearchResults; 
    46 import com.novell.ldap.util.Base64; 
    4745 
    4846public abstract class PIMEntityDAO { 
     
    123121        // -----------------------------------------------------------Public methods 
    124122 
     123        @SuppressWarnings("unchecked") 
    125124        protected String LdapUID(String server, String dc, String user) 
    126125                        throws Exception { 
    127126 
    128                 LDAPConnection ldap = new LDAPConnection(); 
    129                 String searchAttrs[] = { "uidNumber" }; 
    130                 String id_owner = null; 
    131  
    132                 try { 
    133  
    134                         ldap.connect(server, 389); 
    135                         LDAPSearchResults searchResults = ldap.search(dc, 
    136                                         LDAPConnection.SCOPE_SUB, "(uid=" + user + ")", 
    137                                         searchAttrs, false); 
    138  
    139                         while (searchResults.hasMore()) { 
    140  
    141                                 LDAPEntry nextEntry = null; 
    142                                 try { 
    143                                         nextEntry = searchResults.next(); 
    144                                 } catch (LDAPException e) { 
    145                                         if (e.getResultCode() == LDAPException.LDAP_TIMEOUT 
    146                                                         || e.getResultCode() == LDAPException.CONNECT_ERROR) 
    147                                                 break; 
    148                                         else 
    149                                                 continue; 
    150                                 } 
    151                                 LDAPAttributeSet attributeSet = nextEntry.getAttributeSet(); 
    152                                 Iterator allAttributes = attributeSet.iterator(); 
    153  
    154                                 while (allAttributes.hasNext()) { 
    155  
    156                                         LDAPAttribute attribute = (LDAPAttribute) allAttributes 
    157                                                         .next(); 
    158                                         String attributeName = attribute.getName(); 
    159                                         Enumeration allValues = attribute.getStringValues(); 
    160  
    161                                         if (allValues != null) { 
    162  
    163                                                 while (allValues.hasMoreElements()) { 
    164  
    165                                                         String Value = (String) allValues.nextElement(); 
    166  
    167                                                         if (Base64.isLDIFSafe(Value)) { 
    168                                                         } else { 
    169                                                                 Value = Base64.encode(Value.getBytes()); 
    170                                                         } 
    171  
    172                                                         if (attributeName.equalsIgnoreCase("uidNumber")) { 
    173                                                                 id_owner = Value; 
    174                                                                 break; 
    175                                                         } 
    176  
    177                                                 } 
    178                                         } 
    179                                 } 
    180                         } 
    181  
    182                         ldap.disconnect(); 
    183  
    184                         if (id_owner == null) { 
    185                                 throw new LDAPException(); 
    186                         } 
    187  
    188                 } catch (LDAPException e) { 
    189                         log.info("Error while connecting and binding to LDAP: " 
    190                                         + e.toString()); 
    191                 } 
    192  
    193                 return id_owner; 
     127                String uidNumber=null; 
     128                 
     129                Hashtable env = new Hashtable(); 
     130        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
     131        env.put(Context.PROVIDER_URL, "ldap://" + server + ":" + 389); 
     132         
     133        DirContext ctx = new InitialDirContext(env); 
     134        // Searching User 
     135        SearchControls ctls = new SearchControls(); 
     136        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); 
     137        ctls.setCountLimit(1); 
     138        ctls.setTimeLimit(10000); // Espera no max 10 segundos 
     139        String filter = "(uid=" + user + ")"; 
     140         
     141        NamingEnumeration answer = ctx.search(dc, filter, ctls); 
     142        if (answer.hasMore()) { 
     143            SearchResult sr = (SearchResult) answer.next(); 
     144            try { 
     145                // Getting User attributes 
     146                uidNumber = sr.getAttributes().get("uidNumber").get(0).toString(); 
     147            } catch (Exception e) { 
     148                e.printStackTrace(); 
     149            } 
     150        } 
     151        ctx.close(); 
     152                if (uidNumber == null) { 
     153                        log.info("Error while connecting and binding to LDAP"); 
     154                } 
     155 
     156                return uidNumber; 
     157 
     158             
     159//              LDAPConnection ldap = new LDAPConnection(); 
     160//              String searchAttrs[] = { "uidNumber" }; 
     161//              String id_owner = null; 
     162// 
     163//              try { 
     164// 
     165//                      ldap.connect(server, 389); 
     166//                      LDAPSearchResults searchResults = ldap.search(dc, 
     167//                                      LDAPConnection.SCOPE_SUB, "(uid=" + user + ")", 
     168//                                      searchAttrs, false); 
     169// 
     170//                      while (searchResults.hasMore()) { 
     171// 
     172//                              LDAPEntry nextEntry = null; 
     173//                              try { 
     174//                                      nextEntry = searchResults.next(); 
     175//                              } catch (LDAPException e) { 
     176//                                      if (e.getResultCode() == LDAPException.LDAP_TIMEOUT 
     177//                                                      || e.getResultCode() == LDAPException.CONNECT_ERROR) 
     178//                                              break; 
     179//                                      else 
     180//                                              continue; 
     181//                              } 
     182//                              LDAPAttributeSet attributeSet = nextEntry.getAttributeSet(); 
     183//                              Iterator allAttributes = attributeSet.iterator(); 
     184// 
     185//                              while (allAttributes.hasNext()) { 
     186// 
     187//                                      LDAPAttribute attribute = (LDAPAttribute) allAttributes 
     188//                                                      .next(); 
     189//                                      String attributeName = attribute.getName(); 
     190//                                      Enumeration allValues = attribute.getStringValues(); 
     191// 
     192//                                      if (allValues != null) { 
     193// 
     194//                                              while (allValues.hasMoreElements()) { 
     195// 
     196//                                                      String Value = (String) allValues.nextElement(); 
     197// 
     198//                                                      if (Base64.isLDIFSafe(Value)) { 
     199//                                                      } else { 
     200//                                                              Value = Base64.encode(Value.getBytes()); 
     201//                                                      } 
     202// 
     203//                                                      if (attributeName.equalsIgnoreCase("uidNumber")) { 
     204//                                                              id_owner = Value; 
     205//                                                              break; 
     206//                                                      } 
     207// 
     208//                                              } 
     209//                                      } 
     210//                              } 
     211//                      } 
     212// 
     213//                      ldap.disconnect(); 
     214// 
     215//                      if (id_owner == null) { 
     216//                              throw new LDAPException(); 
     217//                      } 
     218// 
     219//              } catch (LDAPException e) { 
     220//                      log.info("Error while connecting and binding to LDAP: " 
     221//                                      + e.toString()); 
     222//              } 
     223//              return id_owner; 
    194224        } 
    195225 
  • contrib/psync/src/main/sql/postgresql/create_schema.sql

    r1103 r1545  
    1 ALTER TABLE phpgw_cal ALTER title TYPE character varying(255); 
    2 ALTER TABLE phpgw_cal ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar; 
    3 ALTER TABLE phpgw_cal ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
     1--ALTER TABLE phpgw_cal ALTER title TYPE character varying(255); 
     2--ALTER TABLE phpgw_cal ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar; 
     3--ALTER TABLE phpgw_cal ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
    44 
    5 ALTER TABLE phpgw_cc_contact ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar; 
    6 ALTER TABLE phpgw_cc_contact ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
    7 ALTER TABLE phpgw_cc_contact ADD COLUMN category character varying(20); 
     5--ALTER TABLE phpgw_cc_contact ADD COLUMN last_status char(1) DEFAULT 'N'::bpchar; 
     6--ALTER TABLE phpgw_cc_contact ADD COLUMN last_update int8 DEFAULT (date_part('epoch'::text, ('now'::text)::timestamp(3) with time zone) * (1000)::double precision); 
     7--ALTER TABLE phpgw_cc_contact ADD COLUMN category character varying(20); 
    88 
  • contrib/psync/src/main/sql/postgresql/drop_schema.sql

    r1009 r1545  
    1 ALTER TABLE public.phpgw_cal DROP COLUMN last_status; 
    2 ALTER TABLE public.phpgw_cal DROP COLUMN last_update; 
     1--ALTER TABLE public.phpgw_cal DROP COLUMN last_status; 
     2--ALTER TABLE public.phpgw_cal DROP COLUMN last_update; 
    33 
    4 ALTER TABLE public.phpgw_cc_contact DROP COLUMN last_status; 
    5 ALTER TABLE public.phpgw_cc_contact DROP COLUMN last_update; 
    6 ALTER TABLE public.phpgw_cc_contact DROP COLUMN category; 
     4--ALTER TABLE public.phpgw_cc_contact DROP COLUMN last_status; 
     5--ALTER TABLE public.phpgw_cc_contact DROP COLUMN last_update; 
     6--ALTER TABLE public.phpgw_cc_contact DROP COLUMN category; 
Note: See TracChangeset for help on using the changeset viewer.