Search in sources :

Example 1 with AdminEntityDTO

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();
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 2 with AdminEntityDTO

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);
    }
}
Also used : AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField)

Example 3 with AdminEntityDTO

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();
}
Also used : AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO)

Example 4 with AdminEntityDTO

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;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO) MatchLocation(org.activityinfo.shared.command.MatchLocation) Location(org.activityinfo.server.database.hibernate.entity.Location)

Example 5 with AdminEntityDTO

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;
}
Also used : HashMap(java.util.HashMap) PointValue(org.activityinfo.shared.report.model.PointValue) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO)

Aggregations

AdminEntityDTO (org.activityinfo.shared.dto.AdminEntityDTO)21 ArrayList (java.util.ArrayList)4 AdminEntityResult (org.activityinfo.shared.command.result.AdminEntityResult)4 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)3 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)3 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)3 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)3 GetAdminEntities (org.activityinfo.shared.command.GetAdminEntities)3 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)3 SiteDTO (org.activityinfo.shared.dto.SiteDTO)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)2 AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)2 Filter (org.activityinfo.shared.command.Filter)2 LocationDTO (org.activityinfo.shared.dto.LocationDTO)2 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)1 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1