Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:de.hybris.platform.integration.cis.payment.cronjob.DefaultCisFraudReportJob.java

@Override
public PerformResult perform(final CisFraudReportCronJobModel cronJob) {
    try {//from  w w  w  .ja va 2s  .c  o  m
        final CisFraudReportRequest request = new CisFraudReportRequest();
        final Date requestStartTime = getLastCronJobEndTime();
        final Date requestEndTime = new Date();
        final Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.HOUR, -24);

        if (requestStartTime.before(calendar.getTime())) {
            LOG.error("CyberSource report time range is only valid for the past 24 hours");
            return new PerformResult(CronJobResult.ERROR, CronJobStatus.ABORTED);
        }

        request.setStartDateTime(requestStartTime);
        request.setEndDateTime(requestEndTime);
        final RestResponse<CisFraudReportResult> response = getOndemandHystrixCommandFactory().newCommand(
                getHystrixCommandConfig(), new HystrixExecutable<RestResponse<CisFraudReportResult>>() {
                    @Override
                    public RestResponse<CisFraudReportResult> runEvent() {
                        return getFraudClient().generateFraudReport(cronJob.getCode(), request);
                    }

                    @Override
                    public RestResponse<CisFraudReportResult> fallbackEvent() {
                        return null;
                    }

                    @Override
                    public RestResponse<CisFraudReportResult> defaultEvent() {
                        return null;
                    }
                }).execute();

        if (response != null) {
            final List<CisFraudTransactionResult> transactionResults = response.getResult().getTransactions();

            if (CollectionUtils.isNotEmpty(transactionResults)) {
                //Retrieve all the transactionIds from each of the transaction results
                final List<String> transactionIds = (List<String>) CollectionUtils.collect(transactionResults,
                        new Transformer() {
                            @Override
                            public Object transform(final Object o) {
                                final CisFraudTransactionResult result = (CisFraudTransactionResult) o;

                                return result.getClientAuthorizationId();
                            }
                        });

                final List<PaymentTransactionEntryModel> transactionEntries = getPaymentTransactionEntryModels(
                        transactionIds);

                //For each transaction result, set the transaction from it's corresponding order and fire the business process event
                for (final CisFraudTransactionResult transactionResult : transactionResults) {
                    final PaymentTransactionEntryModel transactionEntry = (PaymentTransactionEntryModel) CollectionUtils
                            .find(transactionEntries, new Predicate() {
                                @Override
                                public boolean evaluate(final Object o) {
                                    return ((PaymentTransactionEntryModel) o).getCode()
                                            .equalsIgnoreCase(transactionResult.getClientAuthorizationId());
                                }
                            });

                    if (transactionEntry != null && transactionEntry.getPaymentTransaction() != null
                            && transactionEntry.getPaymentTransaction().getOrder() != null) {
                        final PaymentTransactionModel transaction = transactionEntry.getPaymentTransaction();
                        final String guid = transaction.getOrder().getGuid();

                        final PaymentTransactionEntryModel newTransactionEntry = getTransactionResultConverter()
                                .convert(transactionResult);
                        getPaymentService().setPaymentTransactionReviewResult(newTransactionEntry, guid);
                    }
                }
            }

            //Set the LastFraudReportEndTime for use the next time this cron job runs
            cronJob.setLastFraudReportEndTime(requestEndTime);
            getModelService().save(cronJob);

            return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
        }

        return new PerformResult(CronJobResult.ERROR, CronJobStatus.ABORTED);
    } catch (final Exception e) {
        LOG.warn(String.format("Error occurred while processing the fraud reports [%s]",
                e.getLocalizedMessage()));
        if (LOG.isDebugEnabled()) {
            LOG.debug("Error occurred while processing the fraud reports", e);
        }
        return new PerformResult(CronJobResult.ERROR, CronJobStatus.ABORTED);
    }
}

From source file:me.neatmonster.spacertk.scheduler.Job.java

/**
 * Creates a new Job//from   w  w  w  . j av a 2 s  . c  o m
 * @param actionName Action to preform
 * @param actionArguments Arguments to preform the action with
 * @param timeType Type of time to schedule the action with
 * @param timeArgument Argument of time to schedule the action with
 * @param loading If the job is being loaded
 * @throws UnSchedulableException If the action cannot be scheduled
 * @throws UnhandledActionException If the action is unknown
 */
