use of org.molgenis.data.DatabaseAction in project molgenis by molgenis.
the class PackageWizardPage method handleRequest.
@Override
public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) {
ImportWizardUtil.validateImportWizard(wizard);
ImportWizard importWizard = (ImportWizard) wizard;
String entityImportOption = importWizard.getEntityImportOption();
if (entityImportOption != null) {
try {
// convert input to database action
DatabaseAction entityDbAction = ImportWizardUtil.toDatabaseAction(entityImportOption);
if (entityDbAction == null) {
throw new IOException("unknown database action: " + entityImportOption);
}
RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(importWizard.getFile());
ImportService importService = importServiceFactory.getImportService(importWizard.getFile(), repositoryCollection);
// Do integration test only if there are no previous errors found
if (!importWizard.getEntitiesImportable().containsValue(false)) {
// The package name that is selected in the "package selection" page
String selectedPackage = request.getParameter("selectedPackage");
// The entities that can be imported
Map<String, Boolean> entitiesImportable = importService.determineImportableEntities(metaDataService, repositoryCollection, selectedPackage);
// The results of the attribute checks are stored in maps with the entityname as key, those need to be updated with the packagename
updateFieldReports(importWizard, selectedPackage, entitiesImportable);
// Set the entities that can be imported
importWizard.setEntitiesImportable(entitiesImportable);
// The entities that can not be imported. If even one entity can not be imported, everything fails
List<String> entitiesNotImportable = entitiesImportable.entrySet().stream().filter(entity -> !entity.getValue()).map(Map.Entry::getKey).collect(toList());
if (!entitiesNotImportable.isEmpty()) {
throw new MolgenisDataException("You are trying to upload entities that are not compatible with the already existing entities: " + entitiesNotImportable.toString());
}
}
} catch (RuntimeException | IOException e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
}
}
return null;
}
use of org.molgenis.data.DatabaseAction in project molgenis by molgenis.
the class ValidationResultWizardPage method handleRequest.
@Override
public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) {
ImportWizardUtil.validateImportWizard(wizard);
ImportWizard importWizard = (ImportWizard) wizard;
String entityImportOption = importWizard.getEntityImportOption();
if (entityImportOption != null) {
try {
// convert input to database action
DatabaseAction entityDbAction = ImportWizardUtil.toDatabaseAction(entityImportOption);
if (entityDbAction == null)
throw new IOException("unknown database action: " + entityImportOption);
RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(importWizard.getFile());
ImportService importService = importServiceFactory.getImportService(importWizard.getFile(), repositoryCollection);
synchronized (this) {
ImportRun importRun = importRunService.addImportRun(SecurityUtils.getCurrentUsername(), false);
((ImportWizard) wizard).setImportRunId(importRun.getId());
asyncImportJobs.execute(new ImportJob(importService, SecurityContextHolder.getContext(), repositoryCollection, entityDbAction, importRun.getId(), importRunService, request.getSession(), importWizard.getSelectedPackage()));
}
} catch (RuntimeException | IOException e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
}
}
// Convert to list because it's less impossible use in FreeMarker
if (!userAccountService.getCurrentUser().isSuperuser()) {
String username = SecurityUtils.getCurrentUsername();
groups = RunAsSystemAspect.runAsSystem(() -> Lists.newArrayList(userService.getUserGroups(username)));
} else {
groups = dataService.findAll(GROUP, Group.class).collect(toList());
}
((ImportWizard) wizard).setGroups(groups);
return null;
}
use of org.molgenis.data.DatabaseAction in project molgenis by molgenis.
the class ImportWizardController method importFile.
private ImportRun importFile(HttpServletRequest request, File file, String action, Boolean notify, String packageId) {
// no action specified? default is ADD just like the importerPlugin
ImportRun importRun;
String fileExtension = getExtension(file.getName());
DatabaseAction databaseAction = getDatabaseAction(file, action);
if (fileExtension.contains("vcf") && dataService.hasRepository(getBaseName(file.getName()))) {
throw new MolgenisDataException("A repository with name " + getBaseName(file.getName()) + " already exists");
}
ImportService importService = importServiceFactory.getImportService(file.getName());
RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
importRun = importRunService.addImportRun(SecurityUtils.getCurrentUsername(), Boolean.TRUE.equals(notify));
asyncImportJobs.execute(new ImportJob(importService, SecurityContextHolder.getContext(), repositoryCollection, databaseAction, importRun.getId(), importRunService, request.getSession(), packageId));
return importRun;
}
Aggregations