Search in sources :

Example 41 with User

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

the class DataMarshallerIntegrationTest method createTestRecord.

private CollectRecord createTestRecord(CollectSurvey survey) {
    RecordBuilder recordBuilder = record(attribute("id", "123_456"), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "XXX"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), attribute("remarks", "Remarks with UTF-8 character: Í"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
    CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
    User user = userManager.loadByUserName("admin");
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
    record.setModifiedDate(new GregorianCalendar(2012, 2, 3, 9, 30).getTime());
    record.setStep(Step.ENTRY);
    record.setState(State.REJECTED);
    record.updateSummaryFields();
    RecordUpdater recordUpdater = new RecordUpdater();
    recordUpdater.initializeRecord(record);
    Entity cluster = record.getRootEntity();
    recordUpdater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
    recordUpdater.approveMissingValue(cluster, "accessibility");
    NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
    recordUpdater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
    recordUpdater.updateRemarks(boleHeight.getNumberField(), "No value specified");
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) Coordinate(org.openforis.idm.model.Coordinate) NumberAttribute(org.openforis.idm.model.NumberAttribute) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 42 with User

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

the class UserGroupDaoIntegrationTest method testInsert.

@Test
public void testInsert() {
    User admin = userManager.loadAdminUser();
    UserGroup group = new UserGroup();
    group.setCreatedByUser(admin);
    group.setCreationDate(new Timestamp(System.currentTimeMillis()));
    group.setDescription("Test description");
    group.setEnabled(true);
    group.setLabel("Test Group");
    group.setName("test");
    group.setSystemDefined(false);
    group.setVisibility(Visibility.PUBLIC);
    dao.insert(group);
    Assert.assertNotNull(group.getId());
}
Also used : User(org.openforis.collect.model.User) Timestamp(java.sql.Timestamp) UserGroup(org.openforis.collect.model.UserGroup) CollectTest(org.openforis.collect.CollectTest) Test(org.junit.Test)

Example 43 with User

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

the class CreateRecordHandler method execute.

@Override
public List<RecordEvent> execute(CreateRecordCommand command) {
    String username = command.getUsername();
    User user = userManager.loadByUserName(username);
    CollectSurvey survey = surveyManager.getById(command.getSurveyId());
    List<EntityDefinition> rootDefs = survey.getSchema().getRootEntityDefinitions();
    EntityDefinition firstRootEntity = rootDefs.get(0);
    String firstRootEntityName = firstRootEntity.getName();
    CollectRecord record = recordManager.instantiateRecord(survey, firstRootEntityName, user, command.getFormVersion(), Step.ENTRY);
    NodeChangeSet changeSet = recordManager.initializeRecord(record);
    List<String> keyValues = command.getKeyValues();
    Iterator<String> keyValuesIt = keyValues.iterator();
    List<AttributeDefinition> keyAttributeDefinitions = firstRootEntity.getKeyAttributeDefinitions();
    Iterator<AttributeDefinition> keyDefsIt = keyAttributeDefinitions.iterator();
    while (keyDefsIt.hasNext()) {
        AttributeDefinition keyDef = keyDefsIt.next();
        String keyVal = keyValuesIt.next();
        Value keyValue = keyDef.createValue(keyVal);
        Attribute<?, Value> keyAttr = record.findNodeByPath(keyDef.getPath());
        recordUpdater.updateAttribute(keyAttr, keyValue);
    }
    recordManager.save(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, user.getUsername());
    for (RecordEvent recordEvent : events) {
        recordEvent.initializeRecordId(record.getId());
    }
    return events;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) User(org.openforis.collect.model.User) EventProducer(org.openforis.collect.event.EventProducer) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) RecordEvent(org.openforis.collect.event.RecordEvent) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Value(org.openforis.idm.model.Value) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 44 with User

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

the class BaseVM method getLoggedUser.

public User getLoggedUser() {
    String loggedUsername = getLoggedUsername();
    User user = userManager.loadByUserName(loggedUsername);
    return user;
}
Also used : User(org.openforis.collect.model.User)

Example 45 with User

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

the class RecordController method moveRecords.

@RequestMapping(value = "survey/{surveyId}/data/move/records", method = POST, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public JobProxy moveRecords(@PathVariable("surveyId") int surveyId, @RequestParam String fromStep, @RequestParam boolean promote) {
    BulkRecordMoveJob job = jobManager.createJob(BulkRecordMoveJob.class);
    SessionState sessionState = sessionManager.getSessionState();
    User loggedUser = sessionState.getUser();
    CollectSurvey survey = surveyManager.getById(surveyId);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    job.setSurvey(survey);
    job.setRootEntity(rootEntityDef.getName());
    job.setPromote(promote);
    job.setFromStep(Step.valueOf(fromStep));
    job.setUser(loggedUser);
    job.setRecordMovedCallback(new BulkRecordMoveJob.Callback() {

        @Override
        public void recordMoved(CollectRecord record) {
            if (promote) {
                publishRecordPromotedEvents(record, loggedUser.getUsername());
            } else {
                publishRecordDeletedEvent(record, RecordStep.valueOf(fromStep), loggedUser.getUsername());
            }
        }
    });
    jobManager.startSurveyJob(job);
    return new JobProxy(job);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) JobProxy(org.openforis.concurrency.proxy.JobProxy) CollectSurvey(org.openforis.collect.model.CollectSurvey) BulkRecordMoveJob(org.openforis.collect.io.data.BulkRecordMoveJob) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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