public Job(final String actionName, final Object[] actionArguments, final String timeType,
        final String timeArgument, final boolean loading)
        throws UnSchedulableException, UnhandledActionException {
    if (!SpaceRTK.getInstance().actionsManager.contains(actionName)) {
        if (!loading) {
            final String result = Utilities.sendMethod("isSchedulable", "[\"" + actionName + "\"]");
            if (result == null || !result.equals("true"))
                if (result == null || result.equals(""))
                    throw new UnhandledActionException();
                else
                    throw new UnSchedulableException("Action " + actionName + " isn't schedulable!");
        }
    } else if (!SpaceRTK.getInstance().actionsManager.isSchedulable(actionName))
        throw new UnSchedulableException("Action " + actionName + " isn't schedulable!");
    this.actionName = actionName;
    this.actionArguments = actionArguments;
    this.timeType = timeType;
    this.timeArgument = timeArgument;
    if (timeType.equals("EVERYXHOURS"))
        timer.scheduleAtFixedRate(this, Integer.parseInt(timeArgument) * 3600000L,
                Integer.parseInt(timeArgument) * 3600000L);
    else if (timeType.equals("EVERYXMINUTES"))
        timer.scheduleAtFixedRate(this, Integer.parseInt(timeArgument) * 60000L,
                Integer.parseInt(timeArgument) * 60000L);
    else if (timeType.equals("ONCEPERDAYAT")) {
        Calendar nextOccurence = Calendar.getInstance();
        nextOccurence.set(Calendar.HOUR, Integer.parseInt(timeArgument.split(":")[0]));
        nextOccurence.set(Calendar.MINUTE, Integer.parseInt(timeArgument.split(":")[1]));
        if (nextOccurence.before(new Date()))
            nextOccurence = Calendar.getInstance();
        nextOccurence.setTimeInMillis(nextOccurence.getTimeInMillis() + 86400000L);
        timer.scheduleAtFixedRate(this, nextOccurence.getTime(), 86400000L);
    } else if (timeType.equals("XMINUTESPASTEVERYHOUR")) {
        Calendar nextOccurence = Calendar.getInstance();
        nextOccurence.set(Calendar.MINUTE, Integer.parseInt(timeArgument));
        if (nextOccurence.before(new Date()))
            nextOccurence = Calendar.getInstance();
        nextOccurence.setTimeInMillis(nextOccurence.getTimeInMillis() + 3600000L);
        timer.scheduleAtFixedRate(this, nextOccurence.getTime(), 3600000L);
    }
    Scheduler.saveJobs();
}

From source file:es.udc.fic.test.model.CerrarMangaTest.java

@Test
public void cerrarMangaTRealSinPenal() {
    //Creamos una sola regata con la instancia de todos los objetos en memoria
    Regata regata = new Regata();
    regata.setNombre("Mock Regata");
    regata.setDescripcion("Mock Desc");
    regataDao.save(regata);/*  w  ww  . j  a v  a  2 s  .  c  o m*/

    Tipo tipoVLigera = new Tipo("Vela ligera", "Desc Vela ligera", true);
    tipoDao.save(tipoVLigera);
    Tipo tipoLanchas = new Tipo("Lanchas", "Desc Lanchas", true);
    tipoDao.save(tipoLanchas);

    Barco b1 = new Barco(204566, "Juan Sebastian El Cano", tipoVLigera, null, "Lagoon 421");
    inscripcionService.inscribir(regata, b1, "Iago Surez");

    Barco b2 = new Barco(199012, "El Holandes Errante", tipoVLigera, null, "SWAN 66 FD");
    inscripcionService.inscribir(regata, b2, "Samu Paredes");

    Barco b3 = new Barco(201402, "La Perla Negra", tipoVLigera, null, "X6");
    inscripcionService.inscribir(regata, b3, "Adrian Pallas");

    //Ponemos otro tipo para ver como funciona la clasificacion
    Barco b4 = new Barco(206745, "Apolo", tipoLanchas, null, "Laser Radial");
    inscripcionService.inscribir(regata, b4, "Diego Bascoy");

    Calendar dia1 = Calendar.getInstance();
    dia1.add(Calendar.DAY_OF_YEAR, -18);

    Calendar dia2 = Calendar.getInstance();
    dia2.add(Calendar.DAY_OF_YEAR, -18);
    dia2.add(Calendar.HOUR, 2);

    Calendar dia3 = Calendar.getInstance();
    dia3.add(Calendar.DAY_OF_YEAR, -17);

    Manga manga1 = new Manga(dia1, regata, null, 100);

    List<Posicion> posManga1 = new ArrayList<Posicion>();

    //Velas Ligeras
    //Primero -> Puntos 1        
    posManga1.add(new Posicion((long) 3200, Posicion.Penalizacion.NAN, manga1, b1, (long) 0));
    //Segundo-> Puntos 2
    posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b2, (long) 0));
    //Tercero -> Puntos 3
    posManga1.add(new Posicion((long) 3400, Posicion.Penalizacion.NAN, manga1, b3, (long) 0));

    //Lanchas
    //Primero -> Puntos 1
    posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b4, (long) 0));

    manga1.setPosiciones(posManga1);
    regata.addManga(manga1);
    mangaService.cerrarYGuardarManga(manga1);

    //Comprobamos que todas las posiciones tienen puntos mayores que 0
    for (Posicion p : manga1.getPosiciones()) {
        assertTrue(p.getPuntos() > 0);
    }

    //Comprobamos que los puntos son correctos
    //Guardamos las posiciones por tipos
    Map<Barco, Posicion> posPorBarco = new HashMap<Barco, Posicion>();
    for (Posicion p : manga1.getPosiciones()) {
        //Aadimos la posicionActual
        posPorBarco.put(p.getBarco(), p);
    }

    //Velas Ligeras
    //Primero -> Puntos 1 
    assertEquals(posPorBarco.get(b1).getPuntos(), 1);
    //Segundo-> Puntos 2
    assertEquals(posPorBarco.get(b2).getPuntos(), 2);
    //Tercero -> Puntos 3
    assertEquals(posPorBarco.get(b3).getPuntos(), 3);

    //Lanchas
    //Primero -> Puntos 1
    assertEquals(posPorBarco.get(b4).getPuntos(), 1);

}

