StringFeatureSupport extends UimaPrimitiveFeatureSupport_ImplBase<StringFeatureTraits> { @Override public void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, Object aValue) { if ( aValue != null && schemaService != null && aFeature.getTagset() != null && CAS.TYPE_NAME_STRING.equals(aFeature.getType()) && !schemaService.existsTag((String) aValue, aFeature.getTagset()) ) { if (!aFeature.getTagset().isCreateTag()) { throw new IllegalArgumentException("[" + aValue + "] is not in the tag list. Please choose from the existing tags"); } else { Tag selectedTag = new Tag(); selectedTag.setName((String) aValue); selectedTag.setTagSet(aFeature.getTagset()); schemaService.createTag(selectedTag); } } super.setFeatureValue(aCas, aFeature, aAddress, aValue); } StringFeatureSupport(); @Autowired  StringFeatureSupport(PrimitiveUimaFeatureSupportProperties aProperties,
            @Autowired(required = false) AnnotationSchemaService aSchemaService); @Override void afterPropertiesSet(); @Override List<FeatureType> getSupportedFeatureTypes(AnnotationLayer aAnnotationLayer); @Override boolean accepts(AnnotationFeature aFeature); @Override void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, Object aValue); @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 StringFeatureTraits readTraits(AnnotationFeature aFeature); @Override void writeTraits(AnnotationFeature aFeature, StringFeatureTraits aTraits); @Override boolean suppressAutoFocus(AnnotationFeature aFeature);  }
@Test public void thatUsingOutOfTagsetValueInClosedTagsetProducesException() throws Exception { final String tag = "TAG-NOT-IN-LIST"; valueFeature.setTagset(valueTagset); valueTagset.setCreateTag(false); when(schemaService.existsTag(tag, valueTagset)).thenReturn(false); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> sut.setFeatureValue(jcas.getCas(), valueFeature, getAddr(spanFS), tag)) .withMessageContaining("is not in the tag list"); }
@Test public void thatUsingOutOfTagsetValueInOpenTagsetAddsNewValue() throws Exception { final String tag = "TAG-NOT-IN-LIST"; valueFeature.setTagset(valueTagset); valueTagset.setCreateTag(true); when(schemaService.existsTag(tag, valueTagset)).thenReturn(false); sut.setFeatureValue(jcas.getCas(), valueFeature, getAddr(spanFS), tag); verify(schemaService).createTag(new Tag(valueTagset, tag)); }