List of usage examples for org.joda.time DateTime toString
public String toString(String pattern)
From source file:jtodo.ui.CategoryEditorWindow.java
License:Open Source License
private String getCurrentTimeFormattedAsString() { DateTimeFormatter formatter;// w w w . ja v a2s .co m formatter = DateTimeFormat.forPattern("dd.MM.YYYY HH:mm"); DateTime datetime = new DateTime(); return datetime.toString(formatter); }
From source file:matsumana.infra.EntityManagerFactory.java
License:Apache License
@RequestScoped @Produces/* w w w. j a va 2 s . c o m*/ @EntityManagerQualifier public EntityManager getEntityManager() { // ???em01?? DateTime dt = new DateTime(); int sec = Integer.parseInt(dt.toString("s")); if (sec % 2 == 0) { return em01; } else { return em02; } }
From source file:mbsystem.controller.BookDetailsController.java
/** * Borrow the current book//from w w w .j av a 2 s.c om */ public void borrowBook() { // Find current book currentBook = findCurrentBook(); // Find current patron currentPatron = findCurrentPatron(); // If the current patron is able to borrow the current book if (currentBook != null && currentPatron != null) { // Calculate current date and due date DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy hh:mm:ss"); DateTime now = new DateTime(); DateTime added = now.plusDays(14); String currentDate = now.toString(dtf); String dueDate = added.toString(dtf); // Setup a new loan Loan newLoan = new Loan(); newLoan.setPatron(currentPatron); newLoan.setBook(currentBook); newLoan.setLoanDate(currentDate); newLoan.setDueDate(dueDate); // Write to database try { lb.create(newLoan); currentBook.setAvailable(false); currentBook.getLoanList().add(newLoan); currentPatron.getLoanList().add(newLoan); bb.update(currentBook); ub.update(currentPatron); JsfUtil.addSuccessMessage("Loan Created"); } catch (Exception e) { JsfUtil.addErrorMessage(e, "Persistence Error Occured"); } } }
From source file:mekhq.adapter.DateAdapter.java
License:Open Source License
@Override public String marshal(final DateTime object) throws Exception { return object.toString(FORMATTER); }
From source file:mobile.service.core.ClientLogService.java
License:Open Source License
/** * //from w ww . ja va2s . c om * * @param from ??, * @param sourceFile length>0 * @param description ??,? */ public static void uploadLog(final String from, File sourceFile, final String description) { if (sourceFile == null || StringUtils.isBlank(from)) { throw new IllegalArgumentException("illegal param. sourceFile = " + sourceFile + ", from = " + from); } if (sourceFile.length() <= 0) { throw new IllegalArgumentException("sourceFile.length() <= 0"); } String absDestFilePath = JPAUtil.indieTransaction(new IndieTransactionFunc<String>() { @Override public String call(EntityManager em) { // ? DateTime now = new DateTime(); MobileClientLog log = new MobileClientLog(); log.setCreateTime(now.toDate()); log.setDescription(description); log.setDevice(from); JPA.em().persist(log); String destFileName = now.toString("yyyyMMdd-HHmmss") + "-" + log.getId() + ".log"; String absDestFilePath = FileService.getMobileAbsUploadPath() + "clientLog/" + destFileName; String relDestFilePath = FileService.getMobileRelUploadPath() + "clientLog/" + destFileName; log.setLogFileUrl(relDestFilePath); JPA.em().merge(log); return absDestFilePath; } }); File destFile = new File(absDestFilePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } FileService.copyFile(sourceFile.getAbsolutePath(), absDestFilePath); }
From source file:model.TransactionDAO.java
public boolean newTransaction(String requestStaffID, String requestUserID, String requestDelta, String requestReason, DateTime requestTimestamp) throws SQLException { boolean success = false; try (Connection conn = ConnectionManager.getConnection();) { PreparedStatement stmt = conn.prepareStatement( "INSERT INTO TRANSACTION_DETAILS (`Staff`, `User`, `Delta`, `Reason`, `Transaction_DateTime`) VALUES (?, ?, ?, ?, ?);"); stmt.setString(1, requestStaffID); stmt.setString(2, requestUserID); stmt.setInt(3, Integer.parseInt(requestDelta)); stmt.setString(4, requestReason); DateTimeFormatter dtf = DateTimeFormat.forPattern("Y-MM-d HH:mm:ss"); stmt.setString(5, requestTimestamp.toString(dtf)); if (stmt.executeUpdate() == 1) success = true;/*from w w w. j a v a 2s . c o m*/ } catch (SQLException e) { e.printStackTrace(); } return success; }
From source file:model.TransactionDAO.java
public boolean levelUp(String requestStaffID, String requestUserID, int requestDelta, String skillType, DateTime requestTimestamp) throws SQLException { boolean success = false; try (Connection conn = ConnectionManager.getConnection();) { conn.setAutoCommit(false);/*w w w. j a v a 2 s . c om*/ PreparedStatement stmt = conn.prepareStatement( "INSERT INTO TRANSACTION_DETAILS (`Staff`, `User`, `Delta`, `Reason`, `Transaction_DateTime`) VALUES (?, ?, ?, ?, ?);"); stmt.setString(1, requestStaffID); stmt.setString(2, requestUserID); stmt.setInt(3, requestDelta); stmt.setString(4, "Level up: " + skillType); DateTimeFormatter dtf = DateTimeFormat.forPattern("Y-MM-d HH:mm:ss"); stmt.setString(5, requestTimestamp.toString(dtf)); if (stmt.executeUpdate() == 1) success = true; if (!(success && UserDAO.updateUserLevels(requestUserID, skillType))) { conn.rollback(); return false; } else { conn.commit(); conn.setAutoCommit(false); } } catch (SQLException e) { e.printStackTrace(); } return success; }
From source file:module.mission.presentationTier.action.SearchMissionsAction.java
License:Open Source License
public ActionForward downloadSearchResult(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) { final SearchMissionsDTO searchMissions = new SearchMissionsDTO(request); final List<Mission> searchResult = searchMissions.sortedSearch(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=searchResult.xls"); final Spreadsheet spreadsheet = new Spreadsheet("SearchResult"); spreadsheet.setHeader(getExpendituresMessage("label.acquisitionProcessId")); spreadsheet.setHeader(getMissionsMessage("label.mission.type")); spreadsheet.setHeader(getMissionsMessage("label.mission.destination")); spreadsheet.setHeader(getMissionsMessage("label.mission.departure")); spreadsheet.setHeader(getMissionsMessage("label.module.mission.front.page.list.duration")); spreadsheet.setHeader(getMissionsMessage("label.mission.items")); spreadsheet.setHeader(getMissionsMessage("label.mission.value")); spreadsheet.setHeader(getMissionsMessage("label.mission.financer")); spreadsheet.setHeader(getExpendituresMessage("label.accounting.units")); spreadsheet.setHeader(getMissionsMessage("label.mission.requester.person")); spreadsheet.setHeader(getMissionsMessage("label.mission.participants")); spreadsheet.setHeader(getMissionsMessage("label.mission.inactiveSince")); spreadsheet.setHeader(getMissionsMessage("label.mission.canceled")); addMissionStateHeaders(spreadsheet); for (final Mission mission : searchResult) { final MissionProcess missionProcess = mission.getMissionProcess(); final Row row = spreadsheet.addRow(); row.setCell(missionProcess.getProcessIdentification()); row.setCell(getMissionsMessage(/* w w w. j a v a 2 s. c om*/ mission.getGrantOwnerEquivalence() ? "title.mission.process.type.grantOwnerEquivalence" : "title.mission.process.type.dislocation")); row.setCell(mission.getDestinationDescription()); row.setCell(mission.getDaparture().toString("yyyy-MM-dd HH:mm")); row.setCell(mission.getDurationInDays()); row.setCell(mission.getMissionItemsCount()); row.setCell(mission.getValue().toFormatString()); row.setCell(getFinancingUnits(mission)); row.setCell(getAccountingUnits(mission)); row.setCell(mission.getRequestingPerson().getFirstAndLastName()); final StringBuilder builder = new StringBuilder(); for (final Person person : mission.getParticipantesSet()) { if (builder.length() > 0) { builder.append(", "); } builder.append(person.getUser().getProfile().getFullName()); } row.setCell(builder.toString()); final DateTime lastActivity = missionProcess.getDateFromLastActivity(); row.setCell(lastActivity == null ? "" : lastActivity.toString("yyyy-MM-dd HH:mm")); row.setCell(getExpendituresMessage(missionProcess.isCanceled() ? "button.yes" : "button.no")); addMissionStateContent(row, missionProcess); } try { ServletOutputStream writer = response.getOutputStream(); spreadsheet.exportToXLSSheet(writer); } catch (final IOException e) { throw new Error(e); } return null; }
From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java
License:Open Source License
private ActionForward exportInfoToExcel(Set<WorkingCapitalProcess> processes, WorkingCapitalContext context, HttpServletResponse response) throws Exception { final Integer year = context.getWorkingCapitalYear().getYear(); SheetData<WorkingCapitalProcess> sheetData = new SheetData<WorkingCapitalProcess>(processes) { @Override//w w w . ja v a 2s. c o m protected void makeLine(WorkingCapitalProcess workingCapitalProcess) { if (workingCapitalProcess == null) { return; } final WorkingCapital workingCapital = workingCapitalProcess.getWorkingCapital(); final WorkingCapitalInitialization initialization = workingCapital .getWorkingCapitalInitialization(); final AccountingUnit accountingUnit = workingCapital.getAccountingUnit(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("WorkingCapitalProcessState"), workingCapitalProcess.getPresentableAcquisitionProcessState().getLocalizedName()); addCell(getLocalizedMessate("label.module.workingCapital.unit.responsible"), getUnitResponsibles(workingCapital)); addCell(getLocalizedMessate("label.module.workingCapital.initialization.accountingUnit"), accountingUnit == null ? "" : accountingUnit.getName()); addCell(getLocalizedMessate("label.module.workingCapital.requestingDate"), initialization.getRequestCreation().toString("yyyy-MM-dd HH:mm:ss")); addCell(getLocalizedMessate("label.module.workingCapital.requester"), initialization.getRequestor().getName()); final Person movementResponsible = workingCapital.getMovementResponsible(); addCell(getLocalizedMessate("label.module.workingCapital.movementResponsible"), movementResponsible == null ? "" : movementResponsible.getName()); addCell(getLocalizedMessate("label.module.workingCapital.fiscalId"), initialization.getFiscalId()); addCell(getLocalizedMessate("label.module.workingCapital.internationalBankAccountNumber"), initialization.getInternationalBankAccountNumber()); addCell(getLocalizedMessate("label.module.workingCapital.fundAllocationId"), initialization.getFundAllocationId()); final Money requestedAnualValue = initialization.getRequestedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.requestedAnualValue.requested"), requestedAnualValue); addCell(getLocalizedMessate("label.module.workingCapital.requestedMonthlyValue.requested"), requestedAnualValue.divideAndRound(new BigDecimal(6))); final Money authorizedAnualValue = initialization.getAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.authorizedAnualValue"), authorizedAnualValue == null ? "" : authorizedAnualValue); final Money maxAuthorizedAnualValue = initialization.getMaxAuthorizedAnualValue(); addCell(getLocalizedMessate("label.module.workingCapital.maxAuthorizedAnualValue"), maxAuthorizedAnualValue == null ? "" : maxAuthorizedAnualValue); final DateTime lastSubmission = initialization.getLastSubmission(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.lastSubmission"), lastSubmission == null ? "" : lastSubmission.toString("yyyy-MM-dd")); final DateTime refundRequested = initialization.getRefundRequested(); addCell(getLocalizedMessate("label.module.workingCapital.initialization.refundRequested"), refundRequested == null ? "" : refundRequested.toString("yyyy-MM-dd")); final WorkingCapitalTransaction lastTransaction = workingCapital.getLastTransaction(); if (lastTransaction == null) { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), Money.ZERO); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), Money.ZERO); } else { addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), lastTransaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), lastTransaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), lastTransaction.getDebt()); } for (final AcquisitionClassification classification : WorkingCapitalSystem.getInstance() .getAcquisitionClassificationsSet()) { final String description = classification.getDescription(); final String pocCode = classification.getPocCode(); final String key = pocCode + " - " + description; final Money value = calculateValueForClassification(workingCapital, classification); addCell(key, value); } } private Money calculateValueForClassification(final WorkingCapital workingCapital, final AcquisitionClassification classification) { Money result = Money.ZERO; for (final WorkingCapitalTransaction transaction : workingCapital .getWorkingCapitalTransactionsSet()) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTransaction = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTransaction .getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); if (acquisitionClassification == classification) { result = result.add(acquisition.getValueAllocatedToSupplier()); } } } return result; } private String getUnitResponsibles(final WorkingCapital workingCapital) { final StringBuilder builder = new StringBuilder(); final SortedMap<Person, Set<Authorization>> authorizations = workingCapital .getSortedAuthorizations(); if (!authorizations.isEmpty()) { for (final Entry<Person, Set<Authorization>> entry : authorizations.entrySet()) { if (builder.length() > 0) { builder.append("; "); } builder.append(entry.getKey().getName()); } } return builder.toString(); } }; final LocalDate currentLocalDate = new LocalDate(); final SpreadsheetBuilder builder = new SpreadsheetBuilder(); builder.addConverter(Money.class, new CellConverter() { @Override public Object convert(final Object source) { final Money money = (Money) source; return money == null ? null : money.getRoundedValue().doubleValue(); } }); builder.addSheet(getLocalizedMessate("label.module.workingCapital") + " " + year + " - " + currentLocalDate.toString(), sheetData); final List<WorkingCapitalTransaction> transactions = new ArrayList<WorkingCapitalTransaction>(); for (final WorkingCapitalProcess process : processes) { final WorkingCapital workingCapital = process.getWorkingCapital(); transactions.addAll(workingCapital.getSortedWorkingCapitalTransactions()); } final SheetData<WorkingCapitalTransaction> transactionsSheet = new SheetData<WorkingCapitalTransaction>( transactions) { @Override protected void makeLine(WorkingCapitalTransaction transaction) { final WorkingCapital workingCapital = transaction.getWorkingCapital(); final WorkingCapitalProcess workingCapitalProcess = workingCapital.getWorkingCapitalProcess(); addCell(getLocalizedMessate("label.module.workingCapital.year"), year); addCell(getLocalizedMessate("label.module.workingCapital"), workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getNumber()); addCell(getLocalizedMessate("WorkingCapitalProcessState.CANCELED"), transaction.isCanceledOrRejected() ? getLocalizedMessate("label.yes") : getLocalizedMessate("label.no")); addCell(getLocalizedMessate("label.module.workingCapital.transaction.description") + " " + getLocalizedMessate("label.module.workingCapital.transaction.number"), transaction.getDescription()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.approval"), approvalLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.verification"), verificationLabel(transaction)); addCell(getLocalizedMessate("label.module.workingCapital.transaction.value"), transaction.getValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"), transaction.getAccumulatedValue()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), transaction.getBalance()); addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), transaction.getDebt()); if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisitionTx = (WorkingCapitalAcquisitionTransaction) transaction; final WorkingCapitalAcquisition acquisition = acquisitionTx.getWorkingCapitalAcquisition(); final AcquisitionClassification acquisitionClassification = acquisition .getAcquisitionClassification(); final String economicClassification = acquisitionClassification.getEconomicClassification(); final String pocCode = acquisitionClassification.getPocCode(); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.economicClassification"), economicClassification); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.pocCode"), pocCode); addCell(getLocalizedMessate( "label.module.workingCapital.configuration.acquisition.classifications.description"), acquisition.getDescription()); } } private Object verificationLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getVerified() != null) { return getLocalizedMessate("label.verified"); } if (acquisition.getWorkingCapitalAcquisition().getNotVerified() != null) { return getLocalizedMessate("label.notVerified"); } } return "-"; } private String approvalLabel(final WorkingCapitalTransaction transaction) { if (transaction.isAcquisition()) { final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction; if (acquisition.getWorkingCapitalAcquisition().getApproved() != null) { return getLocalizedMessate("label.approved"); } if (acquisition.getWorkingCapitalAcquisition().getRejectedApproval() != null) { return getLocalizedMessate("label.rejected"); } } return "-"; } }; builder.addSheet(getLocalizedMessate("label.module.workingCapital.transactions"), transactionsSheet); return streamSpreadsheet(response, "FundosManeio_" + year + "-" + currentLocalDate.getDayOfMonth() + "-" + currentLocalDate.getMonthOfYear() + "-" + currentLocalDate.getYear(), builder); }