List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.hotwire.test.steps.tools.c3.search.C3SearchModel.java
License:Open Source License
public void verifyCustomerType() { String type = customerInfo.getCustomerType().toString(); CustomerInfo profile = customerProfiles.get(type); assertThat(profile.getAccountType()) .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getAccountType()); LOGGER.info("Customer Type: OK"); assertThat(profile.getWatermark())// w ww . jav a 2 s . c om .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getWatermark()); LOGGER.info("Customer Watermark: OK"); verifyBreadCrumbs(profile.getBreadcrumbs()); switch (customerInfo.getCustomerType()) { case PARTNER: LOGGER.info("Partner purchase"); break; case EX_EXPRESS: LOGGER.info("Former express customer purchase"); final String expressProgramStatus = new C3CustomerInfoFragment(getWebdriverInstance()) .getExpressProgramStatus(); assertThat(expressProgramStatus).contains("Former"); String timestamp = expressProgramStatus.replaceFirst("^.*\\(", "").replaceFirst("\\)$", ""); DateTime parsedTimestamp = DateTimeFormat.forPattern("dd-MMM-yy h:mm a") .parseDateTime(timestamp.replace(" at", "")); //Assert that timestamp that is displayed in C3 not differs timestamp // from DB or differs in 5 seconds range assertThat(Math.abs(parsedTimestamp.getMillis() - customerInfo.getExpressDownGradeDate().getMillis()) / 10000).isLessThanOrEqualTo(5); break; default: assertThat(profile.getExpressProgram()) .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getExpressProgramStatus()); } LOGGER.info("Express Program: OK"); }
From source file:com.hpcloud.mon.infrastructure.persistence.AlarmStateHistoryRepositoryImpl.java
License:Apache License
@Override public Collection<AlarmStateHistory> find(String tenantId, Map<String, String> dimensions, DateTime startTime, @Nullable DateTime endTime) {/*from w w w .ja v a 2 s . c o m*/ List<String> alarmIds = null; // Find alarm Ids for dimensions try (Handle h = mysql.open()) { String sql = String.format(FIND_ALARMS_SQL, SubAlarmQueries.buildJoinClauseFor(dimensions)); Query<Map<String, Object>> query = h.createQuery(sql).bind("tenantId", tenantId); DimensionQueries.bindDimensionsToQuery(query, dimensions); alarmIds = query.map(StringMapper.FIRST).list(); } if (alarmIds == null || alarmIds.isEmpty()) return Collections.emptyList(); // Find alarm state history for alarm Ids try (Handle h = vertica.open()) { // Build sql StringBuilder sbWhere = new StringBuilder(); sbWhere.append(" and alarm_id in ("); for (int i = 0; i < alarmIds.size(); i++) { if (i > 0) sbWhere.append(", "); sbWhere.append('\'').append(alarmIds.get(i)).append('\''); } sbWhere.append(')'); if (startTime != null) sbWhere.append(" and time_stamp >= :startTime"); if (endTime != null) sbWhere.append(" and time_stamp <= :endTime"); String sql = String.format(FIND_BY_ALARM_DEF_SQL, sbWhere); // Build query Query<Map<String, Object>> query = h.createQuery(sql).bind("tenantId", tenantId); if (startTime != null) query.bind("startTime", new Timestamp(startTime.getMillis())); if (endTime != null) query.bind("endTime", new Timestamp(endTime.getMillis())); DimensionQueries.bindDimensionsToQuery(query, dimensions); return query.map(new BeanMapper<>(AlarmStateHistory.class)).list(); } }
From source file:com.hpcloud.mon.infrastructure.persistence.MeasurementRepositoryImpl.java
License:Apache License
@Override public Collection<Measurements> find(String tenantId, String name, Map<String, String> dimensions, DateTime startTime, @Nullable DateTime endTime) { try (Handle h = db.open()) { // Build sql StringBuilder sbWhere = new StringBuilder(); if (name != null) sbWhere.append(" and def.name = :name"); if (endTime != null) sbWhere.append(" and m.time_stamp <= :endTime"); String sql = String.format(FIND_BY_METRIC_DEF_SQL, MetricQueries.buildJoinClauseFor(dimensions), sbWhere);/* ww w . j av a 2 s . c om*/ // Build query Query<Map<String, Object>> query = h.createQuery(sql).bind("tenantId", tenantId).bind("startTime", new Timestamp(startTime.getMillis())); if (name != null) query.bind("name", name); if (endTime != null) query.bind("endTime", new Timestamp(endTime.getMillis())); DimensionQueries.bindDimensionsToQuery(query, dimensions); // Execute query List<Map<String, Object>> rows = query.list(); // Build results Map<ByteBuffer, Measurements> results = new LinkedHashMap<>(); for (Map<String, Object> row : rows) { byte[] defIdBytes = (byte[]) row.get("definition_dimensions_id"); byte[] dimSetIdBytes = (byte[]) row.get("dimension_set_id"); ByteBuffer defId = ByteBuffer.wrap(defIdBytes); long measurementId = (Long) row.get("id"); String timestamp = DATETIME_FORMATTER.print(((Timestamp) row.get("time_stamp")).getTime()); double value = (double) row.get("value"); Measurements measurements = results.get(defId); if (measurements == null) { measurements = new Measurements(name, MetricQueries.dimensionsFor(h, dimSetIdBytes), new ArrayList<Object[]>()); results.put(defId, measurements); } measurements.addMeasurement(new Object[] { measurementId, timestamp, value }); } return results.values(); } }
From source file:com.hpcloud.mon.infrastructure.persistence.StatisticRepositoryImpl.java
License:Apache License
private Map<byte[], Statistics> findDefIds(Handle h, String tenantId, String name, Map<String, String> dimensions, DateTime startTime, DateTime endTime) { List<byte[]> bytes = new ArrayList<>(); // Build query StringBuilder sbWhere = new StringBuilder(); if (name != null) sbWhere.append(" and def.name = :name"); String sql = String.format(FIND_BY_METRIC_DEF_SQL, MetricQueries.buildJoinClauseFor(dimensions), sbWhere); Query<Map<String, Object>> query = h.createQuery(sql).bind("tenantId", tenantId).bind("startTime", startTime);//from www. jav a 2s. c o m if (name != null) { query.bind("name", name); } if (endTime != null) { query.bind("endTime", new Timestamp(endTime.getMillis())); } DimensionQueries.bindDimensionsToQuery(query, dimensions); // Execute List<Map<String, Object>> rows = query.list(); Map<byte[], Statistics> byteIdMap = new HashMap<>(); // Build results byte[] currentId = null; Map<String, String> dims = null; for (Map<String, Object> row : rows) { byte[] defId = (byte[]) row.get("id"); String defName = (String) row.get("name"); String demName = (String) row.get("dname"); String demValue = (String) row.get("dvalue"); if (defId == null || !Arrays.equals(currentId, defId)) { currentId = defId; dims = new HashMap<>(); dims.put(demName, demValue); Statistics statistics = new Statistics(); statistics.setName(defName); statistics.setDimensions(dims); byteIdMap.put(currentId, statistics); } else dims.put(demName, demValue); } bytes.add(currentId); return byteIdMap; }
From source file:com.hpcloud.mon.infrastructure.persistence.vertica.MeasurementVerticaRepositoryImpl.java
License:Apache License
@Override public Collection<Measurements> find(String tenantId, String name, Map<String, String> dimensions, DateTime startTime, @Nullable DateTime endTime) { try (Handle h = db.open()) { // Build sql StringBuilder sbWhere = new StringBuilder(); if (name != null) sbWhere.append(" and def.name = :name"); if (endTime != null) sbWhere.append(" and m.time_stamp <= :endTime"); String sql = String.format(FIND_BY_METRIC_DEF_SQL, MetricQueries.buildJoinClauseFor(dimensions), sbWhere);//from ww w . jav a 2 s . c o m // Build query Query<Map<String, Object>> query = h.createQuery(sql).bind("tenantId", tenantId).bind("startTime", new Timestamp(startTime.getMillis())); if (name != null) query.bind("name", name); if (endTime != null) query.bind("endTime", new Timestamp(endTime.getMillis())); DimensionQueries.bindDimensionsToQuery(query, dimensions); // Execute query List<Map<String, Object>> rows = query.list(); // Build results Map<ByteBuffer, Measurements> results = new LinkedHashMap<>(); for (Map<String, Object> row : rows) { String metricName = (String) row.get("name"); byte[] defIdBytes = (byte[]) row.get("definition_dimensions_id"); byte[] dimSetIdBytes = (byte[]) row.get("dimension_set_id"); ByteBuffer defId = ByteBuffer.wrap(defIdBytes); long measurementId = (Long) row.get("id"); String timestamp = DATETIME_FORMATTER.print(((Timestamp) row.get("time_stamp")).getTime()); double value = (double) row.get("value"); Measurements measurements = results.get(defId); if (measurements == null) { measurements = new Measurements(metricName, MetricQueries.dimensionsFor(h, dimSetIdBytes), new ArrayList<Object[]>()); results.put(defId, measurements); } measurements.addMeasurement(new Object[] { measurementId, timestamp, value }); } return results.values(); } }
From source file:com.ibm.iotf.devicemgmt.device.resource.DateResource.java
License:Open Source License
/** * Updates the value of this resource with the given Json value *//* www . j a va 2 s . c om*/ @Override public int update(JsonElement json, boolean fireEvent) { DateTime dt = new DateTime(json.getAsString()); super.setValue(new Date(dt.getMillis()), fireEvent); return this.getRC(); }
From source file:com.iksgmbh.sql.pojomemodb.connection.SqlPojoResultSet.java
License:Apache License
@Override public Date getDate(int columnOrderNumber) throws SQLException { try {/*from w w w .j a va 2s .c o m*/ final DateTime dateTime = (DateTime) selectedData.get(resultCursorPosition)[columnOrderNumber - 1]; if (dateTime == null) { throw new NullPointerException("null value in db cannot be parsed into an Date value."); } return new java.sql.Date(dateTime.getMillis()); } catch (ClassCastException e) { throwsTypeMismatchException(e); return null; } }
From source file:com.iksgmbh.sql.pojomemodb.connection.SqlPojoResultSet.java
License:Apache License
@Override public Time getTime(int columnOrderNumber) throws SQLException { try {//from w w w . ja v a2s.c om final DateTime dateTime = (DateTime) selectedData.get(resultCursorPosition)[columnOrderNumber - 1]; if (dateTime == null) { throw new NullPointerException("null value in db cannot be parsed into an Date value."); } return new java.sql.Time(dateTime.getMillis()); } catch (ClassCastException e) { throwsTypeMismatchException(e); return null; } }
From source file:com.iksgmbh.sql.pojomemodb.connection.SqlPojoResultSet.java
License:Apache License
@Override public Timestamp getTimestamp(int columnOrderNumber) throws SQLException { try {// w ww . j a v a 2 s .c o m final DateTime dateTime = (DateTime) selectedData.get(resultCursorPosition)[columnOrderNumber - 1]; if (dateTime == null) { throw new NullPointerException("null value in db cannot be parsed into an Date value."); } return new java.sql.Timestamp(dateTime.getMillis()); } catch (ClassCastException e) { throwsTypeMismatchException(e); return null; } }
From source file:com.iksgmbh.sql.pojomemodb.dataobjects.temporal.JoinTable.java
License:Apache License
private boolean compareEquals(final Object o1, final Object o2) throws SQLDataException { if (o1 == null || o2 == null) return false; if (o1.getClass() != o2.getClass()) { throw new SQLDataException("Data type mismatch!"); }/*from www .jav a 2 s . c o m*/ if (o1.getClass().getSimpleName().equals("String")) { final String s1 = (String) o1; final String s2 = (String) o2; return s1.equals(s2); } if (o1.getClass().getSimpleName().equals("BigDecimal")) { final BigDecimal d1 = (BigDecimal) o1; final BigDecimal d2 = (BigDecimal) o2; return d1.compareTo(d2) == 0; } if (o1.getClass().getSimpleName().equals("Integer")) { final Integer i1 = (Integer) o1; final Integer i2 = (Integer) o2; return i1 == i2; } if (o1.getClass().getSimpleName().equals("DateTime")) { final DateTime t1 = (DateTime) o1; final DateTime t2 = (DateTime) o2; return t1.getMillis() == t2.getMillis(); } throw new SQLDataException("Unsupported data type: " + o1.getClass().getName()); }