Search in sources :

Example 21 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class ScheduledJobRepositoryDecoratorTest method testDeleteFails.

@Test
public void testDeleteFails() {
    doThrow(new MolgenisDataException("Failed")).when(delegateRepository).delete(scheduledJob);
    when(scheduledJob.getId()).thenReturn("id");
    try {
        scheduledJobRepositoryDecorator.delete(scheduledJob);
        Assert.fail("delete method should rethrow exception from delegate repository");
    } catch (MolgenisDataException expected) {
    }
    verifyNoMoreInteractions(jobScheduler);
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 22 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class JobTest method testTransactionalJobFailure.

@Test
public void testTransactionalJobFailure() throws Exception {
    when(transactionOperations.execute(actionCaptor.capture())).thenAnswer((call) -> actionCaptor.getValue().doInTransaction(transactionStatus));
    MolgenisDataException mde = new MolgenisDataException();
    when(callable.call()).thenThrow(mde);
    try {
        job.call();
        fail("TransactionalJob call should throw exception if subclass execution fails.");
    } catch (JobExecutionException ex) {
        assertSame(ex.getCause(), mde);
    }
    verify(transactionOperations).execute(any());
    verify(progress).start();
    verify(callable).call();
    verify(progress).failed(mde);
    verifyNoMoreInteractions(callable, progress, transactionOperations);
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) Test(org.testng.annotations.Test)

Example 23 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class EntityTypeMapper method toEntityType.

public EntityType toEntityType(EditorEntityType editorEntityType) {
    if (editorEntityType.getLabelAttribute() == null || editorEntityType.getIdAttribute() == null) {
        throw new MolgenisDataException("ID and Label attribute for EntityType [" + editorEntityType.getLabel() + "] can not be null");
    }
    EntityType entityType = entityTypeFactory.create();
    entityType.setId(editorEntityType.getId());
    entityType.setPackage(packageMapper.toPackageReference(editorEntityType.getPackage()));
    entityType.setLabel(editorEntityType.getLabel());
    if (editorEntityType.getLabelI18n() != null) {
        getLanguageCodes().forEach(languageCode -> entityType.setLabel(languageCode, editorEntityType.getLabelI18n().get(languageCode)));
    }
    entityType.setDescription(editorEntityType.getDescription());
    if (editorEntityType.getDescriptionI18n() != null) {
        getLanguageCodes().forEach(languageCode -> entityType.setDescription(languageCode, editorEntityType.getDescriptionI18n().get(languageCode)));
    }
    entityType.setOwnAllAttributes(attributeMapper.toAttributes(editorEntityType.getAttributes(), editorEntityType));
    entityType.setAbstract(editorEntityType.isAbstract());
    entityType.setExtends(entityTypeParentMapper.toEntityTypeReference(editorEntityType.getEntityTypeParent()));
    entityType.setTags(tagMapper.toTagReferences(editorEntityType.getTags()));
    entityType.setBackend(editorEntityType.getBackend());
    return entityType;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MolgenisDataException(org.molgenis.data.MolgenisDataException)

Example 24 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslator method doTranslate.

private MolgenisDataException doTranslate(SQLException sqlException) {
    if (sqlException instanceof BatchUpdateException) {
        sqlException = sqlException.getNextException();
    }
    if (!(sqlException instanceof PSQLException)) {
        throw new RuntimeException(format("Unexpected exception class [%s]", sqlException.getClass().getSimpleName()));
    }
    PSQLException pSqlException = (PSQLException) sqlException;
    MolgenisDataException molgenisDataException = doTranslate(pSqlException);
    if (molgenisDataException == null) {
        molgenisDataException = new MolgenisDataException(sqlException);
    }
    return molgenisDataException;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) PSQLException(org.postgresql.util.PSQLException) BatchUpdateException(java.sql.BatchUpdateException)

Example 25 with MolgenisDataException

use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslator method doTranslate.

private MolgenisDataException doTranslate(DataAccessException dataAccessException) {
    Throwable cause = dataAccessException.getCause();
    if (!(cause instanceof PSQLException)) {
        throw new RuntimeException(format("Unexpected exception class [%s]", cause.getClass().getSimpleName()));
    }
    PSQLException pSqlException = (PSQLException) cause;
    MolgenisDataException molgenisDataException = doTranslate(pSqlException);
    if (molgenisDataException == null) {
        molgenisDataException = new MolgenisDataException(dataAccessException);
    }
    return molgenisDataException;
}
Also used : MolgenisDataException(org.molgenis.data.MolgenisDataException) PSQLException(org.postgresql.util.PSQLException)

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