use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class DataService method loadRecordSummaries.
/**
* @param rootEntityName
* @param offset
* @param toIndex
* @param orderByFieldName
* @param filter
*
* @return map with "count" and "records" items
*/
@Secured(USER)
public Map<String, Object> loadRecordSummaries(String rootEntityName, int offset, int maxNumberOfRows, List<RecordSummarySortField> sortFields, String[] keyValues) {
Map<String, Object> result = new HashMap<String, Object>();
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey activeSurvey = sessionState.getActiveSurvey();
Schema schema = activeSurvey.getSchema();
EntityDefinition rootEntityDefinition = schema.getRootEntityDefinition(rootEntityName);
RecordFilter filter = new RecordFilter(activeSurvey, rootEntityDefinition.getId());
filter.setKeyValues(keyValues);
filter.setOffset(offset);
filter.setMaxNumberOfRecords(maxNumberOfRows);
// load summaries
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, getProxyContext());
result.put("records", proxies);
// count total records
int count = recordManager.countRecords(filter);
result.put("count", count);
return result;
}
use of org.openforis.collect.model.CollectSurvey in project collect by openforis.
the class DataService method loadRecord.
@Secured(USER)
public RecordProxy loadRecord(int id, Integer stepNumber) {
SessionState sessionState = sessionManager.getSessionState();
final CollectSurvey survey = sessionState.getActiveSurvey();
Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
CollectRecord record = step == null ? recordManager.load(survey, id) : recordManager.load(survey, id, step);
sessionManager.setActiveRecord(record);
return toProxy(record);
}
use of org.openforis.collect.model.CollectSurvey 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.CollectSurvey 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.CollectSurvey in project collect by openforis.
the class DataService method deleteRecord.
@Transactional
@Secured(ENTRY)
public void deleteRecord(int id) throws RecordPersistenceException {
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey survey = sessionState.getActiveSurvey();
String userName = sessionState.getUser().getUsername();
CollectRecord record = recordManager.load(survey, id);
if (record.getStep() != Step.ENTRY) {
throw new IllegalStateException("Cannot delete a record not in ENTRY phase");
}
fileManager.deleteAllFiles(record);
recordManager.delete(id);
publishRecordDeletedEvent(record, record.getStep().toRecordStep(), userName);
}
Aggregations