From source file:RolloverFileOutputStream.java

public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone)
        throws IOException {
    super(null);//from  w  ww.j  a va  2s  .  c o m

    _fileBackupFormat.setTimeZone(zone);
    _fileDateFormat.setTimeZone(zone);

    if (filename != null) {
        filename = filename.trim();
        if (filename.length() == 0)
            filename = null;
    }
    if (filename == null)
        throw new IllegalArgumentException("Invalid filename");

    _filename = filename;
    _append = append;
    _retainDays = retainDays;
    setFile();

    synchronized (RolloverFileOutputStream.class) {
        if (__rollover == null)
            __rollover = new Timer();

        _rollTask = new RollTask();

        Calendar now = Calendar.getInstance();
        now.setTimeZone(zone);

        GregorianCalendar midnight = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                now.get(Calendar.DAY_OF_MONTH), 23, 0);
        midnight.setTimeZone(zone);
        midnight.add(Calendar.HOUR, 1);
        __rollover.scheduleAtFixedRate(_rollTask, midnight.getTime(), 1000L * 60 * 60 * 24);
    }
}

From source file:de.berlios.statcvs.xml.report.CommitActivityChart.java

private XYSeries createXYSeries(String title, Iterator it) {
    XYSeries series = new XYSeries(title);

    while (it.hasNext()) {
        CvsRevision rev = (CvsRevision) it.next();

        Calendar cal = Calendar.getInstance();
        cal.setTime(rev.getDate());//from   w w  w  .  ja v a 2  s .c  o m
        double hour = cal.get(Calendar.HOUR_OF_DAY);
        double minutes = cal.get(Calendar.MINUTE);

        // clear time info
        cal.clear(Calendar.HOUR);
        cal.clear(Calendar.HOUR_OF_DAY);
        cal.clear(Calendar.MINUTE);
        cal.clear(Calendar.SECOND);
        cal.clear(Calendar.MILLISECOND);

        series.add(cal.getTime().getTime(), hour + (minutes / 60));
    }

    return series;
}

From source file:es.indaba.jdbc.test.StoredProceduresTest.java

@Test
public void timeTest() throws Exception {
    Calendar testCal = Calendar.getInstance();
    Date testVal = testCal.getTime();
    DBTester dbTester = BeanProvider.getContextualReference(DBTester.class, false);
    ProcedureResult<Date> result = dbTester.callEchoTimeAsFunction(testVal);

    Calendar resCal = Calendar.getInstance();
    resCal.setTime(result.getValue());/* w  ww .ja va 2 s .com*/

    assertNotNull(result);
    assertEquals(testCal.get(Calendar.HOUR), resCal.get(Calendar.HOUR));
    assertEquals(testCal.get(Calendar.MINUTE), resCal.get(Calendar.MINUTE));
    assertEquals(testCal.get(Calendar.SECOND), resCal.get(Calendar.SECOND));

    result = dbTester.callEchoTimeAsProcedure(testVal);
    resCal.setTime(result.getValue());

    assertNotNull(result);
    assertEquals(testCal.get(Calendar.HOUR), resCal.get(Calendar.HOUR));
    assertEquals(testCal.get(Calendar.MINUTE), resCal.get(Calendar.MINUTE));
    assertEquals(testCal.get(Calendar.SECOND), resCal.get(Calendar.SECOND));
}

