@Test void testViewTagWizardFilterSystemEntityTypes() { when(ontologyService.getOntologies()).thenReturn(emptyList()); String attributeName = "myAttribute"; Attribute attribute = when(mock(Attribute.class).getName()).thenReturn(attributeName).getMock(); String entityTypeId = "MyEntityTypeId"; EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock(); when(entityType.getAttributes()).thenReturn(singletonList(attribute)); Package systemPackage = when(mock(Package.class).getId()).thenReturn("sys").getMock(); EntityType systemEntityType = mock(EntityType.class); when(systemEntityType.getPackage()).thenReturn(systemPackage); when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)) .thenReturn(Stream.of(entityType, systemEntityType)); when(dataService.getEntityType(entityTypeId)).thenReturn(entityType); LinkedHashMultimap<Relation, OntologyTerm> attributeTags = LinkedHashMultimap.create(); when(ontologyTagService.getTagsForAttribute(entityType, attribute)).thenReturn(attributeTags); Model model = mock(Model.class); tagWizardController.viewTagWizard(null, model); Multimap<Object, Object> expectedTaggedAttributes = LinkedHashMultimap.create(); expectedTaggedAttributes.put(attributeName, emptyList()); verify(model).addAttribute("entity", entityType); verify(model).addAttribute("entityTypeIds", singletonList(entityTypeId)); verify(model).addAttribute("attributes", singletonList(attribute)); verify(model).addAttribute("ontologies", emptyList()); verify(model).addAttribute("taggedAttributes", singletonMap(attributeName, attributeTags)); verify(model) .addAttribute( "relations", new Relation[] { Relation.instanceOf, Relation.link, Relation.homepage, Relation.type, Relation.isDefinedBy, Relation.seeAlso, Relation.hasLowerValue, Relation.hasUpperValue, Relation.isRealizationOf, Relation.isGeneralizationOf, Relation.hasSourceId, Relation.hasSourceName, Relation.isAssociatedWith }); }
@GetMapping public String viewTagWizard( @RequestParam(required = false, value = "selectedTarget") String target, Model model) { List<String> entityTypeIds = dataService .findAll(ENTITY_TYPE_META_DATA, EntityType.class) .filter(entityType -> !EntityTypeUtils.isSystemEntity(entityType)) .map(EntityType::getId) .collect(toList()); if (StringUtils.isEmpty(target)) { Optional<String> findFirst = entityTypeIds.stream().findFirst(); if (findFirst.isPresent()) { target = findFirst.get(); } } if (StringUtils.isEmpty(target)) { throw new IllegalStateException("There are no entities available!"); } List<Ontology> ontologies = ontologyService.getOntologies(); EntityType emd = dataService.getEntityType(target); List<Attribute> attributes = newArrayList(emd.getAttributes()); Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream() .collect( toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x)))); model.addAttribute("entity", emd); model.addAttribute("entityTypeIds", entityTypeIds); model.addAttribute("attributes", attributes); model.addAttribute("ontologies", ontologies); model.addAttribute("taggedAttributes", taggedAttributes); model.addAttribute("relations", Relation.values()); return VIEW_TAG_WIZARD; }
TagWizardController extends PluginController { @GetMapping public String viewTagWizard( @RequestParam(required = false, value = "selectedTarget") String target, Model model) { List<String> entityTypeIds = dataService .findAll(ENTITY_TYPE_META_DATA, EntityType.class) .filter(entityType -> !EntityTypeUtils.isSystemEntity(entityType)) .map(EntityType::getId) .collect(toList()); if (StringUtils.isEmpty(target)) { Optional<String> findFirst = entityTypeIds.stream().findFirst(); if (findFirst.isPresent()) { target = findFirst.get(); } } if (StringUtils.isEmpty(target)) { throw new IllegalStateException("There are no entities available!"); } List<Ontology> ontologies = ontologyService.getOntologies(); EntityType emd = dataService.getEntityType(target); List<Attribute> attributes = newArrayList(emd.getAttributes()); Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream() .collect( toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x)))); model.addAttribute("entity", emd); model.addAttribute("entityTypeIds", entityTypeIds); model.addAttribute("attributes", attributes); model.addAttribute("ontologies", ontologies); model.addAttribute("taggedAttributes", taggedAttributes); model.addAttribute("relations", Relation.values()); return VIEW_TAG_WIZARD; } }
TagWizardController extends PluginController { @GetMapping public String viewTagWizard( @RequestParam(required = false, value = "selectedTarget") String target, Model model) { List<String> entityTypeIds = dataService .findAll(ENTITY_TYPE_META_DATA, EntityType.class) .filter(entityType -> !EntityTypeUtils.isSystemEntity(entityType)) .map(EntityType::getId) .collect(toList()); if (StringUtils.isEmpty(target)) { Optional<String> findFirst = entityTypeIds.stream().findFirst(); if (findFirst.isPresent()) { target = findFirst.get(); } } if (StringUtils.isEmpty(target)) { throw new IllegalStateException("There are no entities available!"); } List<Ontology> ontologies = ontologyService.getOntologies(); EntityType emd = dataService.getEntityType(target); List<Attribute> attributes = newArrayList(emd.getAttributes()); Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream() .collect( toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x)))); model.addAttribute("entity", emd); model.addAttribute("entityTypeIds", entityTypeIds); model.addAttribute("attributes", attributes); model.addAttribute("ontologies", ontologies); model.addAttribute("taggedAttributes", taggedAttributes); model.addAttribute("relations", Relation.values()); return VIEW_TAG_WIZARD; } TagWizardController(
      DataService dataService,
      OntologyService ontologyService,
      OntologyTagService ontologyTagService,
      SemanticSearchService semanticSearchService); }
