use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class UserGroupController method createItemInstance.
@Override
protected UserGroup createItemInstance() {
UserGroup userGroup = new UserGroup();
userGroup.setCreationDate(new Timestamp(System.currentTimeMillis()));
userGroup.setCreatedByUser(sessionManager.getSessionState().getUser());
return userGroup;
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class DataRestoreController method startRestoreJob.
private DataRestoreJob startRestoreJob(InputStream fileInputStream, boolean newSurvey, String expectedSurveyName, User user, boolean validateRecords, boolean deleteAllRecords, OverwriteStrategy recordOverwriteStrategy) throws IOException, FileNotFoundException, ZipException {
File tempFile = File.createTempFile("ofc_data_restore", ".collect-backup");
FileUtils.copyInputStreamToFile(fileInputStream, tempFile);
SurveyBackupInfo info = extractInfo(tempFile);
CollectSurvey publishedSurvey = findPublishedSurvey(info);
if (newSurvey) {
checkPackagedNewSurveyValidity(info);
} else {
checkPackagedSurveyValidity(info, expectedSurveyName);
}
UserGroup newSurveyUserGroup = userGroupManager.getDefaultPublicUserGroup();
DataRestoreJob job = jobManager.createJob(DataRestoreJob.JOB_NAME, DataRestoreJob.class);
job.setUser(user);
job.setStoreRestoredFile(true);
job.setPublishedSurvey(publishedSurvey);
job.setNewSurveyUserGroup(newSurveyUserGroup);
job.setFile(tempFile);
job.setRecordOverwriteStrategy(recordOverwriteStrategy);
job.setRestoreUploadedFiles(true);
job.setValidateRecords(validateRecords);
job.setDeleteAllRecordsBeforeRestore(deleteAllRecords);
String lockId = extractSurveyUri(tempFile);
jobManager.start(job, lockId);
return job;
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class SurveyImportVM method startSurveyImport.
protected void startSurveyImport() {
String surveyName = getFormSurveyName();
LabelledItem userGroupItem = (LabelledItem) form.get(USER_GROUP_FIELD_NAME);
UserGroup userGroup = userGroupManager.findByName(userGroupItem.getCode());
String uploadedFileNameExtension = FilenameUtils.getExtension(this.uploadedFileName);
AbstractSurveyRestoreJob job;
if (XML_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
job = jobManager.createJob(XMLSurveyRestoreJob.class);
} else if (CEP_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
job = jobManager.createJob(CESurveyRestoreJob.class);
} else {
job = jobManager.createJob(SurveyRestoreJob.class);
}
job.setFile(uploadedFile);
job.setSurveyName(surveyName);
job.setSurveyUri(uploadedSurveyUri);
job.setUserGroup(userGroup);
job.setRestoreIntoPublishedSurvey(false);
job.setValidateSurvey(false);
job.setActiveUser(getLoggedUser());
jobManager.start(job);
this.restoreJob = job;
openSurveyRestoreStatusPopUp();
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class LocalUserGroupManager method createDefaultPrivateUserGroup.
@Override
@Transactional(readOnly = false, propagation = REQUIRED)
public UserGroup createDefaultPrivateUserGroup(User user, User createdByUser) {
UserGroup userGroup = new UserGroup();
userGroup.setName(getDefaultPrivateUserGroupName(user));
userGroup.setLabel(user.getUsername() + DEFAULT_PRIVATE_USER_GROUP_LABEL_SUFFIX);
userGroup.setVisibility(Visibility.PRIVATE);
userGroup.setSystemDefined(true);
userGroup.setEnabled(true);
userGroup.setCreationDate(new Timestamp(System.currentTimeMillis()));
userGroup.setCreatedBy(createdByUser.getId());
dao.insert(userGroup);
UserInGroup userInGroup = new UserInGroup();
userInGroup.setGroupId(userGroup.getId());
userInGroup.setUserId(user.getId());
userInGroup.setRole(OWNER);
userInGroup.setJoinStatus(ACCEPTED);
userInGroup.setRequestDate(new Date());
userInGroup.setMemberSince(new Date());
dao.insertRelation(userInGroup);
return userGroup;
}
use of org.openforis.collect.model.UserGroup in project collect by openforis.
the class LocalUserGroupManager method deleteDefaultPrivateGroup.
private void deleteDefaultPrivateGroup(User user) {
UserGroup group = dao.loadByName(getDefaultPrivateUserGroupName(user));
dao.delete(group);
}
Aggregations