Skip to content

Commit

Permalink
META-241: Display xml for the assessed items
Browse files Browse the repository at this point in the history
  • Loading branch information
reagan-meant committed Nov 28, 2019
1 parent d80d76e commit b8d0a76
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions api-common/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ metadatasharing.cancel=Cancel
metadatasharing.choose=Choose
metadatasharing.choose.trustLevel=Choose trust level
metadatasharing.next=Next
metadatasharing.compare=Compare in Detail
metadatasharing.proceed=Proceed
metadatasharing.back=Back
metadatasharing.packageContent=Package content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,22 @@
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;
import org.xml.sax.InputSource;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.stream.StreamResult;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -566,8 +578,40 @@ public void assessItem(@ModelAttribute(ITEMS)
assessItemForm.setIndex(index);
assessItemForm.setImportType(importedItem.getImportType());
model.addAttribute(assessItemForm);

XStream xstream= new XStream(new StaxDriver());
String xml1=xstream.toXML(importedItem.getIncoming());
String xml2=xstream.toXML(importedItem.getExisting());

String xmlIncomingString=formatXml(xml1);
String xmlExistingString=formatXml(xml2);

model.addAttribute("xmlExistingString",xmlExistingString);
model.addAttribute("xmlIncomingString", xmlIncomingString);

}

public static String formatXml(String xml) {

try {
Transformer serializer = SAXTransformerFactory.newInstance().newTransformer();

serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

Source xmlSource = new SAXSource(new InputSource(
new ByteArrayInputStream(xml.getBytes())));
StreamResult res = new StreamResult(new ByteArrayOutputStream());

serializer.transform(xmlSource, res);

return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray());

} catch(Exception e) {
return xml;
}
}

@RequestMapping(value = ITEM_PATH, method = RequestMethod.GET, params = "uuid")
public void assessItem(@ModelAttribute(ITEMS)
List<ImportedItem> items, Integer index, String uuid, Model model) {
Expand Down
32 changes: 30 additions & 2 deletions omod/src/main/webapp/import/assessItem.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
<%@ include file="../template/jqueryPage.jsp"%>
<openmrs:htmlInclude
file="${pageContext.request.contextPath}/moduleResources/metadatasharing/css/metadatasharing.css" />


<script type="text/javascript">
<script type="text/javascript" >
var $j = jQuery.noConflict();
var chooseExistingTable;
var chooseExistingDialog;
var tableForItems;
$j(document).ready(function() {
chooseExistingTable = $j("#chooseExistingTable")
.dataTable(
{
Expand Down Expand Up @@ -85,7 +88,20 @@
$j('#chooseExistingButton').click(showChooseExistingDialog);
$j('#nextButton').focus();
$j('#nextButton').focus();
tableForItems = $j('#tableForItems').dialog(
{ autoOpen: false, modal: true, width: '95%', height: $j(window).height()-100,
resizable: false, draggable: false,
title: '<spring:message code="metadatasharing.compare" />'
});
$j('#compare').click(function() {
tableForItems.dialog("open");
});
});
function highlightDifferences() {
Expand Down Expand Up @@ -125,6 +141,7 @@
onclick="window.location='load.form'" />
</p>


<springform:form commandName="assessItemForm">
<spring:message code="metadatasharing.assessingItem" />
${assessItemForm.index + 1} <input
Expand Down Expand Up @@ -237,6 +254,9 @@
</fieldset>
</td>
</tr>

<tr> <td><input type="button" id="compare" value="<spring:message code="metadatasharing.compare" />" /></td><td></td>
</tr>
<tr>
<td><springform:radiobutton path="importType" value="CREATE"
id="createButton" disabled="${!empty incomingInvalid}" />
Expand Down Expand Up @@ -274,6 +294,14 @@
</p>
</springform:form>

<div id="tableForItems">
<table><tr><th>Incoming Item</th><th>Existing Item</th></tr>
<tr><td><div id="str1"><pre> <c:out value="${xmlIncomingString}"/> </pre></div>
</td><td><div id="str2"><pre><c:out value="${xmlExistingString}"/></pre></div>
</td></tr>
</table>
</div>

<div id="chooseExistingDialog">
<table id="chooseExistingTable" style="width: 100%">
<thead>
Expand Down

0 comments on commit b8d0a76

Please sign in to comment.