Search in sources :

Example 1 with CloneDatabase

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

the class CloneDatabaseHandler method createDatabase.

private Database createDatabase(CloneDatabase command, User user) {
    Database db = new Database();
    db.setName(command.getName());
    db.setFullName(command.getDescription());
    db.setCountry(em.find(Country.class, command.getCountryId()));
    db.setOwner(user);
    em.persist(db);
    return db;
}
Also used : CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase)

Example 2 with CloneDatabase

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

the class CloneDatabaseTest method cloneWithoutDataCopy.

@Test
public void cloneWithoutDataCopy() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO pearDb = schema.getDatabaseById(PEAR_DATABASE_ID);
    CloneDatabase cloneDatabase = new CloneDatabase().setSourceDatabaseId(pearDb.getId()).setCopyData(false).setCopyPartners(true).setCopyUserPermissions(true).setCountryId(pearDb.getCountry().getId()).setName("PearClone").setDescription("PearClone Description");
    CreateResult cloneResult = execute(cloneDatabase);
    assertNotEquals(cloneResult.getNewId(), pearDb.getId());
    assertDbCloned(cloneResult.getNewId(), pearDb.getId(), cloneDatabase);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase) Test(org.junit.Test)

Example 3 with CloneDatabase

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

the class CloneDatabaseTest method cloneWithDifferentCountry.

// https://bedatadriven.atlassian.net/browse/AI-315
// it seems that the problem occurs when there is a classic form with a "Village" location. If you change countries,
// you need to change the locationTypeId to a location type in the new country. Users can change the location type afterwards,
// so I would suggest that we apply a simple rule:
// 
// 1. If there is a location type with the same name in the new country, use that location Type
// 2. if the source locationtype is bound to an adminlevel, choose the first root adminlevel in the new country
// 3. If the source locationtype is the null location type ( = Country) then the use the corresponding null locationtype in the new form
// 4. Otherwise use the "Village" location type in the target country.
@Test
public void cloneWithDifferentCountry() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO pearDb = schema.getDatabaseById(PEAR_DATABASE_ID);
    CloneDatabase cloneDatabase = new CloneDatabase().setSourceDatabaseId(pearDb.getId()).setCopyData(false).setCopyPartners(true).setCopyUserPermissions(true).setCountryId(UKRAINE_COUNTRY_ID).setName("PearClone").setDescription("PearClone Description");
    CreateResult cloneResult = execute(cloneDatabase);
    assertNotEquals(cloneResult.getNewId(), pearDb.getId());
    assertDbCloned(cloneResult.getNewId(), pearDb.getId(), cloneDatabase);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase) Test(org.junit.Test)

Example 4 with CloneDatabase

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

the class CloneDatabaseTest method fullClone.

@Test
public void fullClone() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO pearDb = schema.getDatabaseById(PEAR_DATABASE_ID);
    CloneDatabase cloneDatabase = new CloneDatabase().setSourceDatabaseId(pearDb.getId()).setCopyData(true).setCopyPartners(true).setCopyUserPermissions(true).setCountryId(pearDb.getCountry().getId()).setName("PearClone").setDescription("PearClone Description");
    CreateResult cloneResult = execute(cloneDatabase);
    assertNotEquals(cloneResult.getNewId(), pearDb.getId());
    assertDbCloned(cloneResult.getNewId(), pearDb.getId(), cloneDatabase);
// todo assert data copy
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase) Test(org.junit.Test)

Aggregations

CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)4 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 Test (org.junit.Test)3