use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class ExpandTimePeriodAdjuster method adjustInto.
/* (non-Javadoc)
* @see java.time.temporal.TemporalAdjuster#adjustInto(java.time.temporal.Temporal)
*/
@Override
public Temporal adjustInto(Temporal temporal) {
ZonedDateTime zdt = startTime;
ZonedDateTime adjustTime = (ZonedDateTime) temporal;
while (zdt.isBefore(adjustTime)) {
// adjusted in that manner if appropriate, and none of the time advances should alter a lesser field harmfully.
switch(periodType) {
case TimePeriods.MILLISECONDS:
zdt = zdt.plus(periods, ChronoUnit.MILLIS);
break;
case TimePeriods.SECONDS:
zdt = zdt.plus(periods, ChronoUnit.SECONDS);
break;
case TimePeriods.MINUTES:
zdt = zdt.plus(periods, ChronoUnit.MINUTES);
break;
case TimePeriods.HOURS:
zdt = zdt.plus(periods, ChronoUnit.HOURS);
break;
case TimePeriods.DAYS:
zdt = zdt.plus(periods, ChronoUnit.DAYS);
break;
case TimePeriods.WEEKS:
// Don't set the DoW since this may be governed by last year, and shouldn't change by adding weeks
zdt = zdt.plus(periods, ChronoUnit.WEEKS);
break;
case TimePeriods.MONTHS:
zdt = zdt.plus(periods, ChronoUnit.MONTHS);
break;
case TimePeriods.YEARS:
zdt = zdt.plus(periods, ChronoUnit.YEARS);
break;
default:
throw new ShouldNeverHappenException("Unsupported time period: " + periodType);
}
}
return zdt;
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class M2MRecipientListEntryBean method convert.
/**
* @param legacyDao
* @return
*/
public RecipientListEntryBean convert(M2MReportDao legacyDao) {
RecipientListEntryBean bean = new RecipientListEntryBean();
bean.setRecipientType(recipientType);
switch(recipientType) {
case EmailRecipient.TYPE_USER:
String username = legacyDao.getUsername(referenceId);
User user = UserDao.instance.getUser(username);
if (user != null)
bean.setReferenceId(user.getId());
else
throw new ShouldNeverHappenException("User " + username + " not found in Mango.");
break;
case EmailRecipient.TYPE_ADDRESS:
bean.setReferenceAddress(referenceAddress);
break;
case EmailRecipient.TYPE_MAILING_LIST:
String listXid = legacyDao.getMailingListXid(referenceId);
MailingList list = MailingListDao.instance.getMailingList(listXid);
if (list != null)
bean.setReferenceId(list.getId());
else
throw new ShouldNeverHappenException("Mailing list with XID: " + listXid + " not found in Mango.");
break;
}
return bean;
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class ReportPointValueTimeSerializer method getObject.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getObject(byte[], long)
*/
@Override
public ITime getObject(ByteArrayBuilder b, long ts, String seriesId) {
// Get the data type
int dataType = b.getShort();
DataValue dataValue = null;
// Second put in the data value
switch(dataType) {
case DataTypes.ALPHANUMERIC:
String s = b.getString();
dataValue = new AlphanumericValue(s);
break;
case DataTypes.BINARY:
boolean bool = b.getBoolean();
dataValue = new BinaryValue(bool);
break;
case DataTypes.IMAGE:
try {
dataValue = new ImageValue(b.getString());
} catch (InvalidArgumentException e1) {
// Probably no file
}
break;
case DataTypes.MULTISTATE:
int i = b.getInt();
dataValue = new MultistateValue(i);
break;
case DataTypes.NUMERIC:
double d = b.getDouble();
dataValue = new NumericValue(d);
break;
default:
throw new ShouldNeverHappenException("Data type of " + dataType + " is not supported");
}
// Get the annotation
String annotation = b.getString();
if (annotation != null) {
try {
return new AnnotatedPointValueTime(dataValue, ts, TranslatableMessage.deserialize(annotation));
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
} else {
return new PointValueTime(dataValue, ts);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class M2MReportDao method query.
/**
* @param string
* @param objects
* @param pointValueRowMapper
* @param callback
*/
protected void query(String sql, M2MReportRowMapper rowMapper, MappedRowCallback<M2MReportVO> callback) {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = createStatement();
rs = stmt.executeQuery(sql);
int i = 0;
while (rs.next()) {
M2MReportVO pvt = rowMapper.mapRow(rs, i);
callback.row(pvt, i);
i++;
}
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
throw new ShouldNeverHappenException(e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e1) {
LOG.error(e1.getMessage(), e1);
}
}
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class M2MReportDao method getDataPointXid.
/**
* @param pointId
* @return
*/
public String getDataPointXid(int pointId) {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = this.connection.createStatement();
stmt.execute(DATA_POINT_XID_SELECT + " where id = " + pointId);
rs = stmt.getResultSet();
if (rs.next()) {
return rs.getString(1);
} else
return null;
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
throw new ShouldNeverHappenException(e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
}
}
}
Aggregations