Example usage for java.util Calendar DECEMBER

List of usage examples for java.util Calendar DECEMBER

Introduction

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

Prototype

int DECEMBER

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

Click Source Link

Document

Value of the #MONTH field indicating the twelfth month of the year in the Gregorian and Julian calendars.

Usage

From source file:org.techytax.util.DateHelper.java

public static Date getLastDayOfFiscalYear() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(new Date());
    cal.add(Calendar.YEAR, -1);/*from  w w  w .j av a  2 s  .  c  o m*/
    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    cal.set(Calendar.DAY_OF_MONTH, 31);
    return cal.getTime();
}

From source file:org.jfree.data.time.Week.java

/**
 * Creates a time period for the week in which the specified date/time
 * falls, calculated relative to the specified time zone.
 *
 * @param time  the date/time (<code>null</code> not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @since 1.0.7/*from  ww w  .j a v  a 2 s .  c  o  m*/
 */
public Week(Date time, TimeZone zone, Locale locale) {
    ParamChecks.nullNotPermitted(time, "time");
    ParamChecks.nullNotPermitted(zone, "zone");
    ParamChecks.nullNotPermitted(locale, "locale");
    Calendar calendar = Calendar.getInstance(zone, locale);
    calendar.setTime(time);

    // sometimes the last few days of the year are considered to fall in
    // the *first* week of the following year.  Refer to the Javadocs for
    // GregorianCalendar.
    int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR);
    if (tempWeek == 1 && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
        this.week = 1;
        this.year = (short) (calendar.get(Calendar.YEAR) + 1);
    } else {
        this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR);
        int yyyy = calendar.get(Calendar.YEAR);
        // alternatively, sometimes the first few days of the year are
        // considered to fall in the *last* week of the previous year...
        if (calendar.get(Calendar.MONTH) == Calendar.JANUARY && this.week >= 52) {
            yyyy--;
        }
        this.year = (short) yyyy;
    }
    peg(calendar);
}

From source file:gov.nih.nci.firebird.selenium2.tests.profile.credentials.WorkHistoryCredentialsTest.java

private void checkForExpirationBeforeEffectiveDateError(final EditWorkHistoryDialog credentialDialog)
        throws IOException {
    credentialDialog.getHelper().setWorkHistory(workHistoryWithExistingIssuer);
    Date today = new Date();
    credentialDialog.getHelper().setStartDate(DateUtils.setMonths(today, Calendar.DECEMBER));
    credentialDialog.getHelper().setEndDate(DateUtils.setMonths(today, Calendar.OCTOBER));
    ExpectedValidationFailure expectedValidationFailure = new ExpectedValidationFailure(
            "error.end.date.before.start");
    expectedValidationFailure.assertFailureOccurs(new FailingAction() {
        @Override//from w w  w .  ja va  2 s.co  m
        public void perform() {
            credentialDialog.clickSave();
        }
    });
}

From source file:gov.nih.nci.firebird.selenium2.tests.profile.credentials.AbstractSpecialtyCredentialTest.java

private void checkForExpirationBeforeEffectiveDateError(final EditSpecialtyCredentialDialog credentialDialog)
        throws IOException {
    credentialDialog.getHelper().setCredential(getCredentialWithExistingIssuer());
    Date today = new Date();
    credentialDialog.getHelper().setStartDate(DateUtils.setMonths(today, Calendar.DECEMBER));
    credentialDialog.getHelper().setEndDate(DateUtils.setMonths(today, Calendar.OCTOBER));
    ExpectedValidationFailure expectedValidationFailure = new ExpectedValidationFailure(
            "error.end.date.before.start");
    expectedValidationFailure.assertFailureOccurs(new FailingAction() {
        @Override//from  ww  w  . ja va2  s  . com
        public void perform() {
            credentialDialog.clickSave();
        }
    });
}

From source file:com.clustercontrol.systemlog.bean.SyslogMessage.java

/**
 * ??/*w ww . ja  va2s.c  o m*/
 * ?(String)Calendar?(int)???
 * 
 * @param month 
 * @return Calendar?
 */
