use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeMapDatabaseStream in project ma-modules-public by infiniteautomation.
the class PointValueRestController method pointValuesForMultiplePointsAsMultipleArrays.
public ResponseEntity<ObjectStream<Map<String, List<PointValueTime>>>> pointValuesForMultiplePointsAsMultipleArrays(HttpServletRequest request, String[] xids, boolean useRendered, boolean unitConversion, DateTime from, DateTime to, RollupEnum rollup, TimePeriodType timePeriodType, Integer timePeriods, String timezone, Integer limit, String dateTimeFormat) {
RestProcessResult<ObjectStream<Map<String, List<PointValueTime>>>> result = new RestProcessResult<ObjectStream<Map<String, List<PointValueTime>>>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalid", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(xids.length);
DataPointVO vo;
for (String xid : xids) {
vo = DataPointDao.instance.getByXid(xid);
if (vo != null) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
long current = Common.timer.currentTimeMillis();
if (from == null)
from = new DateTime(current);
if (to == null)
to = new DateTime(current);
// better not to for RESTfulness
if (timezone != null) {
DateTimeZone zone = DateTimeZone.forID(timezone);
from = from.withZone(zone);
to = to.withZone(zone);
}
// Are we using rollup
if ((rollup != null) && (rollup != RollupEnum.NONE)) {
if (rollup == RollupEnum.FFT) {
// Special Rollup for FFT's with no time rollup action
// TODO Need a way to return frequency or period values
// IdPointValueFftCalculator calc = new
// IdPointValueFftCalculator(pointIdMap, from.getTime(), to.getTime(),
// true);
// return result.createResponseEntity(calc);
} else {
TimePeriod timePeriod = null;
if ((timePeriodType != null) && (timePeriods != null)) {
timePeriod = new TimePeriod(timePeriods, timePeriodType);
}
XidPointValueMapRollupCalculator calc = new XidPointValueMapRollupCalculator(pointIdMap, useRendered, unitConversion, rollup, timePeriod, from, to, limit, dateTimeFormat, timezone);
return result.createResponseEntity(calc);
}
return result.createResponseEntity();
} else {
XidPointValueTimeMapDatabaseStream pvtDatabaseStream = new XidPointValueTimeMapDatabaseStream(pointIdMap, useRendered, unitConversion, from.getMillis(), to.getMillis(), this.dao, limit, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
}
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
Aggregations