Search in sources :

Example 11 with CollectRecord

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

the class DataService method promote.

protected void promote(Step to) throws RecordPersistenceException, RecordPromoteException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    String userName = sessionState.getUser().getUsername();
    Step currentStep = record.getStep();
    Step exptectedStep = to.getPrevious();
    if (exptectedStep == currentStep) {
        User user = sessionState.getUser();
        sessionEventDispatcher.recordSaved(record);
        recordManager.promote(record, user);
        publishRecordPromotedEvents(record, userName);
        recordManager.releaseLock(record.getId());
        sessionManager.clearActiveRecord();
        if (isCurrentRecordIndexable()) {
            recordIndexService.permanentlyIndex(record);
        }
    } else {
        throw new IllegalStateException("The active record cannot be submitted: it is not in the exptected phase: " + exptectedStep);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step)

Example 12 with CollectRecord

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

the class DataService method findAssignableCodeListItems.

/**
 * Gets the code list items assignable to the specified attribute.
 *
 * @param parentEntityId
 * @param attrName
 * @return
 */
@Secured(USER)
public List<CodeListItemProxy> findAssignableCodeListItems(int parentEntityId, String attrName) {
    CollectRecord record = getActiveRecord();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    UserGroup surveyUserGroup = survey.getUserGroup();
    User user = sessionManager.getLoggedUser();
    final UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGroup, user);
    if (userInGroup == null) {
        throw new IllegalStateException(String.format("User %s not allowed to access survey %s", user.getUsername(), survey.getName()));
    }
    Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
    CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
    List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
    List<CodeListItem> filteredItems = new ArrayList<CodeListItem>(items);
    // filter by user group qualifier (if any)
    UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
    String qualifierName = group.getQualifier1Name();
    String listHierarchicalLevelName = def.getList().isHierarchical() ? def.getHierarchicalLevel() : def.getListName();
    if (qualifierName != null && qualifierName.equals(listHierarchicalLevelName)) {
        CollectionUtils.filter(filteredItems, new Predicate<CodeListItem>() {

            public boolean evaluate(CodeListItem item) {
                return item.getCode().equals(group.getQualifier1Value());
            }
        });
    }
    List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
    List<Node<?>> selectedCodes = parent.getChildren(attrName);
    CodeListItemProxy.setSelectedItems(result, selectedCodes);
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

Example 13 with CollectRecord

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

the class DataService method getCodeListItems.

/**
 * Gets the code list items assignable to the specified attribute and matching the specified codes.
 *
 * @param parentEntityId
 * @param attrName
 * @param codes
 * @return
 */
@Secured(USER)
public List<CodeListItemProxy> getCodeListItems(int parentEntityId, String attrName, String[] codes) {
    CollectRecord record = getActiveRecord();
    Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
    CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
    List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
    List<CodeListItem> filteredItems = new ArrayList<CodeListItem>();
    if (codes != null && codes.length > 0) {
        // filter by specified codes
        for (CodeListItem item : items) {
            for (String code : codes) {
                if (item.getCode().equals(code)) {
                    filteredItems.add(item);
                }
            }
        }
    }
    List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ArrayList(java.util.ArrayList) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

Example 14 with CollectRecord

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

the class DataService method checkoutRecord.

@Secured(ENTRY_LIMITED)
public RecordProxy checkoutRecord(int id, Integer stepNumber, boolean forceUnlock) throws RecordPersistenceException, RecordIndexException {
    SessionState sessionState = sessionManager.getSessionState();
    if (sessionState.isActiveRecordBeingEdited()) {
        throw new MultipleEditException();
    }
    final CollectSurvey survey = sessionState.getActiveSurvey();
    User user = sessionState.getUser();
    Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
    CollectRecord record = step == null ? recordManager.checkout(survey, user, id, sessionState.getSessionId(), forceUnlock) : recordManager.checkout(survey, user, id, step, sessionState.getSessionId(), forceUnlock);
    sessionManager.setActiveRecord(record);
    prepareRecordIndexing();
    return toProxy(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 15 with CollectRecord

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

the class DataService method moveNode.

@Secured(ENTRY_LIMITED)
public void moveNode(int nodeId, int index) {
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    recordManager.moveNode(record, nodeId, index);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9