Search in sources :

Example 41 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.

the class DbProjectEditor method onAdd.

@Override
protected void onAdd() {
    final ProjectDTO newProject = new ProjectDTO();
    this.view.showAddDialog(newProject, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            service.execute(new AddProject(db.getId(), newProject), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    newProject.setId(result.getNewId());
                    store.add(newProject);
                    db.getProjects().add(newProject);
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) AddProject(org.activityinfo.legacy.shared.command.AddProject) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether)

Example 42 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.

the class LocalSchemaChangeTest method createAttributes.

@Test
public void createAttributes() throws Exception {
    Map<String, Object> attributeGroup = Maps.newHashMap();
    attributeGroup.put("name", "New Indicator");
    attributeGroup.put("activityId", 2);
    attributeGroup.put("multipleAllowed", true);
    attributeGroup.put("mandatory", true);
    CreateResult createResult = assertChangeIsSynchronized(2, new CreateEntity(AttributeGroupDTO.ENTITY_NAME, attributeGroup));
    Map<String, Object> attribute = Maps.newHashMap();
    attribute.put("name", "New Attribute");
    attribute.put("attributeGroupId", createResult.getNewId());
    assertChangeIsSynchronized(2, new CreateEntity(AttributeDTO.ENTITY_NAME, attribute));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) Test(org.junit.Test)

Example 43 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.

the class LocalSiteCreateTest method createNew.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void createNew() {
    synchronize();
    // create a new detached, client model
    SiteDTO newSite = SiteDTOs.newSite();
    LocationDTO location = LocationDTOs.newLocation();
    executeLocally(new CreateLocation(location));
    newSite.setLocation(location);
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    CreateResult result = executeLocally(cmd);
    // let the client know the command has succeeded
    newSite.setId(result.getNewId());
    // try to retrieve what we've created FROM OUR CLIENT SIDE DATABASE
    SiteResult loadResult = executeLocally(GetSites.byId(newSite.getId()));
    Assert.assertEquals(1, loadResult.getData().size());
    SiteDTO secondRead = loadResult.getData().get(0);
    // confirm that the changes are there
    SiteDTOs.validateNewSite(secondRead);
    newRequest();
    // now Sync with the server
    synchronize();
    // Confirm that paging works client side
    GetSites pagingRequest = new GetSites();
    pagingRequest.setLimit(1);
    executeLocally(pagingRequest);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 44 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.

the class PartnerTest method testAddNewPartner.

@Test
public void testAddNewPartner() throws Exception {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("VDE");
    newPartner.setFullName("Vision d'Espoir");
    CreateResult cr = execute(new UpdatePartner(1, newPartner));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(1).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals("VDE", partner.getName());
    Assert.assertEquals("Vision d'Espoir", partner.getFullName());
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 45 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.

the class PartnerTest method testAddDuplicatePartner.

public void testAddDuplicatePartner() throws Exception {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("NRC");
    newPartner.setFullName("Norweigen Refugee Committe");
    CreateResult cr = execute(new UpdatePartner(1, newPartner));
    Assert.assertTrue(cr instanceof DuplicateCreateResult);
}
Also used : DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner)

Aggregations

CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)46 Test (org.junit.Test)26 Date (java.util.Date)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)7 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 OnDataSet (org.activityinfo.server.database.OnDataSet)6 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)5 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)3