Search in sources :

Example 46 with GetSchema

use of org.activityinfo.shared.command.GetSchema 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 47 with GetSchema

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

use of org.activityinfo.shared.command.GetSchema 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)

Example 49 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer.

@Test
public void commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(new CacheResult(new SchemaDTO()));
    replay(proxy);
    // no calls should be made to the remote service
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CacheResult(org.activityinfo.client.dispatch.remote.cache.CacheResult) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 50 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method duplicateCommandsShouldBeMergedWithExecutingRequests.

@Test
public void duplicateCommandsShouldBeMergedWithExecutingRequests() {
    expectRemoteCall(new GetSchema());
    replay(service);
    // simulate successive dispatches of the same command from different
    // components of the application
    dispatcher.execute(new GetSchema(), makeNullCallback());
    processPendingCommands();
    dispatcher.execute(new GetSchema(), makeNullCallback());
    // verify that only one command was sent
    verify(service);
}
Also used : GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

GetSchema (org.activityinfo.shared.command.GetSchema)65 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)56 Test (org.junit.Test)42 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.shared.command.result.CreateResult)8 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 Filter (org.activityinfo.shared.command.Filter)5 HashMap (java.util.HashMap)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 Delete (org.activityinfo.shared.command.Delete)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 BatchCommand (org.activityinfo.shared.command.BatchCommand)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2