Search in sources :

Example 1 with JsonToPropertyTreeTranslator

use of com.enonic.xp.json.JsonToPropertyTreeTranslator in project xp by enonic.

the class FlattenedPageDataUpgraderTest method test.

private void test(final String oldJsonFile, final String newJsonFile) throws Exception {
    final JsonNode oldPageComponents = loadJson(oldJsonFile);
    final JsonNode newPageComponents = loadJson(newJsonFile);
    final PropertyTree oldData = new JsonToPropertyTreeTranslator().translate(oldPageComponents);
    final PropertyTree newData = new JsonToPropertyTreeTranslator().translate(newPageComponents);
    final HashMap<String, String> templateControllerMap = new HashMap<>();
    templateControllerMap.put("templateId", "com.enonic.app.features:main");
    FlattenedPageDataUpgrader.create().templateControllerMap(templateControllerMap).build().upgrade(oldData);
    // using string comparison because PropertyTree entries are same but might have different value type
    assertEquals(newData.toString(), oldData.toString());
}
Also used : JsonToPropertyTreeTranslator(com.enonic.xp.json.JsonToPropertyTreeTranslator) HashMap(java.util.HashMap) PropertyTree(com.enonic.xp.data.PropertyTree) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with JsonToPropertyTreeTranslator

use of com.enonic.xp.json.JsonToPropertyTreeTranslator in project xp by enonic.

the class FlattenedPageIndexUpgraderTest method test.

private void test(final String dataFile, final String oldIndexDocumentFile, final String newIndexDocumentFile) throws Exception {
    final JsonNode pageComponents = loadJson(dataFile);
    final PropertyTree data = new JsonToPropertyTreeTranslator().translate(pageComponents);
    final List<PropertySet> components = Lists.newArrayList(data.getSets("components"));
    if (components.size() == 0) {
        throw new RuntimeException("page components is empty");
    }
    final String descriptorKeyStr = data.getString(PropertyPath.from("components.page.descriptor"));
    if (descriptorKeyStr == null) {
        throw new RuntimeException("page descriptorKey is null");
    }
    final DescriptorKey descriptorKey = DescriptorKey.from(descriptorKeyStr);
    final PatternIndexConfigDocument oldDocument = getIndexConfigDocument(oldIndexDocumentFile);
    final PatternIndexConfigDocument newDocument = new FlattenedPageIndexUpgrader(descriptorKey, components).upgrade(oldDocument);
    assertEquals(getIndexConfigDocument(newIndexDocumentFile), newDocument);
}
Also used : JsonToPropertyTreeTranslator(com.enonic.xp.json.JsonToPropertyTreeTranslator) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) FlattenedPageIndexUpgrader(com.enonic.xp.repo.impl.dump.upgrade.flattenedpage.FlattenedPageIndexUpgrader)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)2 JsonToPropertyTreeTranslator (com.enonic.xp.json.JsonToPropertyTreeTranslator)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 PropertySet (com.enonic.xp.data.PropertySet)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 FlattenedPageIndexUpgrader (com.enonic.xp.repo.impl.dump.upgrade.flattenedpage.FlattenedPageIndexUpgrader)1 HashMap (java.util.HashMap)1