Example usage for java.util GregorianCalendar add

List of usage examples for java.util GregorianCalendar add

Introduction

In this page you can find the example usage for java.util GregorianCalendar add.

Prototype

@Override
public void add(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java

private boolean checkMonthDayList(GregorianCalendar cal) {
    if (mByMonthDayList.size() > 0) {
        for (Integer cur : mByMonthDayList) {
            int curMonthDay = cal.get(Calendar.DAY_OF_MONTH);
            if (cur == curMonthDay)
                return true;

            // since the list is in order, if we hit a HIGHER one,
            // then we know out current one isn't in the list, and therefore
            // we should go to this one we just found in the list
            if (cur > curMonthDay) {
                cal.set(Calendar.DAY_OF_MONTH, cur);
                return false;
            }// w ww  .j  av  a 2 s .  co m
        }

        // we've not found a match AND we've not found a
        // higher value in our list -- so wrap
        cal.set(Calendar.DAY_OF_MONTH, mByMonthDayList.get(0));
        cal.add(Calendar.MONTH, 1);
        return false;
    }
    return true;
}

From source file:ezbake.services.search.SSRServiceHandler.java

private Facet getDateRangeFacets(String field, String label) {
    GregorianCalendar calendar = new GregorianCalendar();

    Facet dateFacet = new Facet();
    RangeFacet dateRangeFacet = new RangeFacet();
    BaseFacetValue dateField = new BaseFacetValue();
    dateField.setFacetField(field);/*from w ww . j  ava 2  s  . com*/
    dateRangeFacet.setField(dateField);

    FacetRange last24 = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    last24hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    last24.setRangeFrom(String.valueOf(last24hoursMS));
    dateRangeFacet.addToRanges(last24);

    FacetRange last48 = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    last48hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    last48.setRangeFrom(String.valueOf(last48hoursMS));
    dateRangeFacet.addToRanges(last48);

    FacetRange last72 = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    last72hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    last72.setRangeFrom(String.valueOf(last72hoursMS));
    dateRangeFacet.addToRanges(last72);

    FacetRange lastWeek = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -4);
    last7daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    lastWeek.setRangeFrom(String.valueOf(last7daysMS));
    dateRangeFacet.addToRanges(lastWeek);

    FacetRange last30Days = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -23);
    last30daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    last30Days.setRangeFrom(String.valueOf(last30daysMS));
    dateRangeFacet.addToRanges(last30Days);

    FacetRange last90Days = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -60);
    last90daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    last90Days.setRangeFrom(String.valueOf(last90daysMS));
    dateRangeFacet.addToRanges(last90Days);

    FacetRange lastYear = new FacetRange(RangeType.DATE);
    calendar.add(Calendar.DAY_OF_YEAR, -275);
    last365daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis();
    lastYear.setRangeFrom(String.valueOf(last365daysMS));
    dateRangeFacet.addToRanges(lastYear);

    FacetRequest dateRequest = new FacetRequest();
    dateRequest.setRangeFacet(dateRangeFacet);

    dateFacet.setLabel(label);
    dateFacet.setFacet(dateRequest);

    return dateFacet;
}

From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java

/**
 * This version is for HOURLY/DAILY frequencies: it does NOT check the ordinal at all,
 * it only verifies that the day-of-the-week matches
 *
 * @param cal/*from ww  w  .  j  a  va  2s . c o m*/
 * @return
 */
