Search in sources :

Example 16 with UserGroup

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());
}
Also used : User(org.openforis.collect.model.User) Timestamp(java.sql.Timestamp) UserGroup(org.openforis.collect.model.UserGroup) CollectTest(org.openforis.collect.CollectTest) Test(org.junit.Test)

Example 17 with UserGroup

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());
}
Also used : LabelledItem(org.openforis.collect.designer.model.LabelledItem) TemplateType(org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup) Command(org.zkoss.bind.annotation.Command)

Example 18 with UserGroup

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;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with UserGroup

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;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 20 with UserGroup

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;
}
Also used : ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Aggregations

UserGroup (org.openforis.collect.model.UserGroup)26 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 UserInGroup (org.openforis.collect.model.UserInGroup)7 ArrayList (java.util.ArrayList)6 User (org.openforis.collect.model.User)4 Timestamp (java.sql.Timestamp)3 LabelledItem (org.openforis.collect.designer.model.LabelledItem)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AbstractSurveyRestoreJob (org.openforis.collect.io.AbstractSurveyRestoreJob)2 XMLSurveyRestoreJob (org.openforis.collect.io.XMLSurveyRestoreJob)2 SurveySummary (org.openforis.collect.model.SurveySummary)2 Response (org.openforis.commons.web.Response)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1