use of org.activityinfo.server.util.monitoring.Timed in project activityinfo by bedatadriven.
the class ReportMailer method execute.
@Timed(name = "mail.report")
public void execute(Date today, ReportSubscription sub, Report report) throws IOException {
// set up authentication for the subscriber of this report
authProvider.set(sub.getUser());
// render the report to a temp file
// generate the report
reportGenerator.generate(sub.getUser(), report, null, new DateRange());
ByteArrayOutputStream rtf = new ByteArrayOutputStream();
rtfReportRenderer.render(report, rtf);
rtf.close();
try {
mailReport(sub, report, today, rtf.toByteArray());
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Report mailing of " + sub.getTemplate().getId() + " failed for user " + sub.getUser().getEmail(), e);
}
}
use of org.activityinfo.server.util.monitoring.Timed in project activityinfo by bedatadriven.
the class LocationsResource method query.
@GET
@Timed(name = "api.rest.locations.get")
@Produces(MediaType.APPLICATION_JSON)
public Response query(@QueryParam("type") int typeId) throws IOException {
GetLocations query = new GetLocations();
query.setLocationTypeId(typeId);
LocationResult result = dispatcher.execute(query);
StringWriter writer = new StringWriter();
JsonGenerator json = Jackson.createJsonFactory(writer);
json.writeStartArray();
for (LocationDTO location : result.getData()) {
json.writeStartObject();
json.writeNumberField("id", location.getId());
json.writeStringField("name", location.getName());
if (location.hasAxe()) {
json.writeStringField("code", location.getAxe());
}
if (location.hasCoordinates()) {
json.writeNumberField("latitude", location.getLatitude());
json.writeNumberField("longitude", location.getLongitude());
}
if (!location.getAdminEntities().isEmpty()) {
json.writeObjectFieldStart("adminEntities");
for (AdminEntityDTO entity : location.getAdminEntities()) {
json.writeFieldName(Integer.toString(entity.getLevelId()));
json.writeStartObject();
json.writeNumberField("id", entity.getId());
json.writeStringField("name", entity.getName());
json.writeEndObject();
}
json.writeEndObject();
}
json.writeEndObject();
}
json.writeEndArray();
json.close();
return Response.ok(writer.toString()).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of org.activityinfo.server.util.monitoring.Timed in project activityinfo by bedatadriven.
the class LocationsResource method postNewLocations.
@POST
@Path("/{typeId}")
@Timed(name = "api.rest.locations.post")
public Response postNewLocations(@InjectParam EntityManager entityManager, @PathParam("typeId") int locationTypeId, List<NewLocation> locations) {
KeyGenerator generator = new KeyGenerator();
entityManager.getTransaction().begin();
LocationType locationType = entityManager.getReference(LocationType.class, locationTypeId);
for (NewLocation newLocation : locations) {
Location location = new Location();
location.setId(generator.generateInt());
System.out.println(location.getId());
location.setName(newLocation.getName());
location.setLocationType(locationType);
location.setX(newLocation.getLongitude());
location.setY(newLocation.getLatitude());
location.setTimeEdited(new Date());
location.setAdminEntities(new HashSet<AdminEntity>());
for (int entityId : newLocation.getAdminEntityIds()) {
location.getAdminEntities().add(entityManager.getReference(AdminEntity.class, entityId));
}
entityManager.persist(location);
}
entityManager.getTransaction().commit();
return Response.ok().build();
}
use of org.activityinfo.server.util.monitoring.Timed in project activityinfo by bedatadriven.
the class SitesResources method queryPoints.
@GET
@Path("/points")
@Timed(name = "api.rest.sites.points")
public Response queryPoints(@QueryParam("activity") List<Integer> activityIds, @QueryParam("database") List<Integer> databaseIds, @QueryParam("callback") String callback) throws IOException {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Activity, activityIds);
filter.addRestriction(DimensionType.Database, databaseIds);
GetSites command = new GetSites(filter);
List<SiteDTO> sites = dispatcher.execute(command).getData();
StringWriter writer = new StringWriter();
JsonGenerator json = Jackson.createJsonFactory(writer);
writeGeoJson(sites, json);
if (Strings.isNullOrEmpty(callback)) {
return Response.ok(writer.toString()).type("application/json; charset=UTF-8").build();
} else {
return Response.ok(callback + "(" + writer.toString() + ");").type("application/javascript; charset=UTF-8").build();
}
}
use of org.activityinfo.server.util.monitoring.Timed in project activityinfo by bedatadriven.
the class AdminLevelResource method getFeatures.
@GET
@Timed(name = "site.rest.admin.features")
@Path("/entities/features")
public Response getFeatures(@InjectParam EntityManager em) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(baos, Charsets.UTF_8);
List<AdminEntity> entities = em.createQuery("select e from AdminEntity e where e.deleted = false and e.level = :level").setParameter("level", level).getResultList();
JsonFactory jfactory = new JsonFactory();
JsonGenerator json = jfactory.createJsonGenerator(writer);
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
json.setPrettyPrinter(prettyPrinter);
json.writeStartObject();
json.writeStringField("type", "FeatureCollection");
json.writeFieldName("features");
json.writeStartArray();
GeometrySerializer geometrySerializer = new GeometrySerializer();
for (AdminEntity entity : entities) {
if (entity.getGeometry() != null) {
json.writeStartObject();
json.writeStringField("type", "Feature");
json.writeNumberField("id", entity.getId());
json.writeObjectFieldStart("properties");
json.writeStringField("name", entity.getName());
if (entity.getParentId() != null) {
json.writeNumberField("parentId", entity.getParentId());
}
json.writeEndObject();
json.writeFieldName("geometry");
geometrySerializer.writeGeometry(json, entity.getGeometry());
json.writeEndObject();
}
}
json.writeEndArray();
json.writeEndObject();
json.close();
return Response.ok().entity(baos.toByteArray()).type(MediaType.APPLICATION_JSON).build();
}
Aggregations