<commit_before>package nl.mpi.arbil;

/**
 * FieldChangeTriggers.java
 * Created on Jul 13, 2009, 4:15:02 PM
 * @author <EMAIL>
 */
public class FieldChangeTriggers {
    // the following strings need to be read from a template file or a vocaulary etc

    public void actOnChange(ImdiField changedImdiField) {
        String fieldPath = changedImdiField.getGenericFullXmlPath();
        System.out.println("fieldPath: " + fieldPath);
        for (String[] currentTrigger : changedImdiField.parentImdi.currentTemplate.fieldTriggersArray) {
            if (fieldPath.equals(currentTrigger[0])) {
                // we now have the path for two fields:
                // .METATRANSCRIPT.Session.MDGroup.Actors.Actor(x).Languages.Language(x).Id
                // .METATRANSCRIPT.Session.MDGroup.Actors.Actor(2).Languages.Language(3).Name
                // and we need to put the (\d) back into the (x)
                String originalFieldPath = changedImdiField.getFullXmlPath();
                int lastBracketPos = originalFieldPath.lastIndexOf(")");
                // care must me taken here to prevet issues with child nodes greater than 9 ie (12), (x) etc.
                String targetFieldPath = originalFieldPath.substring(0, lastBracketPos) + currentTrigger[1].substring(currentTrigger[1].lastIndexOf(")"));
                System.out.println("originalFieldPath: " + originalFieldPath);
                System.out.println("targetFieldPath: " + targetFieldPath);
                ImdiField[] targetField = changedImdiField.getSiblingField(targetFieldPath);
                ImdiVocabularies.VocabularyItem vocabItem = changedImdiField.getVocabulary().findVocabularyItem(changedImdiField.fieldValue);
                if (vocabItem != null) {
                    String valueForTargetField = null;
                    if (currentTrigger[2].equals("Content")) {
                        valueForTargetField = vocabItem.descriptionString;
                    } else if (currentTrigger[2].equals("Value")) {<commit_msg>Corrected the node text while loading and after a failed load. Corrected truncated node names in the tree. Corrected error showing the need for save in child nodes of Catalogue nodes. Corrected error viewing imdi xml of remote nodes. Enabled viewing of remote imdi files with pretty formatting, both in Arbil and in the web browser. Added test case and corrected an error showing the need to save to disk for sub nodes. Corrected issue adding catalogue nodes. Added missing catalogue sub nodes to the template file. Corrected error in the triggers read from the template and provided useful error message. Added trigger for catalogue languages. Corrected an error in the adding of sub nodes into subnodes.<commit_after>package nl.mpi.arbil;

/**
 * FieldChangeTriggers.java
 * Created on Jul 13, 2009, 4:15:02 PM
 * @author Peter.<EMAIL>
 */
public class FieldChangeTriggers {
    // the following strings need to be read from a template file or a vocaulary etc

    public void actOnChange(ImdiField changedImdiField) {
        String fieldPath = changedImdiField.getGenericFullXmlPath();
        System.out.println("fieldPath: " + fieldPath);
        for (String[] currentTrigger : changedImdiField.parentImdi.currentTemplate.fieldTriggersArray) {
            if (fieldPath.equals(currentTrigger[0])) {
                // we now have the path for two fields:
                // .METATRANSCRIPT.Session.MDGroup.Actors.Actor(x).Languages.Language(x).Id
                // .METATRANSCRIPT.Session.MDGroup.Actors.Actor(2).Languages.Language(3).Name
                // and we need to put the (\d) back into the (x)
                String originalFieldPath = changedImdiField.getFullXmlPath();
                int lastBracketPos = originalFieldPath.lastIndexOf(")");
                int lastTriggerBracket = currentTrigger[1].lastIndexOf(")");
                if (lastTriggerBracket < 0) {
                    LinorgWindowManager.getSingleInstance().addMessageDialogToQueue("Error in trigger from template (missing bracket): " + currentTrigger[1], "Field Trigger");
                    break;
                }
                // care must me taken here to prevet issues with child nodes greater than 9 ie (12), (x) etc.
                String targetFieldPath = originalFieldPath.substring(0, lastBracketPos) + currentTrigger[1].substring(lastTriggerBracket);
                System.out.println("originalFieldPath: " + originalFieldPath);
                System.out.println("targetFieldPath: " + targetFieldPath);
                ImdiField[] targetField = changedImdiField.getSiblingField(targetFieldPath);
                ImdiVocabularies.VocabularyItem vocabItem = changedImdiField.getVocabulary().findVocabularyItem(changedImdiField.fieldValue);
                if (vocabItem != null) {
                    String valueForTargetField = null;
                    if (currentTrigger[2].equals("Content")) {
                        valueForTargetField = vocabItem.descriptionString;
                    } else if (currentTrigger[2].equals("Value")) {
{'fraction_non_alphanumeric': 0.08823529411764706, 'fraction_numerical': 0.009080142123963679, 'mean_word_length': 2.7533333333333334, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5537605', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1281, 'n_words': 369}