use of org.openforis.collect.model.UserGroup 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());
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class NewSurveyParametersPopUpVM method ok.
@Command
public void ok() throws IdmlParseException, SurveyValidationException, SurveyStoreException {
String name = (String) form.get(SURVEY_NAME_FIELD);
String langCode = ((LabelledItem) form.get(LANGUAGE_FIELD_NAME)).getCode();
String templateCode = ((LabelledItem) form.get(TEMPLATE_FIELD_NAME)).getCode();
TemplateType templateType = TemplateType.valueOf(templateCode);
String userGroupName = ((LabelledItem) form.get(USER_GROUP_FIELD_NAME)).getCode();
CollectSurvey survey;
switch(templateType) {
case BLANK:
survey = createEmptySurvey(name, langCode);
break;
default:
survey = createNewSurveyFromTemplate(name, langCode, templateType);
}
UserGroup userGroup = userGroupManager.findByName(userGroupName);
survey.setUserGroupId(userGroup.getId());
surveyManager.save(survey);
SurveyEditVM.redirectToSurveyEditPage(survey.getId());
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class SurveyController method createSurvey.
@Transactional
@RequestMapping(method = POST)
@ResponseBody
public Response createSurvey(@Valid SurveyCreationParameters params, BindingResult bindingResult) throws Exception {
if (bindingResult.hasErrors()) {
Response res = new Response();
res.setErrorStatus();
res.addObject("errors", bindingResult.getFieldErrors());
return res;
}
CollectSurvey survey;
switch(params.getTemplateType()) {
case BLANK:
survey = createEmptySurvey(params.getName(), params.getDefaultLanguageCode());
break;
default:
survey = createNewSurveyFromTemplate(params.getName(), params.getDefaultLanguageCode(), params.getTemplateType());
}
UserGroup userGroup = userGroupManager.loadById(params.getUserGroupId());
survey.setUserGroupId(userGroup.getId());
surveyManager.save(survey);
SurveySummary surveySummary = SurveySummary.createFromSurvey(survey);
Response res = new Response();
res.setObject(surveySummary);
return res;
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class SurveyManager method updateUserGroup.
public SurveySummary updateUserGroup(int id, int userGroupId) throws SurveyStoreException {
UserGroup userGroup = userGroupManager.loadById(userGroupId);
SurveySummary surveySummary = loadSummaryById(id);
Set<Integer> surveyIdsToUpdate = new HashSet<Integer>();
surveyIdsToUpdate.add(surveySummary.getId());
// consider even updating associated published survey, if any
org.apache.commons.collections.CollectionUtils.addIgnoreNull(surveyIdsToUpdate, surveySummary.getPublishedId());
for (Integer surveyId : surveyIdsToUpdate) {
CollectSurvey s = getOrLoadSurveyById(surveyId);
s.setUserGroup(userGroup);
save(s);
}
return surveySummary;
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class LocalUserGroupManager method findAncestorGroups.
private List<UserGroup> findAncestorGroups(UserGroup userGroup) {
List<UserGroup> result = new ArrayList<UserGroup>();
UserGroup currentGroup = userGroup;
while (currentGroup.getParentId() != null) {
UserGroup parentGroup = loadById(currentGroup.getParentId());
result.add(0, parentGroup);
currentGroup = parentGroup;
}
return result;
}
Aggregations