Search in sources :

Example 31 with PatternIndexConfigDocument

use of com.enonic.xp.index.PatternIndexConfigDocument in project xp by enonic.

the class HtmlAreaNodeDataUpgrader method upgradeNodeData.

private void upgradeNodeData(final PropertySet nodeData, final PatternIndexConfigDocument indexConfigDocument) {
    final List<Pattern> htmlAreaPatterns = indexConfigDocument.getPathIndexConfigs().stream().filter(this::hasHtmlStripperProcessor).map(PathIndexConfig::getPath).map(PropertyPath::toString).map(HtmlAreaNodeDataUpgrader::toPattern).collect(Collectors.toList());
    final PropertyVisitor propertyVisitor = new PropertyVisitor() {

        @Override
        public void visit(final Property property) {
            if (isHtmlAreaProperty(property)) {
                upgradeHtmlAreaProperty(property, false);
            } else if (isBackwardCompatibleHtmlAreaProperty(property)) {
                upgradeHtmlAreaProperty(property, true);
            }
        }

        private boolean isHtmlAreaProperty(Property property) {
            return ValueTypes.STRING.equals(property.getType()) && htmlAreaPatterns.stream().anyMatch(htmlPattern -> htmlPattern.matcher(property.getPath().toString()).matches());
        }

        private boolean isBackwardCompatibleHtmlAreaProperty(Property property) {
            return ValueTypes.STRING.equals(property.getType()) && BACKWARD_COMPATIBILITY_HTML_PROPERTY_PATH_PATTERNS.stream().anyMatch(htmlPattern -> htmlPattern.matcher(property.getPath().toString()).matches());
        }
    };
    propertyVisitor.traverse(nodeData);
}
Also used : Property(com.enonic.xp.data.Property) ContentConstants(com.enonic.xp.content.ContentConstants) IndexValueProcessor(com.enonic.xp.index.IndexValueProcessor) Logger(org.slf4j.Logger) PropertyVisitor(com.enonic.xp.data.PropertyVisitor) PropertySet(com.enonic.xp.data.PropertySet) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ValueFactory(com.enonic.xp.data.ValueFactory) PathIndexConfig(com.enonic.xp.index.PathIndexConfig) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DumpUpgradeStepResult(com.enonic.xp.dump.DumpUpgradeStepResult) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) List(java.util.List) Matcher(java.util.regex.Matcher) Stream(java.util.stream.Stream) Reference(com.enonic.xp.util.Reference) NodeVersion(com.enonic.xp.node.NodeVersion) ValueTypes(com.enonic.xp.data.ValueTypes) PropertyPath(com.enonic.xp.data.PropertyPath) Pattern(java.util.regex.Pattern) PropertyTree(com.enonic.xp.data.PropertyTree) Pattern(java.util.regex.Pattern) PropertyPath(com.enonic.xp.data.PropertyPath) Property(com.enonic.xp.data.Property) PropertyVisitor(com.enonic.xp.data.PropertyVisitor)

Example 32 with PatternIndexConfigDocument

use of com.enonic.xp.index.PatternIndexConfigDocument in project xp by enonic.

the class HtmlAreaDumpUpgrader method upgradeBlobRecord.

private void upgradeBlobRecord(final DumpBlobRecord nodeDumpBlobRecord, final DumpBlobRecord indexDumpBlobRecord) {
    final NodeVersion nodeVersion = getNodeVersion(nodeDumpBlobRecord);
    final PatternIndexConfigDocument indexConfigDocument = getIndexConfigDocument(indexDumpBlobRecord);
    final boolean upgraded = upgradeNodeVersion(nodeVersion, indexConfigDocument);
    if (upgraded) {
        writeNodeVersion(nodeVersion, nodeDumpBlobRecord);
    }
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument)

Example 33 with PatternIndexConfigDocument

use of com.enonic.xp.index.PatternIndexConfigDocument in project xp by enonic.

the class IndexConfigUpgrader method upgradeIndexConfigDocument.

private BlobKey upgradeIndexConfigDocument(final BlobKey blobKey, final NodeVersion nodeVersion) {
    final DumpBlobRecord indexConfigBlobRecord = dumpReader.getDumpBlobStore().getRecord(INDEX_CONFIG_SEGMENT, blobKey);
    final PatternIndexConfigDocument sourceDocument = getIndexConfigDocument(indexConfigBlobRecord);
    PatternIndexConfigDocument upgradedDocument = this.upgradeLanguageIndexConfig(sourceDocument, nodeVersion);
    upgradedDocument = this.upgradePageIndexConfig(upgradedDocument, nodeVersion);
    return !upgradedDocument.equals(sourceDocument) ? storeIndexConfigBlob(upgradedDocument) : blobKey;
}
Also used : DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument)

Aggregations

PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)33 Test (org.junit.jupiter.api.Test)26 Form (com.enonic.xp.form.Form)10 PropertyTree (com.enonic.xp.data.PropertyTree)9 PropertySet (com.enonic.xp.data.PropertySet)5 Page (com.enonic.xp.page.Page)5 Input (com.enonic.xp.form.Input)4 PathIndexConfig (com.enonic.xp.index.PathIndexConfig)3 NodeVersion (com.enonic.xp.node.NodeVersion)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 SiteConfigs (com.enonic.xp.site.SiteConfigs)3 DumpUpgradeStepResult (com.enonic.xp.dump.DumpUpgradeStepResult)2 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)2 Reference (com.enonic.xp.util.Reference)2 ContentConstants (com.enonic.xp.content.ContentConstants)1 Property (com.enonic.xp.data.Property)1 PropertyPath (com.enonic.xp.data.PropertyPath)1 PropertyVisitor (com.enonic.xp.data.PropertyVisitor)1 ValueFactory (com.enonic.xp.data.ValueFactory)1 ValueTypes (com.enonic.xp.data.ValueTypes)1