Changeset 1103 for contrib/psync/src/main/java/br/com/prognus/psync/items
- Timestamp:
- 07/08/09 19:14:32 (15 years ago)
- Location:
- contrib/psync/src/main/java/br/com/prognus/psync/items
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMCalendarDAO.java
r1009 r1103 135 135 private Sync4jPrincipal principal = null; 136 136 137 private Boolean sourceQuery = false; 138 private Timestamp date1 = null; 139 private Timestamp date2 = null; 140 137 141 /* 138 142 * @see PIMEntityDAO#PIMEntityDAO(String, String) 139 143 */ 140 public PIMCalendarDAO(String jndiDataSourceName, Sync4jPrincipal principal ){144 public PIMCalendarDAO(String jndiDataSourceName, Sync4jPrincipal principal, String sourceQuery) throws Exception { 141 145 142 146 super(jndiDataSourceName, principal.getUsername()); 143 147 log.info("\n\n=> Created new PIMCalendarDAO for data source " + jndiDataSourceName + " and user ID " + userId); 144 148 this.principal = principal; 149 150 if(sourceQuery != null){ 151 this.sourceQuery = true; 152 findDates(sourceQuery); 153 } 145 154 } 146 155 … … 178 187 long id_cal = 0; 179 188 189 long datea1 = 0; 190 long datea2 = 0; 191 long dateb1 = 0; 192 180 193 try { 181 194 … … 202 215 } 203 216 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 // } 268 289 269 290 } 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()); 272 292 } finally { 273 293 DBTools.close(con, ps, rs); … … 810 830 dtStart = getDateFromString(stringFrom(c.getCalendarContent().getDtStart())); 811 831 dtEnd = getDateFromString(stringFrom(c.getCalendarContent().getDtEnd())); 832 833 long hj = System.currentTimeMillis(); 834 if(dtStart.getTime() > hj){ 835 return twins; 836 } 812 837 813 838 StringBuffer sqlGetCalendarTwinList = new StringBuffer(SQL_GET_EXP_PIM_CALENDAR_ID_LIST_BY_USER); … … 1437 1462 } 1438 1463 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 1439 1502 } -
contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMContactDAO.java
r1009 r1103 68 68 + "WHERE (id_owner = ?) " 69 69 + "AND ((given_names is null AND (?) = '') " 70 + "OR ( lower(given_names)= ?)) "70 + "OR (given_names = ?)) " 71 71 + "AND ((family_names is null AND (?) = '') " 72 + "OR ( lower(family_names)= ?)) ";72 + "OR (family_names = ?)) "; 73 73 74 74 private static final String SQL_INSERT_INTO_FNBL_PIM_CONTACT = "INSERT INTO phpgw_cc_contact " … … 1006 1006 } 1007 1007 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); 1012 1010 StringBuilder sb = new StringBuilder(100); 1013 1011 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"); 1018 1017 1019 1018 log.info(sb.toString()); … … 1022 1021 + SQL_ORDER_BY_ID); 1023 1022 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); 1028 1027 rs = ps.executeQuery(); 1029 1028 -
contrib/psync/src/main/java/br/com/prognus/psync/items/dao/PIMEntityDAO.java
r1009 r1103 70 70 * Creates a new instance of PIMEntityDAO, ready to be linked to a given 71 71 * DataSource. 72 * 72 * 73 73 * @param jndiDataSourceName 74 74 * the jndiname of the datasource to use … … 197 197 * Looks up the data source, making some guess attempts based on 198 198 * jndiDataSourceName. 199 * 199 * 200 200 * @throws Exception 201 201 */ … … 216 216 * Retrieves the UID list of the new items belonging to the user filtered 217 217 * according to the given time interval. 218 * 218 * 219 219 * @param since 220 220 * the earliest allowed last-update Timestamp … … 234 234 * Retrieves the UID list of the deleted items belonging to the user 235 235 * filtered according to the given time interval. 236 * 236 * 237 237 * @param since 238 238 * the earliest allowed last-update Timestamp … … 252 252 * Retrieves the UID list of the updated items belonging to the user 253 253 * filtered according to the given time interval. 254 * 254 * 255 255 * @param since 256 256 * the earliest allowed last-update Timestamp … … 273 273 * Retrieves the UID list of the items belonging to the user filtered 274 274 * according to the given time interval and status. 275 * 275 * 276 276 * @param since 277 277 * the earliest allowed last-update Timestamp … … 289 289 /** 290 290 * Checks (safely) whether the property is unset. 291 * 291 * 292 292 * @param property 293 293 * may be null 294 294 * @return false only if the property value is a non-null, but possibly 295 295 * empty (""), string 296 * 296 * 297 297 * @see PIMEntityDAO#stringFrom(Property) 298 298 */ … … 304 304 /** 305 305 * Checks (safely) whether the property is unset or set to an empty string. 306 * 306 * 307 307 * @param property 308 308 * may be null 309 309 * @return false only if the property value is a non-null non-empty string 310 * 310 * 311 311 * @see PIMEntityDAO#stringFrom(Property, boolean) 312 312 */ … … 327 327 * considered as an acceptable value for the property: in such a case, an 328 328 * empty String object will be returned. 329 * 329 * 330 330 * @param property 331 331 * may be null … … 349 349 * stringFrom(..., false) will be considered as explicitly kept blank if its 350 350 * value is "". This means that single field deletions can be made tunable. 351 * 351 * 352 352 * @param property 353 353 * may be null … … 356 356 * null; otherwise, in such a case an empty String object will be 357 357 * returned 358 * 358 * 359 359 * @return if existing (and not empty if emptyImpliesNull is true), the 360 360 * property value will be returned as a String object … … 380 380 /** 381 381 * Gets a substring in a safe way. 382 * 382 * 383 383 * @param string 384 384 * may be null or longer than maxLength -
contrib/psync/src/main/java/br/com/prognus/psync/items/manager/PIMCalendarManager.java
r1009 r1103 43 43 44 44 /** 45 * @throws Exception 45 46 * @see PIMEntityDAO#PIMEntityDAO(String, String) 46 47 */ 47 public PIMCalendarManager(String jndiDataSourceName, 48 Sync4jPrincipal principal) { 48 public PIMCalendarManager(String jndiDataSourceName, Sync4jPrincipal principal, String sourceQuery) { 49 49 50 this.dao = new PIMCalendarDAO(jndiDataSourceName, principal); 50 try { 51 this.dao = new PIMCalendarDAO(jndiDataSourceName, principal, sourceQuery); 52 } catch (Exception e) { 53 } 51 54 super.dao = this.dao; 52 55 … … 60 63 /** 61 64 * Updates a calendar. 62 * 65 * 63 66 * @param uid 64 67 * the UID of the calendar
Note: See TracChangeset
for help on using the changeset viewer.