Search in sources :

Example 36 with User

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

the class UserDao method loadById.

@Override
public User loadById(Integer id) {
    UserDSLContext dsl = dsl();
    SelectQuery<?> query = dsl.selectByIdQuery(id);
    Record r = query.fetchOne();
    User user = r != null ? dsl.fromRecord(r) : null;
    return user;
}
Also used : User(org.openforis.collect.model.User) UserDSLContext(org.openforis.collect.persistence.UserDao.UserDSLContext) Record(org.jooq.Record) OfcUserRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRecord) OfcUserRoleRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRoleRecord)

Example 37 with User

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

the class BasicUserProxy method toUser.

public User toUser() {
    User user = new User();
    user.setEnabled(enabled);
    user.setId(id);
    user.setUsername(username);
    return user;
}
Also used : User(org.openforis.collect.model.User)

Example 38 with User

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

the class RecordManagerIntegrationTest method testPublish.

@Test
public void testPublish() throws MissingRecordKeyException, RecordPromoteException {
    CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
    new RecordUpdater().initializeNewRecord(record);
    User user = userManager.loadAdminUser();
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    recordManager.save(record);
    recordManager.promote(record, user, true);
    CollectRecord promotedRecord = recordManager.load(survey, record.getId());
    assertEquals(record, promotedRecord);
    List<CollectRecordSummary> fullSummaries = recordDao.loadFullSummaries(new RecordFilter(survey), null);
    assertEquals(1, fullSummaries.size());
    CollectRecordSummary recordSummary = fullSummaries.get(0);
    assertEquals(2, recordSummary.getStepSummaries().size());
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordUpdater(org.openforis.collect.model.RecordUpdater) RecordFilter(org.openforis.collect.model.RecordFilter) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 39 with User

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

the class RecordManagerIntegrationTest method testRecordSummaryUpdatedInCleansedRecord.

@Test
public void testRecordSummaryUpdatedInCleansedRecord() throws MissingRecordKeyException, RecordPromoteException {
    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");
    RecordUpdater recordUpdater = new RecordUpdater();
    User user = userManager.loadAdminUser();
    recordManager.promote(record, user, true);
    CollectRecord cleansingRecord = recordManager.load(survey, record.getId());
    Entity tree = cleansingRecord.findNodeByPath("/cluster/plot[1]/tree[2]");
    recordUpdater.deleteNode(tree);
    recordManager.save(cleansingRecord);
    CollectRecord reloadedCleansingRecord = recordManager.load(survey, record.getId());
    int cleansingTreesCount = reloadedCleansingRecord.getEntityCounts().get(1);
    assertEquals(1, cleansingTreesCount);
    CollectRecord reloadedEntryRecord = recordManager.load(survey, record.getId(), Step.ENTRY);
    int entryTreesCount = reloadedEntryRecord.getEntityCounts().get(1);
    assertEquals(2, entryTreesCount);
    List<CollectRecordSummary> fullSummaries = recordManager.loadFullSummaries(new RecordFilter(survey));
    CollectRecordSummary recordSummary = fullSummaries.get(0);
    int entryTreesCountInSummary = recordSummary.getSummaryByStep(Step.ENTRY).getEntityCounts().get(1);
    assertEquals(2, entryTreesCountInSummary);
    int cleansingTreesCountInSummary = recordSummary.getSummaryByStep(Step.CLEANSING).getEntityCounts().get(1);
    assertEquals(1, cleansingTreesCountInSummary);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordUpdater(org.openforis.collect.model.RecordUpdater) RecordFilter(org.openforis.collect.model.RecordFilter) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 40 with User

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

the class RecordManagerIntegrationTest method testUpdateCurrentStep.

@Test
public void testUpdateCurrentStep() 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 reloadedCleansingRecord = recordManager.load(survey, record.getId());
    Attribute<?, Code> reloadedDistrict = reloadedCleansingRecord.findNodeByPath("/cluster/district");
    assertEquals(newDistrictValue, reloadedDistrict.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)

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