use of org.openforis.collect.model.User in project collect by openforis.
the class SurveyController method unpublishSurvey.
@RequestMapping(value = "unpublish/{id}", method = POST)
@ResponseBody
public SurveyView unpublishSurvey(@PathVariable int id) throws SurveyStoreException {
User activeUser = sessionManager.getLoggedUser();
CollectSurvey survey = surveyManager.unpublish(id, activeUser);
return generateView(survey, false);
}
use of org.openforis.collect.model.User in project collect by openforis.
the class SurveyController method cloneIntoTemporarySurvey.
@Transactional
@RequestMapping(value = "cloneintotemporary/{surveyId}", method = POST)
@ResponseBody
public Response cloneIntoTemporarySurvey(@PathVariable int surveyId) throws Exception {
Response response = new Response();
User loggedUser = sessionManager.getLoggedUser();
CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
if (survey.isPublished()) {
String surveyUri = survey.getUri();
CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(surveyUri, loggedUser);
response.setObject(temporarySurvey.getId());
} else {
response.setErrorStatus();
response.setErrorMessage(String.format("Survey with id %d is not published as expected", surveyId));
}
return response;
}
use of org.openforis.collect.model.User in project collect by openforis.
the class ValidationController method validateAllRecords.
@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
final ServletOutputStream outputStream = response.getOutputStream();
try {
if (s == null || r == null) {
outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
return;
}
SessionState sessionState = getSessionState(request);
final User user = sessionState.getUser();
final String sessionId = sessionState.getSessionId();
print(outputStream, "Starting validation of all records: ");
final CollectSurvey survey = surveyManager.get(s);
if (survey == null) {
print(outputStream, "Survey not found");
return;
}
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary summary) {
try {
String recordKey = validationMessageHelper.getRecordKey(summary);
long start = System.currentTimeMillis();
print(outputStream, "Start validating record: " + recordKey);
Integer id = summary.getId();
Step step = summary.getStep();
recordManager.validateAndSave(survey, user, sessionId, id, step);
long elapsedMillis = System.currentTimeMillis() - start;
print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
} catch (Exception e) {
try {
String message = "ERROR validating record " + summary.getId();
outputStream.println(message);
LOG.error(message);
} catch (IOException e1) {
}
}
}
});
print(outputStream, "End of validation of all records.");
} catch (Exception e) {
outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.openforis.collect.model.User in project collect by openforis.
the class RecordController method newRecord.
@Transactional
@RequestMapping(value = "survey/{surveyId}/data/records", method = POST, consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public RecordProxy newRecord(@PathVariable("surveyId") int surveyId, @RequestBody NewRecordParameters params) throws RecordPersistenceException {
User user = sessionManager.getLoggedUser();
if (user == null) {
user = loadUser(params.getUserId(), params.getUsername());
}
CollectSurvey survey = surveyManager.getById(surveyId);
params.setRootEntityName(ObjectUtils.defaultIfNull(params.getRootEntityName(), survey.getSchema().getFirstRootEntityDefinition().getName()));
params.setVersionName(ObjectUtils.defaultIfNull(params.getVersionName(), survey.getLatestVersion() != null ? survey.getLatestVersion().getName() : null));
params.setUserId(user.getId());
CollectRecord record = recordGenerator.generate(surveyId, params, params.getRecordKey());
return toProxy(record);
}
use of org.openforis.collect.model.User in project collect by openforis.
the class RecordManagerIntegrationTest method testNewRecordInsert.
@Test
public void testNewRecordInsert() {
CollectRecord record = (CollectRecord) record(attribute("id", "10_117"), attribute("region", "002"), attribute("district", "003")).build(survey, "cluster", "2.0");
new RecordUpdater().initializeNewRecord(record);
User user = userManager.loadAdminUser();
record.setCreatedBy(user);
record.setCreationDate(new Date());
record.setModifiedBy(user);
record.setModifiedDate(new Date());
recordManager.save(record);
CollectRecord reloaded = recordManager.load(survey, record.getId());
assertEquals(record, reloaded);
}
Aggregations