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