From source file:org.kuali.mobility.sakai.controllers.SakaiController.java

@RequestMapping(method = RequestMethod.GET)
public String getSites(HttpServletRequest request, @RequestParam(value = "date", required = false) String date,
        Model uiModel) {/* w  w w.  j  ava 2  s. co  m*/
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
    Home home = sakaiSiteService.findSakaiHome(user.getUserId(), date);
    uiModel.addAttribute("home", home);
    uiModel.addAttribute("tabCount",
            (home.getCourses() != null && home.getCourses().size() > 0 ? 2 : 0)
                    + (home.getProjects() != null && home.getProjects().size() > 0 ? 1 : 0)
                    + (home.getOther() != null && home.getOther().size() > 0 ? 1 : 0));

    Calendar todayDate = Calendar.getInstance();
    if (date != null) {
        try {
            todayDate.setTime(Constants.DateFormat.queryStringDateFormat.getFormat().parse(date));
        } catch (Exception e) {
        }
    }
    todayDate.set(Calendar.HOUR, 0);
    todayDate.set(Calendar.MINUTE, 0);
    todayDate.set(Calendar.SECOND, 0);
    todayDate.set(Calendar.MILLISECOND, 0);
    uiModel.addAttribute("todayDisplay",
            Constants.DateFormat.displayDateFormat.getFormat().format(todayDate.getTime()));
    todayDate.add(Calendar.DATE, -1);
    uiModel.addAttribute("yesterday",
            Constants.DateFormat.queryStringDateFormat.getFormat().format(todayDate.getTime()));
    uiModel.addAttribute("yesterdayButton",
            Constants.DateFormat.buttonDateFormat.getFormat().format(todayDate.getTime()));
    todayDate.add(Calendar.DATE, 2);
    uiModel.addAttribute("tomorrow",
            Constants.DateFormat.queryStringDateFormat.getFormat().format(todayDate.getTime()));
    uiModel.addAttribute("tomorrowButton",
            Constants.DateFormat.buttonDateFormat.getFormat().format(todayDate.getTime()));

    return "sakai/home";
}

From source file:com.vmware.appfactory.common.runner.LicenseStatus.java

/**
 * Find out whether license is expired or not using yesterday midnight.
 * Calculate the number of days until expiration.
 *///from  w ww  .ja  v a2 s  .  c  om
private final void calculateNumDaysToExpiration() {
    final GregorianCalendar gCal = new GregorianCalendar(AfCalendar.LOCAL_TZONE);
    gCal.add(Calendar.DATE, -1);
    final Date yesterdayMidnight = DateUtils.round(gCal.getTime(), Calendar.HOUR);
    setNumDaysToExpiration(
            (_expirationDate.getTime() - yesterdayMidnight.getTime()) / DateUtils.MILLIS_PER_DAY);

    if (getNumDaysToExpiration() <= 0) {
        _isExpired = true;
    } else {
        _isExpired = false;
    }
}

From source file:es.indaba.jdbc.test.InterceptorTest.java

@Test
public void timeTest() throws Exception {
    Calendar testCal = Calendar.getInstance();
    Date testVal = testCal.getTime();
    TestBean testService = BeanProvider.getContextualReference(TestBean.class, false);
    ProcedureResult<Date> result = testService.callEchoTimeAsFunction(testVal);

    Calendar resCal = Calendar.getInstance();
    resCal.setTime(result.getValue());//from  w  w w .  j av  a 2 s .c  om

    assertNotNull(result);
    assertEquals(testCal.get(Calendar.HOUR), resCal.get(Calendar.HOUR));
    assertEquals(testCal.get(Calendar.MINUTE), resCal.get(Calendar.MINUTE));
    assertEquals(testCal.get(Calendar.SECOND), resCal.get(Calendar.SECOND));

    result = testService.callEchoTimeAsProcedure(testVal);
    resCal.setTime(result.getValue());

    assertNotNull(result);
    assertEquals(testCal.get(Calendar.HOUR), resCal.get(Calendar.HOUR));
    assertEquals(testCal.get(Calendar.MINUTE), resCal.get(Calendar.MINUTE));
    assertEquals(testCal.get(Calendar.SECOND), resCal.get(Calendar.SECOND));
}

From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java

private Calendar getWeekBeginning(int position) {
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(m_minDate);//www .  j  ava  2s  .  c  om
    calendar.add(Calendar.WEEK_OF_MONTH, position);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}