Search in sources :

Example 41 with ActivityDTO

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

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

the class DesignTest method testSave.

@Test
public void testSave() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Localisation resources
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.onUIAction(UIActions.SAVE);
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : TreeStore(com.extjs.gxt.ui.client.store.TreeStore) VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 43 with ActivityDTO

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

the class AttributeGroupTest method testCreate.

@Test
public void testCreate() throws Exception {
    // execute the command
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("name", "Type de Conflit");
    properties.put("multipleAllowed", true);
    properties.put("activityId", 1);
    CreateEntity cmd = new CreateEntity("AttributeGroup", properties);
    CreateResult result = execute(cmd);
    // check if it has been added
    SchemaDTO schema = execute(new GetSchema());
    ActivityDTO activity = schema.getActivityById(1);
    AttributeGroupDTO group = activity.getAttributeGroupById(result.getNewId());
    Assert.assertNotNull("attribute group is created", group);
    Assert.assertEquals("name is correct", group.getName(), "Type de Conflit");
    Assert.assertTrue("multiple allowed is set to true", group.isMultipleAllowed());
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) HashMap(java.util.HashMap) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 44 with ActivityDTO

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

the class GetSchemaTest method testAttributes.

@Test
public void testAttributes() throws CommandException {
    // Alex
    setUser(1);
    SchemaDTO schema = execute(new GetSchema());
    assertTrue("no attributes case", schema.getActivityById(3).getAttributeGroups().size() == 0);
    ActivityDTO nfi = schema.getActivityById(1);
    AttributeDTO[] attributes = nfi.getAttributeGroupById(1).getAttributes().toArray(new AttributeDTO[0]);
    assertTrue("attributes are present", attributes.length == 2);
    AttributeDTO test = nfi.getAttributeById(1);
    assertEquals("property:name", "Catastrophe Naturelle", test.getName());
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

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