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