private static int editCalendarMonth(String month) {

    switch (month.toUpperCase()) {
    case "JAN":
        return Calendar.JANUARY;
    case "FEB":
        return Calendar.FEBRUARY;
    case "MAR":
        return Calendar.MARCH;
    case "APR":
        return Calendar.APRIL;
    case "MAY":
        return Calendar.MAY;
    case "JUN":
        return Calendar.JUNE;
    case "JUL":
        return Calendar.JULY;
    case "AUG":
        return Calendar.AUGUST;
    case "SEP":
        return Calendar.SEPTEMBER;
    case "OCT":
        return Calendar.OCTOBER;
    case "NOV":
        return Calendar.NOVEMBER;
    case "DEC":
        return Calendar.DECEMBER;
    }
    return Calendar.UNDECIMBER;
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.CriteriaTest.java

/**
 * Tests pagination of results./*from w ww.  ja  v a 2 s.c om*/
 * @throws Exception
 */
@Test
public void testSetPaging() throws Exception {
    Calendar begin = Calendar.getInstance();
    begin.set(1999, Calendar.JANUARY, 1);
    Calendar end = Calendar.getInstance();
    end.set(2001, Calendar.DECEMBER, 31);

    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
            .setBasePath("/pets").add(Restrictions.betweenDates("@birthDate", begin, end))
            .addOrder(Order.asc("@birthDate")).setPaging(5, 2);

    AdvancedResult result = criteria.execute();
    // first page:
    // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
    // --- 6 (title=George, petType=snake, birthDate=2000-01-20)
    // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
    // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
    // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
    // second page:
    // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
    // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
    // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
    Assert.assertEquals(result.getTotalSize(), 8);

    ResultIterator<? extends Node> iterator = result.getItems();
    Assert.assertEquals(iterator.getSize(), 3);
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "1");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "5");
    Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "3");
}

From source file:org.openmrs.module.sdmxhdintegration.reporting.extension.SDMXHDCrossSectionalReportRenderer.java

/**
  * @see org.openmrs.module.report.renderer.ReportRenderer#render(org.openmrs.module.report.ReportData, java.lang.String, java.io.OutputStream)
  *//*from   w w  w.  j  a  v  a  2  s  . c om*/
