Search in sources :

Example 11 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class DefaultEncoder method internalEncode.

@Override
protected void internalEncode(JsonWrapper wrapper, Node node) {
    DEV_LOG.debug("Default JSON encoder {} is handling templateId {} and is described as '{}' ", getClass(), node.getType().name(), description);
    JsonWrapper childWrapper = new JsonWrapper();
    for (String name : node.getKeys()) {
        String nameForEncode = name.replace("Decoder", "Encoder");
        childWrapper.putString(nameForEncode, node.getValue(name));
    }
    wrapper.putObject(node.getType().name(), childWrapper);
    for (Node child : node.getChildNodes()) {
        childWrapper.putObject(child.getType().name(), childWrapper);
        encode(childWrapper, child);
    }
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) Node(gov.cms.qpp.conversion.model.Node)

Example 12 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class Converter method encode.

/**
 * Place transformed content into an input stream
 *
 * @return content resulting from the transformation
 */
private JsonWrapper encode() {
    JsonOutputEncoder encoder = getEncoder();
    DEV_LOG.info("Encoding template ID {}", decoded.getType());
    try {
        encoder.setNodes(Collections.singletonList(decoded));
        JsonWrapper qpp = encoder.encode();
        details.addAll(encoder.getDetails());
        return qpp;
    } catch (EncodeException e) {
        throw new XmlInputFileException("Issues decoding/encoding.", e);
    }
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) XmlInputFileException(gov.cms.qpp.conversion.decode.XmlInputFileException) JsonOutputEncoder(gov.cms.qpp.conversion.encode.JsonOutputEncoder) EncodeException(gov.cms.qpp.conversion.encode.EncodeException)

Example 13 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class PathCorrelator method prepPath.

/**
 * Assemble an xpath using the given json path and json wrapper.
 *
 * @param jsonPath definite json path
 * @param wrapper object representation of QPP json
 * @return xpath that correlates to supplied json path
 */
public static String prepPath(String jsonPath, JsonWrapper wrapper) {
    String base = "$";
    String leaf = jsonPath;
    int lastIndex = jsonPath.lastIndexOf('.');
    JsonWrapper metaWrapper = new JsonWrapper(wrapper, false);
    if (lastIndex > 0) {
        base = jsonPath.substring(0, lastIndex);
        leaf = jsonPath.substring(lastIndex + 1);
    }
    JsonPath compiledPath = JsonPath.compile(base);
    Map<String, Object> jsonMap = compiledPath.read(metaWrapper.toString());
    Map<String, String> metaMap = getMetaMap(jsonMap, leaf);
    String preparedPath = "";
    if (metaMap != null) {
        preparedPath = makePath(metaMap, leaf);
    }
    return preparedPath;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) JsonPath(com.jayway.jsonpath.JsonPath)

Example 14 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class AuditServiceImplTest method successfulEncodingPrep.

private void successfulEncodingPrep() {
    prepOverlap();
    JsonWrapper wrapper = new JsonWrapper();
    wrapper.putString("meep", "mawp");
    when(report.getQppSource()).thenReturn(wrapper.toSource());
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper)

Example 15 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class ValidationServiceImplTest method setup.

@BeforeAll
static void setup() throws IOException {
    service = new ValidationServiceImpl(null);
    pathToSubmissionError = Paths.get("src/test/resources/submissionErrorFixture.json");
    pathToSubmissionDuplicateEntryError = Paths.get("src/test/resources/submissionDuplicateEntryErrorFixture.json");
    Path toConvert = Paths.get("../qrda-files/valid-QRDA-III-latest.xml");
    qppWrapper = new JsonWrapper(new Converter(new PathSource(toConvert)).transform(), false);
    prepAllErrors();
}
Also used : Path(java.nio.file.Path) JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) PathSource(gov.cms.qpp.conversion.PathSource) Converter(gov.cms.qpp.conversion.Converter) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)24 Test (org.junit.jupiter.api.Test)10 Converter (gov.cms.qpp.conversion.Converter)9 PathSource (gov.cms.qpp.conversion.PathSource)8 Node (gov.cms.qpp.conversion.model.Node)3 Map (java.util.Map)3 Path (java.nio.file.Path)2 Test (org.junit.Test)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPath (com.jayway.jsonpath.JsonPath)1 JsonPathAggregator (gov.cms.qpp.acceptance.helper.JsonPathAggregator)1 JsonPathToXpathHelper (gov.cms.qpp.acceptance.helper.JsonPathToXpathHelper)1 Context (gov.cms.qpp.conversion.Context)1 ConversionReport (gov.cms.qpp.conversion.ConversionReport)1 QrdaDecoderEngine (gov.cms.qpp.conversion.decode.QrdaDecoderEngine)1 XmlInputFileException (gov.cms.qpp.conversion.decode.XmlInputFileException)1 EncodeException (gov.cms.qpp.conversion.encode.EncodeException)1 JsonOutputEncoder (gov.cms.qpp.conversion.encode.JsonOutputEncoder)1