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);
}
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());
}
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);
}
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;
}
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;
}
Aggregations