Search in sources :

Example 11 with MolgenisDataException

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;
}
Also used : DatabaseAction(org.molgenis.data.DatabaseAction) IOException(java.io.IOException) RepositoryCollection(org.molgenis.data.RepositoryCollection) MolgenisDataException(org.molgenis.data.MolgenisDataException) ImportService(org.molgenis.data.importer.ImportService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with MolgenisDataException

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;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) ObjectError(org.springframework.validation.ObjectError) File(java.io.File) MolgenisDataException(org.molgenis.data.MolgenisDataException)

Example 13 with MolgenisDataException

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;
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) MolgenisDataException(org.molgenis.data.MolgenisDataException) AbstractPermission(org.springframework.security.acls.domain.AbstractPermission)

Example 14 with MolgenisDataException

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) IdGenerator(org.molgenis.data.populate.IdGenerator) ONE_TO_MANY(org.molgenis.data.meta.AttributeType.ONE_TO_MANY) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) FileStore(org.molgenis.data.file.FileStore) FileDownloadController(org.molgenis.core.ui.file.FileDownloadController) FileMetaFactory(org.molgenis.data.file.model.FileMetaFactory) Service(org.springframework.stereotype.Service) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) POPULATE(org.molgenis.data.EntityManager.CreationMode.POPULATE) AttributeType(org.molgenis.data.meta.AttributeType) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) MolgenisDateFormat(org.molgenis.data.util.MolgenisDateFormat) EntityType(org.molgenis.data.meta.model.EntityType) FILENAME(org.molgenis.data.file.model.FileMetaMetaData.FILENAME) String.format(java.lang.String.format) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) FileMeta(org.molgenis.data.file.model.FileMeta) FILE_META(org.molgenis.data.file.model.FileMetaMetaData.FILE_META) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) LocalDate(java.time.LocalDate) DataService(org.molgenis.data.DataService) MultipartFile(org.springframework.web.multipart.MultipartFile) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityManager(org.molgenis.data.EntityManager) Entity(org.molgenis.data.Entity) UriComponents(org.springframework.web.util.UriComponents) MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 15 with MolgenisDataException

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}");
    }
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) MultiAllelicResultFilter(org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

MolgenisDataException (org.molgenis.data.MolgenisDataException)51 Entity (org.molgenis.data.Entity)16 Attribute (org.molgenis.data.meta.model.Attribute)11 EntityType (org.molgenis.data.meta.model.EntityType)11 Test (org.testng.annotations.Test)7 IOException (java.io.IOException)6 List (java.util.List)6 DynamicEntity (org.molgenis.data.support.DynamicEntity)6 File (java.io.File)5 AttributeType (org.molgenis.data.meta.AttributeType)5 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)5 Instant (java.time.Instant)4 LocalDate (java.time.LocalDate)4 Collectors.toList (java.util.stream.Collectors.toList)4 DataService (org.molgenis.data.DataService)4 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 String.format (java.lang.String.format)3 DateTimeParseException (java.time.format.DateTimeParseException)3 Map (java.util.Map)3 Stream (java.util.stream.Stream)3