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());
}
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"));
}
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));
}
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;
}
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());
}
Aggregations