use of org.molgenis.data.MolgenisDataException 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.MolgenisDataException in project molgenis by molgenis.
the class OptionsWizardPage method handleRequest.
@Override
public String handleRequest(HttpServletRequest request, BindingResult result, Wizard wizard) {
ImportWizardUtil.validateImportWizard(wizard);
ImportWizard importWizard = (ImportWizard) wizard;
String entityImportOption = request.getParameter("entity_option");
importWizard.setEntityImportOption(entityImportOption);
if (importWizard.getMustChangeEntityName()) {
String userGivenName = request.getParameter("name");
if (StringUtils.isEmpty(userGivenName)) {
result.addError(new ObjectError("wizard", "Please enter an entity name"));
return null;
}
try {
NameValidator.validateEntityName(userGivenName);
if (dataService.hasRepository(userGivenName)) {
result.addError(new ObjectError("wizard", "An entity with this name already exists."));
return null;
}
} catch (MolgenisDataException e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
return null;
}
File tmpFile = importWizard.getFile();
String fileName = tmpFile.getName();
// FIXME: can this be done a bit cleaner?
String extension = FileExtensionUtils.findExtensionFromPossibilities(fileName, fileRepositoryCollectionFactory.createFileRepositoryCollection(tmpFile).getFileNameExtensions());
File file = new File(tmpFile.getParent(), userGivenName + "." + extension);
if (!tmpFile.renameTo(file)) {
LOG.error("Failed to rename '{}' to '{}'", tmpFile.getName(), file.getName());
}
importWizard.setFile(file);
}
try {
return validateInput(importWizard.getFile(), importWizard, result);
} catch (Exception e) {
ImportWizardUtil.handleException(e, importWizard, result, LOG, entityImportOption);
}
return null;
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecorator method isOperationPermitted.
@Override
public boolean isOperationPermitted(Object id, Action action) {
AbstractPermission permission = getPermissionForOperation(action);
boolean hasPermission = userPermissionEvaluator.hasPermission(new EntityTypeIdentity(id.toString()), permission);
if (hasPermission && !permission.equals(EntityTypePermission.COUNT)) {
boolean isSystem = systemEntityTypeRegistry.hasSystemEntityType(id.toString());
if (isSystem && !currentUserIsSystem()) {
throw new MolgenisDataException(format("No [%s] permission on EntityType [%s]", toMessagePermission(action), id));
}
}
return hasPermission;
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class RestService method convertMref.
private List<?> convertMref(Attribute attr, Object paramValue) {
List<?> value;
if (paramValue != null) {
List<?> mrefParamValues;
if (paramValue instanceof String) {
mrefParamValues = asList(StringUtils.split((String) paramValue, ','));
} else if (paramValue instanceof List<?>) {
mrefParamValues = (List<?>) paramValue;
} else {
throw new MolgenisDataException(format("Attribute [%s] value is of type [%s] instead of [%s] or [%s]", attr.getName(), paramValue.getClass().getSimpleName(), String.class.getSimpleName(), List.class.getSimpleName()));
}
EntityType mrefEntity = attr.getRefEntity();
Attribute mrefEntityIdAttr = mrefEntity.getIdAttribute();
value = mrefParamValues.stream().map(mrefParamValue -> toEntityValue(mrefEntityIdAttr, mrefParamValue, null)).map(mrefIdValue -> entityManager.getReference(mrefEntity, mrefIdValue)).collect(toList());
} else {
value = emptyList();
}
return value;
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class MultiAllelicResultFilterTest method filterResultsMergeMultilineMismatchPos.
@Test
public void filterResultsMergeMultilineMismatchPos() {
MultiAllelicResultFilter filter = new MultiAllelicResultFilter(Collections.singletonList(attributeFactory.create().setName("annotation").setDataType(STRING)), true, vcfAttributes);
try {
filter.filterResults(Arrays.asList(entityMismatchPos, resultEntity10), entity10, false);
Assert.fail("Should throw exception for mismatching positions");
} catch (MolgenisDataException actual) {
assertEquals(actual.getMessage(), "Mismatch in location! Location{chrom=1, pos=101} vs Location{chrom=1, pos=100}");
}
}
Aggregations