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);
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations