/** * Sets the annotation for a document. * * @param operation the operation requesting the annotation to be set. * @param doc the document to change the annotation in. * @param start where the annotation should start. * @param end where the annotation should end. * @param key the key of the annotation. * @param value the value of the annotation. * @throws InvalidRequestException if the annotation could not be set. */ private void setDocumentAnnotation( OperationRequest operation, Document doc, int start, int end, String key, String value) throws InvalidRequestException { try { doc.setAnnotation(start, end, key, value); } catch (IndexOutOfBoundsException e) { throw new InvalidRequestException( "Can't set annotation for out of bounds indices " + e.getMessage(), operation, e); } }
public void testGenerateAnnotatedTextChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); String annotationKey = "key"; String annotationValue = "value"; rootBlip.getContent().setAnnotation(0, 1, annotationKey, annotationValue); EventMessageBundle messages = generateAndCheckEvents(EventType.ANNOTATED_TEXT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); AnnotatedTextChangedEvent event = AnnotatedTextChangedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the key of the annotation", annotationKey, event.getName()); assertEquals("Expected the value of the annotation", annotationValue, event.getValue()); }
public void testGenerateAnnotatedTextChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); String annotationKey = "key"; String annotationValue = "value"; rootBlip.getContent().setAnnotation(0, 1, annotationKey, annotationValue); EventMessageBundle messages = generateAndCheckEvents(EventType.ANNOTATED_TEXT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); AnnotatedTextChangedEvent event = AnnotatedTextChangedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the key of the annotation", annotationKey, event.getName()); assertEquals("Expected the value of the annotation", annotationValue, event.getValue()); }
public void testClearAnnotatation() throws Exception { Document doc = getRootBlip().getContent(); doc.setAnnotation(CONTENT_START_XML, CONTENT_START_XML + 1, ANNOTATION_KEY, ANNOTATION_VALUE); String annotation = getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY); assertEquals("Expected the text to be annotated", ANNOTATION_VALUE, annotation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.CLEAR_ANNOTATION, NO_VALUES, ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); assertNull("Expected this text not to be annotated", getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY)); }
public void testClearAnnotatation() throws Exception { Document doc = getRootBlip().getContent(); doc.setAnnotation(CONTENT_START_XML, CONTENT_START_XML + 1, ANNOTATION_KEY, ANNOTATION_VALUE); String annotation = getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY); assertEquals("Expected the text to be annotated", ANNOTATION_VALUE, annotation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.CLEAR_ANNOTATION, NO_VALUES, ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); assertNull("Expected this text not to be annotated", getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY)); }