private boolean checkDayList(GregorianCalendar cal) {
    assert (mFreq != Frequency.MONTHLY && mFreq != Frequency.YEARLY && mFreq != Frequency.WEEKLY);

    if (mByDayList.size() > 0) {
        for (ZWeekDayNum listCur : mByDayList) {
            int curDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
            if (listCur.mDay.getCalendarDay() == curDayOfWeek)
                return true;

            // since the DayOfWeek list is in week-order, if we hit a HIGHER one,
            // then we know out current one isn't in the list, and therefore
            // we should go to this one we just found in the list
            if (listCur.mDay.getCalendarDay() > curDayOfWeek) {
                cal.set(Calendar.DAY_OF_WEEK, listCur.mDay.getCalendarDay());
                return false;
            }
        }

        // we've not found a match AND we've not found a
        // higher value in our list -- so wrap
        cal.set(Calendar.DAY_OF_WEEK, mByDayList.get(0).mDay.getCalendarDay());
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        return false;
    }
    return true;
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static void parseAndSetCalendarRecords(ZCView zcView, Node calendarNode) {

    zcView.setGrouped(true);/*w w  w  .  j a  v  a  2  s.c o  m*/
    NodeList eventsList = calendarNode.getChildNodes();
    int year = zcView.getRecordsMonthYear().getTwo() - 1900;
    int month = zcView.getRecordsMonthYear().getOne();

    GregorianCalendar cureentmnthcalendar = new GregorianCalendar();
    Date currentDate = new Date();

    for (int i = 0; i < eventsList.getLength(); i++) {
        Node eventNode = eventsList.item(i);
        NamedNodeMap eventAttrMap = eventNode.getAttributes();
        long recordid = Long.parseLong(eventAttrMap.getNamedItem("id").getNodeValue()); //No I18N
        String title = getChildNodeValue(eventNode, "title"); //eventAttrMap.getNamedItem("title").getNodeValue(); //No I18N
        boolean isAllDay = Boolean.parseBoolean(eventAttrMap.getNamedItem("allDay").getNodeValue()); //No I18N
        // 07/31/2013 08:00:00
        String dateFormat = "MM/dd/yyyy HH:mm:ss"; //No I18N
        if (isAllDay) {
            dateFormat = "MM/dd/yyyy"; //No I18N
        }

        Date startTime = getDateValue(eventAttrMap.getNamedItem("start").getNodeValue(), dateFormat); //No I18N

        ZCRecord record = zcView.getRecord(recordid);

        record.setEventTitle(title);
        if (isAllDay) {
            zcView.setIsAllDay(isAllDay);

            Node endNode = eventAttrMap.getNamedItem("end");//No I18N
            Date endTime = null;
            if (endNode != null) {
                endTime = getDateValue(endNode.getNodeValue(), dateFormat);
            }

            int startDay = -1;
            if (startTime != null) {
                startDay = startTime.getDate();
            }

            int endDay = -1;
            if (endTime != null) {
                endDay = endTime.getDate();
            }

            if (endDay != -1) {

                currentDate.setDate(1);
                currentDate.setMonth(month);
                currentDate.setYear(year);
                currentDate.setMinutes(0);
                currentDate.setHours(0);
                currentDate.setSeconds(0);

                cureentmnthcalendar.setTime(currentDate);

                cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, -6);
                currentDate = cureentmnthcalendar.getTime();

                for (int j = 0; j < 42; j++) {
                    if ((currentDate.getDate() == startTime.getDate()
                            && currentDate.getMonth() == startTime.getMonth()
                            && currentDate.getYear() == startTime.getYear())
                            || (currentDate.after(startTime) && currentDate.before(endTime))
                            || (currentDate.getDate() == endTime.getDate()
                                    && currentDate.getMonth() == endTime.getMonth()
                                    && currentDate.getYear() == endTime.getYear())) {

                        zcView.setEvent(record, currentDate);
                    }
                    cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, 1);
                    currentDate = cureentmnthcalendar.getTime();
                }
                //Collections.sort(eventRecords);
            }

            record.setEventDate(startTime);
        } else {
            // 07/31/2013 08:00:00
            Date endTime = getDateValue(eventAttrMap.getNamedItem("end").getNodeValue(), dateFormat); //No I18N
            record.setStartTime(startTime);
            record.setEndTime(endTime);

            Calendar startCalendar = new GregorianCalendar();
            startCalendar.setTime(startTime);
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.MILLISECOND, 0);

            Calendar endCalendar = new GregorianCalendar();
            endCalendar.setTime(endTime);
            endCalendar.set(Calendar.HOUR_OF_DAY, 0);
            endCalendar.set(Calendar.MINUTE, 0);
            endCalendar.set(Calendar.SECOND, 0);
            endCalendar.set(Calendar.MILLISECOND, 0);

            Date eventDate = new Date(startCalendar.getTimeInMillis());
            zcView.setEvent(record, eventDate);
            while ((startCalendar.get(Calendar.YEAR) != endCalendar.get(Calendar.YEAR))
                    || (startCalendar.get(Calendar.MONTH) != endCalendar.get(Calendar.MONTH))
                    || (startCalendar.get(Calendar.DATE) != endCalendar.get(Calendar.DATE))) {
                startCalendar.add(Calendar.DATE, 1);
                eventDate = new Date(startCalendar.getTimeInMillis());
                zcView.setEvent(record, eventDate);
            }
        }
    }

    List<ZCGroup> zcGroups = zcView.getGroups();
    HashMap<Date, List<ZCRecord>> eventsMap = zcView.getEventRecordsMap();
    SortedSet<Date> keys = new TreeSet<Date>(eventsMap.keySet());

    for (Date eventDate : keys) {
        List<ZCRecord> eventRecords = eventsMap.get(eventDate);
        List<String> groupHeaderValues = new ArrayList<String>();
        SimpleDateFormat dateFormat = new SimpleDateFormat(zcView.getDateFormat()); //No I18N
        groupHeaderValues.add(dateFormat.format(eventDate));
        ZCGroup zcGroup = new ZCGroup(groupHeaderValues);
        zcGroups.add(zcGroup);
        for (int i = 0; i < eventRecords.size(); i++) {
            ZCRecord eventRecord = eventRecords.get(i);
            zcGroup.addRecord(eventRecord);
        }
    }
    zcView.sortRecordsForCalendar();

}

