Search in sources :

Example 11 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class LocalUserGroupManager method findAllRelatedUserGroups.

@Override
public List<UserGroup> findAllRelatedUserGroups(User user) {
    Set<UserGroup> result = new HashSet<UserGroup>();
    result.add(getDefaultPublicUserGroup());
    result.add(loadDefaultPrivateGroup(user));
    if (user.getRole() == UserRole.ADMIN) {
        // add all user defined groups
        result.addAll(dao.findGroups(false, null));
    } else {
        List<UserGroup> relatedUserGroups = findByUser(user);
        result.addAll(relatedUserGroups);
        // include ancestors
        for (UserGroup userGroup : relatedUserGroups) {
            List<UserGroup> ancestors = findAncestorGroups(userGroup);
            result.addAll(ancestors);
        }
    }
    List<UserGroup> sortedResult = sortBySystemDefinedAndLabel(result);
    return fillLazyLoadedFields(sortedResult);
}
Also used : UserGroup(org.openforis.collect.model.UserGroup) HashSet(java.util.HashSet)

Example 12 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class LocalUserGroupManager method joinToDefaultPublicGroup.

@Override
@Transactional(readOnly = false, propagation = REQUIRED)
public void joinToDefaultPublicGroup(User user, UserGroupRole role) {
    UserGroup publicGroup = getDefaultPublicUserGroup();
    UserInGroup userInGroup = new UserInGroup();
    userInGroup.setGroupId(publicGroup.getId());
    userInGroup.setUserId(user.getId());
    userInGroup.setRole(role);
    userInGroup.setJoinStatus(ACCEPTED);
    Date now = new Date();
    userInGroup.setRequestDate(now);
    userInGroup.setMemberSince(now);
    dao.insertRelation(userInGroup);
}
Also used : UserInGroup(org.openforis.collect.model.UserInGroup) Date(java.util.Date) UserGroup(org.openforis.collect.model.UserGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class SurveyManager method fillReferencedItems.

private void fillReferencedItems(CollectSurvey survey) {
    if (userGroupManager != null) {
        UserGroup userGroup = loadUserGroup(survey.getUserGroupId());
        survey.setUserGroup(userGroup);
    }
}
Also used : UserGroup(org.openforis.collect.model.UserGroup)

Example 14 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class SurveyManager method fillReferencedItems.

private void fillReferencedItems(SurveySummary summary) {
    if (userGroupManager != null) {
        UserGroup userGroup = loadUserGroup(summary.getUserGroupId());
        summary.setUserGroup(userGroup);
    }
}
Also used : UserGroup(org.openforis.collect.model.UserGroup)

Example 15 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class RecordManager method addQualifierValues.

private void addQualifierValues(CollectRecord record, User user) {
    if (userGroupManager == null) {
        return;
    }
    NodeChangeMap changeSet = new NodeChangeMap();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    UserGroup surveyUserGrup = survey.getUserGroup();
    UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGrup, user);
    if (userInGroup == null) {
        throw new IllegalArgumentException(String.format("User %s is not allowed to create records for survey %s", user.getUsername(), survey.getName()));
    }
    UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
    Map<String, String> qualifiersByName = group.getQualifiersByName();
    for (Entry<String, String> qualifier : qualifiersByName.entrySet()) {
        String attributePath = record.getRootEntity().getName() + "/" + qualifier.getKey();
        Attribute<?, Value> attribute = record.findNodeByPath(attributePath);
        Value qualifierValue = attribute.getDefinition().createValue(qualifier.getValue());
        NodeChangeSet changes = updater.updateAttribute(attribute, qualifierValue);
        changeSet.addMergeChanges(changes);
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) UserInGroup(org.openforis.collect.model.UserInGroup) Value(org.openforis.idm.model.Value) NodeChangeMap(org.openforis.collect.model.NodeChangeMap) CollectSurvey(org.openforis.collect.model.CollectSurvey) 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