<commit_before>/*
 * $Revision$
 * $Date$
 *
 * Copyright (C) 1999-$year$ Jive Software. All rights reserved.
 *
 * This software is the proprietary information of Jive Software. Use is subject to license terms.
 */
package com.jivesoftware.os.tasmo.configuration;

import java.util.Map;
import java.util.Set;

/**
 *
 * @author jonathan.colt
 */
public class ValidatingPathCallback implements PathCallback {

    private final EventsModel eventsModel;
    private final PathCallback pathCallback;

    public ValidatingPathCallback(EventsModel eventsModel, PathCallback pathCallback) {
        this.eventsModel = eventsModel;
        this.pathCallback = pathCallback;
    }

    private void assertFieldIsPresent(Set<String> classNames, ValueType type, String[] fieldNames) throws IllegalArgumentException {
        if (type != ValueType.backrefs && type != ValueType.latest_backref && type != ValueType.count) {
            for (String fieldName : fieldNames) {
                for (String className : classNames) {
                    EventModel eventConfiguration = eventsModel.getEvent(className);
                    Map<String, ValueType> event = eventConfiguration.getEventFields();
                    if (event != null && event.containsKey(fieldName)) {
                        if (event.get(fieldName).equals(type)) {
                            continue;
                        } else {
                            if (type == ValueType.value) {
                                if (event.get(fieldName).equals(ValueType.ref)) {
                                    continue;
                                }
                                if (event.get(fieldName).equals(ValueType.refs)) {
                                    continue;
                                }
                            }
                        }
                    }

                    String msg = "The view expects event:" + className + " to have field:" + fieldName + " and be of type:" + type + "."
                            + " found: event:" + ((event == null) ? null : className)
                            + " field:" + ((event == null || !event.containsKey(fieldName)) ? null : fieldName)
                            + " type:" + ((event == null) ? null : event.get(fieldName));
                    throw new IllegalArgumentException(msg);
                }
            }
        }
    }

    @Override
        public void push(Set<String> fieldType, ValueType valueType, String... fieldNames) {
        assertFieldIsPresent(fieldType, valueType, fieldNames);
        pathCallback.push(fieldType, valueType, fieldNames);
    }

    @Override
    public void pop() {
        pathCallback.pop();
    }
}
<commit_msg>changed ValidatingPathCallback so that any event class with the desired field is ok.<commit_after>/*
 * $Revision$
 * $Date$
 *
 * Copyright (C) 1999-$year$ Jive Software. All rights reserved.
 *
 * This software is the proprietary information of Jive Software. Use is subject to license terms.
 */
package com.jivesoftware.os.tasmo.configuration;

import java.util.Map;
import java.util.Set;

/**
 *
 * @author jonathan.colt
 */
public class ValidatingPathCallback implements PathCallback {

    private final EventsModel eventsModel;
    private final PathCallback pathCallback;

    public ValidatingPathCallback(EventsModel eventsModel, PathCallback pathCallback) {
        this.eventsModel = eventsModel;
        this.pathCallback = pathCallback;
    }

    private void assertFieldIsPresent(Set<String> classNames, ValueType type, String[] fieldNames) throws IllegalArgumentException {
        if (type != ValueType.backrefs && type != ValueType.latest_backref && type != ValueType.count) {
            for (String fieldName : fieldNames) {
                int foundEventsWithField = 0;
                for (String className : classNames) {
                    EventModel eventConfiguration = eventsModel.getEvent(className);
                    Map<String, ValueType> event = eventConfiguration.getEventFields();
                    if (event != null && event.containsKey(fieldName)) {
                        if (event.get(fieldName).equals(type)) {
                            foundEventsWithField++;
                        } else {
                            if (type == ValueType.value) {
                                if (event.get(fieldName).equals(ValueType.ref)) {
                                    foundEventsWithField++;
                                } else if (event.get(fieldName).equals(ValueType.refs)) {
                                    foundEventsWithField++;
                                }
                            }
                        }
                    }

                }
                if (foundEventsWithField == 0) {
                    String msg = "The view expects one of these events:" + classNames + " to have field:" + fieldName + " and be of type:" + type;
                    throw new IllegalArgumentException(msg);
                }
            }
        }
    }

    @Override
        public void push(Set<String> fieldType, ValueType valueType, String... fieldNames) {
        assertFieldIsPresent(fieldType, valueType, fieldNames);
        pathCallback.push(fieldType, valueType, fieldNames);
    }

    @Override
    public void pop() {
        pathCallback.pop();
    }
}

{'fraction_non_alphanumeric': 0.09353456307061674, 'fraction_numerical': 0.001863238308179616, 'mean_word_length': 1.7179746835443037, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3963260', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1251, 'n_words': 327}