Search in sources :

Example 36 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class PrintDataEntryForm method renderForm.

private void renderForm(final int activityId, SchemaDTO result) {
    try {
        ActivityDTO activity = result.getActivityById(activityId);
        String html = render(activity);
        getFrameElement().getStyle().setBackgroundColor("white");
        fillIframe(getFrameElement(), html);
    } catch (Exception e) {
        showError(e);
    }
}
Also used : ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 37 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DimensionModel method attributeGroupModels.

public static List<DimensionModel> attributeGroupModels(SchemaDTO schema, Set<Integer> indicators) {
    /*
         * Attribute Groups retain their own identity and ids 
         * by Activity, but once we get to this stage, we treat
         * attribute groups with the same name as the same thing.
         * 
         * This allows user to define attributes across databases
         * and activities through "offline" coordination.
         */
    Set<String> groupsAdded = Sets.newHashSet();
    List<DimensionModel> models = Lists.newArrayList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            if (activity.containsAny(indicators)) {
                for (AttributeGroupDTO attributeGroup : activity.getAttributeGroups()) {
                    if (!groupsAdded.contains(attributeGroup.getName())) {
                        DimensionModel dimModel = new DimensionModel(attributeGroup);
                        models.add(dimModel);
                        groupsAdded.add(attributeGroup.getName());
                    }
                }
            }
        }
    }
    return models;
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 38 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DimensionPruner method pruneModel.

private void pruneModel(SchemaDTO schema) {
    Set<ActivityDTO> activityIds = getSelectedActivities(schema);
    Set<AttributeGroupDimension> dimensions = getSelectedAttributes(schema);
    boolean dirty = false;
    for (AttributeGroupDimension dim : dimensions) {
        if (!isApplicable(schema, activityIds, dim)) {
            LOGGER.fine("Removing attribute group " + dim.getAttributeGroupId());
            model.getRowDimensions().remove(dim);
            model.getColumnDimensions().remove(dim);
            dirty = true;
        }
    }
    if (dirty) {
        reportEventBus.fireChange();
    }
}
Also used : ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension)

Example 39 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO 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();
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) XmlBuilder(org.activityinfo.server.util.xml.XmlBuilder) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema)

Example 40 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class FormSubmissionResource method submit.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_XML)
public Response submit(@FormDataParam("xml_submission_file") String xml) throws Exception {
    if (enforceAuthorization()) {
        return askAuthentication();
    }
    LOGGER.fine("ODK form submitted by user " + getUser().getEmail() + " (" + getUser().getId() + ")");
    // parse
    SiteFormData data = formParser.get().parse(xml);
    if (data == null) {
        return badRequest("Problem parsing submission XML");
    }
    // basic validation
    if (data.getActivity() == 0 || data.getPartner() == 0 || data.getLatitude() == 999 || data.getLongitude() == 999 || data.getDate1() == null || data.getDate2() == null || data.getDate2().before(data.getDate1())) {
        return badRequest("Problem validating submission XML");
    }
    // check if activity exists
    SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
    ActivityDTO activity = schemaDTO.getActivityById(data.getActivity());
    if (activity == null) {
        return notFound("Unknown activity");
    }
    // create site
    try {
        createSite(data, schemaDTO, activity);
    } catch (Exception e) {
        e.printStackTrace();
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
    return Response.status(Status.CREATED).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)44 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)20 GetSchema (org.activityinfo.shared.command.GetSchema)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)13 Test (org.junit.Test)13 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)9 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)9 SiteDTO (org.activityinfo.shared.dto.SiteDTO)8 CreateResult (org.activityinfo.shared.command.result.CreateResult)6 ModelData (com.extjs.gxt.ui.client.data.ModelData)5 AttributeDTO (org.activityinfo.shared.dto.AttributeDTO)5 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)5 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)4 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)3 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)3 HashMap (java.util.HashMap)3 MockEventBus (org.activityinfo.client.MockEventBus)3 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)3 UIConstants (org.activityinfo.client.i18n.UIConstants)3 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)3