TagWizardController extends PluginController { @GetMapping public String viewTagWizard( @RequestParam(required = false, value = "selectedTarget") String target, Model model) { List<String> entityTypeIds = dataService .findAll(ENTITY_TYPE_META_DATA, EntityType.class) .filter(entityType -> !EntityTypeUtils.isSystemEntity(entityType)) .map(EntityType::getId) .collect(toList()); if (StringUtils.isEmpty(target)) { Optional<String> findFirst = entityTypeIds.stream().findFirst(); if (findFirst.isPresent()) { target = findFirst.get(); } } if (StringUtils.isEmpty(target)) { throw new IllegalStateException("There are no entities available!"); } List<Ontology> ontologies = ontologyService.getOntologies(); EntityType emd = dataService.getEntityType(target); List<Attribute> attributes = newArrayList(emd.getAttributes()); Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream() .collect( toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x)))); model.addAttribute("entity", emd); model.addAttribute("entityTypeIds", entityTypeIds); model.addAttribute("attributes", attributes); model.addAttribute("ontologies", ontologies); model.addAttribute("taggedAttributes", taggedAttributes); model.addAttribute("relations", Relation.values()); return VIEW_TAG_WIZARD; } TagWizardController(
      DataService dataService,
      OntologyService ontologyService,
      OntologyTagService ontologyTagService,
      SemanticSearchService semanticSearchService); @GetMapping String viewTagWizard(
      @RequestParam(required = false, value = "selectedTarget") String target, Model model); @PostMapping("/tagattribute") @ResponseBody OntologyTag addTagAttribute(@Valid @RequestBody AddTagRequest request); @PostMapping("/deletesingletag") @ResponseBody void deleteSingleTag(@Valid @RequestBody RemoveTagRequest request); @PostMapping("/clearalltags") @ResponseBody void clearAllTags(@RequestParam String entityTypeId); @PostMapping("/autotagattributes") @ResponseBody Map<String, OntologyTag> autoTagAttributes(
      @Valid @RequestBody AutoTagRequest request); @PostMapping("/getontologyterms") @ResponseBody List<OntologyTerm> getAllOntologyTerms(
      @Valid @RequestBody GetOntologyTermRequest request); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessageResponse handleRuntimeException(RuntimeException e); }
TagWizardController extends PluginController { @GetMapping public String viewTagWizard( @RequestParam(required = false, value = "selectedTarget") String target, Model model) { List<String> entityTypeIds = dataService .findAll(ENTITY_TYPE_META_DATA, EntityType.class) .filter(entityType -> !EntityTypeUtils.isSystemEntity(entityType)) .map(EntityType::getId) .collect(toList()); if (StringUtils.isEmpty(target)) { Optional<String> findFirst = entityTypeIds.stream().findFirst(); if (findFirst.isPresent()) { target = findFirst.get(); } } if (StringUtils.isEmpty(target)) { throw new IllegalStateException("There are no entities available!"); } List<Ontology> ontologies = ontologyService.getOntologies(); EntityType emd = dataService.getEntityType(target); List<Attribute> attributes = newArrayList(emd.getAttributes()); Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream() .collect( toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x)))); model.addAttribute("entity", emd); model.addAttribute("entityTypeIds", entityTypeIds); model.addAttribute("attributes", attributes); model.addAttribute("ontologies", ontologies); model.addAttribute("taggedAttributes", taggedAttributes); model.addAttribute("relations", Relation.values()); return VIEW_TAG_WIZARD; } TagWizardController(
      DataService dataService,
      OntologyService ontologyService,
      OntologyTagService ontologyTagService,
      SemanticSearchService semanticSearchService); @GetMapping String viewTagWizard(
      @RequestParam(required = false, value = "selectedTarget") String target, Model model); @PostMapping("/tagattribute") @ResponseBody OntologyTag addTagAttribute(@Valid @RequestBody AddTagRequest request); @PostMapping("/deletesingletag") @ResponseBody void deleteSingleTag(@Valid @RequestBody RemoveTagRequest request); @PostMapping("/clearalltags") @ResponseBody void clearAllTags(@RequestParam String entityTypeId); @PostMapping("/autotagattributes") @ResponseBody Map<String, OntologyTag> autoTagAttributes(
      @Valid @RequestBody AutoTagRequest request); @PostMapping("/getontologyterms") @ResponseBody List<OntologyTerm> getAllOntologyTerms(
      @Valid @RequestBody GetOntologyTermRequest request); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessageResponse handleRuntimeException(RuntimeException e); static final String ID; static final String URI; }