- Timestamp:
- 07/08/09 19:14:32 (15 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.