Search in sources :

Example 1 with PropertyVisitor

use of com.enonic.xp.data.PropertyVisitor in project xp by enonic.

the class NodeStoreDocumentFactory method addNodeDataProperties.

private void addNodeDataProperties(final IndexItems.Builder builder) {
    PropertyVisitor visitor = new PropertyVisitor() {

        @Override
        public void visit(final Property property) {
            if (!isNullOrEmpty(property.getString())) {
                final IndexConfig configForData = node.getIndexConfigDocument().getConfigForPath(property.getPath());
                if (configForData == null) {
                    throw new RuntimeException("Missing index configuration for data " + property.getPath());
                }
                builder.add(property, node.getIndexConfigDocument());
                addReferenceAggregation(property);
            }
        }

        private void addReferenceAggregation(final Property property) {
            if (property.getType().equals(ValueTypes.REFERENCE)) {
                builder.add(NodeIndexPath.REFERENCE, property.getValue(), createDefaultDocument(IndexConfig.MINIMAL));
            }
        }
    };
    visitor.traverse(this.node.data());
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) Property(com.enonic.xp.data.Property) PropertyVisitor(com.enonic.xp.data.PropertyVisitor)

Example 2 with PropertyVisitor

use of com.enonic.xp.data.PropertyVisitor 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)

Aggregations

Property (com.enonic.xp.data.Property)2 PropertyVisitor (com.enonic.xp.data.PropertyVisitor)2 ContentConstants (com.enonic.xp.content.ContentConstants)1 PropertyPath (com.enonic.xp.data.PropertyPath)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 ValueFactory (com.enonic.xp.data.ValueFactory)1 ValueTypes (com.enonic.xp.data.ValueTypes)1 DumpUpgradeStepResult (com.enonic.xp.dump.DumpUpgradeStepResult)1 IndexConfig (com.enonic.xp.index.IndexConfig)1 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)1 PathIndexConfig (com.enonic.xp.index.PathIndexConfig)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 Reference (com.enonic.xp.util.Reference)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1