Search in sources :

Example 6 with UnknownEntityTypeException

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

the class DataExplorerController method viewEntityDetailsById.

/**
 * Builds a model containing one entity and returns standalone report ftl view
 *
 * @return standalone report view
 * @throws Exception if an entity name or id is not found
 * @throws MolgenisDataAccessException if an EntityType does not exist
 */
@GetMapping("/details/{entityTypeId}/{entityId}")
public String viewEntityDetailsById(@PathVariable(value = "entityTypeId") String entityTypeId, @PathVariable(value = "entityId") String entityId, Model model) {
    EntityType entityType;
    if (dataService.hasEntityType(entityTypeId)) {
        entityType = dataService.getEntityType(entityTypeId);
    } else {
        throw new UnknownEntityTypeException(entityTypeId);
    }
    Object id = getTypedValue(entityId, entityType.getIdAttribute());
    model.addAttribute("entity", dataService.getRepository(entityTypeId).findOneById(id));
    model.addAttribute("entityType", entityType);
    model.addAttribute("entityTypeId", entityTypeId);
    model.addAttribute("entityTypeLabel", entityType.getLabel());
    model.addAttribute(VIEW_NAME, getStandaloneReportViewName(entityTypeId));
    return "view-standalone-report";
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with UnknownEntityTypeException

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

the class IndexMetadataCUDOperationsPlatformIT method testIndexUpdateMetaDataRemoveCompoundAttribute.

public static void testIndexUpdateMetaDataRemoveCompoundAttribute(EntityType entityType, AttributeFactory attributeFactory, ElasticsearchService searchService, MetaDataService metaDataService, IndexJobScheduler indexService) {
    // 1. Create new compound to test delete
    Attribute compound = attributeFactory.create();
    compound.setName("test_compound");
    compound.setDataType(AttributeType.COMPOUND);
    Attribute compoundChild = attributeFactory.create();
    compoundChild.setName("test_compound_child");
    compoundChild.setParent(compound);
    entityType.addAttributes(newArrayList(compound, compoundChild));
    runAsSystem(() -> metaDataService.updateEntityType(entityType));
    waitForWorkToBeFinished(indexService, LOG);
    assertTrue(searchService.hasIndex(entityType));
    // 2. Verify compound and child got added
    EntityType afterAddEntityType = metaDataService.getEntityType(entityType.getId()).orElseThrow(() -> new UnknownEntityTypeException(entityType.getId()));
    assertNotNull(afterAddEntityType.getAttribute("test_compound"));
    assertNotNull(afterAddEntityType.getAttribute("test_compound_child"));
    // 3. Delete compound
    afterAddEntityType.removeAttribute(compound);
    runAsSystem(() -> metaDataService.updateEntityType(afterAddEntityType));
    waitForWorkToBeFinished(indexService, LOG);
    assertTrue(searchService.hasIndex(afterAddEntityType));
    // 4. Verify that compound + child was removed
    EntityType afterRemoveEntityType = metaDataService.getEntityType(entityType.getId()).orElseThrow(() -> new UnknownEntityException(EntityTypeMetadata.ENTITY_TYPE_META_DATA, entityType.getId()));
    org.junit.jupiter.api.Assertions.assertNull(afterRemoveEntityType.getAttribute(compound.getName()));
    org.junit.jupiter.api.Assertions.assertNull(afterRemoveEntityType.getAttribute(compoundChild.getName()));
    EntityType attributeMetadata = metaDataService.getEntityType(AttributeMetadata.ATTRIBUTE_META_DATA).orElseThrow(() -> new UnknownEntityException(EntityTypeMetadata.ENTITY_TYPE_META_DATA, AttributeMetadata.ATTRIBUTE_META_DATA));
    Query<Entity> compoundQuery = new QueryImpl<>().eq(AttributeMetadata.ID, compound.getIdValue());
    Query<Entity> childQuery = new QueryImpl<>().eq(AttributeMetadata.ID, compoundChild.getIdValue());
    assertEquals(0, searchService.count(attributeMetadata, compoundQuery));
    assertEquals(0, searchService.count(attributeMetadata, childQuery));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) UnknownEntityException(org.molgenis.data.UnknownEntityException)

Example 8 with UnknownEntityTypeException

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

the class MetaDataServiceIT method testUpdateEntityType.

@WithMockUser(username = USERNAME)
@Test
@Order(1)
public void testUpdateEntityType() {
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    updatedEntityType.getAttribute(ATTR_STRING).setDataType(ENUM).setEnumOptions(asList("string0", "string1"));
    updatedEntityType.getAttribute(ATTR_BOOL).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_CATEGORICAL).setDataType(LONG).setRefEntity(null);
    updatedEntityType.getAttribute(ATTR_CATEGORICAL_MREF).setDataType(MREF);
    updatedEntityType.getAttribute(ATTR_DATE).setDataType(DATE_TIME);
    updatedEntityType.getAttribute(ATTR_DATETIME).setDataType(DATE);
    updatedEntityType.getAttribute(ATTR_EMAIL).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_DECIMAL).setDataType(INT);
    updatedEntityType.getAttribute(ATTR_HTML).setDataType(TEXT);
    updatedEntityType.getAttribute(ATTR_HYPERLINK).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_LONG).setDataType(DECIMAL);
    updatedEntityType.getAttribute(ATTR_INT).setDataType(LONG);
    updatedEntityType.getAttribute(ATTR_SCRIPT).setDataType(TEXT);
    updatedEntityType.getAttribute(ATTR_XREF).setDataType(CATEGORICAL);
    updatedEntityType.getAttribute(ATTR_MREF).setDataType(CATEGORICAL_MREF);
    updatedEntityType.getAttribute(ATTR_ENUM).setDataType(STRING).setEnumOptions(emptyList());
    metaDataService.updateEntityType(updatedEntityType);
    Entity expectedEntity = new DynamicEntity(updatedEntityType);
    expectedEntity.set(ATTR_ID, "0");
    expectedEntity.set(ATTR_STRING, "string1");
    expectedEntity.set(ATTR_BOOL, "true");
    expectedEntity.set(ATTR_CATEGORICAL, 0L);
    expectedEntity.set(ATTR_CATEGORICAL_MREF, singletonList(refEntities.get(0)));
    expectedEntity.set(ATTR_DATE, LocalDate.parse("2012-12-21").atStartOfDay(systemDefault()).toInstant());
    expectedEntity.set(ATTR_DATETIME, MolgenisDateFormat.parseLocalDate("1985-08-12T06:12:13Z"));
    expectedEntity.set(ATTR_EMAIL, "this.is@mail.address");
    // before update: 0.123
    expectedEntity.set(ATTR_DECIMAL, 0);
    expectedEntity.set(ATTR_HTML, null);
    expectedEntity.set(ATTR_HYPERLINK, "http://www.molgenis.org");
    expectedEntity.set(ATTR_LONG, 0.0);
    expectedEntity.set(ATTR_INT, 10L);
    expectedEntity.set(ATTR_SCRIPT, "/bin/blaat/script.sh");
    expectedEntity.set(ATTR_XREF, refEntities.get(0));
    expectedEntity.set(ATTR_MREF, singletonList(refEntities.get(0)));
    expectedEntity.set(ATTR_COMPOUND_CHILD_INT, 10);
    expectedEntity.set(ATTR_ENUM, "option1");
    expectedEntity = new EntityWithComputedAttributes(expectedEntity);
    assertTrue(EntityUtils.equals(dataService.findOneById(ENTITY_TYPE_ID, "0"), expectedEntity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 9 with UnknownEntityTypeException

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

the class MetaDataServiceIT method testUpdateEntityTypeMrefXrefChange.

@WithMockUser(username = USERNAME)
@Test
@Order(3)
public void testUpdateEntityTypeMrefXrefChange() {
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    updatedEntityType.getAttribute(ATTR_MREF).setDataType(XREF);
    metaDataService.updateEntityType(updatedEntityType);
    Entity expectedEntity = new DynamicEntity(updatedEntityType);
    expectedEntity.set(ATTR_MREF, refEntities.get(0));
    Entity entity = dataService.findOneById(ENTITY_TYPE_ID, "0");
    assertNotNull(entity);
    Entity refEntity = entity.getEntity(ATTR_MREF);
    assertEquals("0", refEntity.getIdValue());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 10 with UnknownEntityTypeException

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

the class MetaDataServiceIT method testUpdateEntityTypeXrefMrefChange.

@WithMockUser(username = USERNAME)
@Test
@Order(2)
public void testUpdateEntityTypeXrefMrefChange() {
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
    updatedEntityType.getAttribute(ATTR_XREF).setDataType(MREF);
    metaDataService.updateEntityType(updatedEntityType);
    Entity expectedEntity = new DynamicEntity(updatedEntityType);
    expectedEntity.set(ATTR_XREF, singletonList(refEntities.get(0)));
    Entity entity = dataService.findOneById(ENTITY_TYPE_ID, "0");
    assertNotNull(entity);
    List<Entity> entities = newArrayList(entity.getEntities(ATTR_XREF));
    assertEquals(1, entities.size());
    assertEquals("0", entities.get(0).getIdValue());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

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