use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SiteDialogLauncher method chooseLocationThenAddSite.
private void chooseLocationThenAddSite(final ActivityDTO activity, final SiteDialogCallback callback) {
LocationDialog dialog = new LocationDialog(dispatcher, activity.getDatabase().getCountry(), activity.getLocationType());
dialog.show(new LocationDialog.Callback() {
@Override
public void onSelected(LocationDTO location, boolean isNew) {
SiteDTO newSite = new SiteDTO();
newSite.setActivityId(activity.getId());
newSite.setLocation(location);
SiteDialog dialog = new SiteDialog(dispatcher, activity);
dialog.showNew(newSite, location, isNew, callback);
}
});
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SiteExporter method createDataRows.
private void createDataRows(ActivityDTO activity, Filter filter, Sheet sheet) {
int rowIndex = 2;
for (SiteDTO site : querySites(activity, filter)) {
Row row = sheet.createRow(rowIndex++);
int column = 0;
createCell(row, column++, site.getDate1());
createCell(row, column++, site.getDate2());
createCell(row, column++, site.getPartnerName());
createCell(row, column++, site.getLocationName());
createCell(row, column++, site.getLocationAxe());
for (Integer indicatorId : indicators) {
createIndicatorValueCell(row, column++, site.getIndicatorValue(indicatorId));
}
for (Integer attribId : attributes) {
Boolean value = site.getAttributeValue(attribId);
if (value != null) {
Cell valueCell = createCell(row, column, value);
valueCell.setCellStyle(attribValueStyle);
}
column++;
}
for (Integer levelId : levels) {
AdminEntityDTO entity = site.getAdminEntity(levelId);
if (entity != null) {
createCell(row, column, "");
createCell(row, column + 1, entity.getName());
}
column += 2;
}
if (site.hasLatLong()) {
createCoordCell(row, column, site.getLongitude());
createCoordCell(row, column + 1, site.getLatitude());
}
column += 2;
if (!Strings.isNullOrEmpty(site.getComments())) {
createCell(row, column, site.getComments());
}
column++;
}
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class KmlDataServlet method writeDocument.
protected void writeDocument(User user, PrintWriter out, int actvityId) throws TransformerConfigurationException, SAXException, CommandException {
// TODO: rewrite using FreeMarker
DomainFilters.applyUserFilter(user, entityManager.get());
XmlBuilder xml = new XmlBuilder(new StreamResult(out));
SchemaDTO schema = dispatcher.execute(new GetSchema());
List<SiteDTO> sites = querySites(user, schema, actvityId);
xml.startDocument();
KMLNamespace kml = new KMLNamespace(xml);
kml.startKml();
ActivityDTO activity = schema.getActivityById(actvityId);
kml.startDocument();
kml.startStyle().at("id", "noDirectionsStyle");
kml.startBalloonStyle();
kml.text("$[description]");
xml.close();
xml.close();
for (SiteDTO pm : sites) {
if (pm.hasLatLong()) {
kml.startPlaceMark();
kml.styleUrl("#noDirectionsStyle");
kml.name(pm.getLocationName());
kml.startSnippet();
xml.cdata(renderSnippet(activity, pm));
// Snippet
xml.close();
kml.startDescription();
xml.cdata(renderDescription(activity, pm));
// Description
xml.close();
kml.startTimeSpan();
if (pm.getDate1() != null) {
kml.begin(pm.getDate1().atMidnightInMyTimezone());
kml.end(pm.getDate2().atMidnightInMyTimezone());
// Timespan
xml.close();
}
kml.startPoint();
kml.coordinates(pm.getLongitude(), pm.getLatitude());
// Point
xml.close();
// Placemark
xml.close();
}
}
// Document
xml.close();
// kml
xml.close();
xml.endDocument();
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SitesResources method queryPoints.
@GET
@Path("/points")
public Response queryPoints(@QueryParam("activity") List<Integer> activityIds, @QueryParam("database") List<Integer> databaseIds, @QueryParam("callback") String callback) throws JsonGenerationException, IOException {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Activity, activityIds);
filter.addRestriction(DimensionType.Database, databaseIds);
List<SiteDTO> sites = dispatcher.execute(new GetSites(filter)).getData();
StringWriter writer = new StringWriter();
JsonGenerator json = Jackson.createJsonFactory(writer);
writeGeoJson(sites, json);
if (Strings.isNullOrEmpty(callback)) {
return Response.ok(writer.toString()).type(MediaType.APPLICATION_JSON_TYPE).build();
} else {
return Response.ok(callback + "(" + writer.toString() + ");").type("application/javascript; charset=UTF-8").build();
}
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SitesResources method query.
@GET
@Produces(MediaType.APPLICATION_JSON)
public String query(@QueryParam("activity") List<Integer> activityIds, @QueryParam("database") List<Integer> databaseIds, @QueryParam("format") String format) throws IOException {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Activity, activityIds);
filter.addRestriction(DimensionType.Database, databaseIds);
List<SiteDTO> sites = dispatcher.execute(new GetSites(filter)).getData();
StringWriter writer = new StringWriter();
JsonGenerator json = Jackson.createJsonFactory(writer);
writeJson(sites, json);
return writer.toString();
}
Aggregations