@Override public Element fromXml(Document doc, E element, Wavelet wavelet) { Map<String, String> properties = Maps.newHashMap(); String attachmentId = doc.getAttribute(element, ATTACHMENT_STR); if (attachmentId != null) { properties.put(Attachment.ATTACHMENT_ID, attachmentId); } String caption = getCaption(doc, element); if (caption != null) { properties.put(Attachment.CAPTION, caption); } if (wavelet != null && attachmentId != null) { Document attachmentDataDoc = wavelet.getDocument(IdConstants.ATTACHMENT_METADATA_PREFIX + "+" + attachmentId); if (attachmentDataDoc != null) { String dataDocument = attachmentDataDoc.toXmlString(); if (dataDocument != null) { properties.put(Attachment.MIME_TYPE, extractValue(dataDocument, MIME_TYPE_PATTERN)); properties.put(Attachment.ATTACHMENT_URL, ElementSerializer.attachmentDownloadHostUrl + getAttachmentUrl(dataDocument)); } } } return new Attachment(properties, null); }
/** * Methods that checks that the new blip was actually created and stored in * the context. As well as that it checks its contents */ private ConversationBlip checkAndGetNewBlip( OperationContextImpl context, ObservableConversation conversation, JsonRpcResponse response) throws InvalidRequestException { // Retrieve the blip using the context so that the temp blip storage is // checked ConversationBlip newBlip = context.getBlip(conversation, TEMP_BLIP_ID); assertEquals("The response didn't contain the id of the new blip", newBlip.getId(), response.getData().get(ParamsProperty.NEW_BLIP_ID)); String actualContent = newBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the contens as specified in the operation", actualContent.contains(NEW_BLIP_CONTENT)); return newBlip; } }
/** * Methods that checks that the new blip was actually created and stored in * the context. As well as that it checks its contents */ private ConversationBlip checkAndGetNewBlip( OperationContextImpl context, ObservableConversation conversation, JsonRpcResponse response) throws InvalidRequestException { // Retrieve the blip using the context so that the temp blip storage is // checked ConversationBlip newBlip = context.getBlip(conversation, TEMP_BLIP_ID); assertEquals("The response didn't contain the id of the new blip", newBlip.getId(), response.getData().get(ParamsProperty.NEW_BLIP_ID)); String actualContent = newBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the contens as specified in the operation", actualContent.contains(NEW_BLIP_CONTENT)); return newBlip; } }
public void testAppendCustomMarkup() throws Exception { String markup = "<custom>this is custom markup</custom>"; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the custom markup to the newly created blip. ConversationBlip markupBlip = conversation.getRootThread().appendBlip(); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("CustomMarkup generated error in service execution.", response.isError()); // The xml in new blip should match custom markup. String actualContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the custom markup as specified in the " + "operation. actualcontent: " + actualContent, actualContent.contains(markup)); }
public void testAppendCustomMarkup() throws Exception { String markup = "<custom>this is custom markup</custom>"; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the custom markup to the newly created blip. ConversationBlip markupBlip = conversation.getRootThread().appendBlip(); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("CustomMarkup generated error in service execution.", response.isError()); // The xml in new blip should match custom markup. String actualContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the custom markup as specified in the " + "operation. actualcontent: " + actualContent, actualContent.contains(markup)); }
/** * Validates the behavior when a caller invokes the DOCUMENT_APPEND_MARKUP * without actually passing in xml markup (so just the text). The behavior * should be to create a default wave line element, so the scenario is: * * input: "Hello World" * output: <line></line>Hello World */ public void testAppendLineMarkup() throws Exception { // Just insert text. should create <line></line>Text. String markup = NEW_BLIP_CONTENT; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the text markup to the newly created blip. DocInitialization blipInitContent = new DocInitializationBuilder().build(); ConversationBlip markupBlip = conversation.getRootThread().appendBlip(blipInitContent); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("LineMarkup generated error in service execution.", response.isError()); // The output should now include the default <line/> element. String lineContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the blip to append the default wave <line/> element. " + "actual content: " + lineContent, lineContent.contains("<line/>"+markup)); }
/** * Validates the behavior when a caller invokes the DOCUMENT_APPEND_MARKUP * without actually passing in xml markup (so just the text). The behavior * should be to create a default wave line element, so the scenario is: * * input: "Hello World" * output: <line></line>Hello World */ public void testAppendLineMarkup() throws Exception { // Just insert text. should create <line></line>Text. String markup = NEW_BLIP_CONTENT; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the text markup to the newly created blip. DocInitialization blipInitContent = new DocInitializationBuilder().build(); ConversationBlip markupBlip = conversation.getRootThread().appendBlip(blipInitContent); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("LineMarkup generated error in service execution.", response.isError()); // The output should now include the default <line/> element. String lineContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the blip to append the default wave <line/> element. " + "actual content: " + lineContent, lineContent.contains("<line/>"+markup)); }