use of org.openforis.collect.web.session.SessionState in project collect by openforis.
the class CSVDataImportService method start.
@Secured("ROLE_ADMIN")
public DataImportStatusProxy start(String tempFileName, int parentEntityId, Step step, boolean transactional, boolean validateRecords, boolean insertNewRecords, String newRecordVersionName, boolean deleteExistingEntities) throws DataImportExeption {
if (importJob == null || !importJob.isRunning()) {
File importFile = new File(tempFileName);
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey survey = sessionState.getActiveSurvey();
if (transactional) {
importJob = jobManager.createJob(TransactionalCSVDataImportJob.class);
} else {
importJob = jobManager.createJob(CSVDataImportJob.BEAN_NAME, CSVDataImportJob.class);
}
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setRecordValidationEnabled(validateRecords);
settings.setInsertNewRecords(insertNewRecords);
settings.setNewRecordVersionName(newRecordVersionName);
settings.setDeleteExistingEntities(deleteExistingEntities);
Step[] steps = step == null ? Step.values() : new Step[] { step };
CSVDataImportInput input = new CSVDataImportInput(importFile, survey, steps, parentEntityId, settings);
importJob.setInput(input);
jobManager.start(importJob);
}
return getStatus();
}
use of org.openforis.collect.web.session.SessionState in project collect by openforis.
the class SpeciesService method getActiveSurvey.
private CollectSurvey getActiveSurvey() {
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey activeSurvey = sessionState.getActiveSurvey();
return activeSurvey;
}
use of org.openforis.collect.web.session.SessionState in project collect by openforis.
the class RecordFileController method download.
@RequestMapping(value = "/downloadRecordFile.htm", method = RequestMethod.POST)
public void download(HttpServletRequest request, HttpServletResponse response, @RequestParam("nodeId") Integer nodeId) throws Exception {
SessionState sessionState = getSessionState(request);
CollectRecord record = sessionState.getActiveRecord();
File file = fileManager.getFile(record, nodeId);
if (file != null && file.exists()) {
Controllers.writeFileToResponse(response, file);
} else {
Integer recordId = record == null ? null : record.getId();
String fileName = file == null ? null : file.getName();
Exception e = new Exception("File not found: " + fileName + " record id: " + recordId + " node id: " + nodeId);
LOG.error(e);
throw e;
}
}
use of org.openforis.collect.web.session.SessionState in project collect by openforis.
the class SessionController method getLoggedUser.
@RequestMapping(value = "user", method = GET)
@ResponseBody
public UserForm getLoggedUser(HttpServletRequest request, HttpServletResponse response) {
SessionState sessionState = sessionManager.getSessionState();
User user = sessionState == null ? null : sessionState.getUser();
if (user == null) {
HttpResponses.setNoContentStatus(response);
return null;
}
if (sessionState.getLocale() == null) {
sessionState.setLocale(request.getLocale());
}
return new UserController.UserForm(user);
}
use of org.openforis.collect.web.session.SessionState 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);
}
}
Aggregations