Search in sources :

Example 1 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 2 with UnknownEntityTypeException

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

the class PlatformIT method testLanguageService.

@WithMockUser(username = USERNAME)
@Test
void testLanguageService() {
    populateUserPermissions();
    assertEquals("labelEn", dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_META_DATA)).getAttribute("labelEn").getName());
    assertEquals("label", dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_META_DATA)).getLabelAttribute("en").getName());
    assertEquals("label", dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_META_DATA)).getLabelAttribute("pt").getName());
    assertEquals("label", dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_META_DATA)).getLabelAttribute("nl").getName());
    assertEquals("label", dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_META_DATA)).getLabelAttribute().getName());
    assertEquals("en", getCurrentUserLanguageCode());
    assertArrayEquals(new String[] { "en", "nl", "de", "es", "it", "pt", "fr", "xx" }, getLanguageCodes().toArray());
    // NL
    assertNotNull(dataService.getEntityType(L10N_STRING).getAttribute("nl"));
    assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("labelNl"));
    assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("descriptionNl"));
    assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("labelNl"));
    assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("descriptionNl"));
    // EN
    assertNotNull(dataService.getEntityType(L10N_STRING).getAttribute("en"));
    assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("labelEn"));
    assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("descriptionEn"));
    assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("labelEn"));
    assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("descriptionEn"));
    L10nString car = l10nStringFactory.create();
    car.setMessageID("car");
    car.set("en", "car");
    car.set("nl", "auto");
    car.setNamespace("platform-it");
    dataService.add(L10nStringMetadata.L10N_STRING, car);
    // Test default value
    assertEquals("car", getBundle().getString("car"));
}
Also used : UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) L10nString(org.molgenis.data.i18n.model.L10nString) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 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 4 with UnknownEntityTypeException

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

the class MappingServiceImpl method createTargetMetadata.

/**
 * Package-private for testability
 */
EntityType createTargetMetadata(MappingTarget mappingTarget, String entityTypeId, String packageId, String label, Boolean addSourceAttribute) {
    EntityType targetMetadata = EntityType.newInstance(mappingTarget.getTarget(), DEEP_COPY_ATTRS, attrMetaFactory);
    targetMetadata.setId(entityTypeId);
    if (label != null) {
        targetMetadata.setLabel(label);
    } else {
        targetMetadata.setLabel(entityTypeId);
    }
    if (TRUE.equals(addSourceAttribute)) {
        targetMetadata.addAttribute(attrMetaFactory.create().setName(SOURCE));
    }
    if (dataService.hasRepository(entityTypeId)) {
        EntityType entityType = dataService.getMeta().getEntityType(entityTypeId).orElseThrow(() -> new UnknownEntityTypeException(entityTypeId));
        targetMetadata.setPackage(entityType.getPackage());
    } else if (packageId != null) {
        Package aPackage = dataService.getMeta().getPackage(packageId).orElseThrow(() -> new UnknownEntityException(PACKAGE, packageId));
        targetMetadata.setPackage(aPackage);
    } else {
        throw new MolgenisDataException("Package can't be null");
    }
    return targetMetadata;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) MolgenisDataException(org.molgenis.data.MolgenisDataException) UnknownEntityException(org.molgenis.data.UnknownEntityException) Package(org.molgenis.data.meta.model.Package)

Example 5 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)30 EntityType (org.molgenis.data.meta.model.EntityType)20 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