Search in sources :

Example 46 with SchemaDTO

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

the class DimensionProxy method load.

@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<DimensionModel>> callback) {
    final List<DimensionModel> list = Lists.newArrayList();
    list.add(new DimensionModel(DimensionType.Indicator, I18N.CONSTANTS.indicator()));
    list.add(new DimensionModel(DimensionType.Partner, I18N.CONSTANTS.partner()));
    list.add(new DimensionModel(DimensionType.Project, I18N.CONSTANTS.project()));
    list.add(new DimensionModel(DimensionType.Target, I18N.CONSTANTS.realizedOrTargeted()));
    list.add(new DimensionModel(DateUnit.YEAR));
    list.add(new DimensionModel(DateUnit.QUARTER));
    list.add(new DimensionModel(DateUnit.MONTH));
    list.add(new DimensionModel(DateUnit.WEEK_MON));
    if (model.getIndicators().isEmpty()) {
        callback.onSuccess(new BaseListLoadResult<DimensionModel>(list));
    } else {
        dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }

            @Override
            public void onSuccess(SchemaDTO schema) {
                addGeographicDimensions(list, schema);
                list.addAll(DimensionModel.attributeGroupModels(schema, model.getIndicators()));
                callback.onSuccess(new BaseListLoadResult<DimensionModel>(list));
            }
        });
    }
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) DimensionModel(org.activityinfo.client.report.editor.pivotTable.DimensionModel) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 47 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO 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 48 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO 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)

Example 49 with SchemaDTO

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

the class KmlActivityServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    // Get Authorization header
    String auth = req.getHeader("Authorization");
    // Do we allow that user?
    User user = authenticator.doAuthentication(auth);
    if (user == null) {
        // Not allowed, or no password provided so report unauthorized
        res.setHeader("WWW-Authenticate", "BASIC realm=\"Utilisateurs authorises\"");
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    String baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/earth/sites?activityId=";
    SchemaDTO schemaDTO = loadSchema(user);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("schema", schemaDTO);
    map.put("baseURL", baseURL);
    Template tpl = templateCfg.getTemplate("kml/ActivitiesNetworkLink.kml.ftl");
    res.setContentType("application/vnd.google-earth.kml+xml; filename=ActivityInfo.kml");
    res.setCharacterEncoding("UTF-8");
    try {
        tpl.process(map, res.getWriter());
    } catch (TemplateException e) {
        res.setStatus(500);
        e.printStackTrace();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Template(freemarker.template.Template)

Example 50 with SchemaDTO

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

the class FormResource method form.

@GET
@Produces(MediaType.TEXT_XML)
public Response form(@QueryParam("id") int id) throws Exception {
    if (enforceAuthorization()) {
        return askAuthentication();
    }
    LOGGER.finer("ODK activityform " + id + " requested by " + getUser().getEmail() + " (" + getUser().getId() + ")");
    SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
    ActivityDTO activity = schemaDTO.getActivityById(id);
    if (activity == null) {
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    if (!activity.getDatabase().isEditAllowed()) {
        throw new WebApplicationException(Status.FORBIDDEN);
    }
    purgePartners(activity);
    return Response.ok(new Viewable("/odk/form.ftl", activity)).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Viewable(com.sun.jersey.api.view.Viewable) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)66 GetSchema (org.activityinfo.shared.command.GetSchema)56 Test (org.junit.Test)41 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)20 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 CreateResult (org.activityinfo.shared.command.result.CreateResult)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)8 MockEventBus (org.activityinfo.client.MockEventBus)6 HashMap (java.util.HashMap)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 Delete (org.activityinfo.shared.command.Delete)5 Filter (org.activityinfo.shared.command.Filter)5 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)5 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)5 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 CreateEntity (org.activityinfo.shared.command.CreateEntity)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4