Search in sources :

Example 21 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class RecordManagerIntegrationTest method testRecordSummaryUpdated.

@Test
public void testRecordSummaryUpdated() {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_114"), attribute("region", "001"), attribute("district", "002"), entity("plot", attribute("no", "1"), entity("tree", attribute("tree_no", "1"), attribute("dbh", "10")), entity("tree", attribute("tree_no", "2"), attribute("dbh", "20")))).build(survey, "cluster", "2.0");
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    recordManager.save(record);
    CollectRecord reloadedRecord = recordManager.load(survey, record.getId());
    String regionQualifier = reloadedRecord.getQualifierValues().get(0);
    assertEquals("001", regionQualifier);
    String districtQualifier = reloadedRecord.getQualifierValues().get(1);
    assertEquals("002", districtQualifier);
    int treesCount = reloadedRecord.getEntityCounts().get(1);
    assertEquals(2, treesCount);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 22 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class RecordManagerIntegrationTest method testUpdateCurrentStepDoesntAffectPreviousStep.

@Test
public void testUpdateCurrentStepDoesntAffectPreviousStep() throws MissingRecordKeyException, RecordPromoteException {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    RecordUpdater recordUpdater = new RecordUpdater();
    recordUpdater.initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    recordManager.save(record);
    recordManager.promote(record, user, true);
    CollectRecord cleansingRecord = recordManager.load(survey, record.getId());
    Attribute<?, Code> district = cleansingRecord.findNodeByPath("/cluster/district");
    Code newDistrictValue = new Code("001");
    recordUpdater.updateAttribute(district, newDistrictValue);
    recordManager.save(cleansingRecord);
    CollectRecord entryRecord = recordManager.load(survey, record.getId(), Step.ENTRY);
    assertEquals(2, (int) entryRecord.getWorkflowSequenceNumber());
    assertEquals(1, (int) entryRecord.getDataWorkflowSequenceNumber());
    Attribute<?, Code> entryDistrict = entryRecord.findNodeByPath("/cluster/district");
    assertEquals(new Code("003"), entryDistrict.getValue());
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUpdater(org.openforis.collect.model.RecordUpdater) Code(org.openforis.idm.model.Code) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 23 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class UserDaoIntegrationTest method testCRUD.

@Test
public void testCRUD() throws Exception {
    // SAVE NEW
    User user = new User();
    user.setEnabled(Boolean.TRUE);
    user.setUsername("user1");
    user.setPassword("pass1");
    user.addRole(UserRole.ENTRY);
    user.addRole(UserRole.CLEANSING);
    userDao.insert(user);
    Integer id = user.getId();
    User reloaded = userDao.loadById(id);
    assertNotNull(reloaded);
    assertEquals(user, reloaded);
    userDao.delete(id);
    reloaded = userDao.loadById(id);
    assertNull(reloaded);
}
Also used : User(org.openforis.collect.model.User) CollectTest(org.openforis.collect.CollectTest) Test(org.junit.Test)

Example 24 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class ClientUserManager method loadAdminUser.

@Override
public User loadAdminUser() {
    User user = loadByUserName(ADMIN_USER_NAME);
    setGenericRoles(user);
    return user;
}
Also used : User(org.openforis.collect.model.User)

Example 25 with User

use of org.openforis.collect.model.User in project collect by openforis.

the class ClientUserManager method save.

@Override
public User save(User user, User modifiedByUser) throws UserPersistenceException {
    User result = post(getUsersRestfulApiUrl() + "/user", user, User.class);
    // if user was new
    user.setId(result.getId());
    return user;
}
Also used : User(org.openforis.collect.model.User)

Aggregations

User (org.openforis.collect.model.User)71 CollectRecord (org.openforis.collect.model.CollectRecord)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 SessionState (org.openforis.collect.web.session.SessionState)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Transactional (org.springframework.transaction.annotation.Transactional)11 RecordFilter (org.openforis.collect.model.RecordFilter)10 Test (org.junit.Test)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 RecordUpdater (org.openforis.collect.model.RecordUpdater)6 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 Date (java.util.Date)4 UserGroup (org.openforis.collect.model.UserGroup)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Secured (org.springframework.security.access.annotation.Secured)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordStep (org.openforis.collect.event.RecordStep)3 Step (org.openforis.collect.model.CollectRecord.Step)3