Search in sources :

Example 21 with CreateResult

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

the class LockedPeriodTest method createTest.

@Test
public void createTest() throws CommandException {
    setUser(1);
    LockedPeriodDTO dto = new LockedPeriodDTO();
    dto.setName("my name");
    dto.setFromDate(new LocalDate(2011, 1, 1));
    dto.setToDate(new LocalDate(2011, 1, 31));
    dto.setEnabled(true);
    CreateLockedPeriod create = new CreateLockedPeriod(dto);
    create.setDatabaseId(1);
    CreateResult result = execute(create);
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("toDate", new LocalDate(2011, 2, 28));
    execute(new UpdateEntity("LockedPeriod", result.getNewId(), changes));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 22 with CreateResult

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

the class PartnerTest method testAddPartner.

@Test
public void testAddPartner() {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("Solidarites");
    CreateResult cr = execute(new UpdatePartner(PEAR_PLUS_DB_ID, newPartner));
    assertThat(cr.getNewId(), not(equalTo(SOL_ID)));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals(newPartner.getName(), partner.getName());
}
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 23 with CreateResult

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

the class CreateSiteHandlerAsync method updateExistingSite.

private void updateExistingSite(final CreateSite cmd, ExecutionContext context, final AsyncCallback<CreateResult> callback) {
    UpdateSite updateSite = new UpdateSite(cmd.getSiteId(), cmd.getProperties());
    context.execute(updateSite, new AsyncCallback<VoidResult>() {

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

        @Override
        public void onSuccess(VoidResult result) {
            callback.onSuccess(new CreateResult(cmd.getSiteId()));
        }
    });
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite)

Example 24 with CreateResult

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

the class DatabaseResource method createFormFromXForm.

@POST
@Path("/forms")
@Consumes("application/xml")
public Response createFormFromXForm(@Context UriInfo uri, XForm xForm) {
    UserDatabaseDTOWithForms schema = getSchema();
    LocationTypeDTO locationType = schema.getCountry().getNullLocationType();
    ActivityFormDTO activityDTO = new ActivityFormDTO();
    activityDTO.setName(xForm.getHead().getTitle());
    activityDTO.set("databaseId", databaseId);
    activityDTO.set("locationTypeId", locationType.getId());
    CreateResult createResult = dispatcher.execute(new CreateEntity(activityDTO));
    int activityId = createResult.getNewId();
    XFormReader builder = new XFormReader(xForm);
    FormClass formClass = builder.build();
    formClass.setId(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(CuidAdapter.databaseId(databaseId));
    MySqlStorageProvider formCatalog = (MySqlStorageProvider) catalog.get();
    formCatalog.createOrUpdateFormSchema(formClass);
    return Response.created(uri.getAbsolutePathBuilder().path(RootResource.class).path("forms").path(formClass.getId().asString()).build()).build();
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) FormClass(org.activityinfo.model.form.FormClass) XFormReader(org.activityinfo.io.xform.XFormReader) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 25 with CreateResult

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

the class SiteDialog method saveNewSite.

private void saveNewSite() {
    final SiteDTO newSite = new SiteDTO();
    keyGenerator = new KeyGenerator();
    newSite.setId(keyGenerator.generateInt());
    newSite.setActivityId(activity.getId());
    if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
        newSite.setReportingPeriodId(new KeyGenerator().generateInt());
    }
    updateModel(newSite);
    dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {

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

        @Override
        public void onSuccess(CreateResult result) {
            hide();
            callback.onSaved();
        }
    });
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) CreateSite(org.activityinfo.legacy.shared.command.CreateSite)

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