use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class UserGroupDao method findByUser.
public List<UserGroup> findByUser(User user) {
DSLContext dsl = dsl();
List<UserGroup> result = dsl.selectFrom(OFC_USERGROUP).where(OFC_USERGROUP.ID.in(dsl.select(OFC_USER_USERGROUP.GROUP_ID).from(OFC_USER_USERGROUP).where(OFC_USER_USERGROUP.USER_ID.eq(user.getId())))).orderBy(OFC_USERGROUP.PARENT_ID, OFC_USERGROUP.NAME).fetchInto(UserGroup.class);
return result;
}
use of org.openforis.collect.model.UserGroup 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.UserGroup in project collect by openforis.
the class DataRestoreTask method validateInput.
@Override
protected void validateInput() throws Throwable {
super.validateInput();
UserGroup surveyGroup = targetSurvey.getUserGroup();
String surveyName = targetSurvey.getName();
if (surveyGroup == null) {
throw new IllegalStateException(String.format("No user group for survey %s found", surveyName));
}
UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyGroup, user);
if (userInGroup == null || !DATA_RESTORE_ALLOWED_USER_GROUP_ROLES.contains(userInGroup.getRole())) {
throw new IllegalStateException(String.format("User %s is not allowed to restore data for survey %s", user.getUsername(), surveyName));
}
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class BaseVM method initUserGroupsModel.
protected void initUserGroupsModel() {
List<LabelledItem> items = new ArrayList<LabelledItem>();
User loggedUser = getLoggedUser();
List<UserGroup> userGroups = userGroupManager.findAllRelatedUserGroups(loggedUser);
for (UserGroup userGroup : userGroups) {
String label = userGroup.getName().equals(UserGroupManager.DEFAULT_PUBLIC_USER_GROUP_NAME) ? Labels.getLabel(PUBLIC_USER_GROUP_LABEL_KEY) : userGroup.getName().equals(userGroupManager.getDefaultPrivateUserGroupName(loggedUser)) ? Labels.getLabel(PRIVATE_USER_GROUP_LABEL_KEY) : userGroup.getLabel();
items.add(new LabelledItem(userGroup.getName(), label));
}
userGroupsModel = new BindingListModelListModel<LabelledItem>(new ListModelList<LabelledItem>(items));
userGroupsModel.setMultiple(false);
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class SurveyController method startSurveyFileImport.
@RequestMapping(value = "startimport", method = POST)
@ResponseBody
public Response startSurveyFileImport(@Valid SurveyImportParameters params, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
Response res = new Response();
res.setErrorStatus();
res.addObject("errors", bindingResult.getFieldErrors());
return res;
}
String surveyName = params.getName();
UserGroup userGroup = userGroupManager.loadById(params.getUserGroupId());
String uploadedFileNameExtension = FilenameUtils.getExtension(this.uploadedSurveyFile.getName());
AbstractSurveyRestoreJob job;
if (Files.XML_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
job = jobManager.createJob(XMLSurveyRestoreJob.class);
} else if (COLLECT_EARTH_PROJECT_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
job = jobManager.createJob(CESurveyRestoreJob.class);
} else {
job = jobManager.createJob(SurveyRestoreJob.class);
}
job.setFile(this.uploadedSurveyFile);
job.setSurveyName(surveyName);
job.setSurveyUri(uploadedSurveyInfo == null ? null : uploadedSurveyInfo.getSurveyUri());
job.setUserGroup(userGroup);
job.setRestoreIntoPublishedSurvey(false);
job.setValidateSurvey(false);
job.setActiveUser(sessionManager.getLoggedUser());
jobManager.start(job);
this.surveyImportJob = job;
Response res = new Response();
res.setObject(new SurveyImportJobView(job));
return res;
}
Aggregations