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();
}
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"));
}
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());
}
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());
}
Aggregations