putToCache(scheduleId, MeasurementSchedule.class, schedule);
}
MeasurementDefinition definition = schedule.getDefinition();
// MetricSchedule metricSchedule = getMetricScheduleInternal(uriInfo,schedule,definition); todo
MetricSchedule metricSchedule = new MetricSchedule(schedule.getId(), definition.getName(),
definition.getDisplayName(),
schedule.isEnabled(), schedule.getInterval(), definition.getUnits().toString(),
definition.getDataType().toString());
metricSchedule.setDefinitionId(definition.getId());
if (schedule.getMtime()!=null)
metricSchedule.setMtime(schedule.getMtime());
// Check for conditional get again
// Interestingly computing the hashCode of the original schedule is slower, as it also
// pulls in data from the definition and the resource
long tim = schedule.getMtime() != null ? schedule.getMtime() : 0;
EntityTag eTag = new EntityTag(Long.toOctalString(schedule.hashCode()+tim));
builder = request.evaluatePreconditions(new Date(tim),eTag); // factor in mtime in etag
if (builder==null) {
// preconditions not met, we need to send the resource
UriBuilder uriBuilder;
URI uri;
Link link;
if (definition.getDataType()==DataType.MEASUREMENT) {
// create link to metrics
uriBuilder = uriInfo.getBaseUriBuilder();
uriBuilder.path("metric/data/" + scheduleId);
uri = uriBuilder.build();
link = new Link("metric",uri.toString());
metricSchedule.addLink(link);
}
// create link to the resource
uriBuilder = uriInfo.getBaseUriBuilder();
uriBuilder.path("resource/" + schedule.getResource().getId());
uri = uriBuilder.build();
link = new Link("resource",uri.toString());
metricSchedule.addLink(link);
// Link for updates
uriBuilder = uriInfo.getAbsolutePathBuilder();
uri = uriBuilder.build();
Link updateLink = new Link("edit",uri.toString());
metricSchedule.addLink(updateLink);
updateLink = new Link("self",uri.toString());
metricSchedule.addLink(updateLink);
metricSchedule.addLink(createUILink(uriInfo, UILinkTemplate.METRIC_SCHEDULE, schedule.getResource().getId()));
if (mediaType.equals(MediaType.TEXT_HTML_TYPE)) {
builder = Response.ok(renderTemplate("metricSchedule", metricSchedule), mediaType);
}
else {