Search in sources :

Example 11 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 12 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 13 with UnknownEntityTypeException

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

the class AttributeRequestMapperImpl method setRefEntityType.

private void setRefEntityType(Attribute attribute, Object value) {
    EntityType refEntityType;
    String refEntityTypeId = getStringValue(value);
    if (refEntityTypeId != null) {
        refEntityType = (EntityType) entityManager.getReference(entityTypeMetadata, refEntityTypeId);
        attribute.setRefEntity(refEntityType);
    } else {
        throw new UnknownEntityTypeException(refEntityTypeId);
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException)

Example 14 with UnknownEntityTypeException

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

the class DataPersisterImpl method updateEntityTypeFirstPass.

private EntityType updateEntityTypeFirstPass(EntityType entityType) {
    String entityTypeId = entityType.getId();
    EntityType existingEntityType = dataService.findOneById(ENTITY_TYPE_META_DATA, entityTypeId, EntityType.class);
    if (existingEntityType == null) {
        throw new UnknownEntityTypeException(entityType.getId());
    }
    return updateEntityTypeFirstPass(entityType, existingEntityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException)

Example 15 with UnknownEntityTypeException

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

the class IndexMetadataCUDOperationsPlatformIT method testIndexCreateMetaData.

public static void testIndexCreateMetaData(SearchService searchService, EntityType entityTypeStatic, EntityType entityTypeDynamic, MetaDataService metaDataService) {
    Query<Entity> q1 = new QueryImpl<>();
    q1.eq(EntityTypeMetadata.ID, entityTypeStatic.getId()).and().eq(EntityTypeMetadata.PACKAGE, entityTypeStatic.getPackage());
    assertEquals(1, searchService.count(metaDataService.getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(entityTypeStatic.getId())), q1));
    Query<Entity> q2 = new QueryImpl<>();
    q2.eq(EntityTypeMetadata.ID, entityTypeDynamic.getId()).and().eq(EntityTypeMetadata.PACKAGE, entityTypeDynamic.getPackage());
    assertEquals(1, searchService.count(metaDataService.getEntityType(ENTITY_TYPE_META_DATA).orElseThrow(() -> new UnknownEntityTypeException(entityTypeDynamic.getId())), q2));
}
Also used : UnknownEntityTypeException(org.molgenis.data.UnknownEntityTypeException) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl)

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