@Override
public void render(ReportData reportData, String argument, OutputStream out)
        throws IOException, RenderingException {
    if (reportData.getDataSets().size() > 1) {
        throw new RenderingException(
                "This report contains multiple DataSets, this renderer does not support multiple DataSets");
    } else if (reportData.getDataSets().size() < 1) {
        throw new RenderingException("No DataSet defined in this report");
    }

    // get results dataSet
    org.openmrs.module.reporting.dataset.DataSet dataSet = reportData.getDataSets()
            .get(reportData.getDataSets().keySet().iterator().next());

    // get OMRS DSD
    Mapped<? extends DataSetDefinition> mappedOMRSDSD = reportData.getDefinition().getDataSetDefinitions()
            .get(reportData.getDefinition().getDataSetDefinitions().keySet().iterator().next());
    SDMXHDCohortIndicatorDataSetDefinition omrsDSD = (SDMXHDCohortIndicatorDataSetDefinition) mappedOMRSDSD
            .getParameterizable();

    // get SDMX-HD DSD
    SDMXHDService sdmxhdService = (SDMXHDService) Context.getService(SDMXHDService.class);
    SDMXHDMessage sdmxhdMessage = sdmxhdService.getMessage(omrsDSD.getSDMXHDMessageId());

    // get keyFamilyId
    KeyFamilyMapping keyFamilyMapping = sdmxhdService
            .getKeyFamilyMappingByReportDefinitionId(reportData.getDefinition().getId());
    String keyFamilyId = keyFamilyMapping.getKeyFamilyId();

    // get reporting month
    Date reportStartDate = (Date) reportData.getContext().getParameterValue("startDate");
    Date reportEndDate = (Date) reportData.getContext().getParameterValue("endDate");
    String timePeriod = null;

    // calculate time period and make sure reporting dates make sense
    String freq = sdmxhdMessage.getGroupElementAttributes().get("FREQ");
    if (freq != null) {
        if (freq.equals("M")) {
            // check that start and end date are the report are beginning and end day of the same month
            Calendar startCal = Calendar.getInstance();
            startCal.setTime(reportStartDate);

            int lastDay = startCal.getActualMaximum(Calendar.DAY_OF_MONTH);
            int month = startCal.get(Calendar.MONTH);
            int year = startCal.get(Calendar.YEAR);

            Calendar endCal = Calendar.getInstance();
            endCal.setTime(reportEndDate);

            if (endCal.get(Calendar.MONTH) != month || endCal.get(Calendar.DAY_OF_MONTH) != lastDay
                    || endCal.get(Calendar.YEAR) != year) {
                throw new RenderingException(
                        "Frequency is set to monthly, but the reporting stat and end date don't correspond to a start and end date of a specific month");
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            timePeriod = sdf.format(reportStartDate);

        } else if (freq.equals("A")) {
            // check start and end date are beginning and end day of same year
            Calendar startCal = Calendar.getInstance();
            startCal.setTime(reportStartDate);

            int startDay = startCal.get(Calendar.DAY_OF_MONTH);
            int startMonth = startCal.get(Calendar.MONTH);
            int startYear = startCal.get(Calendar.YEAR);

            Calendar endCal = Calendar.getInstance();
            endCal.setTime(reportEndDate);

            int endDay = startCal.get(Calendar.DAY_OF_MONTH);
            int endMonth = startCal.get(Calendar.MONTH);
            int endYear = startCal.get(Calendar.YEAR);

            if (startDay != 1 || startMonth != Calendar.JANUARY || startYear != endYear || endDay != 31
                    || endMonth != Calendar.DECEMBER) {
                throw new RenderingException(
                        "Frequency is set to annual, but the reporting start and end date are not the begining of the end day of the same year");
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            timePeriod = sdf.format(reportStartDate);
        }
        // TODO other checks
    }

    try {
        String path = Context.getAdministrationService()
                .getGlobalProperty("sdmxhdintegration.messageUploadDir");
        ZipFile zf = new ZipFile(path + File.separator + sdmxhdMessage.getZipFilename());
        SDMXHDParser parser = new SDMXHDParser();
        org.jembi.sdmxhd.SDMXHDMessage sdmxhdData = parser.parse(zf);
        DSD sdmxhdDSD = sdmxhdData.getDsd();

        //Construct CDS object
        Sender p = new Sender();
        p.setId("OMRS");
        p.setName("OpenMRS");

        Header h = new Header();
        h.setId("SDMX-HD-CSDS");
        h.setTest(false);
        h.setTruncated(false);
        h.getName().addValue("en", "OpenMRS SDMX-HD Export");
        h.setPrepared(iso8601DateFormat.format(new Date()));
        h.getSenders().add(p);

        h.setReportingBegin(iso8601DateFormat.format(reportStartDate));
        h.setReportingEnd(iso8601DateFormat.format(reportEndDate));

        // Construct dataset
        DataSet sdmxhdDataSet = new DataSet();

        sdmxhdDataSet.setReportingBeginDate(iso8601DateFormat.format(reportStartDate));
        sdmxhdDataSet.setReportingEndDate(iso8601DateFormat.format(reportEndDate));

        // Add fixed dataset attributes
        Map<String, String> datasetElementAttributes = sdmxhdMessage.getDatasetElementAttributes();
        for (String attribute : datasetElementAttributes.keySet()) {
            String value = datasetElementAttributes.get(attribute);
            if (StringUtils.hasText(value)) {
                sdmxhdDataSet.addAttribute(attribute, value);
            }
        }

        // Construct group
        Group group = new Group();

        // Set time period and frequency
        if (timePeriod != null)
            group.addAttribute("TIME_PERIOD", timePeriod);
        if (timePeriod != null)
            group.addAttribute("FREQ", freq);

        // Set DataSet attributes
        Map<String, String> dataSetAttachedAttributes = omrsDSD.getDataSetAttachedAttributes();
        for (String key : dataSetAttachedAttributes.keySet()) {
            sdmxhdDataSet.getAttributes().put(key, dataSetAttachedAttributes.get(key));
        }

        // Holder for all sections. Will hold a default section if no explicit hierarchy is found in SL_ISET
        List<Section> sectionList = new ArrayList<Section>();

        // Iterate each row and colum of the dataset
        for (DataSetRow row : dataSet) {
            for (DataSetColumn column : row.getColumnValues().keySet()) {

                CohortIndicatorAndDimensionColumn cidColumn = (CohortIndicatorAndDimensionColumn) column;
                Object value = row.getColumnValues().get(column);
                String columnName = column.getName();

                //get the indicator code for this column
                CohortIndicator indicator = cidColumn.getIndicator().getParameterizable();
                String sdmxhdIndicatorName = omrsDSD.getSDMXHDMappedIndicator(indicator.getId());

                // get indicator/dataelement codelist
                Dimension indDim = sdmxhdDSD.getIndicatorOrDataElementDimension(keyFamilyId);
                CodeList indCodeList = sdmxhdDSD.getCodeList(indDim.getCodelistRef());
                Code indCode = indCodeList.getCodeByDescription(sdmxhdIndicatorName);

                //setup or get the section for this indicator
                Section section = getSectionHelper(indCode, sectionList, sdmxhdDSD); //indicator code, listOfSections, message

                //get the dimension for the list of indicators (CL_INDICATOR)
                Dimension indDimension = sdmxhdDSD.getDimension(indCodeList);

                //construct new (SDMX-HD) obs to contain the indicator value
                Obs obs = new Obs();

                // set the indicator attribute
                obs.getAttributes().put(indDimension.getConceptRef(), indCode.getValue());

                // set Section Attributes
                Map<String, String> seriesAttachedAttributes = omrsDSD.getSeriesAttachedAttributes()
                        .get(columnName);
                if (seriesAttachedAttributes != null) {
                    for (String key : seriesAttachedAttributes.keySet()) {
                        section.getAttributes().put(key, seriesAttachedAttributes.get(key));
                    }
                }

                // write dimensions to obs
                Map<String, String> dimensionOptions = cidColumn.getDimensionOptions();
                // for each dimension option for this column
                for (String omrsDimensionId : dimensionOptions.keySet()) {
                    Integer omrsDimensionIdInt = Integer.parseInt(omrsDimensionId);
                    // find sdmx-hd dimension name in mapping
                    String sdmxhdDimensionName = null;
                    Map<String, Integer> omrsMappedDimensions = omrsDSD.getOMRSMappedDimensions();
                    for (String sdmxhdDimensionNameTemp : omrsMappedDimensions.keySet()) {
                        if (omrsMappedDimensions.get(sdmxhdDimensionNameTemp).equals(omrsDimensionIdInt)) {
                            sdmxhdDimensionName = sdmxhdDimensionNameTemp;
                            break;
                        }
                    }
                    // find sdmx-hd dimension option name in mapping
                    String omrsDimensionOptionName = dimensionOptions.get(omrsDimensionId);
                    String sdmxhdDimensionOptionName = null;
                    Map<String, String> omrsMappedDimensionOptions = omrsDSD.getOMRSMappedDimensionOptions()
                            .get(sdmxhdDimensionName);
                    for (String sdmxhdDimensionOptionNameTemp : omrsMappedDimensionOptions.keySet()) {
                        if (omrsMappedDimensionOptions.get(sdmxhdDimensionOptionNameTemp)
                                .equals(omrsDimensionOptionName)) {
                            sdmxhdDimensionOptionName = sdmxhdDimensionOptionNameTemp;
                            break;
                        }
                    }
                    //find code corresponding to this dimension option
                    Dimension sdmxhdDimension = sdmxhdDSD.getDimension(sdmxhdDimensionName, keyFamilyId);
                    CodeList codeList = sdmxhdDSD.getCodeList(sdmxhdDimension.getCodelistRef());
                    Code code = codeList.getCodeByDescription(sdmxhdDimensionOptionName);
                    obs.addAttribute(sdmxhdDimensionName, code.getValue());
                }

                // add dimensions with default values
                List<String> mappedFixedDimensions = omrsDSD.getMappedFixedDimension(columnName);
                Map<String, String> fixedDimensionValues = omrsDSD.getFixedDimensionValues();
                for (String sdmxhdDimension : mappedFixedDimensions) {
                    if (fixedDimensionValues.get(sdmxhdDimension) != null) {
                        String fixedValue = fixedDimensionValues.get(sdmxhdDimension);
                        Dimension dimension = sdmxhdDSD.getDimension(sdmxhdDimension, keyFamilyId);
                        CodeList codeList = sdmxhdDSD.getCodeList(dimension.getCodelistRef());
                        Code code = codeList.getCodeByDescription(fixedValue);
                        obs.addAttribute(sdmxhdDimension, code.getValue());
                    }
                }

                // set Obs Attributes
                Map<String, String> obsAttachedAttributes = omrsDSD.getObsAttachedAttributes().get(columnName);
                if (obsAttachedAttributes != null) {
                    for (String key : obsAttachedAttributes.keySet()) {
                        obs.getAttributes().put(key, obsAttachedAttributes.get(key));
                    }
                }

                String primaryMeasure = sdmxhdDSD.getKeyFamily(keyFamilyId).getComponents().getPrimaryMeasure()
                        .getConceptRef();
                obs.elementName = primaryMeasure;

                // write value
                if (value instanceof CohortIndicatorAndDimensionResult) {
                    CohortIndicatorAndDimensionResult typedValue = (CohortIndicatorAndDimensionResult) value;
                    obs.getAttributes().put("value", typedValue.getValue().toString());
                } else {
                    obs.getAttributes().put("value", value.toString());
                }

                section.getObs().add(obs);
            }
        }

        // Add all sections to group
        for (Section section : sectionList) {
            group.getSections().add(section);
        }

        // Add group to dataset
        sdmxhdDataSet.getGroups().add(group);

        CSDS csds = new CSDS();
        csds.getDatasets().add(sdmxhdDataSet);
        csds.setHeader(h);

        // build up namespace
        KeyFamily keyFamily = sdmxhdDSD.getKeyFamily(keyFamilyId);
        String derivedNamespace = Constants.DERIVED_NAMESPACE_PREFIX + keyFamily.getAgencyID() + ":"
                + keyFamily.getId() + ":" + keyFamily.getVersion() + ":cross";
        String xml = csds.toXML(derivedNamespace);

        // output csds in original zip
        zf = new ZipFile(path + File.separator + sdmxhdMessage.getZipFilename());
        Utils.outputCsdsInDsdZip(zf, xml, out);
    } catch (IllegalArgumentException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    } catch (XMLStreamException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    } catch (ExternalRefrenceNotFoundException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    } catch (ValidationException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    } catch (SchemaValidationException e) {
        log.error("Error generated", e);
        throw new RenderingException("Error rendering the SDMX-HD message: " + e.getMessage(), e);
    }
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for getting calendar number of month by month
 * description/*w w  w.  j  a  va2  s  .  c  o  m*/
 * 
 * @param monthDescr
 * @return
 */
public static int getMonthNum(String monthDescr) {
    int numOfMonth = -1;
    if (DateTimeConstants.JANUARY.equals(monthDescr)) {
        numOfMonth = Calendar.JANUARY;
    }
    if (DateTimeConstants.FEBRUARY.equals(monthDescr)) {
        numOfMonth = Calendar.FEBRUARY;
    }
    if (DateTimeConstants.MARCH.equals(monthDescr)) {
        numOfMonth = Calendar.MARCH;
    }
    if (DateTimeConstants.APRIL.equals(monthDescr)) {
        numOfMonth = Calendar.APRIL;
    }
    if (DateTimeConstants.MAY.equals(monthDescr)) {
        numOfMonth = Calendar.MAY;
    }
    if (DateTimeConstants.JUNE.equals(monthDescr)) {
        numOfMonth = Calendar.JUNE;
    }
    if (DateTimeConstants.JULY.equals(monthDescr)) {
        numOfMonth = Calendar.JULY;
    }
    if (DateTimeConstants.AUGUST.equals(monthDescr)) {
        numOfMonth = Calendar.AUGUST;
    }
    if (DateTimeConstants.SEPTEMBER.equals(monthDescr)) {
        numOfMonth = Calendar.SEPTEMBER;
    }
    if (DateTimeConstants.OCTOBER.equals(monthDescr)) {
        numOfMonth = Calendar.OCTOBER;
    }
    if (DateTimeConstants.NOVEMBER.equals(monthDescr)) {
        numOfMonth = Calendar.NOVEMBER;
    }
    if (DateTimeConstants.DECEMBER.equals(monthDescr)) {
        numOfMonth = Calendar.DECEMBER;
    }
    return numOfMonth;
}

From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java

@Test
public void findExactOrClosestPastReleaseShouldReturnNullIfNoPastReleaseHasBeenFound() {
    // given/*from   w w  w  .ja  v a2s  .c  o  m*/
    SortedSet<ReleaseEntity> releases = new TreeSet<>();
    releases.add(release1);
    releases.add(release2);
    releases.add(release3);
    releases.add(release4);

    Calendar cal = new GregorianCalendar();
    cal.set(2000, Calendar.DECEMBER, 31);
    Date relevantDate = new Date(cal.getTimeInMillis());

    // when
    ReleaseEntity mostRelevantRelease = service.findExactOrClosestPastRelease(releases, relevantDate);

    // then
    assertNull(mostRelevantRelease);
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene.AclSearchIndexTest.java

/**
 * Tests that the execution of a query on all pets does not return any dog, because of an ACL rule.
 * @throws Exception/*from w ww . ja  va2s  .  c o m*/
 */
@Test
public void testDogsExcluded() throws Exception {
    final AccessManager wrappedAM = MgnlContext.getAccessManager(RepositoryConstants.WEBSITE);

    Assert.assertNotNull(wrappedAM, "AccessManager is null");

    final AccessManager wrapperAM = new AccessManager() {

        public boolean isGranted(String path, long permissions) {
            // ACL rule: read permission on pets subtree
            if (StringUtils.startsWith(path, "/pets/")) {
                // ACL rule: deny permission on dogs subtree
                return !StringUtils.startsWith(path, "/pets/dogs/");
            }
            return wrappedAM.isGranted(path, permissions);
        }

        public void setPermissionList(List<Permission> permissions) {
            wrappedAM.setPermissionList(permissions);
        }

        public List<Permission> getPermissionList() {
            return wrappedAM.getPermissionList();
        }

        public long getPermissions(String path) {
            return wrappedAM.getPermissions(path);
        }
    };
    MgnlContext.setInstance(new ContextDecorator(MgnlContext.getInstance()) {

        /**
         * {@inheritDoc}
         */
        @Override
        public AccessManager getAccessManager(String name) {
            if (RepositoryConstants.WEBSITE.equals(name)) {
                return wrapperAM;
            }
            return super.getAccessManager(name);
        }
    });
    try {
        Calendar begin = Calendar.getInstance();
        begin.set(1999, Calendar.JANUARY, 1);
        Calendar end = Calendar.getInstance();
        end.set(2001, Calendar.DECEMBER, 31);

        Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
                .setBasePath("/pets").add(Restrictions.between("@birthDate", begin, end))
                .addOrder(Order.asc("@birthDate"));

        AdvancedResult result = criteria.execute();

        // Accessible results (dogs excluded):
        // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
        // --- 6 (title=George, petType=snake, birthDate=2000-01-20)
        // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
        // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
        // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
        ResultIterator<? extends Node> iterator = result.getItems();

        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "9");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "6");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "11");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "1");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "5");
        Assert.assertFalse(iterator.hasNext());
    } finally {
        MgnlContext.setInstance(((ContextDecorator) MgnlContext.getInstance()).getWrappedContext());
    }
}