SlotFeatureSupport implements FeatureSupport<LinkFeatureTraits> { @Override public void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, Object aValue) { if ( aValue instanceof List && aFeature.getTagset() != null ) { for (LinkWithRoleModel link : (List<LinkWithRoleModel>) aValue) { if (!annotationService.existsTag(link.role, aFeature.getTagset())) { if (!aFeature.getTagset().isCreateTag()) { throw new IllegalArgumentException("[" + link.role + "] is not in the tag list. Please choose from the existing tags"); } else { Tag selectedTag = new Tag(); selectedTag.setName(link.role); selectedTag.setTagSet(aFeature.getTagset()); annotationService.createTag(selectedTag); } } } } FeatureSupport.super.setFeatureValue(aCas, aFeature, aAddress, aValue); } @Autowired  SlotFeatureSupport(AnnotationSchemaService aAnnotationService); @Override String getId(); @Override void setBeanName(String aBeanName); @Override List<FeatureType> getSupportedFeatureTypes(AnnotationLayer aAnnotationLayer); @Override boolean accepts(AnnotationFeature aFeature); @Override Panel createTraitsEditor(String aId,  IModel<AnnotationFeature> aFeatureModel); @Override FeatureEditor createEditor(String aId, MarkupContainer aOwner,
            AnnotationActionHandler aHandler, final IModel<AnnotatorState> aStateModel,
            final IModel<FeatureState> aFeatureStateModel); @Override void configureFeature(AnnotationFeature aFeature); @Override void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
            AnnotationFeature aFeature); @Override List<LinkWithRoleModel> getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS); @Override void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, Object aValue); @Override List<LinkWithRoleModel> unwrapFeatureValue(AnnotationFeature aFeature, CAS aCAS,
            Object aValue); @Override ArrayList<LinkWithRoleModel> wrapFeatureValue(AnnotationFeature aFeature, CAS aCAS,
            Object aValue); @Override LinkFeatureTraits readTraits(AnnotationFeature aFeature); @Override void writeTraits(AnnotationFeature aFeature, LinkFeatureTraits aTraits);  }
@Test public void thatUsingOutOfTagsetValueInClosedTagsetProducesException() throws Exception { final String role = "TAG-NOT-IN-LIST"; CAS cas = jcas.getCas(); TagSet slotFeatureTagset = new TagSet(); slotFeatureTagset.setCreateTag(false); slotFeature.setTagset(slotFeatureTagset); AnnotationFS hostFS = cas.createAnnotation(hostType, 0, cas.getDocumentText().length()); AnnotationFS targetFS = cas.createAnnotation(targetType, 0, cas.getDocumentText().length()); when(schemaService.existsTag(role, slotFeatureTagset)).thenReturn(false); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> sut.setFeatureValue(jcas.getCas(), slotFeature, getAddr(hostFS), asList(new LinkWithRoleModel(role, "dummy", getAddr(targetFS))))) .withMessageContaining("is not in the tag list"); }
@Test public void thatUsingOutOfTagsetValueInOpenTagsetAddsNewValue() throws Exception { final String role = "TAG-NOT-IN-LIST"; CAS cas = jcas.getCas(); TagSet slotFeatureTagset = new TagSet(); slotFeatureTagset.setCreateTag(true); slotFeature.setTagset(slotFeatureTagset); AnnotationFS hostFS = cas.createAnnotation(hostType, 0, cas.getDocumentText().length()); AnnotationFS targetFS = cas.createAnnotation(targetType, 0, cas.getDocumentText().length()); when(schemaService.existsTag(role, slotFeatureTagset)).thenReturn(false); sut.setFeatureValue(jcas.getCas(), slotFeature, getAddr(hostFS), asList(new LinkWithRoleModel(role, "dummy", getAddr(targetFS)))); verify(schemaService).createTag(new Tag(slotFeatureTagset, role)); }