Search in sources :

Example 16 with EntityType

use of org.molgenis.data.meta.model.EntityType 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) throws Exception {
    EntityType entityType = dataService.getEntityType(entityTypeId);
    if (entityType == null) {
        throw new MolgenisDataAccessException("EntityType with id [" + entityTypeId + "] does not exist. Did you use the correct URL?");
    }
    Object id = getTypedValue(entityId, entityType.getIdAttribute());
    model.addAttribute("entity", dataService.getRepository(entityTypeId).findOneById(id));
    model.addAttribute("entityType", entityType);
    model.addAttribute("entityTypeId", entityTypeId);
    model.addAttribute("viewName", getStandaloneReportViewName(entityTypeId));
    return "view-standalone-report";
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) JSONObject(org.json.JSONObject)

Example 17 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class DataExplorerController method getModule.

@GetMapping("/module/{moduleId}")
public String getModule(@PathVariable("moduleId") String moduleId, @RequestParam("entity") String entityTypeId, Model model) {
    EntityType selectedEntityType;
    Map<String, GenomeBrowserTrack> entityTracks;
    switch(moduleId) {
        case MOD_DATA:
            selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
            entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
            model.addAttribute("genomeTracks", getTracksJson(entityTracks));
            // if multiple tracks are available we assume chrom and pos attribute are the same
            if (!entityTracks.isEmpty()) {
                // FIXME: how to do this cleaner
                GenomeBrowserTrack track = entityTracks.entrySet().iterator().next().getValue();
                model.addAttribute("pos_attr", track.getGenomeBrowserAttrs().getPos());
                model.addAttribute("chrom_attr", track.getGenomeBrowserAttrs().getChrom());
            }
            model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
            break;
        case MOD_ENTITIESREPORT:
            // TODO: figure out if we need to know pos and chrom attrs here
            selectedEntityType = dataService.getMeta().getEntityTypeById(entityTypeId);
            entityTracks = genomeBrowserService.getGenomeBrowserTracks(selectedEntityType);
            model.addAttribute("genomeTracks", getTracksJson(entityTracks));
            model.addAttribute("showDirectoryButton", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("NegotiatorEnabled", directoryController.showDirectoryButton(entityTypeId));
            model.addAttribute("datasetRepository", dataService.getRepository(entityTypeId));
            model.addAttribute("viewName", dataExplorerSettings.getEntityReport(entityTypeId));
            break;
        case MOD_ANNOTATORS:
            // self-explanatory
            if (!permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)) {
                throw new MolgenisDataAccessException("No " + Permission.WRITEMETA + " permission on entity [" + entityTypeId + "], this permission is necessary run the annotators.");
            }
            Entity annotationRun = dataService.findOne(ANNOTATION_JOB_EXECUTION, new QueryImpl<>().eq(AnnotationJobExecutionMetaData.TARGET_NAME, entityTypeId).sort(new Sort(JobExecutionMetaData.START_DATE, Sort.Direction.DESC)));
            model.addAttribute("annotationRun", annotationRun);
            model.addAttribute("entityTypeId", entityTypeId);
            break;
    }
    // TODO bad request in case of invalid module id
    return "view-dataexplorer-mod-" + moduleId;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) GenomeBrowserTrack(org.molgenis.genomebrowser.GenomeBrowserTrack)

Example 18 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeUtilsTest method isSystemEntityNotASystemIfNotInSystemPackage.

@Test
public void isSystemEntityNotASystemIfNotInSystemPackage() {
    EntityType entity = mock(EntityType.class);
    Package entityPackage = mock(Package.class);
    when(entity.getPackage()).thenReturn(entityPackage);
    when(entityPackage.getId()).thenReturn("not-system");
    when(entity.getId()).thenReturn("foo_bar_Entity");
    assertFalse(EntityTypeUtils.isSystemEntity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 19 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeUtilsTest method isSystemEntityNotASystemEntityIfNotInPackage.

@Test
public void isSystemEntityNotASystemEntityIfNotInPackage() {
    EntityType entity = mock(EntityType.class);
    when(entity.getPackage()).thenReturn(null);
    assertFalse(EntityTypeUtils.isSystemEntity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test)

Example 20 with EntityType

use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.

the class EntityTypeUtilsTest method testCreateFetchForReindexingIndexingDepth1.

@Test
public void testCreateFetchForReindexingIndexingDepth1() {
    EntityType entityType = createMockEntityType();
    when(entityType.getIndexingDepth()).thenReturn(1);
    Fetch expectedFetch = new Fetch().field("MyEntityTypeAttr").field("MyEntityTypeRefAttr", new Fetch().field("MyRefEntityTypeAttr").field("MyRefEntityTypeRefAttr"));
    assertEquals(EntityTypeUtils.createFetchForReindexing(entityType), expectedFetch);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15