List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:com.sapienter.jbilling.server.process.AgeingBL.java
/** * Will move the user one step forward in the ageing proces ONLY IF * the user has been long enough in the present status. (for a user * in active status, it always moves it to the first ageing step). * @param userId//from ww w . jav a2 s . co m * @throws NamingException * @throws SessionInternalError */ public void age(UserDTO user, Date today) throws NamingException, SessionInternalError { LOG.debug("Ageing user:" + user.getUserId()); Integer status = user.getStatus().getId(); Integer nextStatus = null; if (status.equals(UserDTOEx.STATUS_ACTIVE)) { // welcome to the ageing process nextStatus = getNextStep(user.getEntity(), UserDTOEx.STATUS_ACTIVE); } else { LOG.debug("she's already in the ageing"); // this guy is already in the ageing AgeingEntityStepDTO step = new AgeingEntityStepDAS().findStep(user.getEntity().getId(), status); if (step != null) { ageing = ageingDas.find(step.getId()); // verify if it is time for another notch GregorianCalendar cal = new GregorianCalendar(); Date lastChange = user.getLastStatusChange(); if (lastChange == null) { lastChange = user.getCreateDatetime(); } cal.setTime(lastChange); cal.add(Calendar.DATE, ageing.getDays()); LOG.debug("last time + days=" + cal.getTime() + " today " + today + "compare=" + cal.getTime().compareTo(today)); if (cal.getTime().compareTo(today) <= 0) { nextStatus = getNextStep(user.getEntity(), user.getStatus().getId()); } else { return; } } else { // this user is an ageing status that has been removed. // may be this is a bug, and a currently-in-use status // should not be removable. // Now it will simple jump to the next status. nextStatus = getNextStep(user.getEntity(), user.getStatus().getId()); } } if (nextStatus != null) { setUserStatus(null, user.getUserId(), nextStatus, today); } else { eLogger.warning(user.getEntity().getId(), user.getUserId(), user.getUserId(), EventLogger.MODULE_USER_MAINTENANCE, EventLogger.NO_FURTHER_STEP, Constants.TABLE_BASE_USER); } }
From source file:edu.jhuapl.openessence.web.util.Filters.java
private Date muckDate(Date date, int prepull, String resolution, int calWeekStartDay) { GregorianCalendar x = new GregorianCalendar(); x.setTime(date);/*from ww w. j a v a 2s . c o m*/ if (resolution != null && resolution.equals("weekly")) { x.add(Calendar.DATE, (-7 * prepull)); // make sure week starts on week start day defined // in message.properties or datasource groovy file while (x.get(Calendar.DAY_OF_WEEK) != calWeekStartDay) { x.add(Calendar.DATE, -1); } } else if (resolution != null && resolution.equals("monthly")) { x.set(Calendar.DAY_OF_MONTH, 1); } else if (resolution != null && resolution.equals("daily")) { x.add(Calendar.DATE, -prepull); } return x.getTime(); }
From source file:fr.paris.lutece.plugins.document.business.Document.java
/** * Control that an document is valid, i.e. that its period of validity * defined// w ww . java 2 s .co m * by its dateValidityBegin and its dateValidityEnd is valid : * an document is valid if the current date > = dateValidityBegin and if * current date < = dateValidityEnd * If the two dates are null, the test of validity will return true * if one of the dates is null, the result of the test will be that carried * out * on the non null date * @return true if the document is valid, false otherwise */ public boolean isValid() { java.sql.Timestamp dateValidityBegin = getDateValidityBegin(); java.sql.Timestamp dateValidityEnd = getDateValidityEnd(); GregorianCalendar gc = new GregorianCalendar(); java.sql.Date dateToday = new java.sql.Date(gc.getTime().getTime()); if ((dateValidityBegin == null) && (dateValidityEnd == null)) { return true; } else if (dateValidityBegin == null) { // Return true if dateValidityEnd >= DateToday, false otherwise : return (dateValidityEnd.compareTo(dateToday) >= 0); } else if (dateValidityEnd == null) { // Return true if dateValidityBegin <= DateToday, false otherwise : return (dateValidityBegin.compareTo(dateToday) <= 0); } else { // Return true if dateValidityBegin <= dateToday <= dateValidityEnd, false // otherwise : return ((dateValidityBegin.compareTo(dateToday) <= 0) && (dateValidityEnd.compareTo(dateToday) >= 0)); } }
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklySummaryStatsAbs(Date startDate, Date endDate, Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { Calendar cal = new GregorianCalendar(); TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap<>(); //SET TO BEGINNING OF WK FOR ABSOLUTE CALC cal.setTime(startDate);/*from ww w .j a v a 2 s. c o m*/ cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); startDate = cal.getTime(); List<Object[]> events = getDailyCounts(startDate, endDate, hospitalser, filter, false, ptflag, scheduledFlag); DateFormat df = new SimpleDateFormat("MM/dd/yy"); cal.setTime(startDate); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); int wk = cal.get(Calendar.WEEK_OF_YEAR); int mo = cal.get(Calendar.MONTH); int yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } String currYrWk = yr + "-" + String.format("%02d", wk); //String prevYrWk = ""; String prevYrWk = currYrWk; SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics(); int i = 0; while (cal.getTime().before(endDate) && i < events.size()) { Object[] event = events.get(i); Date d = (Date) event[0]; Long count = (Long) event[1]; cal.setTime(d); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); wk = cal.get(Calendar.WEEK_OF_YEAR); mo = cal.get(Calendar.MONTH); yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } currYrWk = yr + "-" + String.format("%02d", wk); if (!(prevYrWk.equals(currYrWk))) { GregorianCalendar lastMon = new GregorianCalendar(); lastMon.setTime(cal.getTime()); lastMon.add(Calendar.DATE, -7); retval.put(lastMon.getTime(), currStats); currStats = new SynchronizedDescriptiveStatistics(); } prevYrWk = currYrWk; currStats.addValue(count); i++; } retval.put(cal.getTime(), currStats); return retval; }
From source file:mekhq.campaign.finances.Finances.java
public void newDay(Campaign campaign) { DecimalFormat formatter = new DecimalFormat(); CampaignOptions campaignOptions = campaign.getCampaignOptions(); GregorianCalendar calendar = campaign.getCalendar(); // check for a new year if (calendar.get(Calendar.MONTH) == 0 && calendar.get(Calendar.DAY_OF_MONTH) == 1) { // clear the ledger newFiscalYear(calendar.getTime()); }/* ww w. j ava2s .co m*/ // Handle contract payments if (calendar.get(Calendar.DAY_OF_MONTH) == 1) { for (Contract contract : campaign.getActiveContracts()) { credit(contract.getMonthlyPayOut(), Transaction.C_CONTRACT, String.format(resourceMap.getString("MonthlyContractPayment.text"), contract.getName()), calendar.getTime()); campaign.addReport(String.format(resourceMap.getString("ContractPaymentCredit.text"), formatter.format(contract.getMonthlyPayOut()), contract.getName())); if (campaignOptions.getUseAtB() && campaignOptions.getUseShareSystem() && contract instanceof AtBContract) { long shares = contract.getMonthlyPayOut() * ((AtBContract) contract).getSharesPct() / 100; if (debit(shares, Transaction.C_SALARY, String.format(resourceMap.getString("ContractSharePayment.text"), contract.getName()), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("DistributedShares.text"), formatter.format(shares))); } else { /* * This should not happen, as the shares payment is less than the contract * payment that has just been made. */ campaign.addReport(String.format(resourceMap.getString("NotImplemented.text"), "shares")); } } } } // Handle assets for (Asset asset : assets) { if (asset.getSchedule() == SCHEDULE_YEARLY && campaign.calendar.get(Calendar.DAY_OF_YEAR) == 1) { credit(asset.getIncome(), Transaction.C_MISC, "income from " + asset.getName(), campaign.getCalendar().getTime()); campaign.addReport(String.format(resourceMap.getString("AssetPayment.text"), DecimalFormat.getInstance().format(asset.getIncome()), asset.getName())); } else if (asset.getSchedule() == SCHEDULE_MONTHLY && campaign.calendar.get(Calendar.DAY_OF_MONTH) == 1) { credit(asset.getIncome(), Transaction.C_MISC, "income from " + asset.getName(), campaign.getCalendar().getTime()); campaign.addReport(String.format(resourceMap.getString("AssetPayment.text"), DecimalFormat.getInstance().format(asset.getIncome()), asset.getName())); } } // Handle peacetime operating expenses, payroll, and loan payments if (calendar.get(Calendar.DAY_OF_MONTH) == 1) { if (campaignOptions.usePeacetimeCost()) { if (!campaignOptions.showPeacetimeCost()) { if (debit(campaign.getPeacetimeCost(), Transaction.C_MAINTAIN, resourceMap.getString("PeacetimeCosts.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("PeacetimeCosts.text"), formatter.format(campaign.getPeacetimeCost()))); } else { campaign.addReport( String.format(resourceMap.getString("NotImplemented.text"), "for operating costs")); } } else { if (debit(campaign.getMonthlySpareParts(), Transaction.C_MAINTAIN, resourceMap.getString("PeacetimeCostsParts.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("PeacetimeCostsParts.text"), formatter.format(campaign.getMonthlySpareParts()))); } else { campaign.addReport( String.format(resourceMap.getString("NotImplemented.text"), "for spare parts")); } if (debit(campaign.getMonthlyAmmo(), Transaction.C_MAINTAIN, resourceMap.getString("PeacetimeCostsAmmunition.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("PeacetimeCostsAmmunition.text"), formatter.format(campaign.getMonthlySpareParts()))); } else { campaign.addReport(String.format(resourceMap.getString("NotImplemented.text"), "for training munitions")); } if (debit(campaign.getMonthlyFuel(), Transaction.C_MAINTAIN, resourceMap.getString("PeacetimeCostsFuel.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("PeacetimeCostsFuel.text"), formatter.format(campaign.getMonthlySpareParts()))); } else { campaign.addReport(String.format(resourceMap.getString("NotImplemented.text"), "for fuel")); } } } if (campaignOptions.payForSalaries()) { if (debit(campaign.getPayRoll(), Transaction.C_SALARY, resourceMap.getString("Salaries.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("Salaries.text"), formatter.format(campaign.getPayRoll()))); } else { campaign.addReport( String.format(resourceMap.getString("NotImplemented.text"), "payroll costs")); } } // Handle overhead expenses if (campaignOptions.payForOverhead()) { if (debit(campaign.getOverheadExpenses(), Transaction.C_OVERHEAD, resourceMap.getString("Overhead.title"), calendar.getTime())) { campaign.addReport(String.format(resourceMap.getString("Overhead.text"), formatter.format(campaign.getOverheadExpenses()))); } else { campaign.addReport( String.format(resourceMap.getString("NotImplemented.text"), "overhead costs")); } } } ArrayList<Loan> newLoans = new ArrayList<Loan>(); for (Loan loan : loans) { if (loan.checkLoanPayment(campaign.getCalendar())) { if (debit(loan.getPaymentAmount(), Transaction.C_LOAN_PAYMENT, String.format(resourceMap.getString("Loan.title"), loan.getDescription()), campaign.getCalendar().getTime())) { campaign.addReport(String.format(resourceMap.getString("Loan.text"), DecimalFormat.getInstance().format(loan.getPaymentAmount()), loan.getDescription())); loan.paidLoan(); } else { campaign.addReport(String.format(resourceMap.getString("Loan.insufficient"), loan.getDescription(), DecimalFormat.getInstance().format(loan.getPaymentAmount()))); loan.setOverdue(true); } } if (loan.getRemainingPayments() > 0) { newLoans.add(loan); } else { campaign.addReport(String.format(resourceMap.getString("Loan.paid"), loan.getDescription())); } } if (null != wentIntoDebt && !isInDebt()) { wentIntoDebt = null; } loans = newLoans; }
From source file:org.jfree.data.time.WeekTest.java
/** * A test for a problem in constructing a new Week instance. *//*from w ww . ja va 2 s . c o m*/ @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); }
From source file:com.sapienter.jbilling.client.payment.PaymentCrudAction.java
@Override protected PaymentDTOEx doEditFormToDTO() { PaymentDTOEx dto = new PaymentDTOEx(); // the id, only for payment edits dto.setId((Integer) myForm.get(FIELD_ID) == null ? 0 : (Integer) myForm.get(FIELD_ID)); // set the amount dto.setAmount(string2decimal((String) myForm.get(FIELD_AMOUNT))); // set the date dto.setPaymentDate(parseDate(FIELD_GROUP_DATE, "payment.date")); final String payMethod = (String) myForm.get(FIELD_PAY_METHOD); if ("cheque".equals(payMethod)) { // create the cheque dto PaymentInfoChequeDTO chequeDto = new PaymentInfoChequeDTO(); chequeDto.setBank((String) myForm.get(FIELD_CHEQUE_BANK)); chequeDto.setNumber((String) myForm.get(FIELD_CHEQUE_NUMBER)); chequeDto.setDate(parseDate(FIELD_GROUP_CHEQUE_DATE, "payment.cheque.date")); // set the cheque dto.setCheque(chequeDto);// w ww .j a v a 2 s .c o m dto.setPaymentMethod(new PaymentMethodDTO(Constants.PAYMENT_METHOD_CHEQUE)); // validate required fields required(chequeDto.getNumber(), "payment.cheque.number"); required(chequeDto.getDate(), "payment.cheque.date"); // cheques now are never process realtime (may be later will support // electronic cheques dto.setPaymentResult(new PaymentResultDTO(Constants.RESULT_ENTERED)); session.setAttribute("tmp_process_now", new Boolean(false)); } else if ("cc".equals(payMethod)) { String ccNumber = (String) myForm.get(FIELD_CC_NUMBER); boolean masked = false; // check if cc number is masked if (isMaskedCreditCard(ccNumber)) { LOG.debug("cc no. masked; " + "getting user's existing cc details"); // try to get existing cc details UserDTOEx user = getSessionUser(); CreditCardDTO existingCcDTO = user.getCreditCard(); if (existingCcDTO != null) { String existingNumber = existingCcDTO.getNumber(); // check that four last digits match if (existingNumber.substring(existingNumber.length() - 4) .equals(ccNumber.substring(ccNumber.length() - 4))) { LOG.debug("got a matching masked cc number"); masked = true; ccNumber = existingNumber; } } } // do cc validation for non-masked numbers if (!masked) { validateCreditCard(); // return if credit card validation failed if (!errors.isEmpty()) { return null; } } CreditCardDTO ccDto = new CreditCardDTO(); ccDto.setNumber(ccNumber); ccDto.setName((String) myForm.get(FIELD_CC_NAME)); myForm.set(FIELD_GROUP_CC_EXPIRY + "_day", "01"); // to complete the date ccDto.setCcExpiry(parseDate(FIELD_GROUP_CC_EXPIRY, "payment.cc.date")); if (ccDto.getCcExpiry() != null) { // the expiry can't be past today GregorianCalendar cal = new GregorianCalendar(); cal.setTime(ccDto.getCcExpiry()); cal.add(GregorianCalendar.MONTH, 1); // add 1 month if (Calendar.getInstance().getTime().after(cal.getTime())) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("creditcard.error.expired", "payment.cc.date")); } } dto.setCreditCard(ccDto); // this will be checked when the payment is sent session.setAttribute("tmp_process_now", (Boolean) myForm.get(FIELD_PROCESS_NOW)); // validate required fields required(ccDto.getNumber(), "payment.cc.number"); required(ccDto.getCcExpiry(), "payment.cc.date"); required(ccDto.getName(), "payment.cc.name"); // make sure that the cc is valid before trying to get // the payment method from it if (errors.isEmpty()) { dto.setPaymentMethod(new PaymentMethodDTO(Util.getPaymentMethod(ccDto.getNumber()))); } } else if ("ach".equals(payMethod)) { AchDTO ach = new AchDTO(); ach.setAbaRouting((String) myForm.get(FIELD_ACH_ABA_CODE)); ach.setBankAccount((String) myForm.get(FIELD_ACH_ACCOUNT_NUMBER)); ach.setAccountType((Integer) myForm.get(FIELD_ACH_ACCOUNT_TYPE)); ach.setBankName((String) myForm.get(FIELD_ACH_BANK_NAME)); ach.setAccountName((String) myForm.get(FIELD_ACH_ACCOUNT_NAME)); dto.setAch(ach); //this will be checked when the payment is sent session.setAttribute("tmp_process_now", new Boolean(true)); // since it is one big form for all methods, we need to // validate the required manually required(ach.getAbaRouting(), "ach.aba.prompt"); required(ach.getBankAccount(), "ach.account_number.prompt"); required(ach.getBankName(), "ach.bank_name.prompt"); required(ach.getAccountName(), "ach.account_name.prompt"); if (errors.isEmpty()) { dto.setPaymentMethod(new PaymentMethodDTO(Constants.PAYMENT_METHOD_ACH)); } } // set the customer id selected in the list (not the logged) dto.setUserId((Integer) session.getAttribute(Constants.SESSION_USER_ID)); // specify if this is a normal payment or a refund dto.setIsRefund(session.getAttribute("jsp_is_refund") == null ? 0 : 1); LOG.debug("refund = " + dto.getIsRefund()); // set the selected payment for refunds if (dto.getIsRefund() == 1) { PaymentDTOEx refundPayment = (PaymentDTOEx) session.getAttribute(Constants.SESSION_PAYMENT_DTO); /* * Right now, to process a real-time credit card refund it has to be to * refund a previously done credit card payment. This could be * changed, to say, refund using the customer's credit card no matter * how the guy paid initially. But this might be subjet to the * processor features. * */ ActionError realTimeNoPayment = null; boolean processNow = (Boolean) myForm.get(FIELD_PROCESS_NOW); if ("cc".equals(payMethod) && processNow) { if (refundPayment == null || refundPayment.getCreditCard() == null || refundPayment.getAuthorization() == null || !Constants.RESULT_OK.equals(refundPayment.getPaymentResult().getId())) { realTimeNoPayment = new ActionError(// "refund.error.realtimeNoPayment", "payment.cc.processNow"); } } if (realTimeNoPayment != null) { errors.add(ActionErrors.GLOBAL_ERROR, realTimeNoPayment); } else { dto.setPayment(refundPayment); } // refunds, I need to manually delete the list, because // in the end only the LIST_PAYMENT will be removed session.removeAttribute(Constants.SESSION_LIST_KEY + Constants.LIST_TYPE_REFUND); } // last, set the currency //If a related document is // set (invoice/payment) it'll take it from there. Otherwise it // wil inherite the one from the user Integer currencyId = (Integer) myForm.get(FIELD_CURRENCY); dto.setCurrency(currencyId != null ? new CurrencyDTO((Integer) myForm.get(FIELD_CURRENCY)) : null); if (dto.getCurrency() == null) { dto.setCurrency(getUser(dto.getUserId()).getCurrency()); } if (errors.isEmpty()) { // verify that this entity actually accepts this kind of //payment method if (!myPaymentSession.isMethodAccepted((Integer) session.getAttribute(Constants.SESSION_ENTITY_ID_KEY), dto.getPaymentMethod().getId())) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("payment.error.notAccepted", "payment.method")); } } //LOG.debug("now payment methodId = " + dto.getPaymentMethod().getId()); LOG.debug("now paymentDto = " + dto); return dto; }
From source file:org.geotools.gce.imagemosaic.ImageMosaicPostgisIndexOnlineTest.java
/** * Complex test for Postgis indexing on db. * /*from ww w . ja v a 2 s . co m*/ * @throws Exception */ @Test public void testSortingAndLimiting() throws Exception { final File workDir = new File(TestData.file(this, "."), tempFolderName2); assertTrue(workDir.mkdir()); FileUtils.copyFile(TestData.file(this, "watertemp.zip"), new File(workDir, "watertemp.zip")); TestData.unzipFile(this, tempFolderName2 + "/watertemp.zip"); final URL timeElevURL = TestData.url(this, tempFolderName2); //place datastore.properties file in the dir for the indexing FileWriter out = null; try { out = new FileWriter(new File(TestData.file(this, "."), tempFolderName2 + "/datastore.properties")); final Set<Object> keyset = fixture.keySet(); for (Object key : keyset) { final String key_ = (String) key; final String value = fixture.getProperty(key_); out.write(key_.replace(" ", "\\ ") + "=" + value.replace(" ", "\\ ") + "\n"); } out.flush(); } finally { if (out != null) { IOUtils.closeQuietly(out); } } // now start the test final AbstractGridFormat format = TestUtils.getFormat(timeElevURL); assertNotNull(format); ImageMosaicReader reader = TestUtils.getReader(timeElevURL, format); assertNotNull(reader); final String[] metadataNames = reader.getMetadataNames(); assertNotNull(metadataNames); assertEquals(12, metadataNames.length); assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN")); assertEquals("true", reader.getMetadataValue("HAS_ELEVATION_DOMAIN")); // dispose and create new reader reader.dispose(); final MyImageMosaicReader reader1 = new MyImageMosaicReader(timeElevURL); final RasterManager rasterManager = reader1.getRasterManager(reader1.getGridCoverageNames()[0]); // query final SimpleFeatureType type = rasterManager.granuleCatalog.getType("waterTempPG2"); Query query = null; if (type != null) { // creating query query = new Query(type.getTypeName()); // sorting and limiting // max number of elements query.setMaxFeatures(1); // sorting final SortBy[] clauses = new SortBy[] { new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"), SortOrder.DESCENDING), new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"), SortOrder.ASCENDING), }; query.setSortBy(clauses); } // checking that we get a single feature and that feature is correct final Collection<GranuleDescriptor> features = new ArrayList<GranuleDescriptor>(); rasterManager.getGranuleDescriptors(query, new GranuleCatalogVisitor() { @Override public void visit(GranuleDescriptor granule, Object o) { features.add(granule); } }); assertEquals(features.size(), 1); GranuleDescriptor granule = features.iterator().next(); SimpleFeature sf = granule.getOriginator(); assertNotNull(sf); Object ingestion = sf.getAttribute("ingestion"); assertTrue(ingestion instanceof Timestamp); final GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); gc.setTimeInMillis(1225497600000l); assertEquals(0, (((Timestamp) ingestion).compareTo(gc.getTime()))); Object elevation = sf.getAttribute("elevation"); assertTrue(elevation instanceof Integer); assertEquals(((Integer) elevation).intValue(), 0); // Reverting order (the previous timestamp shouldn't match anymore) final SortBy[] clauses = new SortBy[] { new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"), SortOrder.ASCENDING), new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"), SortOrder.DESCENDING), }; query.setSortBy(clauses); // checking that we get a single feature and that feature is correct features.clear(); rasterManager.getGranuleDescriptors(query, new GranuleCatalogVisitor() { @Override public void visit(GranuleDescriptor granule, Object o) { features.add(granule); } }); assertEquals(features.size(), 1); granule = features.iterator().next(); sf = granule.getOriginator(); assertNotNull(sf); ingestion = sf.getAttribute("ingestion"); assertTrue(ingestion instanceof Timestamp); assertNotSame(0, (((Timestamp) ingestion).compareTo(gc.getTime()))); elevation = sf.getAttribute("elevation"); assertTrue(elevation instanceof Integer); assertNotSame(((Integer) elevation).intValue(), 0); }
From source file:org.webical.web.component.calendar.CalendarPanel.java
/** * Sets the current date for the Calendar Views. * @param currentDate The current date/*from ww w .j ava 2 s.com*/ */ public void setCurrentDate(GregorianCalendar currentDate) { // Update the time in the object, don't change the reference else changes are not reflected in the models this.currentDate.setTime(currentDate.getTime()); }
From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java
/** * Update control dates//from w w w . ja v a 2s. co m * * @param controls */ private void updateDate(List<DbeExpendControl> controls) { GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_MONTH, 1); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = transactionManager.getTransaction(def); for (DbeExpendControl control : controls) { control.setDtNextPeriodStart(cal.getTime()); controlService.createOrUpdate(control); } transactionManager.commit(status); }