use of org.activityinfo.shared.dto.AdminEntityDTO in project activityinfo by bedatadriven.
the class AdminColumnRenderer method render.
private Object render(SiteDTO model) {
StringBuilder qtip = new StringBuilder();
SafeHtmlBuilder summary = new SafeHtmlBuilder();
// we use this set to keep track of names that we've added
// to the summary to avoid duplication that is common between
// territories, zones de sante, provinces and districts, etc
seen.clear();
int summaryLines = 0;
for (AdminLevelDTO level : levels) {
AdminEntityDTO entity = model.getAdminEntity(level.getId());
if (entity != null) {
String name = entity.getName();
if (qtip.length() > 0) {
qtip.append("<br>");
}
qtip.append(level.getName()).append(": ").append(name);
if (summaryLines < 3 && !seen.contains(name)) {
if (summaryLines > 0) {
summary.appendHtmlConstant("<br/>");
}
summary.appendEscaped(name);
seen.add(name);
summaryLines++;
}
}
}
// return summary.toSafeHtml().asString();
return ColumnTemplates.INSTANCE.adminCell(qtip.toString(), summary.toSafeHtml()).asString();
}
use of org.activityinfo.shared.dto.AdminEntityDTO in project activityinfo by bedatadriven.
the class LocationSection method updateForm.
@Override
public void updateForm(LocationDTO location, boolean isNew) {
this.location = location;
this.isNew = isNew;
nameField.setValue(location.getName());
axeField.setValue(location.getAxe());
for (Entry<Integer, LabelField> entry : levelFields.entrySet()) {
AdminEntityDTO entity = location.getAdminEntity(entry.getKey());
entry.getValue().setValue(entity == null ? null : entity.getName());
}
if (location.hasCoordinates()) {
coordinateFields.getLatitudeField().setValue(location.getLatitude());
coordinateFields.getLongitudeField().setValue(location.getLongitude());
} else {
coordinateFields.setValue(null);
}
}
use of org.activityinfo.shared.dto.AdminEntityDTO in project activityinfo by bedatadriven.
the class SiteRenderer method renderLocation.
public String renderLocation(SiteDTO site, ActivityDTO activity) {
StringBuilder html = new StringBuilder();
html.append("<table cellspacing='0'>");
if (!activity.getLocationType().isAdminLevel()) {
html.append("<tr><td>");
html.append(activity.getLocationType().getName()).append(": ");
html.append("</td><td>");
html.append(site.getLocationName());
if (!Strings.isNullOrEmpty(site.getLocationAxe())) {
html.append("<br>").append(site.getLocationAxe());
}
html.append("</td></tr>");
}
for (AdminLevelDTO level : activity.getAdminLevels()) {
AdminEntityDTO entity = site.getAdminEntity(level.getId());
if (entity != null) {
html.append("<tr><td>");
html.append(level.getName()).append(":</td><td>");
html.append(entity.getName());
html.append("</td></tr>");
}
}
html.append("</table>");
return html.toString();
}
use of org.activityinfo.shared.dto.AdminEntityDTO in project activityinfo by bedatadriven.
the class MatchLocationHandler method execute.
@Override
public CommandResult execute(MatchLocation cmd, User user) throws CommandException {
Map<Integer, AdminEntity> matched = Maps.newHashMap();
// now try and match against the text
for (Integer levelId : cmd.getAdminLevels().keySet()) {
matchEntity(matched, cmd.getAdminLevels(), em.find(AdminLevel.class, levelId));
}
Location matchedLocation = matchLocation(cmd.getLocationType(), cmd.getName(), matched.values());
LocationDTO location = new LocationDTO();
if (matchedLocation == null) {
// create a new location object
location.setId(new KeyGenerator().generateInt());
location.setName(cmd.getName());
location.setLatitude(cmd.getLatitude());
location.setLongitude(cmd.getLongitude());
location.setNew(true);
location.setLocationTypeId(cmd.getLocationType());
for (AdminEntity entity : matched.values()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
} else {
location.setNew(false);
location.setId(matchedLocation.getId());
location.setName(matchedLocation.getName());
location.setLatitude(matchedLocation.getY());
location.setLongitude(matchedLocation.getX());
location.setLocationTypeId(matchedLocation.getLocationType().getId());
for (AdminEntity entity : matchedLocation.getAdminEntities()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
}
return location;
}
use of org.activityinfo.shared.dto.AdminEntityDTO in project activityinfo by bedatadriven.
the class AdminLevelClusterer method cluster.
@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
// admin entity id -> cluster
Map<Integer, Cluster> adminClusters = new HashMap<Integer, Cluster>();
for (PointValue pv : points) {
AdminEntityDTO entity = getAdminEntityId(pv);
if (entity != null) {
Cluster cluster = adminClusters.get(entity.getId());
if (cluster == null) {
cluster = new Cluster(pv);
cluster.setPoint(adminCenter(map, entity));
cluster.setTitle(entity.getName());
adminClusters.put(entity.getId(), cluster);
} else {
cluster.addPointValue(pv);
}
}
}
ArrayList<Cluster> clusters = Lists.newArrayList();
// update centers of clusters based on points, if any
for (Cluster cluster : adminClusters.values()) {
updateCenter(cluster);
if (cluster.hasPoint()) {
clusters.add(cluster);
}
}
radiiCalculator.calculate(clusters);
return clusters;
}
Aggregations