Search in sources :

Example 26 with UnknownEntityTypeException

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

the class EntityTypeRequestMapperImpl method toEntityType.

@Override
public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) {
    EntityType entityType = entityTypeFactory.create();
    String entityTypeId = entityTypeRequest.getId();
    if (entityTypeId != null) {
        entityType.setId(entityTypeId);
    }
    String packageId = entityTypeRequest.getPackage();
    Package pack = null;
    if (packageId != null) {
        pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage()));
    }
    entityType.setPackage(pack);
    String extendsEntityTypeId = entityTypeRequest.getExtends();
    if (extendsEntityTypeId != null) {
        EntityType extendsEntityType = metaDataService.getEntityType(extendsEntityTypeId).orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId));
        entityType.setExtends(extendsEntityType);
    }
    processI18nLabel(entityTypeRequest.getLabel(), entityType);
    processI18nDescription(entityTypeRequest.getDescription(), entityType);
    List<Attribute> ownAttributes = attributeRequestMapper.toAttributes(entityTypeRequest.getAttributes(), entityTypeRequest, entityType);
    entityType.setOwnAllAttributes(ownAttributes);
    Boolean abstractEntityType = entityTypeRequest.getAbstract();
    if (abstractEntityType != null) {
        entityType.setAbstract(abstractEntityType);
    }
    entityType.setBackend(metaDataService.getDefaultBackend().getName());
    processSelfReferencingAttributes(entityType, ownAttributes);
    return entityType;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Attribute(org.molgenis.data.meta.model.Attribute) UnknownPackageException(org.molgenis.data.UnknownPackageException) Package(org.molgenis.data.meta.model.Package)

Example 27 with UnknownEntityTypeException

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

the class RestControllerTest method retrieveAttributeUnknownEntity.

@Test
void retrieveAttributeUnknownEntity() throws Throwable {
    String entityTypeId = "unknown";
    when(dataService.getEntityType(entityTypeId)).thenThrow(new UnknownEntityTypeException(entityTypeId));
    String HREF_UNKNOWN_ENTITY_META = BASE_URI + "/" + entityTypeId + "/meta";
    try {
        mockMvc.perform(get(HREF_UNKNOWN_ENTITY_META + "/attribute"));
    } catch (NestedServletException e) {
        Exception exception = assertThrows(UnknownEntityTypeException.class, () -> {
            throw e.getCause();
        });
        assertThat(exception.getMessage()).containsPattern("id:unknown");
    }
}
Also used : UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) NestedServletException(org.springframework.web.util.NestedServletException) UnknownEntityException(org.molgenis.data.UnknownEntityException) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) PermissionDeniedException(org.molgenis.data.security.exception.PermissionDeniedException) MolgenisDataAccessException(org.molgenis.data.MolgenisDataAccessException) MolgenisDataException(org.molgenis.data.MolgenisDataException) UnknownAttributeException(org.molgenis.data.UnknownAttributeException) EntityTypePermissionDeniedException(org.molgenis.data.security.exception.EntityTypePermissionDeniedException) NestedServletException(org.springframework.web.util.NestedServletException) Test(org.junit.jupiter.api.Test)

Example 28 with UnknownEntityTypeException

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

the class RestControllerTest method handleUnknownEntityException.

@Test
void handleUnknownEntityException() throws Throwable {
    String entityTypeId = "bogus";
    when(dataService.getEntityType(entityTypeId)).thenThrow(new UnknownEntityTypeException(entityTypeId));
    try {
        mockMvc.perform(get(BASE_URI + "/" + entityTypeId + "/1"));
    } catch (NestedServletException e) {
        assertThrows(UnknownEntityTypeException.class, () -> {
            throw e.getCause();
        });
    }
}
Also used : UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) NestedServletException(org.springframework.web.util.NestedServletException) Test(org.junit.jupiter.api.Test)

Example 29 with UnknownEntityTypeException

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

the class MetaDataServiceImpl method updateEntityType.

@Transactional
@Override
public void updateEntityType(EntityType entityType) {
    EntityType existingEntityType = dataService.query(ENTITY_TYPE_META_DATA, EntityType.class).eq(EntityTypeMetadata.ID, entityType.getId()).fetch(getEntityTypeFetch()).findOne();
    if (existingEntityType == null) {
        throw new UnknownEntityTypeException(entityType.getId());
    }
    updateEntityType(entityType, existingEntityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with UnknownEntityTypeException

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

the class EntityTypeRepositoryDecorator method deleteById.

@Override
public void deleteById(Object id) {
    EntityType entityType = findOneById(id);
    if (entityType == null) {
        throw new UnknownEntityTypeException(id.toString());
    }
    deleteEntityType(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException)

Aggregations

UnknownEntityTypeException (org.molgenis.data.UnknownEntityTypeException)31 EntityType (org.molgenis.data.meta.model.EntityType)21 Test (org.junit.jupiter.api.Test)15 UnknownEntityException (org.molgenis.data.UnknownEntityException)9 MolgenisDataException (org.molgenis.data.MolgenisDataException)8 Attribute (org.molgenis.data.meta.model.Attribute)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Order (org.junit.jupiter.api.Order)7 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)7 Entity (org.molgenis.data.Entity)7 EntityTypePermissionDeniedException (org.molgenis.data.security.exception.EntityTypePermissionDeniedException)7 NestedServletException (org.springframework.web.util.NestedServletException)7 RepositoryAlreadyExistsException (org.molgenis.data.RepositoryAlreadyExistsException)5 RepositoryNotCapableException (org.molgenis.data.RepositoryNotCapableException)5 Package (org.molgenis.data.meta.model.Package)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Mockito.anyString (org.mockito.Mockito.anyString)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)4 UnknownAttributeException (org.molgenis.data.UnknownAttributeException)3