List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:com.att.pirates.controller.ProjectController.java
public static List<ProjectDetailsStatusViewModel> getProjectDetailsStatus(String prismId, String uuid) { List<ProjectDetailsStatusViewModel> detailStatus = new ArrayList<ProjectDetailsStatusViewModel>(); try {// w ww .j a v a 2 s . c o m // logger.error("getProjectDetailsStatus, before calling getProjectAppOwners(prismId)"); List<ProjectAppOwnerModel> results = getProjectAppOwners(prismId); // logger.error("getProjectDetailsStatus, after calling getProjectAppOwners(prismId)"); if (!results.isEmpty()) { ArrayList<String> list = new ArrayList<String>(); for (ProjectAppOwnerModel p : results) { list.add(p.getApplicationName()); } // convert the List into a Set Set<String> set = new HashSet<String>(list); // create a new List from the Set // now, they are unique ArrayList<String> distinctApps = new ArrayList<String>(set); Collections.sort(distinctApps); for (String app : distinctApps) { int impactTypeId = DataService.getImpactTypeIdByPrismIdAndApplicationName(prismId, app); boolean validateThreshold = !(impactTypeId == 4); ProjectDetailsStatusViewModel aRow = new ProjectDetailsStatusViewModel(); List<ProjectAppOwnerModel> thisAppRows = getAppOwnerModelObjectsByAppName(results, app); if (!thisAppRows.isEmpty()) { aRow.setApplicationId(thisAppRows.get(0).getApplicationId()); aRow.setApplication(app); aRow.setImpactType(impactTypeId); // 1. BR List<ProjectAppOwnerModel> allBRs = getProjectAppOwnerModelObjectByArtifactName(thisAppRows, PiratesConstants.BR); if (!allBRs.isEmpty()) { aRow.setBR(allBRs.get(0).getPercentageComplete()); aRow.setBRheaderDueDate(allBRs.get(0).getDueDate()); aRow.setBRDuedate(allBRs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allBRs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allBRs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setBR(aRow.getBR() + "," + h.getPercentageComplete()); aRow.setBRDuedate(aRow.getBRDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setBRStr(getRowDueDatePercentageString(aRow.getBR(), aRow.getBRDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getBRheaderDueDate(), false, validateThreshold)); } // end processing isEmpty() else { aRow.setBR("0%"); aRow.setBRDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setBRheaderDueDate("NA"); aRow.setBRStr(getRowDueDatePercentageString(aRow.getBR(), aRow.getBRDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getBRheaderDueDate(), false, validateThreshold)); } // end of BR // 2. SR List<ProjectAppOwnerModel> allSRs = getProjectAppOwnerModelObjectByArtifactName(thisAppRows, PiratesConstants.SR); if (!allSRs.isEmpty()) { aRow.setSR(allSRs.get(0).getPercentageComplete()); aRow.setSRheaderDueDate(allSRs.get(0).getDueDate()); aRow.setSRDuedate(allSRs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allSRs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allSRs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setSR(aRow.getSR() + "," + h.getPercentageComplete()); aRow.setSRDuedate(aRow.getSRDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setSRStr(getRowDueDatePercentageString(aRow.getSR(), aRow.getSRDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getSRheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setSR("0%"); aRow.setSRDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setSRheaderDueDate("NA"); aRow.setSRStr(getRowDueDatePercentageString(aRow.getSR(), aRow.getSRDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getSRheaderDueDate(), true, validateThreshold)); } // end of SR // 3. HLD List<ProjectAppOwnerModel> allHLDs = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.HLD); if (!allHLDs.isEmpty()) { aRow.setHLD(allHLDs.get(0).getPercentageComplete()); aRow.setHLDheaderDueDate(allHLDs.get(0).getDueDate()); aRow.setHLDDuedate(allHLDs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allHLDs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allHLDs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setHLD(aRow.getHLD() + "," + h.getPercentageComplete()); aRow.setHLDDuedate(aRow.getHLDDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setHLDStr(getRowDueDatePercentageString(aRow.getHLD(), aRow.getHLDDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getHLDheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setHLD("0%"); aRow.setHLDDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setHLDheaderDueDate("NA"); aRow.setHLDStr(getRowDueDatePercentageString(aRow.getHLD(), aRow.getHLDDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getHLDheaderDueDate(), true, validateThreshold)); } // end of HLD // 4. AID List<ProjectAppOwnerModel> allAIDs = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.AID); if (!allAIDs.isEmpty()) { aRow.setAID(allAIDs.get(0).getPercentageComplete()); aRow.setAIDheaderDueDate(allAIDs.get(0).getDueDate()); aRow.setAIDDuedate(allAIDs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allAIDs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allAIDs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setAID(aRow.getAID() + "," + h.getPercentageComplete()); aRow.setAIDDuedate(aRow.getAIDDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setAIDStr(getRowDueDatePercentageString(aRow.getAID(), aRow.getAIDDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getAIDheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setAID("0%"); aRow.setAIDDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setAIDheaderDueDate("NA"); aRow.setAIDStr(getRowDueDatePercentageString(aRow.getAID(), aRow.getAIDDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getAIDheaderDueDate(), true, validateThreshold)); } // end of AID // 5. AD List<ProjectAppOwnerModel> allADs = getProjectAppOwnerModelObjectByArtifactName(thisAppRows, PiratesConstants.DES); if (!allADs.isEmpty()) { aRow.setDES(allADs.get(0).getPercentageComplete()); aRow.setDESheaderDueDate(allADs.get(0).getDueDate()); aRow.setDESDuedate(allADs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allADs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allADs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setDES(aRow.getDES() + "," + h.getPercentageComplete()); aRow.setDESDuedate(aRow.getDESDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setDESStr(getRowDueDatePercentageString(aRow.getDES(), aRow.getDESDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getDESheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setDES("0%"); aRow.setDESDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setDESheaderDueDate("NA"); aRow.setDESStr(getRowDueDatePercentageString(aRow.getDES(), aRow.getDESDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getDESheaderDueDate(), true, validateThreshold)); } // end of DES // 6. DEV List<ProjectAppOwnerModel> allDEVs = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.DEV); if (!allDEVs.isEmpty()) { aRow.setDEV(allDEVs.get(0).getPercentageComplete()); aRow.setDEVheaderDueDate(allDEVs.get(0).getDueDate()); aRow.setDEVDuedate(allDEVs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allDEVs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allDEVs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setDEV(aRow.getDEV() + "," + h.getPercentageComplete()); aRow.setDEVDuedate(aRow.getDEVDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setDEVStr(getRowDueDatePercentageString(aRow.getDEV(), aRow.getDEVDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getDEVheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setDEV("0%"); aRow.setDEVDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setDEVheaderDueDate("NA"); aRow.setDEVStr(getRowDueDatePercentageString(aRow.getDEV(), aRow.getDEVDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getDEVheaderDueDate(), true, validateThreshold)); } // end of DEV // 7. IST List<ProjectAppOwnerModel> allISTs = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.IST); if (!allISTs.isEmpty()) { aRow.setIST(allISTs.get(0).getPercentageComplete()); aRow.setISTheaderDueDate(allISTs.get(0).getDueDate()); aRow.setISTDuedate(allISTs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allISTs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allISTs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setIST(aRow.getIST() + "," + h.getPercentageComplete()); aRow.setISTDuedate(aRow.getISTDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setISTStr(getRowDueDatePercentageString(aRow.getIST(), aRow.getISTDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getISTheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setIST("0%"); aRow.setISTDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setISTheaderDueDate("NA"); aRow.setISTStr(getRowDueDatePercentageString(aRow.getIST(), aRow.getISTDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getISTheaderDueDate(), true, validateThreshold)); } // end of IST // 8. ISTExec List<ProjectAppOwnerModel> allISTExecs = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.ISTExec); if (!allISTExecs.isEmpty() && impactTypeId != 4) { aRow.setISTExec(allISTExecs.get(0).getPercentageComplete()); aRow.setISTExecheaderDueDate(allISTExecs.get(0).getDueDate()); aRow.setISTExecDuedate(allISTExecs.get(0).getDateCreated()); aRow.setUpdatedByUUID(allISTExecs.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allISTExecs.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setISTExec(aRow.getISTExec() + "," + h.getPercentageComplete()); aRow.setISTExecDuedate(aRow.getISTExecDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setISTExecStr(getRowDueDatePercentageString(aRow.getISTExec(), aRow.getISTExecDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getISTExecheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setISTExec("0%"); aRow.setISTExecDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setISTExecheaderDueDate("NA"); aRow.setISTExecStr(getRowDueDatePercentageString(aRow.getISTExec(), aRow.getISTExecDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getISTExecheaderDueDate(), true, validateThreshold)); } // end of ISTExec // 9. CloseOut List<ProjectAppOwnerModel> allCloseout = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.CLOSEOUT); if (!allCloseout.isEmpty()) { aRow.setCloseOut(allCloseout.get(0).getPercentageComplete()); aRow.setCloseOutheaderDueDate(allCloseout.get(0).getDueDate()); aRow.setCloseOutDuedate(allCloseout.get(0).getDateCreated()); aRow.setUpdatedByUUID(allCloseout.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allCloseout.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setCloseOut(aRow.getCloseOut() + "," + h.getPercentageComplete()); aRow.setCloseOutDuedate(aRow.getCloseOutDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setCloseOutStr(getRowDueDatePercentageString(aRow.getCloseOut(), aRow.getCloseOutDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getCloseOutheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setCloseOut("0%"); aRow.setCloseOutDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setCloseOutheaderDueDate("NA"); aRow.setCloseOutStr(getRowDueDatePercentageString(aRow.getCloseOut(), aRow.getCloseOutDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getCloseOutheaderDueDate(), true, validateThreshold)); } // end of CloseOut // 10. Agile List<ProjectAppOwnerModel> allAgile = getProjectAppOwnerModelObjectByArtifactName( thisAppRows, PiratesConstants.AGILE); if (!allAgile.isEmpty()) { aRow.setAgile(allAgile.get(0).getPercentageComplete()); aRow.setAgileheaderDueDate(allAgile.get(0).getDueDate()); aRow.setAgileDuedate(allAgile.get(0).getDateCreated()); aRow.setUpdatedByUUID(allAgile.get(0).getUpdatedByUUID()); // get history records List<AppProjectArtifactOwnersHistory> history = getStatusHistoryListByApplicationOwner( allAgile.get(0)); if (!history.isEmpty()) { for (AppProjectArtifactOwnersHistory h : history) { // for percentage aRow.setAgile(aRow.getAgile() + "," + h.getPercentageComplete()); aRow.setAgileDuedate(aRow.getAgileDuedate() + "," + h.getDateLogged()); aRow.setUpdatedByUUID(aRow.getUpdatedByUUID() + "," + h.getUpdatedByUUID()); } } // after processing each history record aRow.setAgileStr(getRowDueDatePercentageString(aRow.getAgile(), aRow.getAgileDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getAgileheaderDueDate(), true, validateThreshold)); } // end processing isEmpty() else { aRow.setAgile("0%"); aRow.setAgileDuedate("NA"); aRow.setUpdatedByUUID("NA"); aRow.setAgileheaderDueDate("NA"); aRow.setAgileStr(getRowDueDatePercentageString(aRow.getAgile(), aRow.getAgileDuedate(), aRow.getUpdatedByUUID(), uuid, aRow.getAgileheaderDueDate(), true, validateThreshold)); } // end of Agile aRow.setPrismId(prismId); detailStatus.add(aRow); } // end thisAppRow.ANY() check } // end distinct appName loop } } catch (Exception ex) { logger.error(msgHeader + "Error occurred getProjectDetailsStatuc... " + ex.getMessage()); } // new code SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yyyy"); List<Date> tmpDates = new ArrayList<Date>(); Date BR = null; Date SR = null; Date HLD = null; Date AID = null; Date AD = null; Date DEV = null; Date IST = null; Date ISTExec = null; Date CloseOut = null; Date Agile = null; // Process BR for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getBRheaderDueDate()))) { try { Date t = yFormat.parse(i.getBRheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getBRheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); BR = tmpDates.get(0); } tmpDates.clear(); // Process SR for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getSRheaderDueDate()))) { try { Date t = yFormat.parse(i.getSRheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getSRheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); SR = tmpDates.get(0); } tmpDates.clear(); // Process HLD for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getHLDheaderDueDate()))) { try { Date t = yFormat.parse(i.getHLDheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getHLDheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); HLD = tmpDates.get(0); } tmpDates.clear(); // Process AID for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getAIDheaderDueDate()))) { try { Date t = yFormat.parse(i.getAIDheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getAIDheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); AID = tmpDates.get(0); } tmpDates.clear(); // Process AD for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getDESheaderDueDate()))) { try { Date t = yFormat.parse(i.getDESheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getDESheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); AD = tmpDates.get(0); } tmpDates.clear(); // Process DEV for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getDEVheaderDueDate()))) { try { Date t = yFormat.parse(i.getDEVheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getDEVheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); DEV = tmpDates.get(0); } tmpDates.clear(); // Process IST for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getISTheaderDueDate()))) { try { Date t = yFormat.parse(i.getISTheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getISTheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); IST = tmpDates.get(0); } tmpDates.clear(); // Process ISTExec for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getISTExecheaderDueDate()))) { try { Date t = yFormat.parse(i.getISTExecheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getISTExecheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); ISTExec = tmpDates.get(0); } tmpDates.clear(); // Process Closeout for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getCloseOutheaderDueDate()))) { try { Date t = yFormat.parse(i.getCloseOutheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getCloseOutheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); CloseOut = tmpDates.get(0); } tmpDates.clear(); // Process Agile for (ProjectDetailsStatusViewModel i : detailStatus) { if (!("NA".equalsIgnoreCase(i.getAgileheaderDueDate()))) { try { Date t = yFormat.parse(i.getAgileheaderDueDate()); tmpDates.add(t); } catch (ParseException pe) { logger.error("can't parse date from value " + i.getAgileheaderDueDate() + ", so skipping .. exception: " + pe.getMessage()); } } } if (tmpDates.size() > 0) { // sort all BRduedates, pick the earliest one as the final one Collections.sort(tmpDates, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); Agile = tmpDates.get(0); } tmpDates.clear(); // TODO if (BR != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setBRheaderDueDate(yFormat.format(BR)); } } catch (Exception pe) { logger.error("Can not convert BR from Date " + BR.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (SR != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setSRheaderDueDate(yFormat.format(SR)); } } catch (Exception pe) { logger.error("Can not convert SR from Date " + SR.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (HLD != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setHLDheaderDueDate(yFormat.format(HLD)); } } catch (Exception pe) { logger.error("Can not convert HLD from Date " + HLD.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (AID != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setAIDheaderDueDate(yFormat.format(AID)); } } catch (Exception pe) { logger.error("Can not convert AID from Date " + AID.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (AD != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setDESheaderDueDate(yFormat.format(AD)); } } catch (Exception pe) { logger.error("Can not convert AD from Date " + AD.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (DEV != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setDEVheaderDueDate(yFormat.format(DEV)); } } catch (Exception pe) { logger.error("Can not convert DEV from Date " + DEV.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (IST != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setISTheaderDueDate(yFormat.format(IST)); } } catch (Exception pe) { logger.error("Can not convert IST from Date " + IST.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (ISTExec != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setISTExecheaderDueDate(yFormat.format(ISTExec)); } } catch (Exception pe) { logger.error("Can not convert ISTExec from Date " + ISTExec.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (CloseOut != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setCloseOutheaderDueDate(yFormat.format(CloseOut)); } } catch (Exception pe) { logger.error("Can not convert CloseOut from Date " + CloseOut.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } if (Agile != null) { try { for (ProjectDetailsStatusViewModel i : detailStatus) { i.setAgileheaderDueDate(yFormat.format(Agile)); } } catch (Exception pe) { logger.error("Can not convert Agile from Date " + Agile.toString() + ", pe: " + pe.getMessage() + ". Skipping.."); } } return detailStatus; }
From source file:de.unihannover.l3s.mws.bean.SearchAll.java
public String calculateTimeline(ArrayList<SearchResult> searchResult) { List<String> urlAnalyzed = new ArrayList<String>(); Date dinizio = new Date(); Timeline timeline1 = new Timeline(); timeline1.setHeadline("Starting"); timeline1.setType("default"); timeline1.setStartDate("2009,1"); timeline1.setText("Starting Point"); Asset a = new Asset(); a.setMedia("aaa"); a.setCredit(""); a.setCaption(""); timeline1.setAsset(a);/* ww w .ja v a 2 s . c om*/ timeline1.setDate(new ArrayList<de.unihannover.l3s.mws.model.timeline.Date>()); // if (this.searchResult!=null) for (SearchResult sr : searchResult) { System.out.println(sr.getUrl()); if (sr.getUrl().contains("wikipedia") || sr.getUrl().contains("youtube") || sr.getUrl().contains("slideshare") || sr.getUrl().contains("flickr")) { de.unihannover.l3s.mws.model.timeline.Date date2 = new de.unihannover.l3s.mws.model.timeline.Date(); int year = 2009 + (int) (Math.random() * ((2013 - 2009) + 1)); int month = 1 + (int) (Math.random() * ((12 - 1) + 1)); date2.setStartDate(year + "," + month); date2.setHeadline(sr.getUrl().replace(".", " ").replace("-", " ").replace(",", "").replace("_", " ") .replace("?", "").replace("=", " ")); date2.setText(""); Asset a2 = new Asset(); a2.setCaption(""); a2.setCredit(""); if (sr.getUrl().contains("wikipedia")) { if (!chechAny(urlAnalyzed, sr.getUrl())) { urlAnalyzed.add(sr.getUrl()); SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy,MM"); Date d = DateManager.getWikipediaDate(sr.getUrl()); if (d != null) { String data1 = FORMATTER.format(d); date2.setStartDate(data1); date2.setAsset(a2); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.MONTH, -2); if (dinizio.compareTo(cal.getTime()) > 0) { dinizio = cal.getTime(); timeline1.setStartDate(FORMATTER.format(dinizio)); } a2.setMedia( "http://localhost:8080/mwsace2/javax.faces.resource/img/icon/icon-wikipedia.png.jsf?ln=timeline"); timeline1.getDate().add(date2); } } } else if (sr.getUrl().contains("youtube")) { if (!chechAny(urlAnalyzed, sr.getUrl())) { urlAnalyzed.add(sr.getUrl()); SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy,MM"); Date d = DateManager.getYoutubeDate(sr.getUrl()); if (d != null) { String data1 = FORMATTER.format(d); date2.setStartDate(data1); date2.setAsset(a2); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.MONTH, -2); if (dinizio.compareTo(cal.getTime()) > 0) { dinizio = cal.getTime(); timeline1.setStartDate(FORMATTER.format(dinizio)); } a2.setMedia( "http://localhost:8080/mwsace2/javax.faces.resource/img/icon/y_icon.png.jsf?ln=timeline"); timeline1.getDate().add(date2); } } } else if (sr.getUrl().contains("slideshare")) { if (!chechAny(urlAnalyzed, sr.getUrl()) && sr.getUrl().startsWith("http://www.slideshare.net/") && sr.getUrl().compareTo("http://www.slideshare.net/") != 0 && !sr.getUrl().contains("www.slideshare.net/login")) { urlAnalyzed.add(sr.getUrl()); SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy,MM"); Date d = DateManager.getSlideshareDate(sr.getUrl()); if (d != null) { String data1 = FORMATTER.format(d); date2.setStartDate(data1); date2.setAsset(a2); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.MONTH, -2); if (dinizio.compareTo(cal.getTime()) > 0) { dinizio = cal.getTime(); timeline1.setStartDate(FORMATTER.format(dinizio)); } a2.setMedia( "http://localhost:8080/mwsace2/javax.faces.resource/img/icon/slideshare-icon.png.jsf?ln=timeline"); timeline1.getDate().add(date2); } } } else if (sr.getUrl().contains("flickr")) { a2.setMedia( "http://localhost:8080/mwsace2/javax.faces.resource/img/icon/flickr-icon.png.jsf?ln=timeline"); date2.setAsset(a2); timeline1.getDate().add(date2); } } } //else // System.out.println("SR NULL"); /* de.unihannover.l3s.mws.model.timeline.Date date1=new de.unihannover.l3s.mws.model.timeline.Date(); date1.setStartDate("2009,2"); date1.setHeadline("My first experiment in time-lapse photography"); date1.setText("Nature at its finest in this video."); Asset a1=new Asset(); a1.setMedia(""); a1.setCaption(""); a1.setCredit(""); date1.setAsset(a1); timeline1.getDate().add(date1); */ WholeTimeline wl = new WholeTimeline(); wl.setTimeline(timeline1); if (this.searchResult1 != null) { timeline = (new JSONObject(wl)).toString(); // timeline=" var timeline = new VMM.Timeline(); timeline.init('"+timeline+"'); "; timeline = " $(\"#timeline\").empty(); var timeline = new VMM.Timeline(); timeline.init('" + timeline + "'); "; } else timeline = ""; System.out.println(timeline); return timeline; }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
@Override public List<Motransaction> findbytransactionRegisterList(int theFrom, int theTo, ArrayList<?> theFilterDetails, int moaccountid) throws BankingException { Session aSession = null;/*from w ww. ja va 2 s.c o m*/ String param1 = null, param2 = null, value = null, param3 = "0"; if (theFilterDetails != null) { for (int i = 0; i < theFilterDetails.size(); i++) { if (i == 0) { param1 = theFilterDetails.get(i).toString(); } else if (i == 1) { param2 = theFilterDetails.get(i).toString(); } else if (i == 2) { value = theFilterDetails.get(i).toString(); } else if (i == 3) { param3 = theFilterDetails.get(i).toString(); } } } List<Motransaction> aQueryList = new ArrayList<Motransaction>(); String aCustomerQry = "SELECT *,CASE WHEN moTransaction.rxMasterID IS NULL THEN description ELSE (SELECT NAME FROM rxMaster WHERE " + " rxMasterID=moTransaction.rxMasterID) END 'namedescription' FROM moTransaction WHERE moAccountID =" + moaccountid; Motransaction aMotransaction = null; if (param1 != null && param1.equalsIgnoreCase("Amount")) { if (param2 != null && param2.equalsIgnoreCase("Exact")) aCustomerQry += " and IF(amount < 0, amount*-1, amount) =" + value; else if (param2 != null && param2.equalsIgnoreCase("Greater")) aCustomerQry += " and IF(amount < 0, amount*-1, amount) >" + value; else if (param2 != null && param2.equalsIgnoreCase("Greater or equal")) aCustomerQry += " and IF(amount < 0, amount*-1, amount) >=" + value; else if (param2 != null && param2.equalsIgnoreCase("Less")) aCustomerQry += " and IF(amount < 0, amount*-1, amount) <" + value; else if (param2 != null && param2.equalsIgnoreCase("Less or equal")) aCustomerQry += " and IF(amount < 0, amount*-1, amount) <=" + value; } else if (param1 != null && param1.equalsIgnoreCase("Cleared Status")) { if (param2 != null && param2.equalsIgnoreCase("Reconcile")) aCustomerQry += " and reconciled=1 "; else if (param2 != null && param2.equalsIgnoreCase("Unreconciled")) aCustomerQry += " and reconciled=0 and status=0"; /*if (param3.equals("0")) aCustomerQry += " limit " + theFrom + " ," + theTo; if (param3.equals("1")) aCustomerQry += " limit " + theFrom + " ," + theTo;*/ System.out.println("==============================================>" + aCustomerQry); } else if (param1 != null && param1.equalsIgnoreCase("Date")) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat parseDateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date fromDate = null, toDate = null; try { if (param2 != null) fromDate = parseDateFormat.parse(param2); } catch (ParseException e) { e.printStackTrace(); } if (param2 != null && value.equals("0")) aCustomerQry += " and transactionDate >='" + simpleDateFormat.format(fromDate) + "'"; else if (param2 == null && value != null) aCustomerQry += " and transactionDate <='" + simpleDateFormat.format(toDate) + "'"; else if (param2 != null && value != null && !value.equals("0")) { if (value != null && !value.equals("0")) try { toDate = parseDateFormat.parse(value); } catch (ParseException e) { e.printStackTrace(); } aCustomerQry += " and transactionDate between '" + simpleDateFormat.format(fromDate) + "' and '" + simpleDateFormat.format(toDate) + "'"; } } else if (param1 != null && param1.equalsIgnoreCase("Reference")) { if (param2 != null && param2.equalsIgnoreCase("Contains")) aCustomerQry += " and reference like '%" + value + "%'"; else if (param2 != null && param2.equalsIgnoreCase("Exact")) aCustomerQry += " and reference ='" + value + "'"; } else if (param1 != null && param1.equalsIgnoreCase("G/L Account #")) { aCustomerQry += " and coAccountID =" + param2 + ""; } else if (param1 != null && param1.equalsIgnoreCase("Type")) { if (param2 != null && param2.equalsIgnoreCase("Deposit")) aCustomerQry += " and amount > 0 "; else aCustomerQry += " and amount < 0 "; } //aCustomerQry +=" ORDER BY moTransactionID DESC"; String sort = (String) theFilterDetails.get(theFilterDetails.size() - 1); String descriptionFilter = ""; if (param1 != null && param1.equalsIgnoreCase("Description")) { if (sort.equals("0")) aCustomerQry += " ORDER BY transactionDate ASC"; else aCustomerQry += " ORDER BY transactionDate DESC"; if (param2 != null && param2.equalsIgnoreCase("Contains")) descriptionFilter += " description like '%" + value + "%' or namedescription like '%" + value + "%'"; else if (param2 != null && param2.equalsIgnoreCase("Ends with")) descriptionFilter += " description like '%" + value + "' or namedescription like '%" + value + "'"; else if (param2 != null && param2.equalsIgnoreCase("Exact")) descriptionFilter += " description ='" + value + "' or namedescription = '" + value + "'"; else if (param2 != null && param2.equalsIgnoreCase("Starts with")) descriptionFilter += " description like '" + value + "%' or namedescription like '" + value + "%'"; aCustomerQry = "Select * from (" + aCustomerQry + ")as subquery where " + descriptionFilter; if (sort.equals("0")) aCustomerQry += " limit " + theFrom + " ," + theTo; else aCustomerQry += " limit " + theFrom + " ," + theTo; } else { if (sort.equals("0")) aCustomerQry += " ORDER BY transactionDate ASC limit " + theFrom + " ," + theTo; else aCustomerQry += " ORDER BY transactionDate DESC limit " + theFrom + " ," + theTo; } System.out.println("aCustomerQry===" + aCustomerQry); try { aSession = itsSessionFactory.openSession(); Query aQuery = aSession.createSQLQuery(aCustomerQry); Iterator<?> aIterator = aQuery.list().iterator(); while (aIterator.hasNext()) { aMotransaction = new Motransaction(); Object[] aObj = (Object[]) aIterator.next(); aMotransaction.setMoTransactionId((Integer) aObj[0]); aMotransaction.setRxMasterId((Integer) aObj[1]); aMotransaction.setRxAddressId((Integer) aObj[2]); aMotransaction.setCoAccountId((Integer) aObj[3]); aMotransaction.setMoAccountId((Integer) aObj[4]); if (aObj[5] != null && aObj[5] != "") aMotransaction.setTransDate((String) DateFormatUtils.format((Date) aObj[5], "MM/dd/yyyy")); aMotransaction.setMoTransactionTypeId((Short) aObj[6]); aMotransaction.setMoTypeId((Short) aObj[6]); aMotransaction.setCheckType((Short) aObj[7]); aMotransaction.setReference((String) aObj[8]); aMotransaction.setDescription((String) aObj[9]); aMotransaction.setVoid_((Byte) aObj[10]); aMotransaction.setReconciled((Byte) aObj[11]); aMotransaction.setTempRec((Byte) aObj[12]); aMotransaction.setPrinted((Byte) aObj[13]); aMotransaction.setAmount((BigDecimal) aObj[14]); aMotransaction.setWithDrawel((BigDecimal) aObj[14]); aMotransaction.setDirectDeposit((Byte) aObj[15]); aMotransaction.setBalance((BigDecimal) aObj[16]); aMotransaction.setStatus((Boolean) aObj[17]); aMotransaction.setMemo((String) aObj[18]); aMotransaction.setDisplaydiscription((String) aObj[21]); Date myDate = new Date(); String futureornot = "Current Transaction"; if ((Date) aObj[5] != null) { if (myDate.compareTo((Date) aObj[5]) < 0 || myDate.compareTo((Date) aObj[5]) == 0) { futureornot = "Future Transaction"; } else { futureornot = "Current Transaction"; } } aMotransaction.setFutureorcurrent(futureornot); aQueryList.add(aMotransaction); } } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); throw aBankingException; } finally { aSession.flush(); aSession.close(); aCustomerQry = null; } return aQueryList; }
From source file:com.att.pirates.controller.ProjectController.java
@RequestMapping(value = "/pid/{prismId}/getProjectNotesJson", method = RequestMethod.GET) public @ResponseBody String getCompanies(@PathVariable("prismId") String prismId, HttpServletRequest request) { // logger.error(msgHeader + " getCompanies prismId: " + prismId); JQueryDataTableParamModel param = DataTablesParamUtility.getParam(request); String sEcho = param.sEcho;/*from www . j a va 2 s . c o m*/ int iTotalRecords; // total number of records (unfiltered) int iTotalDisplayRecords; //value will be set when code filters companies by keyword List<Company> allNotes = GlobalDataController.GetCompanies(prismId); iTotalRecords = allNotes.size(); List<Company> companies = new LinkedList<Company>(); for (Company c : allNotes) { if (c.getName().toLowerCase().contains(param.sSearch.toLowerCase()) || c.getAddress().toLowerCase().contains(param.sSearch.toLowerCase()) || c.getTown().toLowerCase().contains(param.sSearch.toLowerCase()) || c.getDateCreated().toLowerCase().contains(param.sSearch.toLowerCase())) { companies.add(c); // add company that matches given search criterion } } iTotalDisplayRecords = companies.size();// number of companies that match search criterion should be returned final int sortColumnIndex = param.iSortColumnIndex; final int sortDirection = param.sSortDirection.equals("asc") ? -1 : 1; Collections.sort(companies, new Comparator<Company>() { @Override public int compare(Company c1, Company c2) { switch (sortColumnIndex) { case 0: return 0; // sort by id is not allowed case 1: return c1.getName().compareTo(c2.getName()) * sortDirection; case 2: return c1.getAddress().compareTo(c2.getAddress()) * sortDirection; case 3: return c1.getTown().compareTo(c2.getTown()) * sortDirection; case 4: SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yyyy"); try { Date c1d = yFormat.parse(c1.getDateCreated()); Date c2d = yFormat.parse(c2.getDateCreated()); return c1d.compareTo(c2d) * sortDirection; } catch (ParseException ex) { logger.error(ex.getMessage()); } } return 0; } }); if (companies.size() < param.iDisplayStart + param.iDisplayLength) { companies = companies.subList(param.iDisplayStart, companies.size()); } else { companies = companies.subList(param.iDisplayStart, param.iDisplayStart + param.iDisplayLength); } try { JsonObject jsonResponse = new JsonObject(); jsonResponse.addProperty("sEcho", sEcho); jsonResponse.addProperty("iTotalRecords", iTotalRecords); jsonResponse.addProperty("iTotalDisplayRecords", iTotalDisplayRecords); Gson gson = new Gson(); jsonResponse.add("aaData", gson.toJsonTree(companies)); String tmp = jsonResponse.toString(); // logger.error(msgHeader + ".. json string: " + tmp); return jsonResponse.toString(); } catch (JsonIOException e) { logger.error(msgHeader + e.getMessage()); } return null; }
From source file:com.att.pirates.controller.ProjectController.java
private void processProjectAppOwnersByArtifactName(List<ProjectAppOwnerModel> existingOwners, List<ProjectAppOwnerModel> userSelectedOwners, String artifactName, String dueDateForArtifact, String UUID, int impactId) { if (impactId == 4 && artifactName.equalsIgnoreCase(PiratesConstants.ISTExec)) { return;/*from w w w. java2 s . c o m*/ } Connection con = null; PreparedStatement updateRow = null; PreparedStatement deleteRow = null; PreparedStatement insertRow = null; PreparedStatement syncRow = null; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String today = format.format(Calendar.getInstance().getTime()); String insertSQL = " INSERT INTO [AppProjectArtifactOwners] " + " ([UUID] " + " ,[DueDate] " + " ,[ArtifactName] " + " ,[PRISMId] " + " ,[ApplicationName] " + " ,[ModuleId] " + " ,[IsPrimaryOwner] " + " ,[MileStoneId] " + " ,[DateCreated] " + " ,[UpdatedByUUID] " + " ,[SystemNote]) " + " VALUES " + " ( ?,?,?,?,?,?,?,?,?,?,?) "; String updateSQL = " UPDATE AppProjectArtifactOwners " + " SET DueDate = ? " + " ,UpdatedByUUID = ? " + " ,SystemNote = ? " + " WHERE " + " UUID = ? and ArtifactName = ? and PRISMId = ? and ApplicationName = ? and ModuleId = ? and MileStoneId = ? "; String deleteSQL = " DELETE FROM AppProjectArtifactOwners " + " WHERE " + " UUID = ? and ArtifactName = ? and PRISMId = ? and ApplicationName = ? and ModuleId = ? and MileStoneId = ? "; // we need to make sure duedates for each artifact for all applications in this project // to be in sync String syncSQL = " Update a " + " Set a.duedate = t.duedate " + " from AppProjectArtifactOwners a " + " join " + " ( " + " select prismid, applicationname, artifactname, duedate " + " from AppProjectArtifactOwners " + " Where artifactname = ? and prismid = ? " + " And applicationname = ? " + " and isprimaryowner = 1 " + " ) t " + " on a.prismid=t.prismid and a.artifactname=t.artifactname " + " and a.applicationname <> t.applicationname " + " where a.isprimaryowner = 1 "; try { List<String> artifactNames = new ArrayList<String>(); String prismId = ""; String applicationName = ""; con = DBUtility.getDBConnection(); con.setAutoCommit(false); insertRow = con.prepareStatement(insertSQL); // inserts boolean isAdd = false; for (ProjectAppOwnerModel o : userSelectedOwners) { if (o.getIsNew()) { if (!isAdd) isAdd = true; logger.error(msgHeader + " userSelectedOwners " + artifactName + " " + o.getUUID() + " is being added.."); insertRow.setString(1, o.getUUID()); insertRow.setString(2, o.getDueDate()); insertRow.setString(3, o.getArtifactName()); insertRow.setString(4, o.getPrismId()); insertRow.setString(5, o.getApplicationName()); insertRow.setInt(6, Integer.valueOf(o.getModuleId())); insertRow.setInt(7, 1); insertRow.setInt(8, Integer.valueOf(o.getMileStoneId())); insertRow.setString(9, today); insertRow.setString(10, o.getUpdatedByUUID()); insertRow.setString(11, "Record created by " + o.getUpdatedByUUID() + " on " + o.getDateCreated()); insertRow.addBatch(); // update artifactNames list if (!artifactNames.contains(o.getArtifactName())) { artifactNames.add(o.getArtifactName()); } if (prismId.isEmpty()) { prismId = o.getPrismId(); } if (applicationName.isEmpty()) { applicationName = o.getApplicationName(); } } } if (isAdd) insertRow.executeBatch(); if (!isAdd) logger.error(msgHeader + " processProjectAppOwnersByArtifactName.. nothing to insert"); // updates boolean isUpdate = false; updateRow = con.prepareStatement(updateSQL); for (ProjectAppOwnerModel o : existingOwners) { if (o.getIsNew()) { // do nothing here... } else { SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yyyy"); Date userSelected = yFormat.parse(dueDateForArtifact); Date existing = yFormat.parse(o.getDueDate()); if (existing.compareTo(userSelected) == 0) { logger.error(msgHeader + " new duedate: " + dueDateForArtifact + " is the same as existing duedate " + o.getDueDate() + " , nothing to do here..."); } else { if (!isUpdate) isUpdate = true; logger.error(msgHeader + " existingOwners " + artifactName + " " + o.getUUID() + " is being updated.."); updateRow.setString(1, dueDateForArtifact); updateRow.setString(2, UUID); updateRow.setString(3, "Record updated by " + UUID + " on " + today); updateRow.setString(4, o.getUUID()); updateRow.setString(5, o.getArtifactName()); updateRow.setString(6, o.getPrismId()); updateRow.setString(7, o.getApplicationName()); updateRow.setInt(8, Integer.valueOf(o.getModuleId())); updateRow.setInt(9, Integer.valueOf(o.getMileStoneId())); updateRow.addBatch(); // update artifactNames list if (!artifactNames.contains(o.getArtifactName())) { artifactNames.add(o.getArtifactName()); } if (prismId.isEmpty()) { prismId = o.getPrismId(); } if (applicationName.isEmpty()) { applicationName = o.getApplicationName(); } } } } if (isUpdate) updateRow.executeBatch(); if (!isUpdate) logger.error(msgHeader + " processProjectAppOwnersByArtifactName.. nothing to update"); // deletes boolean isDelete = false; deleteRow = con.prepareStatement(deleteSQL); for (ProjectAppOwnerModel o : existingOwners) { if (o.getIsNew()) { if (!isDelete) isDelete = true; logger.error(msgHeader + " existingOwners " + artifactName + " " + o.getUUID() + " is being deleted.."); deleteRow.setString(1, o.getUUID()); deleteRow.setString(2, o.getArtifactName()); deleteRow.setString(3, o.getPrismId()); deleteRow.setString(4, o.getApplicationName()); deleteRow.setInt(5, Integer.valueOf(o.getModuleId())); deleteRow.setInt(6, Integer.valueOf(o.getMileStoneId())); deleteRow.addBatch(); } else { // do nothing here } } if (isDelete) deleteRow.executeBatch(); if (!isDelete) logger.error(msgHeader + " processProjectAppOwnersByArtifactName.. nothing to delete"); if (isAdd || isUpdate || isDelete) { // sync up same artifact, same project different application's due dates if (!artifactNames.isEmpty()) { syncRow = con.prepareStatement(syncSQL); for (String a : artifactNames) { logger.error("Setting syncup parameters.. artifactname: " + a + ", prismId: " + prismId + ", applicationName: " + applicationName); syncRow.setString(1, a); syncRow.setString(2, prismId); syncRow.setString(3, applicationName); syncRow.addBatch(); } syncRow.executeBatch(); } con.commit(); } else { logger.error(msgHeader + " processProjectAppOwnersByArtifactName.. nothing to commit"); } } catch (SQLException e) { if (con != null) { try { logger.error(e.getMessage() + ", processProjectAppOwnersByArtifactName.. Transaction is being rolled back.. " + e.getMessage()); con.rollback(); } catch (SQLException excep) { logger.error(excep.getMessage() + ", processProjectAppOwnersByArtifactName.. Transaction is being rolled back.." + excep.getMessage()); try { con.rollback(); } catch (SQLException logOrIgnore) { } } } } catch (Exception ex) { logger.error(ex + ", processProjectAppOwnersByArtifactName.. Transaction is being rolled back.." + ex.getMessage()); try { con.rollback(); } catch (SQLException logOrIgnore) { } } finally { if (updateRow != null) { try { updateRow.close(); } catch (SQLException e) { } } if (deleteRow != null) { try { deleteRow.close(); } catch (SQLException e) { } } if (insertRow != null) { try { insertRow.close(); } catch (SQLException e) { } } if (con != null) { try { con.setAutoCommit(true); con.close(); } catch (SQLException logOrIgnore) { } } } }
From source file:com.relecotech.common.controller.AcceptParameterController.java
@RequestMapping(value = "/{name}", method = RequestMethod.GET) //public String getMovie(@PathVariable String name, ModelMap model) { public @ResponseBody ModelAndView getParameter(@PathVariable String name) throws ParserConfigurationException { //String param =name; try {/*from ww w . ja v a2 s . c o m*/ Map<String, String> valueMap = new HashMap<String, String>(); String[] data = name.split("&"); for (String str : data) { String[] mapPair = str.split("="); valueMap.put(mapPair[0], mapPair[1]); } String logoutUrl = "https://" + valueMap.get("URL") + ".com"; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); SAMLCredential credential = (SAMLCredential) authentication.getCredentials(); TimeZone timeZone = TimeZone.getTimeZone(valueMap.get("timeZone").replace("*", "/")); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm a"); dateFormat.setTimeZone(timeZone); Calendar calobj = Calendar.getInstance(timeZone); String SystemCurrentTime = dateFormat.format(calobj.getTime()); Date SystemCurrentDateTime = dateFormat.parse(SystemCurrentTime); // Date SystemCurrentDateTime = calobj.getTime(); //SFDC Meeting DATE/TIME String sfdcMeetingTime = valueMap.get("d").replace("*", "/"); System.out.println("sfdcMeetingTime=" + sfdcMeetingTime); Date sfdcMeetingDateTime = dateFormat.parse(sfdcMeetingTime); //TIME Before Meeting can satarted Date sfdcMeetingBeforeDateTime = dateFormat .parse(AddSubtractTime.getSubtractedTime(sfdcMeetingTime, timeZone)); //TIME after Meeting cannot be satarted Date sfdcMeetingAfterDateTime = dateFormat .parse(AddSubtractTime.getAddedTime(sfdcMeetingTime, timeZone)); System.out.println("SystemCurrentDateTime=" + SystemCurrentDateTime); System.out.println("sfdcMeetingDateTime=" + sfdcMeetingDateTime); System.out.println("sfdcMeetingAfterDateTime=" + sfdcMeetingAfterDateTime); System.out.println("sfdcMeetingBeforeDateTime=" + sfdcMeetingBeforeDateTime); if (SystemCurrentDateTime.after(sfdcMeetingBeforeDateTime) && SystemCurrentDateTime.before(sfdcMeetingAfterDateTime)) { APIGenerator aPIGenerator = new APIGenerator(); System.out.println("converted id=" + SalesforceIDConverter.convertID(valueMap.get("code"))); System.out.println((credential.getAttributeAsString("ContactId"))); if (valueMap.get("code") .matches(SalesforceIDConverter.convertID(credential.getAttributeAsString("ContactId")))) { System.out.println("valuemap=" + valueMap); System.out.println("logout url=" + logoutUrl); String create = "attendeePW=ap" + "&meetingID=" + valueMap.get("name") + "&moderatorPW=newuser" + "&name=" + valueMap.get("name") + "&logoutURL=" + logoutUrl; System.out.println("create parameter=" + create); XmlParser.runAPI(aPIGenerator.createAPI("create", create)); // String join = "fullName=" + valueMap.get("fullName") + "&meetingID=" + valueMap.get("meetingID") + "&password=newuser"; String join = "fullName=" + credential.getAttributeAsString("username") + "&meetingID=" + valueMap.get("name") + "&password=newuser"; System.out.println("joinparam=" + join); aPIGenerator.createAPI("join", join); return new ModelAndView("redirect:" + aPIGenerator.apiWithChecksum); } else { Map<String, String> responceMap = XmlParser.runAPI( aPIGenerator.createAPI("isMeetingRunning", "meetingID=" + valueMap.get("name"))); String join = "fullName=" + credential.getAttributeAsString("username") + "&meetingID=" + valueMap.get("name") + "&password=ap"; if (responceMap.get("running").matches("true")) { aPIGenerator.createAPI("join", join); return new ModelAndView("redirect:" + aPIGenerator.apiWithChecksum); } else { String student = "<center> <h1>Wait! Presenter has not joined meeting yet!</h1>\n" // +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> " + " <h2>\n" + " Please try after few minutes.\n" + " \n" + "<br>Meeting Date/Time:" + dateFormat.format(sfdcMeetingDateTime) + "<br><a href=" + logoutUrl + ">Back</a>" + " </h2></center> "; // return new ModelAndView("redirect:" + "/student.jsp"); return new ModelAndView("student", "student", student); } } } else { // if (SystemCurrentDateTime.compareTo(sfdcMeetingDateTime) == -1) { String wait = "<center> <h1>Too Early for Meeting!</h1><br></center>\n" // +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> " + " <center> <h2>Meeting is not yet open.<br>\n" + " Please check meeting schedule time. \n<br>" + "<br>Meeting Date/Time:" + dateFormat.format(sfdcMeetingDateTime) + "</h2><h3>System Current Date/Time:" + dateFormat.format(SystemCurrentDateTime) + "<br>*Meeting will open 15 minutes before scheduled time</h3><a href=" + logoutUrl + ">Back</a>" + " </center> "; return new ModelAndView("wait", "wait", wait); } //for Past Date if (SystemCurrentDateTime.compareTo(sfdcMeetingDateTime) == 1) { String wait = "<center> <h1>Meeting is Over!</h1><br></center>\n" // +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> " + " <center> <h2>Meeting can not open.<br>\n" + " Meeting was scheduled on - \n<br>" + "<br>Meeting Date/Time:" + dateFormat.format(sfdcMeetingDateTime) + "</h2><h3><br>System Current Date/Time:" + dateFormat.format(SystemCurrentDateTime) + "<br><a href=" + logoutUrl + ">Back</a>" + " </h3> </center> "; return new ModelAndView("wait", "wait", wait); } // } } catch (Exception ex) { System.out.println("Exception=" + ex); } return null; }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
@Override public List<Motransaction> getTransactionRegisterList(int theFrom, int theTo, ArrayList<?> theTransactionDetails, int moaccountid) throws BankingException { Session aSession = null;/* w w w . j ava2 s. c o m*/ StringBuilder aStringBuilder = new StringBuilder(""); if (moaccountid != 0) { aStringBuilder.append("WHERE moAccountID =" + moaccountid + ""); } if (theTransactionDetails != null) { /*if(theTransactionDetails.get(0) !="" && theTransactionDetails.get(0) != null){ aStringBuilder.append("WHERE moAccountID ="+theTransactionDetails.get(0)+""); }*/ if (theTransactionDetails.get(1) != "" && theTransactionDetails.get(1) != null && theTransactionDetails.get(2) != "" && theTransactionDetails.get(2) != null) { String aTranDateString = theTransactionDetails.get(1).toString(); String aTranToDateString = theTransactionDetails.get(2).toString(); String[] aTranSactionDate = aTranDateString.split("%2F"); String[] aTranSactionToDate = aTranToDateString.split("%2F"); String aFromTranDate = aTranSactionDate[2] + "-" + aTranSactionDate[0] + "-" + aTranSactionDate[1]; String aToTranDate = aTranSactionToDate[2] + "-" + aTranSactionToDate[0] + "-" + aTranSactionToDate[1]; aStringBuilder.append(" AND date(TransactionDate) >= '" + aFromTranDate + "' AND date(TransactionDate) <= '" + aToTranDate + "'"); } if (theTransactionDetails.get(3) != "" && theTransactionDetails.get(3) != null) { aStringBuilder.append(" AND moTransactionTypeID =" + theTransactionDetails.get(3) + ""); } if (theTransactionDetails.get(4) != "" && theTransactionDetails.get(4) != null) { aStringBuilder.append(" AND moTransactionTypeID =" + theTransactionDetails.get(4) + ""); } if (theTransactionDetails.get(5) != "" && theTransactionDetails.get(5) != null) { aStringBuilder.append(" AND moTransactionTypeID =" + theTransactionDetails.get(5) + ""); } if (theTransactionDetails.get(6) != "" && theTransactionDetails.get(6) != null) { aStringBuilder.append(" AND moTransactionTypeID =" + theTransactionDetails.get(6) + ""); } if (theTransactionDetails.get(7) != "" && theTransactionDetails.get(7) != null) { aStringBuilder.append(" AND moTransactionTypeID =" + theTransactionDetails.get(7) + ""); } if (theTransactionDetails.get(8) != "" && theTransactionDetails.get(8) != null) { aStringBuilder.append(" AND Reconciled =" + theTransactionDetails.get(8) + ""); } if (theTransactionDetails.get(9) != "" && theTransactionDetails.get(9) != null) { aStringBuilder.append(" AND Void =" + theTransactionDetails.get(9) + ""); } } List<Motransaction> aQueryList = new ArrayList<Motransaction>(); String aCustomerQry = "SELECT *,CASE WHEN moTransaction.rxMasterID IS NULL THEN description ELSE IF((moTransaction.Void = 1 OR pageflagVoid = 1) ,description,(SELECT NAME FROM rxMaster WHERE rxMasterID=moTransaction.rxMasterID )) END 'namedescription' FROM moTransaction " + aStringBuilder + " ORDER BY moTransactionID DESC LIMIT " + theFrom + ", " + theTo; Motransaction aMotransaction = null; BigDecimal balance = new BigDecimal("0.00"); try { aSession = itsSessionFactory.openSession(); Query aQuery = aSession.createSQLQuery(aCustomerQry); Iterator<?> aIterator = aQuery.list().iterator(); while (aIterator.hasNext()) { aMotransaction = new Motransaction(); Object[] aObj = (Object[]) aIterator.next(); aMotransaction.setMoTransactionId((Integer) aObj[0]); aMotransaction.setRxMasterId((Integer) aObj[1]); aMotransaction.setRxAddressId((Integer) aObj[2]); aMotransaction.setCoAccountId((Integer) aObj[3]); aMotransaction.setMoAccountId((Integer) aObj[4]); if (aObj[5] != null) aMotransaction.setTransDate((String) DateFormatUtils.format((Date) aObj[5], "MM/dd/yyyy")); aMotransaction.setMoTransactionTypeId((Short) aObj[6]); aMotransaction.setMoTypeId((Short) aObj[6]); aMotransaction.setCheckType((Short) aObj[7]); aMotransaction.setReference((String) aObj[8]); aMotransaction.setDescription((String) aObj[9]); aMotransaction.setVoid_((Byte) aObj[10]); aMotransaction.setReconciled((Byte) aObj[11]); aMotransaction.setTempRec((Byte) aObj[12]); aMotransaction.setPrinted((Byte) aObj[13]); aMotransaction.setAmount((BigDecimal) aObj[14]); aMotransaction.setWithDrawel((BigDecimal) aObj[14]); aMotransaction.setDirectDeposit((Byte) aObj[15]); /*if(aMotransaction.getMoTransactionTypeId()!=null){ if(aMotransaction.getMoTransactionTypeId()==0){ System.out.println("DepositAmount=="+aMotransaction.getAmount()); balance=balance.add(aMotransaction.getAmount()); }else{ System.out.println("WithDrawel=="+aMotransaction.getAmount()); balance=balance.add(aMotransaction.getAmount()); } }*/ //balance=balance.multiply(new BigDecimal(-1)); //aMotransaction.setBalance(balance); aMotransaction.setBalance((BigDecimal) aObj[16]); aMotransaction.setStatus((Boolean) aObj[17]); aMotransaction.setMemo((String) aObj[18]); aMotransaction.setDisplaydiscription((String) aObj[21]); Date myDate = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String dateAsString_format = simpleDateFormat.format(myDate); String futureornot = "Current Transaction"; //System.out.println("Date"+(Date)aObj[5]); if ((Date) aObj[5] != null) { if (myDate.compareTo((Date) aObj[5]) < 0 || myDate.compareTo((Date) aObj[5]) == 0) { futureornot = "Future Transaction"; } else { futureornot = "Current Transaction"; } } aMotransaction.setFutureorcurrent(futureornot); aQueryList.add(aMotransaction); } } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); throw aBankingException; } finally { aSession.flush(); aSession.close(); aStringBuilder = null; } return aQueryList; }
From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java
/** * Get the submissions to the assessment made by all users. * /* w ww . j a v a 2 s . c o m*/ * @param assessment * The assessment. * @param sort * The sort. * @param question * An optional question, to use for sort-by-score (the score would be for this question in the submission, not the overall). * @param filterByPermission * if true, return submissions only from users who are currently permitted to submit, otherwise return any submissions found. * @return A List<Submission> of the submissions for the assessment. */ protected List<SubmissionImpl> getAssessmentSubmissions(Assessment assessment, final FindAssessmentSubmissionsSort sort, final Question question, boolean filterByPermission) { // collect the submissions to this assessment List<SubmissionImpl> rv = this.storage.getAssessmentSubmissions(assessment); // get all possible users who can submit Set<String> userIds = this.securityService.getUsersIsAllowed(MnemeService.SUBMIT_PERMISSION, assessment.getContext()); // filter out any userIds that are not currently defined List<User> users = this.userDirectoryService.getUsers(userIds); userIds.clear(); for (User user : users) { userIds.add(user.getId()); } // if any user is not represented in the submissions we found, add an empty submission for (String userId : userIds) { boolean found = false; for (Submission s : rv) { if (s.getUserId().equals(userId)) { found = true; break; } } if (!found) { SubmissionImpl s = this.getPhantomSubmission(userId, assessment); rv.add(s); } } // filter out any submissions found that are not for one of the users in the userIds list (they may have lost permission) if (filterByPermission) { for (Iterator<SubmissionImpl> i = rv.iterator(); i.hasNext();) { SubmissionImpl submission = i.next(); if (!userIds.contains(submission.getUserId())) { i.remove(); } } } // for all but user name & status sorts, separate out the completed, not-started, in-progress List<SubmissionImpl> inProgress = new ArrayList<SubmissionImpl>(); List<SubmissionImpl> notStarted = new ArrayList<SubmissionImpl>(); if ((sort != FindAssessmentSubmissionsSort.userName_a) && (sort != FindAssessmentSubmissionsSort.userName_d) && (sort != FindAssessmentSubmissionsSort.status_a) && (sort != FindAssessmentSubmissionsSort.status_d)) { for (Iterator i = rv.iterator(); i.hasNext();) { SubmissionImpl submission = (SubmissionImpl) i.next(); if (!submission.getIsStarted().booleanValue()) { notStarted.add(submission); i.remove(); } else if (!submission.getIsComplete().booleanValue()) { inProgress.add(submission); i.remove(); } } } // sort - secondary sort of user name, or if primary is title, on submit date Collections.sort(rv, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; FindAssessmentSubmissionsSort secondary = null; switch (sort) { case userName_a: case userName_d: case status_a: case status_d: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); // Note: leave status sort ascending if (sort == FindAssessmentSubmissionsSort.userName_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.sdate_a; break; } case final_a: case final_d: { Float final0 = null; Float final1 = null; if (question != null) { Answer a0 = ((Submission) arg0).getAnswer(question); Answer a1 = ((Submission) arg1).getAnswer(question); final0 = ((a0 == null) ? Float.valueOf(0f) : a0.getTotalScore()); final1 = ((a1 == null) ? Float.valueOf(0f) : a1.getTotalScore()); } else { final0 = ((Submission) arg0).getTotalScore(); final1 = ((Submission) arg1).getTotalScore(); } // null sorts small if ((final0 == null) && (final1 == null)) { rv = 0; } else if (final0 == null) { rv = -1; } else if (final1 == null) { rv = 1; } else { rv = final0.compareTo(final1); } if (sort == FindAssessmentSubmissionsSort.final_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case sdate_a: case sdate_d: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = date0.compareTo(date1); } if (sort == FindAssessmentSubmissionsSort.sdate_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case evaluated_a: case evaluated_d: { Boolean evaluated0 = ((Submission) arg0).getEvaluation().getEvaluated(); Boolean evaluated1 = ((Submission) arg1).getEvaluation().getEvaluated(); rv = evaluated0.compareTo(evaluated1); if (sort == FindAssessmentSubmissionsSort.evaluated_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } case released_a: case released_d: { Boolean released0 = ((Submission) arg0).getIsReleased(); Boolean released1 = ((Submission) arg1).getIsReleased(); rv = released0.compareTo(released1); if (sort == FindAssessmentSubmissionsSort.released_d) rv = -1 * rv; secondary = FindAssessmentSubmissionsSort.userName_a; break; } } // secondary sort FindAssessmentSubmissionsSort third = null; if ((rv == 0) && (secondary != null)) { switch (secondary) { case userName_a: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); third = FindAssessmentSubmissionsSort.sdate_a; break; } case sdate_a: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } // third sort if ((rv == 0) && (third != null)) { switch (third) { case sdate_a: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } return rv; } }); // if we have in-progress and not-started to deal with if (!inProgress.isEmpty()) { // sort them by user name asc Collections.sort(inProgress, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); return rv; } }); rv.addAll(inProgress); } if (!notStarted.isEmpty()) { // sort them by user name asc Collections.sort(notStarted, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); return rv; } }); rv.addAll(notStarted); } return rv; }
From source file:skoa.helpers.Graficos.java
private void compararFicheros(String freferencia, String fcomparar) { System.out.println("min=" + rangoMinutos + "."); File fr = new File(ruta + freferencia); //El primer fichero es el de referencia, y del que se sacan los incrementos. File fc = new File(ruta + fcomparar); FileReader fr1 = null, fr2 = null; BufferedReader linea1 = null, linea2 = null; String L1 = null, L2 = null;//from w w w . j ava2 s. c om SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //Vamos a abrir los dos ficheros a la vez, leyendo lnea por lnea y comparando. try { File temp = new File(ruta + "temp.txt"); if (!temp.exists()) temp.createNewFile(); //Crea el fichero //LEEMOS EL PRIMER FICHERO fr1 = new FileReader(fr); linea1 = new BufferedReader(fr1); Vector<String> fechas = new Vector<String>(); //vector donde irn todas las fechas Date d1 = null, dini = null, dfin = null; boolean primeravez = true, nuevo = true; float media1 = 0; int nelem1 = 0, segd1 = 0; String fecha = "", aux = "", lant = ""; while ((L1 = linea1.readLine()) != null) { aux = L1.substring(0, L1.indexOf("\t")); //Fecha de la lnea. d1 = formatoDelTexto.parse(aux); String Ssegd1 = aux.substring(aux.indexOf(" ") + 7, aux.indexOf(" ") + 9); segd1 = Integer.parseInt(Ssegd1); d1.setSeconds(segd1); if (nuevo) { //Si terminamos el intervalo, pasamos al siguiente. Calendar c = Calendar.getInstance(); if (!primeravez) {//Si no es la primera iteracion, se guarda antes de inicializar. //System.out.println(media1+" "+nelem1); media1 = media1 / nelem1; BufferedWriter bw = new BufferedWriter(new FileWriter(ruta + "temp.txt", true)); //Para escribir. String x1 = "" + media1; if (!x1.contentEquals("NaN")) bw.write("" + fecha + "\t" + media1 + " " + unidad + "\n"); bw.close(); media1 = nelem1 = 0; String v = lant.substring(lant.indexOf("\t") + 1); v = v.substring(0, v.indexOf(" ")); media1 = Float.parseFloat(v);//Se inicializan con los valores de la anterior linea. nelem1 = 1; } else { String u = L1.substring(L1.indexOf("\t") + 1); unidad = u.substring(u.indexOf(" ") + 1); lant = L1; //Si es la 1 vez, tambin se inicializa la fecha inicial. } primeravez = false; fecha = lant.substring(0, lant.indexOf("\t")); fechas.add(fecha); //Inserta la fecha en el vector de fechas, para luego usarlo en el 2 fichero. Date diniaux = formatoDelTexto.parse(fecha); String Ssegd2 = fecha.substring(fecha.indexOf(" ") + 7, fecha.indexOf(" ") + 9); int segd2 = Integer.parseInt(Ssegd2); c.setTime(diniaux); dini = c.getTime(); dini.setSeconds(segd2); //System.out.println("Ini="+dini); c.add(Calendar.MINUTE, Integer.parseInt(rangoMinutos)); dfin = c.getTime(); dfin.setSeconds(segd2); //System.out.println("Fin="+dfin); nuevo = false;//Esta variable se usa para definir otra vez un nuevo intervalo } if (d1.compareTo(dini) == 0) { //Fechas Iguales aux = L1.substring(L1.indexOf("\t") + 1); aux = aux.substring(0, aux.indexOf(" ")); media1 = media1 + Float.parseFloat(aux); nelem1++; } else if (d1.compareTo(dini) > 0 && d1.compareTo(dfin) < 0) { //Est dentro del intervalo aux = L1.substring(L1.indexOf("\t") + 1); aux = aux.substring(0, aux.indexOf(" ")); media1 = media1 + Float.parseFloat(aux); nelem1++; } else {//Si la fecha es menor que la fecha inicial o mayor que la final, se cambia de intervalo. nuevo = true; } lant = L1; } //guardo lo ultimo y penultimo si lo hay media1 = media1 / nelem1; BufferedWriter bw = new BufferedWriter(new FileWriter(ruta + "temp.txt", true)); //Para escribir. String x1 = "" + media1; String auxi = dini.toGMTString(); //d mon yyyy hh:mm:ss String d = auxi.substring(0, auxi.indexOf(" ")); if (Integer.parseInt(d) < 10) d = "0" + d; auxi = auxi.substring(auxi.indexOf(" ") + 1); String m = auxi.substring(0, auxi.indexOf(" ")); if (m.contentEquals("Jan")) m = "01"; if (m.contentEquals("Feb")) m = "02"; if (m.contentEquals("Mar")) m = "03"; if (m.contentEquals("Apr")) m = "04"; if (m.contentEquals("May")) m = "05"; if (m.contentEquals("Jun")) m = "06"; if (m.contentEquals("Jul")) m = "07"; if (m.contentEquals("Aug")) m = "08"; if (m.contentEquals("Sep")) m = "09"; if (m.contentEquals("Oct")) m = "10"; if (m.contentEquals("Nov")) m = "11"; if (m.contentEquals("Dec")) m = "12"; auxi = auxi.substring(auxi.indexOf(" ") + 1); String y = auxi.substring(0, auxi.indexOf(" ")); auxi = auxi.substring(auxi.indexOf(" ") + 1); String h = auxi.substring(0, auxi.indexOf(" ")); //System.out.println(y+"-"+m+"-"+d+" "+h); if (!x1.contentEquals("NaN")) bw.write("" + y + "-" + m + "-" + d + " " + h + "\t" + media1 + " " + unidad + "\n"); bw.close(); fechas.add(y + "-" + m + "-" + d + " " + h); fecha = lant.substring(0, lant.indexOf("\t")); if (!fecha.isEmpty()) { String auxr = lant.substring(lant.indexOf("\t") + 1); auxr = auxr.substring(0, auxr.indexOf(" ")); media1 = Float.parseFloat(auxr); bw = new BufferedWriter(new FileWriter(ruta + "temp.txt", true)); //Para escribir. x1 = "" + media1; if (!x1.contentEquals("NaN")) bw.write("" + fecha + "\t" + media1 + " " + unidad + "\n"); bw.close(); fechas.add(fecha); } fr1.close(); //for (int i=0;i<fechas.size();i++) System.out.println("*"+fechas.elementAt(i)); //Leido el primer fichero, leo el segundo. File temp2 = new File(ruta + "temp2.txt"); if (!temp2.exists()) temp2.createNewFile(); //Crea el fichero fr2 = new FileReader(fc); linea2 = new BufferedReader(fr2); int pos = 0; String fechaf = ""; media1 = nelem1 = 0; nuevo = true; primeravez = true; while ((L2 = linea2.readLine()) != null) { aux = L2.substring(0, L2.indexOf("\t")); //Fecha de la lnea. d1 = formatoDelTexto.parse(aux); String Ssegd1 = aux.substring(aux.indexOf(" ") + 7, aux.indexOf(" ") + 9); segd1 = Integer.parseInt(Ssegd1); d1.setSeconds(segd1); if (nuevo) { //Si terminamos el intervalo, pasamos al siguiente. Calendar c = Calendar.getInstance(); if (!primeravez) {//Si no es la primera iteracion, se guarda antes de inicializar. media1 = media1 / nelem1; BufferedWriter bw1 = new BufferedWriter(new FileWriter(ruta + "temp2.txt", true)); //Para escribir. x1 = "" + media1; if (!x1.contentEquals("NaN")) bw1.write("" + /*fechas.elementAt(pos)+"\t"+*/media1 + " " + unidad + "\n"); bw1.close(); pos++; //media1=nelem1=0; String v = lant.substring(lant.indexOf("\t") + 1); v = v.substring(0, v.indexOf(" ")); media1 = Float.parseFloat(v);//Se inicializan con los valores de la anterior linea. nelem1 = 1; } else { String u = L2.substring(L2.indexOf("\t") + 1); unidad = u.substring(u.indexOf(" ") + 1); lant = L1; pos = 0; //Si es la 1 vez, tambin se inicializa la fecha inicial. } //System.out.println(fechas.elementAt(pos)); primeravez = false; fecha = fechas.elementAt(pos); Date diniaux = formatoDelTexto.parse(fecha); String Ssegd2 = fecha.substring(fecha.indexOf(" ") + 7, fecha.indexOf(" ") + 9); int segd2 = Integer.parseInt(Ssegd2); c.setTime(diniaux); dini = c.getTime(); //FECHA INICIAL. dini.setSeconds(segd2); if (pos + 1 >= fechas.size()) break; fechaf = fechas.elementAt(pos + 1); Date dfinaux = formatoDelTexto.parse(fechaf); Ssegd2 = fecha.substring(fechaf.indexOf(" ") + 7, fechaf.indexOf(" ") + 9); segd2 = Integer.parseInt(Ssegd2); c.setTime(dfinaux); dfin = c.getTime(); //FECHA FINAL dfin.setSeconds(segd2); //System.out.println("INI="+dini); //System.out.println("FIN="+dfin); nuevo = false;//Esta variable se usa para definir otra vez un nuevo intervalo } if (d1.compareTo(dini) == 0) { //Fechas Iguales aux = L2.substring(L2.indexOf("\t") + 1); aux = aux.substring(0, aux.indexOf(" ")); media1 = media1 + Float.parseFloat(aux); nelem1++; } else if (d1.compareTo(dini) > 0 && d1.compareTo(dfin) < 0) { //Est dentro del intervalo aux = L2.substring(L2.indexOf("\t") + 1); aux = aux.substring(0, aux.indexOf(" ")); media1 = media1 + Float.parseFloat(aux); nelem1++; } else {//Si la fecha es menor que la fecha inicial o mayor que la final, se cambia de intervalo. nuevo = true; } lant = L2; } //guardo lo ultimo si lo hay fecha = lant.substring(0, lant.indexOf("\t")); if (!fecha.isEmpty()) { String auxr = lant.substring(lant.indexOf("\t") + 1); auxr = auxr.substring(0, auxr.indexOf(" ")); media1 = Float.parseFloat(auxr); BufferedWriter bw2 = new BufferedWriter(new FileWriter(ruta + "temp2.txt", true)); //Para escribir. x1 = "" + media1; if (!x1.contentEquals("NaN")) bw2.write("" + /*fechas.elementAt(pos+1)+"\t"+*/media1 + " " + unidad + "\n"); bw2.close(); } fr2.close(); //CREAMOS EL UNIFICADO File unificado = new File(ruta + "unificado.txt"); if (!unificado.exists()) unificado.createNewFile(); //Crea el fichero fr1 = new FileReader(temp); linea1 = new BufferedReader(fr1); fr2 = new FileReader(temp2); linea2 = new BufferedReader(fr2); L1 = L2 = ""; BufferedWriter bwf = new BufferedWriter(new FileWriter(ruta + "unificado.txt", true)); //Para escribir. while ((L1 = linea1.readLine()) != null && (L2 = linea2.readLine()) != null) { bwf.write(L1 + "\t" + L2 + "\n"); } bwf.close(); fechas.removeAllElements(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (null != fr1) fr1.close(); //cierra el 1 fichero. if (null != fr2) fr2.close(); //cierra el 2 fichero. } catch (Exception e2) { //Sino salta una excepcion. e2.printStackTrace(); } } File temp1 = new File(ruta + "temp.txt"); File temp2 = new File(ruta + "temp2.txt"); temp1.delete(); temp2.delete(); }