From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java

/**
 * @param aFile the file to write to/*from  ww  w.  j av a  2  s  .co m*/
 * @param aGran the granularity
 */
private void exportCSV(final File aFile, final ExportGranularities aGran) {
    //TODO: implement CSV-export

    FileWriter fw = null;
    try {
        fw = new FileWriter(aFile);
        // write headers
        List<TransactionSum> sums = mySums;
        fw.write("day");
        for (TransactionSum transactionSum : sums) {
            fw.write(",");
            fw.write(transactionSum.getName());
        }
        fw.write("\n");

        // write data
        GregorianCalendar cal = new GregorianCalendar();
        int add = aGran.getCalendarConstant();
        DateFormat dateFormat = DateFormat.getDateInstance();
        //NumberFormat numberFormat = NumberFormat.getInstance();
        // we do NOT use getCurrencyInstance because it
        // contains a locale-specific currency-symbol
        for (int i = 0; i < 100; i++) {
            Date maxDate = cal.getTime();

            fw.write(dateFormat.format(maxDate));
            int transactionsCounted = 0;
            for (TransactionSum transactionSum : sums) {
                fw.write(",");
                try {
                    transactionSum.setMaxDate(maxDate);
                    FixedPointNumber value = transactionSum.getValue();
                    if (value != null) {
                        //fw.write(numberFormat.format(value));
                        fw.write(value.toString());
                    }
                    transactionsCounted += transactionSum.getTransactionsCounted();
                } catch (JAXBException e) {
                    LOGGER.error("Error calculating one of the TransactionSums", e);
                    fw.write("ERROR");
                }
            }
            fw.write("\n");
            if (transactionsCounted == 0) {
                break;
                // we are walking back in time,
                // when there are no matching transactions,
                // all future runs will we a waste of time.
                // This happens often when add==YEAR
            }

            long old = cal.getTimeInMillis();
            if (add == GregorianCalendar.MONTH) {
                cal.set(GregorianCalendar.DAY_OF_MONTH, 1);
            }
            if (add == GregorianCalendar.YEAR) {
                cal.set(GregorianCalendar.DAY_OF_MONTH, 1);
                cal.set(GregorianCalendar.MONTH, 1);
            }
            // usually we are in the middle of a month,
            // so do not skip the first day of the current
            // month
            if (i != 0 || old == cal.getTimeInMillis() || add == GregorianCalendar.DAY_OF_MONTH) {
                cal.add(add, -1);
            }
        }

        fw.close();
        fw = null;
    } catch (IOException e) {
        LOGGER.error("cannot write csv-file", e);
        JOptionPane.showMessageDialog(this, "Cannot write CSV-file\n" + e.getMessage());
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                LOGGER.error("cannot close csv-file", e);
            }
        }
        for (TransactionSum transactionSum : mySums) {
            try {
                transactionSum.setMaxDate(null);
            } catch (JAXBException e) {
                LOGGER.error("cannot set maxDate back to it's original value", e);
            }
        }
    }
}

