Search in sources :

Example 11 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.

the class DbListPresenterTest method setUp.

@Before
public void setUp() throws Exception {
    ownedDb = new UserDatabaseDTO(OWNED_DB_ID, "My Database");
    ownedDb.setAmOwner(true);
    ownedDb.setDesignAllowed(true);
    ownedDb.setManageUsersAllowed(true);
    schema.getDatabases().add(ownedDb);
    designableDb = new UserDatabaseDTO(DESIGNABLE_DB_ID, "My Database");
    designableDb.setAmOwner(false);
    designableDb.setDesignAllowed(true);
    designableDb.setManageUsersAllowed(true);
    schema.getDatabases().add(designableDb);
    viewableDb = new UserDatabaseDTO(VIEWABLE_DB_ID, "My database");
    viewableDb.setAmOwner(false);
    viewableDb.setDesignAllowed(false);
    viewableDb.setManageUsersAllowed(false);
    schema.getDatabases().add(viewableDb);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) Before(org.junit.Before)

Example 12 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.

the class SchemaImporterV2Test method doImport.

private UserDatabaseDTO doImport(String resourceName) throws IOException {
    Map<String, Object> dbProps = Maps.newHashMap();
    dbProps.put("name", "Syria");
    dbProps.put("countryId", 1);
    int databaseId = execute(new CreateEntity("UserDatabase", dbProps)).getNewId();
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(databaseId);
    if (db == null) {
        throw new AssertionError("database not created");
    }
    SchemaImporterV2 importer = new SchemaImporterV2(getDispatcher(), db, warningTemplates());
    importer.setProgressListener(new SchemaImporterV2.ProgressListener() {

        @Override
        public void submittingBatch(int batchNumber, int batchCount) {
            System.out.println("Submitting batch " + batchNumber + " of " + batchCount);
        }
    });
    boolean success = importer.parseColumns(source(resourceName));
    if (success) {
        importer.processRows();
    }
    for (SafeHtml warning : importer.getWarnings()) {
        System.err.println(warning);
    }
    if (!success) {
        throw new AssertionError("there were fatal errors");
    }
    importer.persist(new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
            System.out.println("Success");
        }

        @Override
        public void onFailure(Throwable caught) {
            throw new AssertionError(caught);
        }
    });
    return execute(new GetSchema()).getDatabaseById(databaseId);
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 13 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.

the class SchemaImporterV2Test method syria.

@Test
public void syria() throws IOException {
    UserDatabaseDTO syria = doImport("schema_1064.csv");
    int activityId = syria.getActivities().get(0).getId();
    ActivityFormDTO cash = execute(new GetActivityForm(activityId));
    for (AttributeGroupDTO group : cash.getAttributeGroups()) {
        System.out.println(group.getName());
    }
    assertThat(cash.getName(), equalTo("1.Provision of urgent cash assistance"));
    assertThat(cash.getAttributeGroups().size(), equalTo(3));
    SchemaCsvWriter writer = new SchemaCsvWriter(getDispatcherSync());
    writer.write(syria.getId());
    Files.write(writer.toString(), TestOutput.getFile(getClass(), "syria", ".csv"), Charsets.UTF_8);
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) SchemaCsvWriter(org.activityinfo.server.endpoint.rest.SchemaCsvWriter) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 14 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.

the class CreateDatabaseTest method createWithSpecificCountry.

@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("Warchild Haiti");
    db.setFullName("Warchild Haiti");
    setUser(1);
    CreateEntity cmd = new CreateEntity(db);
    cmd.getProperties().put("countryId", 2);
    CreateResult cr = execute(cmd);
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertThat(newdb.getCountry(), is(notNullValue()));
    assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 15 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.

the class LocationTypeProxy method load.

@Override
public void load(DataReader<ListLoadResult<LocationTypeEntry>> reader, Object loadConfig, AsyncCallback<ListLoadResult<LocationTypeEntry>> callback) {
    dispatcher.execute(new GetSchema()).then(new Function<SchemaDTO, ListLoadResult<LocationTypeEntry>>() {

        @Override
        public ListLoadResult<LocationTypeEntry> apply(SchemaDTO schema) {
            // Build a dictionary of databases that have been shared with the user
            Map<Integer, String> databaseNames = new HashMap<>();
            for (UserDatabaseDTO db : schema.getDatabases()) {
                databaseNames.put(db.getId(), db.getName());
            }
            List<LocationTypeEntry> list = new ArrayList<>();
            for (LocationTypeDTO locationType : schema.getCountryById(countryId).getLocationTypes()) {
                if (!locationType.isDeleted()) {
                    if (locationType.getDatabaseId() == null) {
                        list.add(new LocationTypeEntry(locationType));
                    } else {
                        list.add(new LocationTypeEntry(locationType, databaseNames.get(locationType.getDatabaseId())));
                    }
                }
            }
            Collections.sort(list);
            return new BaseListLoadResult<>(list);
        }
    }).then(callback);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) LocationTypeDTO(org.activityinfo.legacy.shared.model.LocationTypeDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) Function(com.google.common.base.Function) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Aggregations

UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)18 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)11 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)9 Test (org.junit.Test)8 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)4 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)2 Before (org.junit.Before)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 Function (com.google.common.base.Function)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 XFormList (org.activityinfo.io.xform.formList.XFormList)1