Search in sources :

Example 1 with IndexDefinition

use of com.enonic.xp.repository.IndexDefinition in project xp by enonic.

the class CreateRepositoryHandler method setIndexDefinitions.

public void setIndexDefinitions(final ScriptValue data) {
    if (data != null) {
        final Map<String, Object> indexDefinitionsMap = data.getMap();
        final IndexDefinitions.Builder indexDefinitionsBuilder = IndexDefinitions.create();
        for (IndexType indexType : IndexType.values()) {
            final Map indexDefinitionMap = (Map) indexDefinitionsMap.get(indexType.getName());
            if (indexDefinitionMap != null) {
                final Map indexDefinitionSettingsMap = (Map) indexDefinitionMap.get("settings");
                IndexSettings indexSettings = indexDefinitionSettingsMap == null ? null : new IndexSettings(createJson(indexDefinitionSettingsMap));
                final Map indexDefinitionMappingMap = (Map) indexDefinitionMap.get("mapping");
                IndexMapping indexMapping = indexDefinitionMappingMap == null ? null : new IndexMapping(createJson(indexDefinitionMappingMap));
                final IndexDefinition indexDefinition = IndexDefinition.create().settings(indexSettings).mapping(indexMapping).build();
                indexDefinitionsBuilder.add(indexType, indexDefinition);
            }
        }
        this.indexDefinitions = indexDefinitionsBuilder.build();
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexDefinition(com.enonic.xp.repository.IndexDefinition) IndexSettings(com.enonic.xp.repository.IndexSettings) IndexType(com.enonic.xp.index.IndexType) Map(java.util.Map) IndexDefinitions(com.enonic.xp.repository.IndexDefinitions)

Example 2 with IndexDefinition

use of com.enonic.xp.repository.IndexDefinition in project xp by enonic.

the class RepositoryNodeTranslator method toNodeData.

private static void toNodeData(final IndexDefinitions indexDefinitions, final PropertyTree data) {
    if (indexDefinitions != null) {
        final PropertySet indexConfigsPropertySet = data.addSet(INDEX_CONFIG_KEY);
        for (IndexType indexType : IndexType.values()) {
            final IndexDefinition indexDefinition = indexDefinitions.get(indexType);
            if (indexDefinition != null) {
                final PropertySet indexConfigPropertySet = indexConfigsPropertySet.addSet(indexType.getName());
                final IndexMapping indexMapping = indexDefinition.getMapping();
                if (indexMapping != null) {
                    final PropertySet indexMappingPropertySet = JsonToPropertyTreeTranslator.translate(indexMapping.getNode()).getRoot();
                    indexConfigPropertySet.setSet(MAPPING_KEY, indexMappingPropertySet);
                }
                final IndexSettings indexSettings = indexDefinition.getSettings();
                if (indexSettings != null) {
                    final PropertySet indexSettingsPropertySet = JsonToPropertyTreeTranslator.translate(indexSettings.getNode()).getRoot();
                    indexConfigPropertySet.setSet(SETTINGS_KEY, indexSettingsPropertySet);
                }
            }
        }
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexDefinition(com.enonic.xp.repository.IndexDefinition) IndexSettings(com.enonic.xp.repository.IndexSettings) PropertySet(com.enonic.xp.data.PropertySet) IndexType(com.enonic.xp.index.IndexType)

Example 3 with IndexDefinition

use of com.enonic.xp.repository.IndexDefinition in project xp by enonic.

the class RepositoryMapper method serialize.

private void serialize(final MapGenerator gen, final IndexDefinitions indexDefinitions) {
    if (indexDefinitions != null) {
        gen.map("definitions");
        for (IndexType indexType : IndexType.values()) {
            final IndexDefinition indexDefinition = indexDefinitions.get(indexType);
            if (indexDefinition != null) {
                gen.map(indexType.getName());
                if (indexDefinition.getSettings() != null) {
                    gen.map("settings");
                    serialize(gen, indexDefinition.getSettings().getNode());
                    gen.end();
                }
                if (indexDefinition.getMapping() != null) {
                    gen.map("mapping");
                    serialize(gen, indexDefinition.getMapping().getNode());
                    gen.end();
                }
                gen.end();
            }
        }
        gen.end();
    }
}
Also used : IndexDefinition(com.enonic.xp.repository.IndexDefinition) IndexType(com.enonic.xp.index.IndexType)

Aggregations

IndexType (com.enonic.xp.index.IndexType)3 IndexDefinition (com.enonic.xp.repository.IndexDefinition)3 IndexMapping (com.enonic.xp.repository.IndexMapping)2 IndexSettings (com.enonic.xp.repository.IndexSettings)2 PropertySet (com.enonic.xp.data.PropertySet)1 IndexDefinitions (com.enonic.xp.repository.IndexDefinitions)1 Map (java.util.Map)1