From source file:org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.java

/**
 *
 *//*www . j av a2 s  .  c  om*/
public boolean doAuthenticate(String userName, Object credential) throws UserStoreException {

    if (!checkUserNameValid(userName)) {
        return false;
    }

    if (!checkUserPasswordValid(credential)) {
        return false;
    }

    if (UserCoreUtil.isRegistryAnnonymousUser(userName)) {
        log.error("Anonnymous user trying to login");
        return false;
    }

    Connection dbConnection = null;
    ResultSet rs = null;
    PreparedStatement prepStmt = null;
    String sqlstmt = null;
    String password = (String) credential;
    boolean isAuthed = false;

    try {
        dbConnection = getDBConnection();
        dbConnection.setAutoCommit(false);

        if (isCaseSensitiveUsername()) {
            sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER);
        } else {
            sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER_CASE_INSENSITIVE);
        }

        if (log.isDebugEnabled()) {
            log.debug(sqlstmt);
        }

        prepStmt = dbConnection.prepareStatement(sqlstmt);
        prepStmt.setString(1, userName);
        if (sqlstmt.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
            prepStmt.setInt(2, tenantId);
        }

        rs = prepStmt.executeQuery();

        if (rs.next() == true) {
            String storedPassword = rs.getString(3);
            String saltValue = null;
            if ("true".equalsIgnoreCase(
                    realmConfig.getUserStoreProperty(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
                saltValue = rs.getString(4);
            }

            boolean requireChange = rs.getBoolean(5);
            Timestamp changedTime = rs.getTimestamp(6);

            GregorianCalendar gc = new GregorianCalendar();
            gc.add(GregorianCalendar.HOUR, -24);
            Date date = gc.getTime();

            if (requireChange == true && changedTime.before(date)) {
                isAuthed = false;
            } else {
                password = this.preparePassword(password, saltValue);
                if ((storedPassword != null) && (storedPassword.equals(password))) {
                    isAuthed = true;
                }
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while retrieving user authentication info for user : " + userName;
        if (log.isDebugEnabled()) {
            log.debug(msg, e);
        }
        throw new UserStoreException("Authentication Failure", e);
    } finally {
        DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
    }

    if (log.isDebugEnabled()) {
        log.debug("User " + userName + " login attempt. Login success :: " + isAuthed);
    }

    return isAuthed;
}

From source file:org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.java

/**
 *
 *///from  w  w  w  . j a  v  a 2s . c om
public Date getPasswordExpirationTime(String userName) throws UserStoreException {

    if (userName != null && userName.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
        return super.getPasswordExpirationTime(userName);
    }

    Connection dbConnection = null;
    ResultSet rs = null;
    PreparedStatement prepStmt = null;
    String sqlstmt = null;
    Date date = null;

    try {
        dbConnection = getDBConnection();
        dbConnection.setAutoCommit(false);

        if (isCaseSensitiveUsername()) {
            sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER);
        } else {
            sqlstmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.SELECT_USER_CASE_INSENSITIVE);
        }

        if (log.isDebugEnabled()) {
            log.debug(sqlstmt);
        }

        prepStmt = dbConnection.prepareStatement(sqlstmt);
        prepStmt.setString(1, userName);
        if (sqlstmt.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
            prepStmt.setInt(2, tenantId);
        }

        rs = prepStmt.executeQuery();

        if (rs.next() == true) {
            boolean requireChange = rs.getBoolean(5);
            Timestamp changedTime = rs.getTimestamp(6);
            if (requireChange) {
                GregorianCalendar gc = new GregorianCalendar();
                gc.setTime(changedTime);
                gc.add(GregorianCalendar.HOUR, 24);
                date = gc.getTime();
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while retrieving password expiration time for user : " + userName;
        if (log.isDebugEnabled()) {
            log.debug(msg, e);
        }
        throw new UserStoreException(msg, e);
    } finally {
        DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
    }
    return date;
}

From source file:de.innovationgate.wga.server.api.WGA.java

/**
 * Modifies a date by adding/substracting a certain timespan
 * This is a utility method for simple modifications to dates without the use of {@link Calendar} objects. it returns a new {@link Date} object which represents the date of the parameter "date" plus/minus a given timespan.
 * In order to add a timespan one is first to choose which time unit to use via argument "unit" and then the amount of units to add via argument "amount". In order to substract a timespan from the date a negative amount value is to be used.
 * The unit is determined by the date string character that would be used by {@link SimpleDateFormat} for the time unit:
 * <ul>//from   w  ww  . jav a  2s.  co m
 * <li> d" or "D" - Day
 * <li> "M" - Month
 * <li> "w" or "W" - Week
 * <li> "y" - Year
 * <li> "H" or "h" - Hour
 * <li> "m" - Minute
 * <li> "s" - Second
 * <li> "S" - Millisecond
 * <ul>
 * @param date Date to modify
 * @param unit Modify unit. See table above.
 * @param amount Amount of date units to add to the date. Specify negative amounts to substract. 
 * @return The modified date
 * @throws WGAServerException
 */
public Date modifyDate(Date date, String unit, int amount) throws WGException {

    int field;
    switch (unit.charAt(0)) {

    case 'd':
    case 'D':
        field = GregorianCalendar.DAY_OF_MONTH;
        break;

    case 'M':
        field = GregorianCalendar.MONTH;
        break;

    case 'w':
    case 'W':
        field = GregorianCalendar.WEEK_OF_YEAR;
        break;

    case 'y':
        field = GregorianCalendar.YEAR;
        break;

    case 'H':
    case 'h':
        field = GregorianCalendar.HOUR;
        break;

    case 'm':
        field = GregorianCalendar.MINUTE;
        break;

    case 's':
        field = GregorianCalendar.SECOND;
        break;

    case 'S':
        field = GregorianCalendar.MILLISECOND;
        break;

    default:
        throw new WGAServerException("Unknown date field literal: " + unit);

    }

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(field, amount);
    return cal.getTime();

}

From source file:org.apache.lens.server.metastore.TestMetastoreService.java

private XDimension createDimension(String dimName) throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(new Date());
    final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.add(GregorianCalendar.DAY_OF_MONTH, 7);
    final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

    XDimension dimension = cubeObjectFactory.createXDimension();
    dimension.setName(dimName);/*from  w ww  .java2s  .  c  om*/

    dimension.setAttributes(new XDimAttributes());
    dimension.setExpressions(new XExpressions());
    dimension.setJoinChains(new XJoinChains());
    dimension.setProperties(new XProperties().withProperty(
            new XProperty().withName(MetastoreUtil.getDimTimedDimensionKey(dimName)).withValue("dt")));
    XDimAttribute xd1 = cubeObjectFactory.createXDimAttribute();
    xd1.setName("col1");
    xd1.setType("STRING");
    xd1.setDescription("first column");
    xd1.setDisplayString("Column1");
    // Don't set endtime on this dim to validate null handling on server side
    xd1.setStartTime(startDate);

    XDimAttribute xd2 = cubeObjectFactory.createXDimAttribute();
    xd2.setName("col2");
    xd2.setType("INT");
    xd2.setDescription("second column");
    xd2.setDisplayString("Column2");
    // Don't set start time on this dim to validate null handling on server side
    xd2.setEndTime(endDate);

    dimension.getAttributes().getDimAttribute().add(xd1);
    dimension.getAttributes().getDimAttribute().add(xd2);

    XExprColumn xe1 = new XExprColumn();
    xe1.setName("dimexpr");
    xe1.setType("STRING");
    xe1.setDescription("dimension expression");
    xe1.setDisplayString("Dim Expression");
    XExprSpec es = new XExprSpec();
    es.setExpr("substr(col1, 3)");
    xe1.getExprSpec().add(es);
    dimension.getExpressions().getExpression().add(xe1);

    XProperty xp1 = cubeObjectFactory.createXProperty();
    xp1.setName("dimension.foo");
    xp1.setValue("dim.bar");
    dimension.getProperties().getProperty().add(xp1);
    return dimension;
}

From source file:org.apache.lens.server.metastore.TestMetastoreService.java

private XBaseCube createTestCube(String cubeName) throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(new Date());
    final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.add(GregorianCalendar.DAY_OF_MONTH, 7);
    final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

    XBaseCube cube = cubeObjectFactory.createXBaseCube();
    cube.setName(cubeName);// www  .ja v  a 2s .  c o m
    cube.setDimAttributes(new XDimAttributes());
    cube.setExpressions(new XExpressions());
    cube.setMeasures(new XMeasures());
    cube.setJoinChains(new XJoinChains());
    cube.setProperties(new XProperties());
    XDimAttribute xd1 = cubeObjectFactory.createXDimAttribute();
    xd1.setName("dim1");
    xd1.setType("STRING");
    xd1.setDescription("first dimension");
    xd1.setDisplayString("Dimension1");
    // Don't set endtime on this dim to validate null handling on server side
    xd1.setStartTime(startDate);
    xd1.setNumDistinctValues(2000L);

    XDimAttribute xd2 = cubeObjectFactory.createXDimAttribute();
    xd2.setName("dim2");
    xd2.setType("INT");
    xd2.setDescription("second dimension");
    xd2.setDisplayString("Dimension2");
    // Don't set start time on this dim to validate null handling on server side
    xd2.setEndTime(endDate);

    XDimAttribute xd3 = cubeObjectFactory.createXDimAttribute();
    xd3.setName("testdim2col2");
    xd3.setType("STRING");
    xd3.setDescription("ref chained dimension");
    xd3.setDisplayString("Chained Dimension");
    XChainColumn xcc = new XChainColumn();
    xcc.setChainName("chain1");
    xcc.setRefCol("col2");
    xd3.getChainRefColumn().add(xcc);
    xd3.setNumDistinctValues(1000L);

    // add attribute with complex type
    XDimAttribute xd4 = cubeObjectFactory.createXDimAttribute();
    xd4.setName("dim4");
    xd4.setType("struct<a:INT,b:array<string>,c:map<int,array<struct<x:int,y:array<int>>>");
    xd4.setDescription("complex attribute");
    xd4.setDisplayString("Complex Attribute");

    cube.getDimAttributes().getDimAttribute().add(xd1);
    cube.getDimAttributes().getDimAttribute().add(xd2);
    cube.getDimAttributes().getDimAttribute().add(xd3);
    cube.getDimAttributes().getDimAttribute().add(xd4);

    XMeasure xm1 = new XMeasure();
    xm1.setName("msr1");
    xm1.setType(XMeasureType.DOUBLE);
    xm1.setDescription("first measure");
    xm1.setDisplayString("Measure1");
    // Don't set start time and end time to validate null handling on server side.
    //xm1.setStarttime(startDate);
    //xm1.setEndtime(endDate);
    xm1.setDefaultAggr("sum");

    XMeasure xm2 = new XMeasure();
    xm2.setName("msr2");
    xm2.setType(XMeasureType.INT);
    xm2.setDescription("second measure");
    xm2.setDisplayString("Measure2");
    xm2.setStartTime(startDate);
    xm2.setEndTime(endDate);
    xm2.setDefaultAggr("max");

    cube.getMeasures().getMeasure().add(xm1);
    cube.getMeasures().getMeasure().add(xm2);

    XJoinChain xj1 = new XJoinChain();
    xj1.setName("chain1");
    xj1.setDescription("first chain");
    xj1.setDisplayString("Chain-1");
    xj1.setPaths(new XJoinPaths());
    XJoinPath path1 = cubeObjectFactory.createXJoinPath();
    path1.setEdges(new XJoinEdges());
    XTableReference link1 = new XTableReference();
    link1.setTable(cubeName);
    link1.setColumn("col1");
    XTableReference link2 = new XTableReference();
    link2.setTable("testdim");
    link2.setColumn("col1");
    link2.setMapsToMany(true);
    XJoinEdge edge1 = cubeObjectFactory.createXJoinEdge();
    edge1.setFrom(link1);
    edge1.setTo(link2);
    path1.getEdges().getEdge().add(edge1);
    xj1.getPaths().getPath().add(path1);
    cube.getJoinChains().getJoinChain().add(xj1);

    XJoinChain xj2 = new XJoinChain();
    xj2.setName("dim2chain");
    xj2.setDescription("testdim2 chain");
    xj2.setDisplayString("Chain-2");
    xj2.setPaths(new XJoinPaths());
    XJoinPath path = cubeObjectFactory.createXJoinPath();
    path.setEdges(new XJoinEdges());
    path.getEdges().getEdge().add(edge1);
    XJoinEdge edge2 = cubeObjectFactory.createXJoinEdge();
    XTableReference link3 = new XTableReference();
    link3.setTable("testdim");
    link3.setColumn("col2");
    XTableReference link4 = new XTableReference();
    link4.setTable("testdim2");
    link4.setColumn("col1");
    edge2.setFrom(link3);
    edge2.setTo(link4);
    path.getEdges().getEdge().add(edge2);
    xj2.getPaths().getPath().add(path);
    cube.getJoinChains().getJoinChain().add(xj2);

    XExprColumn xe1 = new XExprColumn();
    xe1.setName("expr1");
    xe1.setType("DOUBLE");
    xe1.setDescription("first expression");
    xe1.setDisplayString("Expression1");
    XExprSpec es = new XExprSpec();
    es.setExpr("msr1/1000");
    xe1.getExprSpec().add(es);

    XExprColumn xe2 = new XExprColumn();
    xe2.setName("expr2");
    xe2.setType("float");
    xe2.setDescription("multi expression");
    xe2.setDisplayString("Expression2");
    XExprSpec es1 = new XExprSpec();
    es1.setExpr("msr1/1000");
    xe2.getExprSpec().add(es1);
    XExprSpec es2 = new XExprSpec();
    es2.setExpr("(msr1/1000) + 0.01");
    es2.setStartTime(startDate);
    xe2.getExprSpec().add(es2);
    XExprSpec es3 = new XExprSpec();
    es3.setExpr("(msr1/1000) + 0.03");
    es3.setEndTime(endDate);
    xe2.getExprSpec().add(es3);
    XExprSpec es4 = new XExprSpec();
    es4.setExpr("(msr1/1000) - 0.01");
    es4.setStartTime(startDate);
    es4.setEndTime(endDate);
    xe2.getExprSpec().add(es4);

    cube.getExpressions().getExpression().add(xe1);
    cube.getExpressions().getExpression().add(xe2);

    XProperty xp1 = cubeObjectFactory.createXProperty();
    xp1.setName("foo");
    xp1.setValue("bar");
    cube.getProperties().getProperty().add(xp1);
    return cube;
}