List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.rti.zcore.dar.report.OIDailyActivityReport.java
/** */* w ww. ja v a 2 s.c o m*/ * @param beginDate * @param endDate * @param siteId */ public void getPatientRegister(Date beginDate, Date endDate, int siteId) { PreparedStatement ps = null; ResultSet rs = null; String sql = null; Form encounterForm = ((Form) DynaSiteObjects.getForms().get(new Long(132))); String className = "org.rti.zcore.dar.gen." + StringManipulation.fixClassname(encounterForm.getName()); Class clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { e.printStackTrace(); } Connection conn = null; try { conn = DatabaseUtils.getZEPRSConnection(org.rti.zcore.Constants.DATABASE_ADMIN_USERNAME); // Get the stock each patient used. try { balanceBF = new OIPatient(); received = new OIPatient(); balanceCF = new OIPatient(); onHand = new OIPatient(); losses = new OIPatient(); Integer currentBalance = null; //HashMap<Long, List<StockControl>> stockMap = InventoryDAO.getPatientStockMap(conn, siteId, beginDate, endDate); HashMap<Long, StockReport> balanceMap = InventoryDAO.getBalanceMap(conn, siteId, null, endDate); HashMap<Long, StockReport> balanceBFMap = InventoryDAO.getBalanceMap(conn, siteId, beginDate, endDate); //EncounterData encounter = (EncounterData) PatientItemDAO.getEncounterRawValues(conn, encounterForm, "132", encounterId, clazz); List<DropdownItem> list = WidgetUtils.getList(conn, "item", "id", "WHERE (ITEM_GROUP_ID > 3 AND ITEM_GROUP_ID < 9)", "ORDER BY id", DropdownItem.class, null); for (DropdownItem dropdownItem : list) { Long itemId = Long.valueOf(dropdownItem.getDropdownId()); /*List<StockControl> stockChanges = (List<StockControl>) InventoryDAO.getStockChanges(conn, itemId, siteId, beginDate, endDate); List<StockControl> patientStockChanges = stockMap.get(itemId); if (patientStockChanges == null) { patientStockChanges = new ArrayList<StockControl>(); } List<StockControl> stockEncounterChanges = InventoryDAO.getStockEncounterChanges(conn, itemId, siteId, beginDate, endDate, stockChanges, patientStockChanges); StockReport stockReport = InventoryDAO.generateStockSummary(conn, itemId, beginDate, stockEncounterChanges, false); currentBalance = stockReport.getOnHand();*/ List<StockControl> stockChanges = (List<StockControl>) InventoryDAO.getStockChanges(conn, itemId, siteId, beginDate, endDate); StockReport stockReport = balanceMap.get(itemId); if (stockReport == null) { currentBalance = 0; } else { currentBalance = stockReport.getOnHand(); } Integer stockReceived = 0; Integer stockLoss = 0; int i = 0; if (stockChanges.size() > 0) { for (Iterator iterator = stockChanges.iterator(); iterator.hasNext();) { StockControl stock = (StockControl) iterator.next(); i++; Integer changeType = stock.getType_of_change(); Integer quantity = stock.getChange_value(); //expiryValue = stock.getExpiry_date(); /*Timestamp created = stock.getCreated();*/ if (quantity != null) { /*if (expiryValue != null) { Boolean sixMonthsExpiry = DateUtils.checkExpiry(endDate, expiryValue); // TODO: need to make sure that previous stock is not exhausted // currently you may use the remaining field in the form to tweak the results. if (sixMonthsExpiry == true) { //stock6monthExpiry++; stock6monthExpiry = currentBalance; if (remaining != null) { stockRemaining = stockRemaining + remaining; } // do not display expiry unless stock6monthExpiry >0 if (stock6monthExpiry >0) { if (isExpirySet == false) { expiry = expiryValue; isExpirySet = true; } } } }*/ switch (changeType.intValue()) { case 3263: // received stockReceived = stockReceived + quantity; break; case 3265: // loss stockLoss = stockLoss + quantity; break; /* case 3266: // Pos. Adjust. stockPosAdjust = stockPosAdjust + quantity; break; case 3267: // Neg. Adjust. stockNegAdjust = stockNegAdjust + quantity; break; case 3279: // Out-of-stock if (i==1) { // calc how many days since this out-of-stock record was created long days = DateUtils.calculateDays(created, endDate); outOfStockDays = Long.valueOf(days).intValue(); if (outOfStockDays == 0) { outOfStockDays = 1; } } break;*/ default: break; } } } } /*StockControl beginningStockControl = InventoryDAO.getBeginningStockBalance(conn, 161, itemId, beginDate); Integer beginningBalance = beginningStockControl.getBalance();*/ StockReport stockReportBbf = balanceBFMap.get(itemId); Integer beginningBalance = 0; if (stockReportBbf == null) { beginningBalance = 0; } else { beginningBalance = stockReportBbf.getOnHand(); } Integer stockOnHand = beginningBalance + stockReceived; // keep the report easy-to-read - not a bunch of zeros. if (stockLoss == 0) { stockLoss = null; } if (stockReceived == 0) { stockReceived = null; } if (currentBalance == 0) { currentBalance = null; } if (beginningBalance == 0) { beginningBalance = null; } if (stockOnHand == 0) { stockOnHand = null; } switch (itemId.intValue()) { case 51: balanceBF.setAcyclovir200mg(beginningBalance); balanceCF.setAcyclovir200mg(currentBalance); received.setAcyclovir200mg(stockReceived); onHand.setAcyclovir200mg(stockOnHand); losses.setAcyclovir200mg(stockLoss); break; case 52: balanceBF.setAcyclovirIVInfusion(beginningBalance); balanceCF.setAcyclovirIVInfusion(currentBalance); received.setAcyclovirIVInfusion(stockReceived); onHand.setAcyclovirIVInfusion(stockOnHand); losses.setAcyclovirIVInfusion(stockLoss); break; case 50: balanceBF.setAminosidineSulphate(beginningBalance); balanceCF.setAminosidineSulphate(currentBalance); received.setAminosidineSulphate(stockReceived); onHand.setAminosidineSulphate(stockOnHand); losses.setAminosidineSulphate(stockLoss); break; case 49: balanceBF.setAminosidineSulphateliquid(beginningBalance); balanceCF.setAminosidineSulphateliquid(currentBalance); received.setAminosidineSulphateliquid(stockReceived); onHand.setAminosidineSulphateliquid(stockOnHand); losses.setAminosidineSulphateliquid(stockLoss); break; case 44: balanceBF.setAmphotericinBInjection(beginningBalance); balanceCF.setAmphotericinBInjection(currentBalance); received.setAmphotericinBInjection(stockReceived); onHand.setAmphotericinBInjection(stockOnHand); losses.setAmphotericinBInjection(stockLoss); break; case 48: balanceBF.setCeftriaxoneInj250mgIM(beginningBalance); balanceCF.setCeftriaxoneInj250mgIM(currentBalance); received.setCeftriaxoneInj250mgIM(stockReceived); onHand.setCeftriaxoneInj250mgIM(stockOnHand); losses.setCeftriaxoneInj250mgIM(stockLoss); break; case 47: balanceBF.setCiprofloxacinTabs500mg(beginningBalance); balanceCF.setCiprofloxacinTabs500mg(currentBalance); received.setCiprofloxacinTabs500mg(stockReceived); onHand.setCiprofloxacinTabs500mg(stockOnHand); losses.setCiprofloxacinTabs500mg(stockLoss); break; case 46: balanceBF.setCotrimoxazoleDS960mg(beginningBalance); balanceCF.setCotrimoxazoleDS960mg(currentBalance); received.setCotrimoxazoleDS960mg(stockReceived); onHand.setCotrimoxazoleDS960mg(stockOnHand); losses.setCotrimoxazoleDS960mg(stockLoss); break; case 174: balanceBF.setCotrimoxazoleTabs480mg(beginningBalance); balanceCF.setCotrimoxazoleTabs480mg(currentBalance); received.setCotrimoxazoleTabs480mg(stockReceived); onHand.setCotrimoxazoleTabs480mg(stockOnHand); losses.setCotrimoxazoleTabs480mg(stockLoss); break; case 45: balanceBF.setCotrimoxazolesusp240mg_5ml(beginningBalance); balanceCF.setCotrimoxazolesusp240mg_5ml(currentBalance); received.setCotrimoxazolesusp240mg_5ml(stockReceived); onHand.setCotrimoxazolesusp240mg_5ml(stockOnHand); losses.setCotrimoxazolesusp240mg_5ml(stockLoss); break; case 35: balanceBF.setDiflucan200mg(beginningBalance); balanceCF.setDiflucan200mg(currentBalance); received.setDiflucan200mg(stockReceived); onHand.setDiflucan200mg(stockOnHand); losses.setDiflucan200mg(stockLoss); break; case 37: balanceBF.setDiflucanInfusion(beginningBalance); balanceCF.setDiflucanInfusion(currentBalance); received.setDiflucanInfusion(stockReceived); onHand.setDiflucanInfusion(stockOnHand); losses.setDiflucanInfusion(stockLoss); break; case 36: balanceBF.setDiflucansuspension(beginningBalance); balanceCF.setDiflucansuspension(currentBalance); received.setDiflucansuspension(stockReceived); onHand.setDiflucansuspension(stockOnHand); losses.setDiflucansuspension(stockLoss); break; case 39: balanceBF.setFluconazole150mg(beginningBalance); balanceCF.setFluconazole150mg(currentBalance); received.setFluconazole150mg(stockReceived); onHand.setFluconazole150mg(stockOnHand); losses.setFluconazole150mg(stockLoss); break; case 38: balanceBF.setFluconazole200mg(beginningBalance); balanceCF.setFluconazole200mg(currentBalance); received.setFluconazole200mg(stockReceived); onHand.setFluconazole200mg(stockOnHand); losses.setFluconazole200mg(stockLoss); break; case 40: balanceBF.setFluconazole50mg(beginningBalance); balanceCF.setFluconazole50mg(currentBalance); received.setFluconazole50mg(stockReceived); onHand.setFluconazole50mg(stockOnHand); losses.setFluconazole50mg(stockLoss); break; case 41: balanceBF.setKetaconazole200mg(beginningBalance); balanceCF.setKetaconazole200mg(currentBalance); received.setKetaconazole200mg(stockReceived); onHand.setKetaconazole200mg(stockOnHand); losses.setKetaconazole200mg(stockLoss); break; case 42: balanceBF.setMiconazoleNitrate2OralGel(beginningBalance); balanceCF.setMiconazoleNitrate2OralGel(currentBalance); received.setMiconazoleNitrate2OralGel(stockReceived); onHand.setMiconazoleNitrate2OralGel(stockOnHand); losses.setMiconazoleNitrate2OralGel(stockLoss); break; case 43: balanceBF.setNystatinOralSuspension100000Units(beginningBalance); balanceCF.setNystatinOralSuspension100000Units(currentBalance); received.setNystatinOralSuspension100000Units(stockReceived); onHand.setNystatinOralSuspension100000Units(stockOnHand); losses.setNystatinOralSuspension100000Units(stockLoss); break; case 53: balanceBF.setPyridoxine25mg(beginningBalance); balanceCF.setPyridoxine25mg(currentBalance); received.setPyridoxine25mg(stockReceived); onHand.setPyridoxine25mg(stockOnHand); losses.setPyridoxine25mg(stockLoss); break; default: break; } } /*if (patient != null) { this.setOnHand(patient); }*/ } catch (SQLException e) { log.error(e); } /*} } catch (SQLException e) { log.error(e); }*/ // For each patient, load the report class and add this patient to the list // also increment the total dispensed values totalDispensed = new OIPatient(); try { //rs = getOIEncounters(conn, siteId, beginDate, endDate); rs = InventoryUtils.getPatientDispensaryEncounters(conn, siteId, beginDate, endDate); } catch (Exception e) { e.printStackTrace(); } try { while (rs.next()) { try { Long encounterId = rs.getLong("id"); Long patientId = rs.getLong("patient_id"); String districtPatientId = rs.getString("district_patient_id"); String firstName = rs.getString("first_name"); String surname = rs.getString("surname"); Date dateVisit = rs.getDate("date_visit"); int currentSiteId = rs.getInt("site_id"); Integer ageCategory = rs.getInt("age_category"); String createdBy = rs.getString("created_by"); Timestamp created = rs.getTimestamp("created"); OIPatient patient = new OIPatient(); patient.setEncounterId(encounterId); patient.setPatientId(patientId); patient.setClientId(districtPatientId); patient.setFirstName(firstName); patient.setSurname(surname); patient.setDateVisit(dateVisit); patient.setSiteId(currentSiteId); patient.setPharmacist(createdBy); patient.setCreated(created); switch (ageCategory) { case 3283: patient.setChildOrAdult("A"); break; case 3284: patient.setChildOrAdult("C"); break; default: patient.setChildOrAdult("A"); break; } EncounterData encounter = (EncounterData) PatientItemDAO.getEncounterRawValues(conn, encounterForm, "132", encounterId, clazz); Map encMap = encounter.getEncounterMap(); Set encSet = encMap.entrySet(); boolean isOiVisit = false; for (Iterator iterator = encSet.iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); Long key = (Long) entry.getKey(); Integer value = (Integer) entry.getValue(); int n = 0; if (key != null) { switch (key.intValue()) { case 51: patient.setAcyclovir200mg(value); isOiVisit = true; if (totalDispensed.getAcyclovir200mg() != null) { n = totalDispensed.getAcyclovir200mg() + value; } else { n = value; } totalDispensed.setAcyclovir200mg(n); break; case 52: patient.setAcyclovirIVInfusion(value); isOiVisit = true; if (totalDispensed.getAcyclovirIVInfusion() != null) { n = totalDispensed.getAcyclovirIVInfusion() + value; } else { n = value; } totalDispensed.setAcyclovirIVInfusion(n); break; case 50: patient.setAminosidineSulphate(value); isOiVisit = true; if (totalDispensed.getAminosidineSulphate() != null) { n = totalDispensed.getAminosidineSulphate() + value; } else { n = value; } totalDispensed.setAminosidineSulphate(n); break; case 49: patient.setAminosidineSulphateliquid(value); isOiVisit = true; if (totalDispensed.getAminosidineSulphateliquid() != null) { n = totalDispensed.getAminosidineSulphateliquid() + value; } else { n = value; } totalDispensed.setAminosidineSulphateliquid(n); break; case 44: patient.setAmphotericinBInjection(value); isOiVisit = true; if (totalDispensed.getAmphotericinBInjection() != null) { n = totalDispensed.getAmphotericinBInjection() + value; } else { n = value; } totalDispensed.setAmphotericinBInjection(n); break; case 48: patient.setCeftriaxoneInj250mgIM(value); isOiVisit = true; if (totalDispensed.getCeftriaxoneInj250mgIM() != null) { n = totalDispensed.getCeftriaxoneInj250mgIM() + value; } else { n = value; } totalDispensed.setCeftriaxoneInj250mgIM(n); break; case 47: patient.setCiprofloxacinTabs500mg(value); isOiVisit = true; if (totalDispensed.getCiprofloxacinTabs500mg() != null) { n = totalDispensed.getCiprofloxacinTabs500mg() + value; } else { n = value; } totalDispensed.setCiprofloxacinTabs500mg(n); break; case 46: patient.setCotrimoxazoleDS960mg(value); isOiVisit = true; if (totalDispensed.getCotrimoxazoleDS960mg() != null) { n = totalDispensed.getCotrimoxazoleDS960mg() + value; } else { n = value; } totalDispensed.setCotrimoxazoleDS960mg(n); break; case 174: patient.setCotrimoxazoleTabs480mg(value); isOiVisit = true; if (totalDispensed.getCotrimoxazoleTabs480mg() != null) { n = totalDispensed.getCotrimoxazoleTabs480mg() + value; } else { n = value; } totalDispensed.setCotrimoxazoleTabs480mg(n); break; case 45: patient.setCotrimoxazolesusp240mg_5ml(value); isOiVisit = true; if (totalDispensed.getCotrimoxazolesusp240mg_5ml() != null) { n = totalDispensed.getCotrimoxazolesusp240mg_5ml() + value; } else { n = value; } totalDispensed.setCotrimoxazolesusp240mg_5ml(n); break; case 35: patient.setDiflucan200mg(value); isOiVisit = true; if (totalDispensed.getDiflucan200mg() != null) { n = totalDispensed.getDiflucan200mg() + value; } else { n = value; } totalDispensed.setDiflucan200mg(n); break; case 37: patient.setDiflucanInfusion(value); isOiVisit = true; if (totalDispensed.getDiflucanInfusion() != null) { n = totalDispensed.getDiflucanInfusion() + value; } else { n = value; } totalDispensed.setDiflucanInfusion(n); break; case 36: patient.setDiflucansuspension(value); isOiVisit = true; if (totalDispensed.getDiflucansuspension() != null) { n = totalDispensed.getDiflucansuspension() + value; } else { n = value; } totalDispensed.setDiflucansuspension(n); break; case 39: patient.setFluconazole150mg(value); isOiVisit = true; if (totalDispensed.getFluconazole150mg() != null) { n = totalDispensed.getFluconazole150mg() + value; } else { n = value; } totalDispensed.setFluconazole150mg(n); break; case 38: patient.setFluconazole200mg(value); isOiVisit = true; if (totalDispensed.getFluconazole200mg() != null) { n = totalDispensed.getFluconazole200mg() + value; } else { n = value; } totalDispensed.setFluconazole200mg(n); break; case 40: patient.setFluconazole50mg(value); isOiVisit = true; if (totalDispensed.getFluconazole50mg() != null) { n = totalDispensed.getFluconazole50mg() + value; } else { n = value; } totalDispensed.setFluconazole50mg(n); break; case 41: patient.setKetaconazole200mg(value); isOiVisit = true; if (totalDispensed.getKetaconazole200mg() != null) { n = totalDispensed.getKetaconazole200mg() + value; } else { n = value; } totalDispensed.setKetaconazole200mg(n); break; case 42: patient.setMiconazoleNitrate2OralGel(value); isOiVisit = true; if (totalDispensed.getMiconazoleNitrate2OralGel() != null) { n = totalDispensed.getMiconazoleNitrate2OralGel() + value; } else { n = value; } totalDispensed.setMiconazoleNitrate2OralGel(n); break; case 43: patient.setNystatinOralSuspension100000Units(value); isOiVisit = true; if (totalDispensed.getNystatinOralSuspension100000Units() != null) { n = totalDispensed.getNystatinOralSuspension100000Units() + value; } else { n = value; } totalDispensed.setNystatinOralSuspension100000Units(n); break; case 53: patient.setPyridoxine25mg(value); isOiVisit = true; if (totalDispensed.getPyridoxine25mg() != null) { n = totalDispensed.getPyridoxine25mg() + value; } else { n = value; } totalDispensed.setPyridoxine25mg(n); break; default: break; } } } // don't add this patient if it's not an OI visit if (isOiVisit == true) { // check if this is the first visit - there might be multiples ones for this encounter Date firstVisit = EncountersDAO.getFirstVisit(conn, patientId); if (firstVisit.getTime() == dateVisit.getTime()) { patient.setRevisit(false); } else { patient.setRevisit(true); } } /*if (patient.getChildOrAdult().equals("A")) { this.addPatient(patient); }*/ if (isOiVisit == true) { patient.setEncounter(encounter); this.addPatient(patient); } } catch (SQLException e) { log.error(e); } } } catch (SQLException e) { log.error(e); } } catch (Exception e) { e.printStackTrace(); } finally { try { conn.close(); } catch (SQLException e) { log.error(e); } } }
From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java
@Test public void testDatetime() throws SQLException { trace("test DATETIME"); ResultSet rs;// ww w. ja v a 2 s . c o m Object o; // rs = stat.executeQuery("call date '99999-12-23'"); // rs.next(); // assertEquals("99999-12-23", rs.getString(1)); // rs = stat.executeQuery("call timestamp '99999-12-23 01:02:03.000'"); // rs.next(); // assertEquals("99999-12-23 01:02:03.0", rs.getString(1)); // rs = stat.executeQuery("call date '-99999-12-23'"); // rs.next(); // assertEquals("-99999-12-23", rs.getString(1)); // rs = stat.executeQuery("call timestamp '-99999-12-23 01:02:03.000'"); // rs.next(); // assertEquals("-99999-12-23 01:02:03.0", rs.getString(1)); stat = conn.createStatement(); // stat.execute("CREATE TABLE test(ID INT PRIMARY KEY,VALUE DATETIME)"); stat.execute( "INSERT INTO test (column1,column6,column2,column3) VALUES (1,'2011-11-11 0:0:0', 13, 'testDatetime')"); stat.execute( "INSERT INTO test (column1,column6,column2,column3) VALUES (2,'2002-02-02 02:02:02', 13, 'testDatetime')"); stat.execute( "INSERT INTO test (column1,column6,column2,column3) VALUES (3,'1800-01-01 0:0:0', 13, 'testDatetime')"); stat.execute( "INSERT INTO test (column1,column6,column2,column3) VALUES (4,'9999-12-31 23:59:59', 13, 'testDatetime')"); stat.execute( "INSERT INTO test (column1,column6,column2,column3) VALUES (5,'9999-12-31 23:59:59', 13, 'testDatetime')"); // stat.execute("INSERT INTO test (column1,column6,column2,column3) VALUES(5,NULL)"); rs = stat.executeQuery("SELECT column1,column6 FROM test where column3='testDatetime' ORDER BY column1"); // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] { // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0, // 10 }); // rs = stat.executeQuery("SELECT * FROM test ORDER BY ID"); // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] { // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0, // 10 }); rs.next(); java.sql.Date date; java.sql.Time time; Timestamp ts; date = rs.getDate(2); assertTrue(!rs.wasNull()); time = rs.getTime(2); assertTrue(!rs.wasNull()); ts = rs.getTimestamp(2); assertTrue(!rs.wasNull()); trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString()); trace("Date ms: " + date.getTime() + " Time ms:" + time.getTime() + " Timestamp ms:" + ts.getTime()); trace("1970 ms: " + Timestamp.valueOf("1970-01-01 00:00:00.0").getTime()); assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), date.getTime()); assertEquals(Timestamp.valueOf("1970-01-01 00:00:00.0").getTime(), time.getTime()); assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), ts.getTime()); assertTrue(date.equals(java.sql.Date.valueOf("2011-11-11"))); assertTrue(time.equals(java.sql.Time.valueOf("00:00:00"))); assertTrue(ts.equals(Timestamp.valueOf("2011-11-11 00:00:00.0"))); assertFalse(rs.wasNull()); o = rs.getObject(2); trace(o.getClass().getName()); assertTrue(o instanceof Timestamp); assertTrue(((Timestamp) o).equals(Timestamp.valueOf("2011-11-11 00:00:00"))); assertFalse(rs.wasNull()); rs.next(); date = rs.getDate("COLUMN6"); assertTrue(!rs.wasNull()); time = rs.getTime("COLUMN6"); assertTrue(!rs.wasNull()); ts = rs.getTimestamp("COLUMN6"); assertTrue(!rs.wasNull()); trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString()); assertEquals("2002-02-02", date.toString()); assertEquals("02:02:02", time.toString()); assertEquals("2002-02-02 02:02:02.0", ts.toString()); rs.next(); assertEquals("1800-01-01", rs.getDate("column6").toString()); assertEquals("00:00:00", rs.getTime("column6").toString()); assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("column6").toString()); rs.next(); assertEquals("9999-12-31", rs.getDate("Column6").toString()); assertEquals("23:59:59", rs.getTime("Column6").toString()); assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Column6").toString()); // assertTrue(!rs.next()); }
From source file:org.kuali.kra.negotiations.service.NegotiationServiceImpl.java
@Override public List<NegotiationActivityHistoryLineBean> getNegotiationActivityHistoryLineBeans( List<NegotiationActivity> activities) { List<NegotiationActivityHistoryLineBean> beans = new ArrayList<NegotiationActivityHistoryLineBean>(); for (NegotiationActivity activity : activities) { if (activity.getLocation() != null && activity.getActivityType() != null) { NegotiationActivityHistoryLineBean bean = new NegotiationActivityHistoryLineBean(activity); beans.add(bean);/* w w w . j a v a 2 s. c o m*/ } } Collections.sort(beans); // now set the effective dates and calculate the location days. Date previousStartDate = null; Date previousEndDate = null; String previousLocation = ""; int counter = 1; List<NegotiationActivityHistoryLineBean> beansToReturn = new ArrayList<NegotiationActivityHistoryLineBean>(); for (NegotiationActivityHistoryLineBean bean : beans) { if (StringUtils.equals(previousLocation, bean.getLocation())) { if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate) && isDateBetween(bean.getEndDate(), previousStartDate, previousEndDate)) { //current date range lies within the previous date range setBeanStuff(bean, null, null, ZERO_DAYS_LONG_STRING); //leave previous alone } else if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate) && (bean.getEndDate() == null || bean.getEndDate().after(previousEndDate))) { //current date range starts within the previous range, but finishes past it. Date previousEndDatePlusOneDay = new Date( previousEndDate.getTime() + NegotiationActivity.MILLISECS_PER_DAY); previousEndDate = bean.getEndDate() != null ? bean.getEndDate() : new Date(Calendar.getInstance().getTimeInMillis()); setBeanStuff(bean, previousEndDatePlusOneDay, bean.getEndDate(), NegotiationActivity.getNumberOfDays(previousEndDatePlusOneDay, bean.getEndDate())); } else { //completely separate range. previousStartDate = bean.getStartDate(); previousEndDate = bean.getEndDate(); setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(), NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate())); } } else { // new location so set the effective date previousStartDate = bean.getStartDate(); previousEndDate = bean.getEndDate(); previousLocation = bean.getLocation(); setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(), NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate())); if (!beansToReturn.isEmpty()) { beansToReturn.add(new NegotiationActivityHistoryLineBean()); } } bean.setLineNumber(String.valueOf(counter)); beansToReturn.add(bean); counter++; } return beansToReturn; }
From source file:org.kuali.kfs.module.tem.document.service.TravelDocumentServiceTest.java
/** * Find a PerDiem to use for the unit test * @param date a date for the unit test// w w w . j a v a 2s.co m * @return a PerDiem */ private PerDiem findSomePerDiem(java.sql.Date date) { final BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class); final PerDiemService perDiemService = SpringContext.getBean(PerDiemService.class); Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put(KFSPropertyConstants.ACTIVE, Boolean.TRUE); final List<PrimaryDestination> dests = new ArrayList<PrimaryDestination>(); dests.addAll(boService.findMatching(PrimaryDestination.class, fieldValues)); if (dests.size() > 1) { Random r = new Random(); int priDestIndex = r.nextInt(dests.size()); PerDiem perDiem = perDiemService.getPerDiem(dests.get(priDestIndex).getId(), new java.sql.Timestamp(date.getTime()), date); while (perDiem == null || org.apache.commons.lang.ObjectUtils.equals(perDiem.getPrimaryDestinationId(), TemConstants.CUSTOM_PRIMARY_DESTINATION_ID)) { priDestIndex = r.nextInt(dests.size()); perDiem = perDiemService.getPerDiem(dests.get(priDestIndex).getId(), new java.sql.Timestamp(date.getTime()), date); } return perDiem; } return null; }
From source file:com.krawler.esp.servlets.deskeramob.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request//w ww .j a v a 2s. c om * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SessionExpiredException { response.setContentType("text/html;charset=UTF-8"); ResultSet rs = null; ResultSet rsForSubQ = null; PreparedStatement pstmt = null; String result = ""; Connection conn = null; try { conn = DbPool.getConnection(); int action = Integer.parseInt(request.getParameter("action")); int mode = Integer.parseInt(request.getParameter("mode")); switch (action) { case 0: // generate application id String u = request.getParameter("u"); String p = request.getParameter("p"); String d = request.getParameter("d"); String udid = request.getParameter("udid"); result = generateAppID(conn, u, p, d, udid); break; case 1: // dashboard request int limit = 15, offset = 0; String userid = getUserid(conn, request.getParameter("applicationid").toString()); String projectlist = DashboardHandler.getProjectList(conn, userid, 1000, 0, ""); JSONArray projList = null; try { JSONObject projListObj = new JSONObject(projectlist); projList = projListObj.getJSONArray("data"); } catch (JSONException ex) { result = "{\"data\":[{\"success\":false,\"data\":" + ex.getMessage() + "}]}"; } switch (mode) { case 1: // due tasks try { PreparedStatement pstmt1 = null; JSONObject jobj = new JSONObject(); String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } if (projList == null) { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } else { for (int i = 0; i < projList.length(); i++) { JSONObject temp = projList.getJSONObject(i); String projid = temp.getString("id"); String qry = ""; String projName = ""; boolean moderator = DashboardHandler.isModerator(conn, userid, projid); if (!moderator) { qry = "(SELECT taskid FROM proj_task WHERE projectid=? AND taskid NOT IN " + "(SELECT taskid FROM proj_taskresourcemapping)) " + "UNION " + "(SELECT taskid FROM proj_taskresourcemapping WHERE resourceid = ? " + "AND taskid IN (SELECT taskid FROM proj_task WHERE projectid = ?))"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); pstmt1.setString(2, userid); pstmt1.setString(3, projid); } else { qry = "SELECT taskid FROM proj_task WHERE projectid = ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); } rs1 = pstmt1.executeQuery(); String tids = ""; while (rs1.next()) { tids += "'" + rs1.getString("taskid") + "',"; } if (tids.length() > 0) { tids = tids.substring(0, (tids.length() - 1)); pstmt1 = conn.prepareStatement( "SELECT projectname FROM project WHERE projectid = ?"); pstmt1.setString(1, projid); rs1 = pstmt1.executeQuery(); if (rs1.next()) { projName = rs1.getString("projectname"); } qry = "SELECT priority,taskname,percentcomplete,DATE_FORMAT(startdate,'%D %b %y') AS startdate,DATE_FORMAT(enddate,'%D %b %y') AS enddate, taskid " + "FROM proj_task " + "WHERE percentcomplete < 100 AND taskid IN (" + tids + ") AND (date(enddate)>=date(now())) AND (date(startdate) <= date(now()))"; // pstmt.setInt(1, limit); pstmt1 = conn.prepareStatement(qry); rs1 = pstmt1.executeQuery(); while (rs1.next()) { JSONObject j = new JSONObject(); j.put("projectname", projName); j.put("taskname", rs1.getString("taskname")); j.put("taskid", rs1.getString("taskid")); j.put("complete", rs1.getString("percentcomplete")); j.put("startdate", rs1.getString("startdate")); j.put("enddate", rs1.getString("enddate")); int ptr = rs1.getInt("priority"); String pStr = "medium"; if (ptr == 0) { pStr = "low"; } else if (ptr == 2) { pStr = "high"; } j.put("priority", pStr); if (moderator) { String res = DashboardHandler.getTaskResources(conn, rs1.getString("taskid"), projid, userid); if (!StringUtil.equal(res, "{}")) { JSONObject jobj1 = new JSONObject(res); JSONArray jarr = jobj1.getJSONArray("data"); String resr = ""; for (int cnt = 0; cnt < jarr.length(); cnt++) { resr += jarr.getJSONObject(cnt).getString("resourcename") + ", "; } resr = resr.substring(0, (resr.length() - 2)); if (!StringUtil.isNullOrEmpty(resr)) { j.put("assignedto", resr); } } } jobj.append("data", j); } } } } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", String.valueOf(count)); jobj.append("msgcount", fin); result = jobj.toString(); } else { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } } catch (JSONException ex) { } break; case 0: // overdue tasks try { JSONObject jobj = new JSONObject(); PreparedStatement pstmt1 = null; String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } if (projList == null) { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } else { for (int i = 0; i < projList.length(); i++) { JSONObject temp = projList.getJSONObject(i); String projid = temp.getString("id"); String qry = ""; String projName = ""; boolean moderator = DashboardHandler.isModerator(conn, userid, projid); if (!moderator) { qry = "(SELECT taskid FROM proj_task WHERE projectid=? AND taskid NOT IN " + "(SELECT taskid FROM proj_taskresourcemapping)) " + "UNION " + "(SELECT taskid FROM proj_taskresourcemapping WHERE resourceid = ?)"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); pstmt1.setString(2, userid); } else { qry = "SELECT taskid FROM proj_task WHERE projectid = ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setString(1, projid); } rs1 = pstmt1.executeQuery(); String tids = ""; while (rs1.next()) { tids += "'" + rs1.getString("taskid") + "',"; } if (tids.length() > 0) { tids = tids.substring(0, (tids.length() - 1)); pstmt1 = conn.prepareStatement( "SELECT projectname FROM project WHERE projectid = ?"); pstmt1.setString(1, projid); rs1 = pstmt1.executeQuery(); if (rs1.next()) { projName = rs1.getString("projectname"); } qry = "SELECT priority,taskname,percentcomplete, datediff(CURRENT_DATE,date(enddate)) as overdueby,DATE_FORMAT(enddate,'%D %b %y') AS enddate, taskid " + "FROM proj_task " + "WHERE percentcomplete < 100 AND taskid IN (" + tids + ") AND date(proj_task.enddate) < date(now()) LIMIT ? OFFSET ?"; pstmt1 = conn.prepareStatement(qry); pstmt1.setInt(1, limit); pstmt1.setInt(2, offset); rs1 = pstmt1.executeQuery(); while (rs1.next()) { JSONObject j = new JSONObject(); j.put("projectname", projName); j.put("taskid", rs1.getString("taskid")); j.put("taskname", rs1.getString("taskname")); j.put("complete", rs1.getString("percentcomplete")); j.put("overdueby", rs1.getString("overdueby")); j.put("enddate", rs1.getString("enddate")); int ptr = rs1.getInt("priority"); String pStr = "medium"; if (ptr == 0) { pStr = "low"; } else if (ptr == 2) { pStr = "high"; } j.put("priority", pStr); if (moderator) { String res = DashboardHandler.getTaskResources(conn, rs1.getString("taskid"), projid, userid); if (!StringUtil.equal(res, "{}")) { JSONObject jobj1 = new JSONObject(res); JSONArray jarr = jobj1.getJSONArray("data"); String resr = ""; for (int cnt = 0; cnt < jarr.length(); cnt++) { resr += jarr.getJSONObject(cnt).getString("resourcename") + ", "; } resr = resr.substring(0, (resr.length() - 2)); if (!StringUtil.isNullOrEmpty(resr)) { j.put("assignedto", resr); } } } jobj.append("data", j); } } } } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", count); jobj.append("msgcount", fin); result = jobj.toString(); } else { result = "{\"success\":[{\"result\": true}],\"msgcount\":[{\"count\":\"" + Integer.toString(count) + "\"}],\"data\":[]}"; } } catch (JSONException ex) { } break; case 2: // calendar events PreparedStatement pstmt1 = null; String query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt1 = conn.prepareStatement(query); pstmt1.setString(1, "0"); pstmt1.setString(2, userid); ResultSet rs1 = pstmt1.executeQuery(); int count = 0; if (rs1.next()) { count = rs1.getInt("count"); } String sqlquery = "SELECT calendarevents.subject,project.projectname, DATE_FORMAT(calendarevents.startts,'%D %b %y') AS 'startdate' ," + "DATE_FORMAT(calendarevents.startts,'%h:%i %p') AS 'starttime'," + "CASE calendarevents.priority WHEN 'm' THEN 'Medium' WHEN 'l' THEN 'Low' WHEN 'h' THEN 'High' END AS priority" + " FROM calendarevents INNER JOIN calendars ON calendars.cid =calendarevents.cid INNER JOIN project ON project.projectid = calendars.userid " + " WHERE project.projectid IN (SELECT project.projectid FROM project INNER JOIN projectmembers ON " + " projectmembers.projectid = project.projectid WHERE userid = ?) AND calendars.timestamp> ? " + " AND date(startts)>=CURRENT_DATE AND date(startts)<=(ADDDATE(CURRENT_DATE, 7)) ORDER BY startts LIMIT ? OFFSET ?"; pstmt = conn.prepareStatement(sqlquery); pstmt.setString(1, userid); pstmt.setString(2, "1970-01-01 00:00:00"); pstmt.setInt(3, limit); pstmt.setInt(4, offset); rsForSubQ = pstmt.executeQuery(); try { JSONObject jobj = new JSONObject(); while (rsForSubQ.next()) { JSONObject j = new JSONObject(); j.put("subject", rsForSubQ.getString("subject")); j.put("projectname", rsForSubQ.getString("projectname")); j.put("startdate", rsForSubQ.getString("startdate")); j.put("starttime", rsForSubQ.getString("starttime")); j.put("priority", rsForSubQ.getString("priority")); jobj.append("data", j); } if (jobj.has("data")) { JSONObject fin = new JSONObject(); fin.put("count", String.valueOf(count)); jobj.append("msgcount", fin); result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } //result = kwljson.GetJsonForGrid(rsForSubQ); break; case 3: // unread personal msgs query = "Select count(post_id) AS count from mailmessages inner join users " + "on users.userid = mailmessages.poster_id where folder = ? and to_id = ? and readflag = false ORDER BY post_time"; pstmt = conn.prepareStatement(query); pstmt.setString(1, "0"); pstmt.setString(2, userid); rsForSubQ = pstmt.executeQuery(); count = 0; if (rsForSubQ.next()) { count = rsForSubQ.getInt("count"); } query = "Select post_id ,concat(fname,' ',lname) as post_fullname,userlogin.username as poster_id , post_text , post_subject ," + " DATE_FORMAT(post_time,'%D %b %y %h:%i%p') as post_time from mailmessages inner join users " + "on users.userid = mailmessages.poster_id inner join userlogin on users.userid =userlogin.userid where folder = ? and to_id = ? and readflag = false ORDER BY post_time DESC"; pstmt = conn.prepareStatement(query); pstmt.setString(1, "0"); pstmt.setString(2, userid); // pstmt.setInt(3, limit); // pstmt.setInt(4, offset); rsForSubQ = pstmt.executeQuery(); //result = kwljson.GetJsonForGrid(rsForSubQ); try { JSONObject jobj = new JSONObject(); String companyid = getCompanyID(conn, userid); String subdomain = CompanyHandler.getCompanySubdomainByCompanyID(conn, companyid); while (rsForSubQ.next()) { JSONObject j = new JSONObject(); j.put("post_id", rsForSubQ.getString("post_id")); j.put("post_fullname", rsForSubQ.getString("post_fullname")); j.put("poster_id", rsForSubQ.getString("poster_id")); j.put("post_text", insertSmiley(rsForSubQ.getString("post_text"), URLUtil.getPageURL(request, com.krawler.esp.web.resource.Links.loginpageFull, subdomain))); j.put("post_subject", rsForSubQ.getString("post_subject")); j.put("post_time", rsForSubQ.getString("post_time")); jobj.append("data", j); } if (jobj.has("data")) { JSONObject temp = new JSONObject(); temp.put("count", String.valueOf(count)); jobj.append("msgcount", temp); result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 4: // list of users's projects String companyid = getCompanyID(conn, userid); boolean isSuperUser = DashboardHandler.isSuperUser(conn, companyid, userid); try { JSONObject projectList = new JSONObject( DashboardHandler.getProjectListMember(conn, userid, 10, 0)); JSONArray projArray = projectList.getJSONArray("data"); int prc = projArray.length(); JSONObject jobj = new JSONObject(); if (prc > 0) { for (int i = 0; i < projArray.length(); i++) { JSONObject j = new JSONObject(); j.put("name", projArray.getJSONObject(i).getString("name")); j.put("id", projArray.getJSONObject(i).getString("id")); jobj.append("data", j); } } if (jobj.has("data")) { result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 5: // list of project resources String responseText = projdb.getProjectResources(conn, request.getParameter("id")); try { JSONObject jobj = new JSONObject(); if (responseText.compareTo("{data:{}}") != 0) { JSONObject resJOBJ = new JSONObject(responseText); JSONArray jArray = resJOBJ.getJSONArray("data"); int prec = jArray.length(); if (prec > 0) { for (int i = 0; i < prec; i++) { JSONObject j = new JSONObject(); j.put("name", jArray.getJSONObject(i).getString("resourcename")); j.put("id", jArray.getJSONObject(i).getString("resourceid")); jobj.append("data", j); } } } if (jobj.has("data")) { result = jobj.toString(); } else { result = "{\"success\":true,\"data\":[]}"; } } catch (JSONException ex) { result = "{\"success\":false,\"data\":" + ex.getMessage() + "}"; } break; case 6:// display project list companyid = getCompanyID(conn, userid); result = AdminServlet.getProjData(conn, request, companyid, ""); break; case 7:// fetch assigned/unassigned members result = getAssiUnAssiProjctMembers(conn, request.getParameter("projectid")); break; case 8:// isSuperUser companyid = getCompanyID(conn, userid); boolean isSuper = DashboardHandler.isSuperUser(conn, companyid, userid); JSONObject temp = new JSONObject(); JSONObject jobj = new JSONObject(); temp.put("superuser", isSuper); jobj.append("data", temp); result = jobj.toString(); break; case 9:// manage members String userids = request.getParameter("userid"); if (StringUtil.isNullOrEmpty(userids)) { result = "{\"result\":[{\"success\":false}], \"msg\":[{\"msgText\": \"Can not remove all project members.\"}]}"; } else { userids = userids.substring(0, (userids.length() - 1)); String[] uids = userids.split(","); String pid = request.getParameter("projectid"); result = manageMembers(conn, pid, uids); } break; case 10: // company user list companyid = getCompanyID(conn, userid); String companyMembers = AdminServlet.getAdminUserData(conn, request, companyid, "", false); // result = "{\"result\":[{\"success\":false}], \"msg\":[{\"msgText\": \"Could not complete your request.\"}]}"; result = "{\"result\":[{\"success\":true}],\"data\":" + companyMembers + "}"; break; } break; case 2: // Update Records userid = getUserid(conn, request.getParameter("applicationid").toString()); switch (mode) { case 1:// set read flag String post_id = request.getParameter("post_id"); String query = "update mailmessages set readflag=true where post_id = ?"; pstmt = conn.prepareStatement(query); pstmt.setString(1, post_id); int rows = pstmt.executeUpdate(); if (rows > 0) { conn.commit(); result = "{\"success\":true}"; } else { result = "{\"success\":false}"; } break; case 2:// update percent value for record String taskid = request.getParameter("taskid"); String pcomplete = request.getParameter("complete"); query = "update proj_task set percentcomplete = ? where taskid = ?"; pstmt = conn.prepareStatement(query); pstmt.setString(1, pcomplete); pstmt.setString(2, taskid); rows = pstmt.executeUpdate(); if (rows > 0) { conn.commit(); result = "{\"success\":true}"; } else { result = "{\"success\":false}"; } break; case 3:// insert tasks try { String projId = request.getParameter("projectid"); pstmt = conn.prepareStatement( "select max(taskindex) as maxindex from proj_task where projectid=?"); pstmt.setString(1, projId); rs = pstmt.executeQuery(); int rowindex = 0; if (rs.next()) { rowindex = rs.getInt(1) + 1; } java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd"); UUID ud = new UUID(2312, 4123); taskid = ud.randomUUID().toString(); String taskname = request.getParameter("name"); String stdate = request.getParameter("start"); String enddate = request.getParameter("end"); int priority = 1; if (!StringUtil.isNullOrEmpty(request.getParameter("priority"))) { priority = Integer.parseInt(request.getParameter("priority")); } String duration = "1"; String nonworkdays = projdb.getNonWorkWeekdays(conn, projId); String Holidays = projdb.getCmpHolidaydays(conn, projId); JSONObject nmweekObj = new JSONObject(nonworkdays); int nonworkweekArr[] = new int[nmweekObj.getJSONArray("data").length()]; for (int cnt = 0; cnt < nmweekObj.getJSONArray("data").length(); cnt++) { nonworkweekArr[cnt] = Integer .parseInt(nmweekObj.getJSONArray("data").getJSONObject(cnt).getString("day")); } String holidayArr[] = new String[1]; holidayArr[0] = ""; if (Holidays.compareTo("{data:{}}") != 0) { nmweekObj = new JSONObject(Holidays); holidayArr = new String[nmweekObj.getJSONArray("data").length()]; for (int cnt = 0; cnt < nmweekObj.getJSONArray("data").length(); cnt++) { holidayArr[cnt] = nmweekObj.getJSONArray("data").getJSONObject(cnt) .getString("holiday"); } } duration = projectReport.calculateWorkingDays(sdf.parse(stdate), sdf.parse(enddate), nonworkweekArr, holidayArr) + ""; pstmt = conn.prepareStatement( "INSERT INTO proj_task(taskid, taskname, duration, startdate, enddate, projectid, " + "taskindex, level, parent, actualstartdate, actualduration, percentcomplete, notes, priority, " + "isparent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); pstmt.setString(1, taskid); pstmt.setString(2, taskname); pstmt.setString(3, duration); java.util.Date DateVal = sdf.parse(stdate); Timestamp ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(4, ts); DateVal = sdf.parse(enddate); ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(5, ts); pstmt.setString(6, projId); pstmt.setString(7, String.valueOf(rowindex)); pstmt.setString(8, "0"); pstmt.setString(9, "0"); DateVal = sdf.parse(stdate); ts = new Timestamp(DateVal.getTime()); pstmt.setTimestamp(10, ts); pstmt.setString(11, duration); pstmt.setString(12, "0"); pstmt.setString(13, ""); pstmt.setInt(14, priority); pstmt.setBoolean(15, false); boolean flag = pstmt.execute(); if (!request.getParameter("assignto").equals("")) { String[] resArray = request.getParameter("assignto").split(","); for (int i = 0; i < resArray.length; i++) { int dur = 0; String rid = resArray[i]; pstmt = conn.prepareStatement( "insert into proj_taskresourcemapping (taskid,resourceid,resduration) values(?,?,?)"); pstmt.setString(1, taskid); pstmt.setString(2, rid); pstmt.setInt(3, dur); pstmt.execute(); } } conn.commit(); result = "{\"success\":[{\"result\":true}]}"; } catch (ParseException ex) { Logger.getLogger(deskeramob.class.getName()).log(Level.SEVERE, null, ex); result = "{\"success\":[{\"result\":false}],\"data\":" + ex.getMessage() + "}"; } catch (JSONException ex) { result = "{\"success\":[{\"result\":false}],\"data\":" + ex.getMessage() + "}"; } break; case 5: // import contacts result = importContacts(conn, request); break; case 6: // export contacts result = exportContacts(conn, request); if (!StringUtil.isNullOrEmpty(result)) { result = "{\"import\":[{\"result\":true}]," + result.substring(1, (result.length() - 1)) + "}"; } else { result = "{\"import\":[{\"result\":true,\"error\":\"There seem to be some problem with server. Could not import contacts.\"}]}"; } break; } break; case 3: // company updates switch (mode) { case 2: //create project userid = getUserid(conn, request.getParameter("applicationid").toString()); String subdomain = CompanyHandler.getCompanySubdomainByUser(conn, userid); String companyid = getCompanyID(conn, userid); result = createProject(conn, request, companyid, subdomain, userid); if (StringUtil.equal("success", result)) { result = "{\"success\":[{\"result\":true}]}"; } else { result = "{\"success\":[{\"result\":false,\"error\":\"" + result + "\"}]}"; } break; case 3: //delete project userid = getUserid(conn, request.getParameter("applicationid").toString()); companyid = getCompanyID(conn, userid); result = AdminServlet.deleteProject(conn, request, companyid, userid, "iPhone"); if (StringUtil.equal("failure", result)) { result = "{\"success\":[{\"result\":false}]}"; DbPool.quietRollback(conn); } else { result = "{\"success\":[{\"result\":true}]}"; conn.commit(); } break; } break; } } catch (JSONException ex) { Logger.getLogger(deskeramob.class.getName()).log(Level.SEVERE, null, ex); result = "{\"success\":[{\"result\":\"1\"}],\"data\":" + ex.getMessage() + "}"; } catch (ServiceException ex) { result = "{\"success\":[{\"result\":\"0\"}],\"data\":" + ex.getMessage() + "}"; } catch (SQLException ex) { result = "{\"success\":[{\"result\":\"0\"}],\"data\":" + ex.getMessage() + "}"; } finally { DbPool.quietClose(conn); response.getWriter().println(result); } response.getWriter().close(); }
From source file:kx.c.java
void w(Date d) { long j = d.getTime(); w(j == nj ? ni : (int) (lg(j) / 86400000 - 10957)); }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
private static void initDateTableValues(String tablename, Connection conn, String tenantId, Date startDate) throws Exception { double dateIncrement = 2.0; PreparedStatement stmt = conn.prepareStatement("upsert into " + tablename + "(" + " ORGANIZATION_ID, " + " \"DATE\", " + " FEATURE, " + " UNIQUE_USERS, " + " TRANSACTIONS, " + " CPU_UTILIZATION, " + " DB_UTILIZATION, " + " REGION, " + " IO_TIME)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, tenantId);/*ww w.j av a2 s. c o m*/ stmt.setDate(2, startDate); stmt.setString(3, "A"); stmt.setInt(4, 10); stmt.setLong(5, 100L); stmt.setBigDecimal(6, BigDecimal.valueOf(0.5)); stmt.setBigDecimal(7, BigDecimal.valueOf(0.2)); stmt.setString(8, R2); stmt.setNull(9, Types.BIGINT); stmt.execute(); startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement)); stmt.setString(1, tenantId); stmt.setDate(2, startDate); stmt.setString(3, "B"); stmt.setInt(4, 20); stmt.setLong(5, 200); stmt.setBigDecimal(6, BigDecimal.valueOf(1.0)); stmt.setBigDecimal(7, BigDecimal.valueOf(0.4)); stmt.setString(8, null); stmt.setLong(9, 2000); stmt.execute(); startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement)); stmt.setString(1, tenantId); stmt.setDate(2, startDate); stmt.setString(3, "C"); stmt.setInt(4, 30); stmt.setLong(5, 300); stmt.setBigDecimal(6, BigDecimal.valueOf(2.5)); stmt.setBigDecimal(7, BigDecimal.valueOf(0.6)); stmt.setString(8, R1); stmt.setNull(9, Types.BIGINT); stmt.execute(); startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement)); stmt.setString(1, tenantId); stmt.setDate(2, startDate); stmt.setString(3, "D"); stmt.setInt(4, 40); stmt.setLong(5, 400); stmt.setBigDecimal(6, BigDecimal.valueOf(3.0)); stmt.setBigDecimal(7, BigDecimal.valueOf(0.8)); stmt.setString(8, R1); stmt.setLong(9, 4000); stmt.execute(); startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement)); stmt.setString(1, tenantId); stmt.setDate(2, startDate); stmt.setString(3, "E"); stmt.setInt(4, 50); stmt.setLong(5, 500); stmt.setBigDecimal(6, BigDecimal.valueOf(3.5)); stmt.setBigDecimal(7, BigDecimal.valueOf(1.2)); stmt.setString(8, R2); stmt.setLong(9, 5000); stmt.execute(); startDate = new Date(startDate.getTime() + (long) (QueryConstants.MILLIS_IN_DAY * dateIncrement)); stmt.setString(1, tenantId); stmt.setDate(2, startDate); stmt.setString(3, "F"); stmt.setInt(4, 60); stmt.setLong(5, 600); stmt.setBigDecimal(6, BigDecimal.valueOf(4.0)); stmt.setBigDecimal(7, BigDecimal.valueOf(1.4)); stmt.setString(8, null); stmt.setNull(9, Types.BIGINT); stmt.execute(); }
From source file:kx.c.java
void w(java.util.Date z) { long j = z.getTime(); w(j == nj ? nf : (lg(j) - k) / 8.64e7); }
From source file:org.kuali.coeus.common.budget.impl.calculator.AbstractBudgetCalculator.java
/** * Use the combined & sorted Prop & LA rates to create Boundary objects. Each Boundary will contain start date & end date. Check * whether any rate changes, and break at this point to create a new boundary. * /* w ww.ja v a 2 s .com*/ * @return List of boundary objects */ public List<Boundary> createBreakupBoundaries(QueryList<AbstractBudgetRate> qlCombinedRates, Date liStartDate, Date liEndDate) { List<Boundary> boundaries = new ArrayList<Boundary>(); if (qlCombinedRates != null && qlCombinedRates.size() > 0) { Date tempStartDate = liStartDate; Date tempEndDate = liEndDate; Date rateChangeDate; GreaterThan greaterThan = new GreaterThan(START_DATE, liStartDate); qlCombinedRates = qlCombinedRates.filter(greaterThan); qlCombinedRates.sort(START_DATE, true); for (AbstractBudgetRate laRate : qlCombinedRates) { rateChangeDate = laRate.getStartDate(); if (rateChangeDate.after(tempStartDate)) { Calendar temEndCal = dateTimeService.getCalendar(rateChangeDate); temEndCal.add(Calendar.DAY_OF_MONTH, -1); try { tempEndDate = dateTimeService.convertToSqlDate(temEndCal.get(Calendar.YEAR) + "-" + (temEndCal.get(Calendar.MONTH) + 1) + "-" + temEndCal.get(Calendar.DAY_OF_MONTH)); } catch (ParseException e) { tempEndDate = new Date(rateChangeDate.getTime() - 86400000); } Boundary boundary = new Boundary(tempStartDate, tempEndDate); boundaries.add(boundary); tempStartDate = rateChangeDate; } } /** * add one more boundary if no rate change on endDate and atleast one boundary is present */ if (boundaries.size() > 0) { Boundary boundary = new Boundary(tempStartDate, liEndDate); boundaries.add(boundary); } /** * if no rate changes during the period create one boundary with startDate & endDate same as that for line item */ if (boundaries.size() == 0) { Boundary boundary = new Boundary(liStartDate, liEndDate); boundaries.add(boundary); } } return boundaries; }
From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborScrubberProcess.java
/** * This method modifies the run date if it is before the cutoff time specified by calling the setCutoffTimeForPreviousDay * method. See KULRNE-70 This method is public to facilitate unit testing * * @param currentDate/* w ww. jav a 2 s . c o m*/ * @return */ public java.sql.Date calculateRunDate(java.util.Date currentDate) { Calendar currentCal = Calendar.getInstance(); currentCal.setTime(currentDate); if (isCurrentDateBeforeCutoff(currentCal)) { // time to set the date to the previous day's last minute/second currentCal.add(Calendar.DAY_OF_MONTH, -1); // per old COBOL code (see KULRNE-70), // the time is set to 23:59:59 (assuming 0 ms) currentCal.set(Calendar.HOUR_OF_DAY, 23); currentCal.set(Calendar.MINUTE, 59); currentCal.set(Calendar.SECOND, 59); currentCal.set(Calendar.MILLISECOND, 0); return new java.sql.Date(currentCal.getTimeInMillis()); } return new java.sql.Date(currentDate.getTime()); }