Warning : session_start(): open(/var/lib/php/sessions/sess_n9ke8b1e66mshli8pdbqk39lkb, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
//FILENAME: gazelle/main.java
package gazelle;
import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import loadableUtils.utils.BetterThreadLocal;
import x30_pkg.x30_util;
import static x30_pkg.x30_util.VF1;
import static x30_pkg.x30_util.l;
import static x30_pkg.x30_util.indexOf;
import static x30_pkg.x30_util.getOpt;
import static x30_pkg.x30_util.setOpt;
import static x30_pkg.x30_util.callOpt;
import static x30_pkg.x30_util.get;
import static x30_pkg.x30_util.assertTrue;
import static x30_pkg.x30_util.isTrue;
import x30_pkg.x30_util.DynamicObject;
import loadableUtils.utils;
import loadableUtils.utils.CloseablesHolder;
import loadableUtils.utils.WithTimestamp;
import static loadableUtils.utils.fail;
import static loadableUtils.utils.javaCompileToJar_localLibraries;
import static loadableUtils.utils.dm_current_mandatory;
import static loadableUtils.utils.match;
import static loadableUtils.utils.getField;
import static loadableUtils.utils.fieldType;
import static loadableUtils.utils.struct;
import static loadableUtils.utils.structure;
import static loadableUtils.utils.dm_current_generic;
import static loadableUtils.utils.dm_current_mandatory_generic;
import static loadableUtils.utils.cset;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.rethrow;
import static loadableUtils.utils.concepts_internStringsLongerThan;
import static loadableUtils.utils.realMC_tl;
import loadableUtils.utils.F0;
import loadableUtils.utils.F1;
import loadableUtils.utils.IF0;
import loadableUtils.utils.IF1;
import loadableUtils.utils.IVF1;
import loadableUtils.utils.IVF2;
import loadableUtils.utils.Matches;
import loadableUtils.utils.Q;
import loadableUtils.utils.structure_Data;
import loadableUtils.utils.structure_ClassInfo;
import loadableUtils.utils.MultiSet;
import loadableUtils.utils.Concept;
import loadableUtils.utils.Concepts;
import loadableUtils.utils.RC;
import loadableUtils.utils.IConceptIndex;
import loadableUtils.utils.IFieldIndex;
import loadableUtils.utils.DynModule;
import loadableUtils.utils.Pt;
import loadableUtils.utils.SecretValue;
import static loadableUtils.utils.dynamicObjectIsLoading_threadLocal;
import loadableUtils.utils.HCRUD;
import loadableUtils.utils.HCRUD_Data;
import loadableUtils.utils.HCRUD_Concepts;
import loadableUtils.utils.ValueConverterForField;
import loadableUtils.utils.DefaultValueConverterForField;
import loadableUtils.utils.OrError;
import loadableUtils.utils.HTML;
import static loadableUtils.utils.appendParamsToURL;
import static loadableUtils.utils.litset;
import static loadableUtils.utils.printStackTrace;
import static loadableUtils.utils.loadJQuery2;
import static loadableUtils.utils.cget;
import static loadableUtils.utils.javaTok;
import static loadableUtils.utils.getConcept;
import static loadableUtils.utils.toTokCondition;
import static loadableUtils.utils.targetBlank;
import static loadableUtils.utils.b;
import static loadableUtils.utils.i;
import static loadableUtils.utils.n;
import static loadableUtils.utils.p;
import static loadableUtils.utils.findConceptWhere;
import static loadableUtils.utils.addParamToURL;
import static loadableUtils.utils.match2;
import static loadableUtils.utils.trueOrNull;
import static loadableUtils.utils.empty;
import static loadableUtils.utils.containsAngleBracketVars;
import static loadableUtils.utils.list;
import static loadableUtils.utils.hasMethod;
import static loadableUtils.utils.toUtf8;
import static loadableUtils.utils.cic;
import static loadableUtils.utils.remove;
import static loadableUtils.utils.emptyList;
import static loadableUtils.utils.programID;
import static loadableUtils.utils.hselect;
import static loadableUtils.utils.print_byThread;
import static loadableUtils.utils.conceptsWhere;
import static loadableUtils.utils.dm_makeModule;
import static loadableUtils.utils.charAt;
import static loadableUtils.utils.conceptWhere;
import static loadableUtils.utils.tok_identifiersInOrder;
import static loadableUtils.utils.grabValueAndCancel;
import static loadableUtils.utils.simpleDateFormat;
import static loadableUtils.utils.toArray;
import static loadableUtils.utils.cloneList;
import static loadableUtils.utils.defaultTimerName;
import static loadableUtils.utils.regexp;
import static loadableUtils.utils.ping;
import static loadableUtils.utils.cmp;
import static loadableUtils.utils.formatFunctionCall;
import static loadableUtils.utils.ahref_onClick;
import static loadableUtils.utils.getDBProgramID;
import static loadableUtils.utils.countConceptsCI;
import static loadableUtils.utils.div_center;
import static loadableUtils.utils.divUnlessEmpty;
import static loadableUtils.utils.parseLong;
import static loadableUtils.utils.uniqCI2;
import static loadableUtils.utils.js_setRedirect;
import static loadableUtils.utils.massageArgsForVarArgsCall;
import static loadableUtils.utils.eqOneOf;
import static loadableUtils.utils.joinWithBR;
import static loadableUtils.utils.javaxDataDir;
import static loadableUtils.utils.substring;
import static loadableUtils.utils.toSeconds;
import static loadableUtils.utils.getConceptOpt;
import static loadableUtils.utils.hhtml;
import static loadableUtils.utils.appendBracketed;
import static loadableUtils.utils.aGlobalID;
import static loadableUtils.utils.removeSubList;
import static loadableUtils.utils.javaTokForJFind_array;
import static loadableUtils.utils.boostHashCombine;
import static loadableUtils.utils.formatDoubleArrowMap_horizontallyAligned;
import static loadableUtils.utils.thinAProgramsBackups;
import static loadableUtils.utils.tempSetTL;
import static loadableUtils.utils.pnl;
import static loadableUtils.utils.hPopDownButton;
import static loadableUtils.utils.hcenter3;
import static loadableUtils.utils.shortClassNameIs;
import static loadableUtils.utils.shortName;
import static loadableUtils.utils.camelCase;
import static loadableUtils.utils.instancesOf;
import static loadableUtils.utils.getProgramID;
import static loadableUtils.utils.swic;
import static loadableUtils.utils.unnull;
import static loadableUtils.utils.findTranslators2;
import static loadableUtils.utils.joinWithComma;
import static loadableUtils.utils.conceptsWithFieldGreaterThan_sorted;
import static loadableUtils.utils.replaceDollarVars;
import static loadableUtils.utils.tdTop;
import static loadableUtils.utils.subList;
import static loadableUtils.utils.formatDouble;
import static loadableUtils.utils.evalWithTimeoutOrFail;
import static loadableUtils.utils.addAll;
import static loadableUtils.utils.getVar;
import static loadableUtils.utils.ahref;
import static loadableUtils.utils.serveJSON_breakAtLevels;
import static loadableUtils.utils.unlock;
import static loadableUtils.utils.replaceVars;
import static loadableUtils.utils.last;
import static loadableUtils.utils.warn;
import static loadableUtils.utils.isStringList;
import static loadableUtils.utils.plural;
import static loadableUtils.utils.trimAll;
import static loadableUtils.utils.getClassLoader;
import static loadableUtils.utils.htmldecode_dropAllTags;
import static loadableUtils.utils.addIfNotNull;
import static loadableUtils.utils.distinctCIFieldValuesOfConcepts;
import static loadableUtils.utils.startQ;
import static loadableUtils.utils.filterKeys;
import static loadableUtils.utils.pair;
import static loadableUtils.utils.hbutton;
import static loadableUtils.utils.parseInt;
import static loadableUtils.utils.lastIndexOf;
import static loadableUtils.utils.parseFirstLong;
import static loadableUtils.utils.litciset;
import static loadableUtils.utils.joinWithSpace;
import static loadableUtils.utils.doAfter;
import static loadableUtils.utils.printIndent;
import static loadableUtils.utils.put;
import static loadableUtils.utils.replaceSublist;
import static loadableUtils.utils.fileNotEmpty;
import static loadableUtils.utils.emptyObjectArray;
import static loadableUtils.utils.deleteConcepts;
import static loadableUtils.utils.conceptID;
import static loadableUtils.utils.isSubclassOf;
import static loadableUtils.utils.joinSubList;
import static loadableUtils.utils._hashCode;
import static loadableUtils.utils.className;
import static loadableUtils.utils.hjs_copyToClipboard;
import static loadableUtils.utils.iround;
import static loadableUtils.utils.listPlus;
import static loadableUtils.utils.dm_ownResource;
import static loadableUtils.utils.small;
import static loadableUtils.utils.h2_title;
import static loadableUtils.utils.sortedIC;
import static loadableUtils.utils.addAnchorToURL;
import static loadableUtils.utils.pcallF;
import static loadableUtils.utils.replace;
import static loadableUtils.utils.ownResource;
import static loadableUtils.utils.findCodeTokens;
import static loadableUtils.utils.regexpFirstGroupIC;
import static loadableUtils.utils.wrapInDiv;
import static loadableUtils.utils.hjs;
import static loadableUtils.utils.ciSet;
import static loadableUtils.utils.getClassName;
import static loadableUtils.utils.sortedByCalculatedFieldDesc;
import static loadableUtils.utils.iterateWithIndex1;
import static loadableUtils.utils.sleepSeconds;
import static loadableUtils.utils.values;
import static loadableUtils.utils.unicodeFromCodePoint;
import static loadableUtils.utils.parseLongOpt;
import static loadableUtils.utils.toObjectArray;
import static loadableUtils.utils.loadTextFile;
import static loadableUtils.utils.mapValues;
import static loadableUtils.utils.clear;
import static loadableUtils.utils.hbody;
import static loadableUtils.utils.call_withVarargs;
import static loadableUtils.utils.stringIf;
import static loadableUtils.utils.third;
import static loadableUtils.utils.hsansserif;
import static loadableUtils.utils.div_vbar;
import static loadableUtils.utils.javaTokWithAngleBrackets;
import static loadableUtils.utils.javaCompile_overInternalBot;
import static loadableUtils.utils.conceptsWhereCI;
import static loadableUtils.utils.callF;
import static loadableUtils.utils.eqic_gen;
import static loadableUtils.utils.trim;
import static loadableUtils.utils.replaceAngleBracketVars_curly;
import static loadableUtils.utils.phraseCache;
import static loadableUtils.utils.roundToInt;
import static loadableUtils.utils.htitle_h2;
import static loadableUtils.utils.isStaticMethod;
import static loadableUtils.utils.paramsPlus;
import static loadableUtils.utils.pre_htmlencode;
import static loadableUtils.utils.hscript;
import static loadableUtils.utils.exceptionToStringShort;
import static loadableUtils.utils.toString;
import static loadableUtils.utils.stepAllWithTimeout;
import static loadableUtils.utils.sortedByConceptIDDesc;
import static loadableUtils.utils.joinNemptiesWithColon;
import static loadableUtils.utils.joinNemptiesWithSpace;
import static loadableUtils.utils.conceptsWhereIC;
import static loadableUtils.utils.lithashset;
import static loadableUtils.utils.dropLoadableUtilsPackageFromStruct;
import static loadableUtils.utils.setOpt_findField;
import static loadableUtils.utils.hashCode;
import static loadableUtils.utils.newFileOutputStream;
import static loadableUtils.utils.shortClassName;
import static loadableUtils.utils.postProcess;
import static loadableUtils.utils.htextfield;
import static loadableUtils.utils.hhidden;
import static loadableUtils.utils.length;
import static loadableUtils.utils.print;
import static loadableUtils.utils.mapPairs;
import static loadableUtils.utils.identityHashCode;
import static loadableUtils.utils.lock;
import static loadableUtils.utils.firstToLower;
import static loadableUtils.utils.htmlEncode2_gen;
import static loadableUtils.utils.simpleSpacesTrim_javaTok;
import static loadableUtils.utils.isSubtypeOf;
import static loadableUtils.utils.hpostform;
import static loadableUtils.utils.loadFunction_cached;
import static loadableUtils.utils.litlist;
import static loadableUtils.utils.toMS;
import static loadableUtils.utils.map;
import static loadableUtils.utils.isStringCollection;
import static loadableUtils.utils.max;
import static loadableUtils.utils.addParamsToURL;
import static loadableUtils.utils.f2s;
import static loadableUtils.utils.asCIMap;
import static loadableUtils.utils.md5;
import static loadableUtils.utils.javaValueToHTML;
import static loadableUtils.utils.isTrue_getOpt;
import static loadableUtils.utils.isConceptList;
import static loadableUtils.utils.getThreadLocal;
import static loadableUtils.utils.sort;
import static loadableUtils.utils.htmlEncode_quote;
import static loadableUtils.utils.indexConceptFieldIC;
import static loadableUtils.utils.jextract;
import static loadableUtils.utils.hotwire_makeClassLoader;
import static loadableUtils.utils.deref;
import static loadableUtils.utils.matchesToMapUsingVarList_ciMap;
import static loadableUtils.utils.dbBot;
import static loadableUtils.utils.putAll;
import static loadableUtils.utils.dropSuffix;
import static loadableUtils.utils.cForwardAndBackRefsWithFieldIndicator;
import static loadableUtils.utils.objectsWhereCI;
import static loadableUtils.utils.getStringOpt;
import static loadableUtils.utils.pIfNempty;
import static loadableUtils.utils.removeAll;
import static loadableUtils.utils.elapsedSeconds_sysNow;
import static loadableUtils.utils.pairsA;
import static loadableUtils.utils.checkFieldsIC;
import static loadableUtils.utils.swic_notSame;
import static loadableUtils.utils.uncurly;
import static loadableUtils.utils.min;
import static loadableUtils.utils.arraycopy;
import static loadableUtils.utils.htmlTable2_noHtmlEncode;
import static loadableUtils.utils.parseSecondLong;
import static loadableUtils.utils.cloneMap;
import static loadableUtils.utils.ifThenElse;
import static loadableUtils.utils.jsQuote;
import static loadableUtils.utils.htmlEncode2_nlToBr;
import static loadableUtils.utils.ymd_minus_hms;
import static loadableUtils.utils.unlisted;
import static loadableUtils.utils.hsnippetimg_scaleToWidth;
import static loadableUtils.utils.tempAdd;
import static loadableUtils.utils.compileRegexp;
import static loadableUtils.utils.evalWithTimeout;
import static loadableUtils.utils.dbLock;
import static loadableUtils.utils.lookupPossiblyCI;
import static loadableUtils.utils.strOrNull;
import static loadableUtils.utils.concatMap;
import static loadableUtils.utils.isAngleBracketVar;
import static loadableUtils.utils._close;
import static loadableUtils.utils.starsToAngleBracketedNumbers;
import static loadableUtils.utils.countPred;
import static loadableUtils.utils.close_pcall;
import static loadableUtils.utils.wrapPatternSyntaxException;
import static loadableUtils.utils._entrySet;
import static loadableUtils.utils.first;
import static loadableUtils.utils.span;
import static loadableUtils.utils.litorderedmap;
import static loadableUtils.utils.multiSetToPairsByPopularity;
import static loadableUtils.utils.objectToMap;
import static loadableUtils.utils.renderEqualsCommaProperties;
import static loadableUtils.utils.hjs_autoExpandingTextAreas;
import static loadableUtils.utils.hmobilefix;
import static loadableUtils.utils.printVars_str;
import static loadableUtils.utils.hotwire;
import static loadableUtils.utils.span_title;
import static loadableUtils.utils.hNotificationPopups;
import static loadableUtils.utils.firstNotNull;
import static loadableUtils.utils.score;
import static loadableUtils.utils.quote;
import static loadableUtils.utils.htmlEncode_nlToBr_withIndents;
import static loadableUtils.utils.htmlTable2;
import static loadableUtils.utils.llNonNulls;
import static loadableUtils.utils.contains;
import static loadableUtils.utils.countConceptsWhereCI;
import static loadableUtils.utils.uniqCI;
import static loadableUtils.utils.jsonEncodeMap;
import static loadableUtils.utils.sleep;
import static loadableUtils.utils.allConcepts;
import static loadableUtils.utils.isB;
import static loadableUtils.utils.uniquifyCI;
import static loadableUtils.utils.close;
import static loadableUtils.utils.isFile;
import static loadableUtils.utils.conceptWhereIC;
import static loadableUtils.utils.swing;
import static loadableUtils.utils.findEndOfBracketPart;
import static loadableUtils.utils._getClass;
import static loadableUtils.utils.indentStructureString_firstLevels;
import static loadableUtils.utils.add;
import static loadableUtils.utils.ciMultiMap;
import static loadableUtils.utils.mapKeys;
import static loadableUtils.utils.clearTokens;
import static loadableUtils.utils.subBot_serve500;
import static loadableUtils.utils.saveTextFile;
import static loadableUtils.utils.conceptWhereCI;
import static loadableUtils.utils.pnlToString;
import static loadableUtils.utils.emptyDoubleArray;
import static loadableUtils.utils.lines;
import static loadableUtils.utils.unquote;
import static loadableUtils.utils.nempty;
import static loadableUtils.utils.isEmpty;
import static loadableUtils.utils.dm_os;
import static loadableUtils.utils.serveText;
import static loadableUtils.utils.sortByConceptID;
import static loadableUtils.utils.vm_busListenersByMessage_live;
import static loadableUtils.utils.shorten;
import static loadableUtils.utils.jfindAll;
import static loadableUtils.utils.litmap;
import static loadableUtils.utils.weakSet;
import static loadableUtils.utils.myClassLoader;
import static loadableUtils.utils.findConceptsWhereCI;
import static loadableUtils.utils.jfind_preprocess;
import static loadableUtils.utils.hrefresh;
import static loadableUtils.utils.fileInSameDir;
import static loadableUtils.utils.synchronizedSet;
import static loadableUtils.utils.countConceptsWhereIC;
import static loadableUtils.utils.beforeVerticalBar;
import static loadableUtils.utils.isIdentifier;
import static loadableUtils.utils.getTimeZone;
import static loadableUtils.utils.dropTrailingSlashIfNemptyAfterwards;
import static loadableUtils.utils.neq;
import static loadableUtils.utils.all;
import static loadableUtils.utils.paramsPlus_inFront;
import static loadableUtils.utils.inputText;
import static loadableUtils.utils.regexpMatcherIC;
import static loadableUtils.utils.uniq;
import static loadableUtils.utils.nullIfEmpty;
import static loadableUtils.utils.isSafeStandardFunction;
import static loadableUtils.utils.indent;
import static loadableUtils.utils.angleBracketVarsToStars;
import static loadableUtils.utils.derefRef;
import static loadableUtils.utils.dbBotStandardName;
import static loadableUtils.utils.joinNempties;
import static loadableUtils.utils.keySet;
import static loadableUtils.utils.optCast;
import static loadableUtils.utils.emptyIntArray;
import static loadableUtils.utils.reversed;
import static loadableUtils.utils.stdcompare;
import static loadableUtils.utils.eqGetOneOf;
import static loadableUtils.utils.done2_always;
import static loadableUtils.utils.isInstance;
import static loadableUtils.utils.regexpReplace;
import static loadableUtils.utils.programFile;
import static loadableUtils.utils.dropFirstAndLast;
import static loadableUtils.utils.dm_doEvery;
import static loadableUtils.utils.setOptAllDyn_pcall;
import static loadableUtils.utils.onIndividualConceptChange_notOnAllChanged;
import static loadableUtils.utils.pcallOpt;
import static loadableUtils.utils.nonNulls;
import static loadableUtils.utils.hinputfield;
import static loadableUtils.utils.asCIMultiSet;
import static loadableUtils.utils.dm_getModule;
import static loadableUtils.utils.deleteConcept;
import static loadableUtils.utils.replaceAngleBracketVars;
import static loadableUtils.utils.litobjectarray;
import static loadableUtils.utils.getMainBot;
import static loadableUtils.utils.strOrEmpty;
import static loadableUtils.utils.call;
import static loadableUtils.utils.cnew;
import static loadableUtils.utils.uniqCI_returnIfNew;
import static loadableUtils.utils.run;
import static loadableUtils.utils.isInteger;
import static loadableUtils.utils.indexConceptFieldDesc;
import static loadableUtils.utils.cdelete;
import static loadableUtils.utils.ciMap;
import static loadableUtils.utils.flexMatchIC_iterate;
import static loadableUtils.utils.now;
import static loadableUtils.utils.smartTimerTask;
import static loadableUtils.utils.csetIfUnset;
import static loadableUtils.utils.hsubmit;
import static loadableUtils.utils.eqicOneOf;
import static loadableUtils.utils.htitle;
import static loadableUtils.utils.lastException;
import static loadableUtils.utils.splitAtSpace;
import static loadableUtils.utils.htmlEncode2;
import static loadableUtils.utils.optPar;
import static loadableUtils.utils.javaxCachesDir;
import static loadableUtils.utils.h1_title;
import static loadableUtils.utils.singleObjectMethodProxy;
import static loadableUtils.utils.sameSnippetID;
import static loadableUtils.utils.compareIC;
import static loadableUtils.utils.callFAll;
import static loadableUtils.utils.listZip;
import static loadableUtils.utils.match3_withIntsAndIDs;
import static loadableUtils.utils.getClass;
import static loadableUtils.utils.syncIdentityHashSet;
import static loadableUtils.utils.containsKey;
import static loadableUtils.utils.jsonEncode;
import static loadableUtils.utils.regexpMatcher;
import static loadableUtils.utils.collectionMutex;
import static loadableUtils.utils.joinNemptiesWithVBar;
import static loadableUtils.utils.mapGet;
import static loadableUtils.utils.parseSnippetID;
import static loadableUtils.utils.conceptFields;
import static loadableUtils.utils.firstToUpper;
import static loadableUtils.utils.asList;
import static loadableUtils.utils.getType;
import static loadableUtils.utils.endsWith;
import static loadableUtils.utils.listSet;
import static loadableUtils.utils.vmBus_send;
import static loadableUtils.utils.dm_getStem;
import static loadableUtils.utils.set;
import static loadableUtils.utils.hselect_list;
import static loadableUtils.utils.dm_rEnter;
import static loadableUtils.utils.loadLibraryOrSrcLib;
import static loadableUtils.utils.callOpt_getCache;
import static loadableUtils.utils.sfu;
import static loadableUtils.utils.getAndClearThreadLocal;
import static loadableUtils.utils.getStackTrace;
import static loadableUtils.utils.javax;
import static loadableUtils.utils.isQuoted;
import static loadableUtils.utils.emptyCharArray;
import static loadableUtils.utils.hhiddenMulti;
import static loadableUtils.utils.isFalse;
import static loadableUtils.utils.eq;
import static loadableUtils.utils.isDigit;
import static loadableUtils.utils.hinlinepostform;
import static loadableUtils.utils.dm_callOS;
import static loadableUtils.utils.isDirectory;
import static loadableUtils.utils.hform;
import static loadableUtils.utils.h2;
import static loadableUtils.utils.h3;
import static loadableUtils.utils.random;
import static loadableUtils.utils.trimSubstring;
import static loadableUtils.utils.md5OrNull;
import static loadableUtils.utils.pcallFAll;
import static loadableUtils.utils.synchronizedMRUCache;
import static loadableUtils.utils.getString;
import static loadableUtils.utils.conceptsFile;
import static loadableUtils.utils.urlencode;
import static loadableUtils.utils.hr;
import static loadableUtils.utils.dm_call;
import static loadableUtils.utils.saveTiming_tl;
import static loadableUtils.utils.join;
import static loadableUtils.utils.fsI;
import static loadableUtils.utils.odd;
import static loadableUtils.utils.isInstanceOf;
import static loadableUtils.utils.lmap;
import static loadableUtils.utils.ahref_undecorated;
import static loadableUtils.utils.javaTokForStructure;
import static loadableUtils.utils.change;
import static loadableUtils.utils.vmBus_query;
import static loadableUtils.utils.assertEquals;
import static loadableUtils.utils.joinMap;
import static loadableUtils.utils.tlft;
import static loadableUtils.utils.dm_vmBus_onMessage;
import static loadableUtils.utils.endsWithLetterOrDigit;
import static loadableUtils.utils.dm_startQ;
import static loadableUtils.utils.ll;
import static loadableUtils.utils.concatArrays;
import static loadableUtils.utils.n2;
import static loadableUtils.utils.lines_rtrim;
import static loadableUtils.utils.second;
import static loadableUtils.utils.replaceTokens;
import static loadableUtils.utils.takeFirst;
import static loadableUtils.utils.hparagraphs;
import static loadableUtils.utils.codeTokensAsStringArray;
import static loadableUtils.utils.hijackPrint;
import static loadableUtils.utils.keys;
import static loadableUtils.utils.uniqCI2_sync;
import static loadableUtils.utils.smartIndexOf;
import static loadableUtils.utils.assertIdentifier;
import static loadableUtils.utils.ol;
import static loadableUtils.utils.or;
import static loadableUtils.utils.syncMRUCache;
import static loadableUtils.utils.dropPunctuation;
import static loadableUtils.utils.rtrim;
import static loadableUtils.utils.iterator;
import static loadableUtils.utils.assertNotNull;
import static loadableUtils.utils.currentThread;
import static loadableUtils.utils.transpileRaw;
import static loadableUtils.utils.str;
import static loadableUtils.utils.tempInterceptPrint;
import static loadableUtils.utils.printWithIndent;
import static loadableUtils.utils.appendRoundBracketed;
import static loadableUtils.utils.hideCredentials;
import static loadableUtils.utils.intRange;
import static loadableUtils.utils.intern;
import static loadableUtils.utils.asCISet;
import static loadableUtils.utils.syncMapPut2_createLinkedHashMap;
import static loadableUtils.utils.th;
import static loadableUtils.utils.syncMapToPairs;
import static loadableUtils.utils.tr;
import static loadableUtils.utils.tt;
import static loadableUtils.utils.dm_moduleID;
import static loadableUtils.utils.conceptIDOrNull;
import static loadableUtils.utils.ul;
import static loadableUtils.utils.programDir;
import static loadableUtils.utils.or2;
import static loadableUtils.utils.similarEmptyMap;
import static loadableUtils.utils._get;
import static loadableUtils.utils.div_alignRight;
import static loadableUtils.utils.gazelle_allSyntacticPatternsFromInput;
import static loadableUtils.utils.getConceptFieldCIIndex;
import static loadableUtils.utils.ul_htmlEncode;
import static loadableUtils.utils.checkFields;
import static loadableUtils.utils.eqic;
import static loadableUtils.utils.hpre_htmlencode;
import static loadableUtils.utils.pairA;
import static loadableUtils.utils.parseIntOpt;
import static loadableUtils.utils._handleException;
import static loadableUtils.utils.dropFirst;
import static loadableUtils.utils.pairB;
import static loadableUtils.utils.htitledSectionWithDiv;
import static loadableUtils.utils.urldecode;
import static loadableUtils.utils.nConcepts;
import static loadableUtils.utils.dropPrefix;
import static loadableUtils.utils.deAngleBracket;
import static loadableUtils.utils.emptyMap;
import static loadableUtils.utils.tok_integersInOrder;
import static loadableUtils.utils.allToString;
import static loadableUtils.utils.filter;
import static loadableUtils.utils.getWeakRef;
import static loadableUtils.utils.ensureConceptClassIsIndexed;
import static loadableUtils.utils.ensureDBNotRunning;
import static loadableUtils.utils.findStaticMethod;
import static loadableUtils.utils.findBackRefs;
import static loadableUtils.utils.nempties;
import static loadableUtils.utils.htmlEncode_nlToBR;
import static loadableUtils.utils.tok_findEndOfStatement;
import static loadableUtils.utils.tag;
import static loadableUtils.utils.syncL;
import static loadableUtils.utils.htextarea;
import static loadableUtils.utils.hhead;
import static loadableUtils.utils.toLong;
import static loadableUtils.utils.localTimeWithSeconds;
import static loadableUtils.utils.hjs_selectize;
import static loadableUtils.utils.concatLists;
import static loadableUtils.utils.invokeMethod;
import static loadableUtils.utils.isInQ;
import static loadableUtils.utils.countTokens;
import static loadableUtils.utils.sysNow;
import static loadableUtils.utils.countConcepts;
import static loadableUtils.utils.hPopDownButtonWithText;
import static loadableUtils.utils.countWordsWithoutAngleBracketedAndStars;
import static loadableUtils.utils.startsWith;
import loadableUtils.utils.Var;
import loadableUtils.utils.Scorer;
import loadableUtils.utils.ITokCondition;
import loadableUtils.utils.ConceptsRefChecker;
import loadableUtils.utils.FixedRateTimer;
import loadableUtils.utils.IterableIterator;
import loadableUtils.utils.F2;
import loadableUtils.utils.Flag;
import loadableUtils.utils.StringBufferWithMaxSize;
import loadableUtils.utils.IFieldsToList;
import loadableUtils.utils.IF2;
import loadableUtils.utils.DynNewBot2;
import loadableUtils.utils._MethodCache;
import loadableUtils.utils.DynGazelleRocks;
import loadableUtils.utils.ConceptWithGlobalID;
import loadableUtils.utils.MultiMap;
import loadableUtils.utils.HTMLTabs;
import loadableUtils.utils.BreadthFirstPathFinder_withLinkType;
import loadableUtils.utils.ReliableSingleThread_Multi;
import loadableUtils.utils.Steppable;
import loadableUtils.utils.Pair;
import loadableUtils.utils.HTMLFramer1;
import loadableUtils.utils.JavaXClassLoader;
import loadableUtils.utils.IntRange;
import loadableUtils.utils.FieldIndicator;
import loadableUtils.utils.JavaXClassLoaderWithParent2;
import loadableUtils.utils.HDivWithVerticalExpandButton;
import loadableUtils.utils.ConceptFieldIndexCI_withTopTen;
import loadableUtils.utils.Timed;
import loadableUtils.utils.CMissingObject;
import loadableUtils.utils.SteppableAndIF0;
import loadableUtils.utils.ConceptsShadowLogger;
import loadableUtils.utils.ConceptClassesDependentValue;
import loadableUtils.utils.RealmCopy;
import loadableUtils.utils.ConceptShadow;
import loadableUtils.utils.HTMLPopDownButton;
import loadableUtils.utils.TransitiveHull;
import loadableUtils.utils.CreatedDeletedChanged;
import loadableUtils.utils.HTMLPaginator;
import loadableUtils.utils.User;
import loadableUtils.utils.UserPost;
import loadableUtils.utils.Conversation;
import loadableUtils.utils.ExecutedStep;
import loadableUtils.utils.InputHandled;
import static loadableUtils.utils.passwordSalt;
import java.text.*;
public class main {
static public class GazelleBEATester extends GazelleBEA {
}
static public boolean _moduleClass_GazelleBEATester = true;
static public String mainLibID = "#1030952";
static public String programID;
static public void _onLoad_initUtils() {
utils.__javax = javax();
}
static public ThreadLocal dynamicObjectIsLoading_threadLocal() {
return DynamicObject_loading;
}
static public class BEACalculations {
public GazelleBEA mod;
public BEACalculations(GazelleBEA mod) {
this.mod = mod;
}
transient public int liveOutputDelay = 1000;
transient public double algoTimeout = 30.0;
public void reactAllInputsWithSomePatterns() {
for (BEAObject input : mod.beaObjectsOfType("input")) {
ReactInputWithSomePatterns r = new ReactInputWithSomePatterns();
r.input = input;
r.ccOut = db_mainConcepts();
r.max = 10;
r.start();
stepAllWithTimeout(10.0, r);
}
}
public void reactAllInputsWithAllSyntacticPatterns() {
for (BEAObject input : mod.beaList("input")) {
ping();
for (BEAObject pattern : mod.beaList("Syntactic Pattern")) {
ping();
{
if (patternAlwaysMatches(pattern))
continue;
}
reactInputWithPattern(input, pattern);
}
}
}
public void reactAllInputsWithPattern(BEAObject pattern) {
for (BEAObject input : mod.beaList("input")) {
ping();
reactInputWithPattern(input, pattern);
}
}
public boolean patternAlwaysMatches(BEAObject pat) {
return isTrue_getOpt("alwaysMatches", pat);
}
public class ReactInputWithSomePatterns implements Steppable {
public BEAObject input;
public Concepts ccOut;
public int max = 3, n;
public Iterator patterns;
public void start() {
n = countConceptsWhereIC(ccOut, BEAObject.class, "input", input, "type", "match");
patterns = iterator(sortByConceptID(conceptsWhereIC(BEAObject.class, "type", "Pattern")));
}
public boolean step() {
if (n >= max)
return false;
if (!patterns.hasNext())
return false;
if (reactInputWithPattern(input, patterns.next(), ccOut) != null)
++n;
return true;
}
}
public Pair> matchInputWithPatternList(String text, BEAObject patternList) {
List patterns = (List) (cget("patterns", patternList));
for (BEAObject pattern : unnullForIteration(patterns)) {
Map mapping = matchInputWithPattern(text, pattern);
if (mapping != null)
return pair(pattern, mapping);
}
return null;
}
public ThreadLocal matchInput_droppedPunctuation = new ThreadLocal();
public Map matchInputWithPattern(BEAObject input, BEAObject pattern) {
String text = getString("text", input);
return matchInputWithPattern(text, pattern);
}
public Map matchInputWithPattern(String text, BEAObject pattern) {
String pat = getString("text", pattern);
boolean punctuationOnly = isTrue_getOpt("punctuationOnly", pattern);
if (pattern.typeIs("Syntactic Pattern"))
return matchInputWithSyntacticPattern(text, pat, punctuationOnly);
else if (eqic_gen(getOpt("subType", pattern), "PhraseCache"))
return phraseCache(pat, text) ? litmap() : null;
else
return matchInputWithPattern(text, pat, punctuationOnly);
}
public Map matchInputWithSyntacticPattern(String text, String pat) {
return matchInputWithSyntacticPattern(text, pat, false);
}
public Map matchInputWithSyntacticPattern(String text, String pat, boolean punctuationOnly) {
pat = starsToAngleBracketedNumbers(pat);
return matchInputWithPattern(text, pat, punctuationOnly);
}
public Map matchInputWithPattern(String text, String pat) {
return matchInputWithPattern(text, pat, false);
}
public Map matchInputWithPattern(String text, String pat, boolean punctuationOnly) {
Map mapping = flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_first(pat, text);
if (mapping != null || punctuationOnly)
return mapping;
return null;
}
public BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern) {
return reactInputWithPattern(input, pattern, db_mainConcepts());
}
public BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern, Concepts ccOut) {
if (input == null || pattern == null)
return null;
matchInput_droppedPunctuation.set(false);
Map mapping = matchInputWithPattern(input, pattern);
if (mapping == null)
return null;
BEAObject match = uniqCI(ccOut, BEAObject.class, "type", "Match", "input", input, "pattern", pattern);
cset(match, "mapping", mapping, "droppedPunctuation", trueOrNull(matchInput_droppedPunctuation.get()));
return match;
}
public Object serveAnalyzeInput(GazelleBEA.Req req) {
Concepts ccOut = new Concepts();
BEAObject input = getConcept(BEAObject.class, parseLong(req.get("id")));
if (input == null)
input = cnew(ccOut, BEAObject.class, "type", "Input", "text", req.get("q"));
String text = getString("text", input);
ReactInputWithSomePatterns r = new ReactInputWithSomePatterns();
r.input = input;
r.ccOut = ccOut;
r.max = 1000;
r.start();
stepAllWithTimeout(10.0, r);
Collection matches = conceptsWhereIC(ccOut, BEAObject.class, "type", "Match");
return h1_title("Analyze Input") + p("Input: " + b(htmlEncode_nlToBr_withIndents(text))) + p(empty(matches) ? "No matches" : "Matches") + ul_htmlEncode(matches);
}
public Object serveQueryPage(GazelleBEA.Req req) {
return serveQueryPage(req, false);
}
public Object serveQueryPage(GazelleBEA.Req req, boolean withFrame) {
String q = req.get("q"), algorithm = req.get("algorithm");
boolean dontRun = eq(req.get("dontRun"), "1");
boolean liveOutput = eq(req.get("liveOutput"), "1");
if (liveOutput)
req.noSpam();
if (eqic(algorithm, "process input"))
algorithm = "Process new input v3";
Map> algorithms = algorithms();
String output = empty(algorithm) || dontRun ? null : doAlgorithm(algorithms, algorithm, q, liveOutput);
if (liveOutput)
return jsonEncode(litorderedmap("answer", output));
String right = withFrame ? "" : mod.html_loggedIn();
Algorithm alg = callF(lookupPossiblyCI(algorithms, algorithm));
if (alg != null) {
alg.q = q;
alg.req = mod.currentReq();
}
String centered = (withFrame ? "" : htitle_h2(ahref(mod.baseLink + "/", "Gazelle") + " Query" + htmlEncode2((empty(q) ? "" : ": " + q) + appendSquareBracketed(algorithm)))) + hscript(replaceVars("\r\n var sugLoading = false, sugTriggerAgain = false;\r\n\r\n function sugTrigger() {\r\n console.log(\"sugTrigger\");\r\n if (sugLoading) { sugTriggerAgain = true; return; }\r\n\r\n // get form data as JSON\r\n \r\n var data = {\r\n \"liveOutput\" : \"1\",\r\n \"q\": $(\"textarea[name=q]\").val(),\r\n \"algorithm\": $(\"select[name=algorithm]\").val(),\r\n \"algorithmID\": $(\"select[name=algorithmID]\").val(), // XXX: do this for all additional alg parameters\r\n };\r\n \r\n const url = \"/query\";\r\n console.log(\"Loading \" + url + \" with \" + data);\r\n sugLoading = true;\r\n $.post(url, data,\r\n function(result) {\r\n console.log(\"Suggestor result: \" + result);\r\n const answer = !result ? \"\" : JSON.parse(result).answer;\r\n if (answer) {\r\n $(\"#liveResult .sectionContents\").html(answer);\r\n $(\"#liveResult\").show();\r\n } else\r\n $(\"#liveResult\").hide();\r\n //$(\"#suggestorResult\").html(answer ? \"Suggestor says: \" + answer : \"\");\r\n }\r\n ).always(function() {\r\n console.log(\"sug loading done\");\r\n setTimeout(function() {\r\n sugLoading = false;\r\n if (sugTriggerAgain) { sugTriggerAgain = false; sugTrigger(); }\r\n }, liveOutputDelay);\r\n });\r\n }\r\n\r\n $(document).ready(function() {\r\n $(\"textarea[name=q], input[name=q], select[name=algorithm]\").on('input propertychange change', sugTrigger);\r\n sugTrigger();\r\n });\r\n ", "liveOutputDelay", liveOutputDelay)) + hform(p("Query (Ctrl+Enter): " + htextarea(q, "id", "mainInput", "name", "q", "class", "auto-expand", "style", "width: 300px", "onkeydown", jquery_submitFormOnCtrlEnter(), "autofocus", dontRun || empty(q) ? true : null) + " " + (alg == null ? "" : alg.additionalInputs()) + " Algorithm: " + hselect_list(keys(algorithms), algorithm, "name", "algorithm") + " " + hbutton("Go")));
String content = (empty(right) ? "" : div_alignRight(right)) + div_center(centered) + htitledSectionWithDiv("Live Result", "", "id", "liveResult", "style", "display: none", "innerDivStyle", "max-height: 150px; overflow: auto") + (output == null ? "" : h3(algorithm) + output);
if (withFrame) {
req.framer.addInHead(hjs_handleScrollToAnchor());
req.framer.add(content);
return mod.completeFrame(req);
} else
return hhtml(hhead(hmobilefix() + hsansserif() + loadJQuery2() + hjs_handleScrollToAnchor() + hjs_autoExpandingTextAreas() + mod.webSocketHeadStuff(req) + hNotificationPopups()) + hbody(content));
}
public String doAlgorithm(Map> algorithms, String algorithm, String q, boolean liveMode) {
GazelleBEA.Req req = mod.currentReq();
StringBufferWithMaxSize out = new StringBufferWithMaxSize(1000000);
IF0 algo = lookupPossiblyCI(algorithms, algorithm);
if (algo == null)
out.append("Algorithm not found: " + algorithm);
else {
if (isB(evalWithTimeout(algoTimeout, new Runnable() {
public void run() {
try {
AutoCloseable __21 = mod.enter();
try {
AutoCloseable __22 = tempSetTL(mod.currentReq, req);
try {
Algorithm alg = algo.get();
alg.liveMode = liveMode;
alg.out = out;
alg.q = q;
alg.req = mod.currentReq();
alg.runIt();
} finally {
_close(__22);
}
} finally {
_close(__21);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp mod.enter();\r\n temp tempSetTL(mod.currentReq, req);\r\n Algo...";
}
})))
out.append("\n[algorithm timeout]");
}
return str(out);
}
public class Algorithm implements Runnable {
public String q;
public GazelleBEA.Req req;
public Appendable out;
public boolean liveMode = false;
public Concepts localConcepts = db_mainConcepts();
public List nonMatches;
public void run() {
}
public void runLiveMode() {
}
public String additionalInputs() {
return "";
}
public void appendHTML(String html) {
appendHTML(this.out, html);
}
public void appendHTML(Appendable out, String html) {
try {
if (empty(html))
return;
html = wrapInDiv(html, "style", "margin-top: 0.5em");
out.append(html).append("\n");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void appendHTML_raw(String html) {
try {
out.append(html).append("\n");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void appendText(String text) {
appendText(this.out, text);
}
public void appendText(Appendable out, String text) {
try {
if (empty(text))
return;
out.append(hpre_htmlencode(rtrim(text)));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void appendTextBold(String text) {
appendTextBold(this.out, text);
}
public void appendTextBold(Appendable out, String text) {
try {
if (empty(text))
return;
out.append(b(hpre_htmlencode(rtrim(text))));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void allowSuggestingAnswer(BEAObject input) {
if (input == null)
return;
String text = input.text();
String url = mod.baseLink + "/saveAnswer";
appendHTML(hpostform("Suggest an answer to " + htmlEncode_quote(text) + ": " + htextarea(text, "id", "suggestAnswer", "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("inputID", input.id) + hhidden("redirect", "") + " " + hsubmit("Save answer") + " [Optional rewrite type: " + hinputfield("rewriteType", "style", "width: 100px") + " ]", "action", url, "onsubmit", js_setRedirect()));
}
public void allowSuggestingPattern(BEAObject input) {
if (input == null)
return;
String text = input.text();
String url = mod.baseLink + "/savePattern";
appendHTML(hpostform("Suggest a pattern (with angle bracket vars): " + htextarea(text, "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("fromInput", conceptIDOrNull(input)) + hhidden("userTyped", true) + hhidden("redirect", "") + " " + hsubmit("Save pattern"), "action", url, "onsubmit", js_setRedirect()));
}
public void allowSuggestingSyntacticPattern(BEAObject input) {
if (input == null)
return;
String text = input.text();
String url = mod.baseLink + "/saveSyntacticPattern";
appendHTML(hpostform("Suggest a syntactic pattern (with * vars): " + htextarea(text, "name", "text", "class", "auto-expand", "style", "width: 300px") + hhidden("fromInput", conceptIDOrNull(input)) + hhidden("userTyped", true) + hhidden("redirect", "") + " " + hsubmit("Save syntactic pattern"), "action", url, "onsubmit", js_setRedirect()));
}
public BEAObject saveInput(String q) {
if (userAgentIsBot(beaMod().currentUserAgent()))
return null;
Pair p = uniqCI2(BEAObject.class, "type", "Input", "text", q);
BEAObject input = p.a;
mod.saveUserAgent(input);
if (p.b) {
csetIfUnset(input, "createdBy", mod.user(mod.currentReq()));
appendHTML("Input saved");
}
return input;
}
public void runNonMatches() {
if (nempty(nonMatches)) {
appendHTML(hr());
callFAll(nonMatches);
}
}
public void addNonMatch(Runnable r) {
add(nonMatches, r);
}
public void runIt() {
if (liveMode)
runLiveMode();
else
run();
runNonMatches();
}
}
public class ReverseInput extends Algorithm {
public void run() {
appendText(reversed(q));
}
public void runLiveMode() {
run();
}
}
public class TimeoutTest extends Algorithm {
public void run() {
sleepSeconds(120);
}
}
public class RunPattern extends Algorithm {
public void run() {
BEAObject pattern = mod.beaGet(parseFirstLong(q));
if (pattern == null) {
appendText("Pattern not found");
return;
}
appendText("Pattern: " + pattern);
for (BEAObject input : mod.beaList("Input")) {
String text = input.text();
Map mapping = matchInputWithPattern(input, pattern);
if (mapping == null)
addNonMatch(new Runnable() {
public void run() {
try {
appendText("Checking Input: " + input + " - No match");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "appendText(\"Checking Input: \" + input + \" - No match\");";
}
});
else {
String result = "\n" + renderMappingAsText(mapping);
appendText("Checking Input: " + input + result);
allowStoringMatch(this, input, pattern, mapping);
}
}
}
}
public String renderMappingAsText(Map mapping) {
return indent(formatDoubleArrowMap_horizontallyAligned(mapping));
}
public class FindRewrites extends Algorithm {
public void run() {
BEAObject match = mod.beaGet(parseFirstLong(q));
if (match == null || !match.typeIs("Match")) {
appendText("Match not found");
return;
}
BEAObject pattern = (BEAObject) (cget("pattern", match));
BEAObject input = (BEAObject) (cget("input", match));
Map mapping = (Map) (get("mapping", match));
appendText("Match: " + match);
appendText("Input: " + input);
appendText("Pattern: " + pattern);
appendText("Mapping:\n" + renderMappingAsText(mapping));
appendRewrites(this, input, input.text(), pattern, match, mapping);
}
}
public List appendRewrites(Algorithm algo, BEAObject input, String inputText, BEAObject pattern, BEAObject match, Map mapping) {
Collection rewrites = mod.beaBackRefs(pattern, "Rewrite");
List texts = new ArrayList();
for (BEAObject r : rewrites) {
String text = r.text();
String textWithVars = text;
if (pattern.typeIs("Syntactic pattern"))
textWithVars = starsToAngleBracketedNumbers(text);
String text2 = replaceAngleBracketVars_curly(textWithVars, mapping);
algo.appendText(" Using pattern rewrite: " + text);
algo.appendTextBold(" " + inputText + "\n" + " => " + text2);
texts.add(text2);
BEAObject existing = match == null || input == null ? null : conceptWhereIC(BEAObject.class, "type", "Rewrite", "input", input, "text", text2, "match", match, "patternRewrite", r, "label", "good");
if (existing != null)
algo.appendHTML("Rewrite exists: " + mod.beaLinkHTML(existing));
else if (match == null)
algo.appendText("[Can't save, no match]");
else if (input == null)
algo.appendText("[Can't save, no input object]");
else
algo.appendHTML(hinlinepostform(hhiddenMulti("action", "create", "f_type", "Rewrite", "f_text", text2, "f_input", input.id, "metaInfo_input", "concept", "f_match", match.id, "metaInfo_match", "concept", "f_patternRewrite", r.id, "metaInfo_patternRewrite", "concept", "f_label", "good") + hbutton("Good rewrite"), "target", "_blank", "action", mod.crudLink(BEAObject.class)));
}
return texts;
}
public class ProcessNewInput extends Algorithm {
public void run() {
BEAObject input = handleInput(this, q = trim(q), false);
for (BEAObject pattern : mod.beaListAny("Pattern", "Syntactic Pattern")) {
checkPattern(this, input, q, pattern);
}
}
}
public void checkPattern(Algorithm algo, BEAObject input, String q, BEAObject pattern) {
Map mapping = matchInputWithPattern(q, pattern);
if (mapping == null)
algo.addNonMatch(new Runnable() {
public void run() {
try {
algo.appendText("Checking Pattern: " + pattern + " - No match");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "algo.appendText(\"Checking Pattern: \" + pattern + \" - No match\");";
}
});
else {
String result = "\n" + renderMappingAsText(mapping);
algo.appendText("Checking Pattern: " + pattern + result);
if (input == null) {
} else
allowStoringMatch(algo, input, pattern, mapping);
appendRewrites(algo, input, q, pattern, null, mapping);
}
}
public class ProcessNewInput_v2 extends Algorithm {
public void run() {
q = trim(q);
saveInput(q);
BEAObject input = handleInput(this, q, false);
if (input != null) {
Collection rewrites = mod.beaBackRefs(input, "Rewrite");
BEAObject rewrite = random(rewrites);
if (rewrite != null)
appendHTML("My answer: " + b(htmlEncode2(rewrite.text())) + " " + ahref(mod.beaShortURL(rewrite), "[source]"));
}
allowSuggestingAnswer(input);
allowSuggestingPattern(input);
allowSuggestingSyntacticPattern(input);
for (BEAObject pattern : syntacticPatternsSortedBySpecificityDesc()) {
{
if (patternAlwaysMatches(pattern))
continue;
}
Map mapping = matchInputWithPattern(q, pattern);
if (mapping == null)
addNonMatch(new Runnable() {
public void run() {
try {
appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern) + " - No match");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "appendHTML(\"Checking Syntactic Pattern: \" + mod.beaLinkHTML(pattern) + \" - No...";
}
});
else {
String result = "Grouped as: " + replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), mapping) + "\n" + renderMappingAsText(mapping);
appendHTML(hr());
appendHTML("Checking Syntactic Pattern: " + mod.beaLinkHTML(pattern));
appendText(result);
BEAObject match = null;
if (input == null) {
} else
match = allowStoringMatch(this, input, pattern, mapping);
MultiMap subInputRewrites = ciMultiMap();
for (String subInput : uniquifyCI(values(mapping))) if (!eqic(subInput, q)) {
BEAObject subInputObj = handleInput(this, subInput, "Sub-Input", true);
if (subInputObj != null) {
List subRewrites = concatLists(conceptsWhereCI(BEAObject.class, "type", "Rewrite", "input", subInputObj), conceptsWhereCI(BEAObject.class, "type", "Rewrite", "isRewriteOf", subInputObj));
for (BEAObject r : subRewrites) appendHTML(" Sub-Rewrite found: " + r);
subInputRewrites.putAll(subInput, subRewrites);
}
}
appendRewrites(this, input, q, pattern, match, mapping);
Map rewrittenMapping = mapValues(mapping, s -> {
BEAObject rewrite = random(subInputRewrites.get(s));
return rewrite == null ? s : uncurly(rewrite.text());
});
String randomRewrite = replaceAngleBracketVars_curly(starsToAngleBracketedNumbers(pattern.text()), rewrittenMapping);
if (neq(randomRewrite, q))
appendText("Random rewrite from sub-inputs: " + randomRewrite);
}
}
}
}
public class ProcessNewInput_v3 extends Algorithm {
public void run() {
q = trim(q);
saveInput(q);
BEAObject input = handleInput(this, q, false);
HTMLTabs tabs = new HTMLTabs();
{
StringBuffer toTab = new StringBuffer();
Algorithm alg = new ProcessNewInput_v2();
alg.q = q;
alg.out = toTab;
alg.runIt();
tabs.add("Match input with patterns", toTab);
}
{
StringBuffer toTab = new StringBuffer();
Algorithm alg = new SyntacticPatternFromInput();
alg.q = q;
alg.out = toTab;
alg.runIt();
tabs.add("Make syntactic pattern", toTab);
}
appendHTML(tabs.html());
}
}
public BEAObject allowStoringMatch(Algorithm algo, BEAObject input, BEAObject pattern, Map mapping) {
BEAObject match = conceptWhereCI(BEAObject.class, "type", "Match", "pattern", pattern, "input", input, "mapping", mapping);
if (match != null) {
algo.appendHTML("Match exists: " + mod.beaLinkHTML(match));
return match;
}
algo.appendHTML(joinWithSpace(storeMatchForm(input, pattern, "good"), storeMatchForm(input, pattern, "bad")));
return null;
}
public String storeMatchForm(BEAObject input, BEAObject pattern, String label) {
return hinlinepostform(hhiddenMulti("pattern", pattern.id, "input", input.id, "label", label, "redirect", "") + hbutton(firstToUpper(label) + " match"), "action", mod.baseLink + "/storeMatch", "onsubmit", js_redirectAutoScroll2());
}
public class MakeSyntacticPatterns extends Algorithm implements Runnable {
public void run() {
for (BEAObject p : mod.beaList("Pattern")) {
appendText(p + " => " + makeSyntacticPattern(p));
}
}
}
public String syntacticPatternText(BEAObject p) {
return simpleSpacesTrim_javaTok(angleBracketVarsToStars(p.text()));
}
public BEAObject makeSyntacticPattern(BEAObject p) {
if (p == null || !p.typeIs("Pattern") || empty(p.text()))
return null;
String text = syntacticPatternText(p);
BEAObject sp = uniqCI(BEAObject.class, "type", "Syntactic Pattern", "text", text);
cset(p, "syntacticPattern", sp);
return sp;
}
public String processInputURL(String q) {
return addParamsToURL(mod.baseLink + "/query", "q", q, "algorithm", "process input");
}
public BEAObject handleInput(Algorithm algo, String q, boolean showProcessLink) {
return handleInput(algo, q, "Input", showProcessLink);
}
public BEAObject handleInput(Algorithm algo, String q, String desc, boolean showProcessLink) {
algo.appendHTML(hSingleRowTable_withSpacing((desc + ":"), tt(htmlEncode_nlToBr_withIndents(q)), !showProcessLink ? "" : targetBlank_noFollow(processInputURL(q), "Process")));
BEAObject input = mod.findInput(q);
algo.appendHTML(inputHTML(input, desc, q));
return input;
}
public String inputHTML(BEAObject input, String q) {
return inputHTML(input, "Input", q);
}
public String inputHTML(BEAObject input, String desc, String q) {
return input != null ? (desc + " exists: ") + mod.beaLinkHTML(input) : !mod.requestAuthed() && !mod.allowAnonymousInputUpload ? null : hinlinepostform(hhiddenMulti("text", q, "redirect", "") + hbutton(("Save " + desc)), "action", mod.baseLink + "/saveInput", "onsubmit", js_setRedirect());
}
public String syntacticPatternLinkHTML(BEAObject obj, String text) {
return syntacticPatternLinkHTML(obj, text, null);
}
public String syntacticPatternLinkHTML(BEAObject obj, String text, BEAObject fromInput) {
String desc = "Syntactic pattern";
return obj != null ? mod.beaLinkHTML(obj) : !mod.requestAuthed() ? null : hinlinepostform(hhiddenMulti("text", text, "fromInput", conceptIDOrNull(fromInput), "redirect", "") + hbutton(("Save " + (firstToLower(desc)))), "action", mod.baseLink + "/saveSyntacticPattern", "onsubmit", js_setRedirect());
}
public class SyntacticPatternFromInput extends Algorithm implements Runnable {
public void run() {
BEAObject input = handleInput(this, q, false);
if (countTokens(q) > 10) {
appendText("Input too long to extract syntactic patterns");
return;
}
String q2 = dropPunctuation(q);
List data = new ArrayList();
for (String pat : sortedIC(gazelle_allSyntacticPatternsFromInput(q))) {
Map mapping = matchInputWithSyntacticPattern(q2, pat);
BEAObject obj = conceptWhereIC(BEAObject.class, "type", "Syntactic Pattern", "text", pat);
Map row = litorderedmap("Syntactic Pattern", htmlEncode2(pat), "In database", syntacticPatternLinkHTML(obj, pat, input));
for (Map.Entry extends String, ? extends String> __19 : _entrySet(mapping)) {
String key = __19.getKey();
String val = __19.getValue();
row.put("Argument " + key, htmlEncode2(val));
}
data.add(row);
}
appendHTML(htmlTable2_noHtmlEncode(data));
}
}
public class ApplyTextFunctions extends Algorithm {
public void run() {
q = trim(q);
saveInput(q);
BEAObject input = handleInput(this, q, false);
LinkedHashSet objectsMade = new LinkedHashSet();
for (BEAObject f : mod.beaList("JavaX Standard Function")) {
try {
addIfNotNull(objectsMade, reactFunctionWithInput(this, f, input));
} catch (Throwable __e) {
_handleException(__e);
}
}
appendHTML(h3("Results of function calls"));
HCRUD crud = mod.makeCRUD(BEAObject.class, mod.currentReq());
HCRUD_Concepts crudData = (HCRUD_Concepts) (crud.data);
crudData.listConcepts_firstStep = () -> objectsMade;
appendHTML(crud.renderTable(true));
}
}
public class FindPath extends Algorithm {
public BreadthFirstPathFinder_withLinkType pathFinder = new BreadthFirstPathFinder_withLinkType();
public BEAObject start, dest;
public void run() {
start = mod.beaGet(parseFirstLong(q));
dest = mod.beaGet(parseSecondLong(q));
if (start == null || dest == null) {
appendText("Please supply object IDs of start and end");
return;
}
appendHTML("Looking for path from " + mod.beaToHTML(start) + " to " + mod.beaToHTML(dest));
pathFinder.getChildren = o -> cForwardAndBackRefsWithFieldIndicator(BEAObject.class, o);
pathFinder.add(start);
while (!pathFinder.nodeReached(dest) && pathFinder.step()) {
}
List> path = pathFinder.examplePathWithTypes(start, dest);
if (path == null)
appendText("No path found!");
else {
appendHTML(b("Path found!"));
appendHTML(ol(map(path, p -> {
String html = mod.beaHTML(p.a);
if (p.b == null)
return html;
String arrow = ifThenElse(p.b.forward, ">>", "<<");
return html + " " + htmlEncode2(joinNemptiesWithSpace(arrow, p.b.field, arrow));
})));
}
}
}
public class ExecuteTextQuery extends Algorithm {
public void run() {
saveInput(q = trim(q));
appendHTML(h3("Result"));
appendHTML(htmlEncode2(strOrEmpty(executeTextQuery(q))));
}
}
public class InputSummary extends Algorithm {
public void run() {
BEAObject mainInput = saveInput(q = trim(q));
Collection inputs = conceptsWhere(BEAObject.class, "type", "Input", "text", q);
if (l(inputs) > 1)
appendHTML("Note: Input appears " + l(inputs) + " times in the database: " + joinWithSpace(map(o -> mod.beaToHTML(o), inputs)));
for (BEAObject input : inputs) {
if (input != mainInput) {
appendHTML(hr());
appendHTML("Input: " + input);
}
Collection rewrites = mod.beaBackRefs(input, "Rewrite");
if (empty(rewrites))
appendHTML(h3("No rewrites"));
else
for (Pair __17 : iterateWithIndex1(rewrites)) {
int i = pairA(__17);
BEAObject r = pairB(__17);
appendHTML("Rewrite " + i + ": " + ahref(mod.beaURL(r), tok_dropCurlyBrackets(r.text())));
}
}
}
}
public class ApplyPatternList extends Algorithm {
public String additionalInputs() {
return hselect("patternListID", mapToKey(__62 -> conceptID(__62), mod.beaList("Pattern List")), req.get("patternListID"));
}
public void run() {
BEAObject input = handleInput(this, q = trim(q), false);
BEAObject patternList = mod.beaGet("patternListID", req);
if (patternList == null)
return;
List patterns = (List) (cget("patterns", patternList));
appendHTML("Pattern list: " + mod.beaHTML(patternList));
for (BEAObject pattern : unnullForIteration(patterns)) {
appendText("Trying pattern " + pattern);
checkPattern(this, input, q, pattern);
}
}
}
public class ApplyAlgorithmObject extends Algorithm {
public String additionalInputs() {
return hselect("algorithmID", mapToKey(__63 -> conceptID(__63), concatLists(wideningListCast(Concept.class, list(BEARegExpReplacement.class)), wideningListCast(Concept.class, conceptsWhereIC(UserPost.class, "type", "JavaX Code (HTML Bot)")))), req.get("algorithmID"));
}
public void runLiveMode() {
Concept algo = getConcept(parseLongOpt(req.get("algorithmID")));
appendHTML("Algorithm object: " + htmlEncode2_nlToBr(str(algo)));
if (algo instanceof UserPost) {
Object result = mod.callHtmlBot_dropMadeByComment(((UserPost) algo).id, req.params());
appendText("Result: " + result);
} else if (algo instanceof BEARegExpReplacement) {
Object result = ((BEARegExpReplacement) algo).apply(q);
appendText("Result: " + result);
} else if (algo == null)
appendText("Algorithm object not found");
else
appendText("Unknown algorithm object type: " + _className(algo));
}
}
public class ApplyRegExpReplacement extends Algorithm {
public void run() {
BEARegExpReplacement regExpReplacement = (BEARegExpReplacement) (mod.beaGet(q));
if (regExpReplacement == null) {
appendText("Please enter reg exp replacement ID");
return;
}
appendHTML("Applying " + beaHTML(regExpReplacement));
for (BEAObject input : sortedByConceptIDDesc(mod.beaList("Input"))) {
String text = input.text();
String replaced = regExpReplacement.apply(text);
if (neq(text, replaced)) {
appendHTML(hr());
appendText(" " + text + "\n=> " + replaced);
appendPossibleRewrite(this, input, replaced, litmap("f_regularExpression", regExpReplacement.id, "metaInfo_regularExpression", "concept"));
}
}
}
}
public class BackEndAlgorithm extends Algorithm {
public String prefix() {
return shortClassName(this) + ": ";
}
@Override
public void appendText(String s) {
printWithIndent(prefix(), s);
}
@Override
public void appendHTML(String s) {
appendText(htmlDecode_dropTags(s));
}
@Override
public void addNonMatch(Runnable r) {
r.run();
}
}
public class MatchInputWithAllPatternLists extends Algorithm {
public void run() {
BEAObject input = saveInput(q);
for (BEAObject patternList : sortedByConceptIDDesc(beaList("Pattern List"))) reactInputWithPatternList(this, input, q, patternList, 1, 2);
}
}
public class RunTestCasesOnCodePost extends Algorithm {
public String additionalInputs() {
MultiSet ms = distinctCIFieldValuesOfConcepts_multiSet(BEAObject.class, "type");
List types = filter(pairsA(multiSetToPairsByPopularity(ms)), type -> cic(type, "test case"));
return "Test case type: " + hselect_list("testCaseType", types, req.get("testCaseType")) + " " + hselect("algorithmID", mapToKey(__64 -> conceptID(__64), conceptsWhereIC(UserPost.class, "type", "JavaX Code (HTML Bot)")), req.get("algorithmID"));
}
public void run() {
String testCaseType = req.get("testCaseType");
Concept algo = getConcept(parseLongOpt(req.get("algorithmID")));
Collection testCases = beaList(testCaseType);
appendText(n2(testCases, "test case") + " found for type " + quote(testCaseType));
appendHTML("Algorithm object: " + htmlEncode2_nlToBr(str(algo)));
if (!(algo instanceof UserPost))
return;
Scorer scorer = new Scorer();
for (BEAObject testCase : testCases) {
ping();
Map fields = toCIMap(objectToMap(testCase));
String input = str(getAny(fields, "input"));
String expected = str(getAny(fields, "output", "result"));
String result = str(mod.callHtmlBot_dropMadeByComment(algo.id, litmap("q", input)));
boolean ok = eq(result, expected);
appendText((ok ? "OK" : "BAD") + ": Input: " + quote(input) + ", expected output: " + quote(expected) + ", result: " + quote(result));
scorer.add(ok);
}
appendText(str(scorer));
}
}
public void reactInputWithPatternList(Algorithm algo, BEAObject input, String text, BEAObject patternList, int level, int recursionLevels) {
Pair> match = matchInputWithPatternList(text, patternList);
algo.appendHTML(hr());
algo.appendHTML(joinNemptiesWithColon(level == 1 ? beaHTML(patternList) : null, stringIf(match == null, "No match")));
if (match != null) {
BEAObject pattern = match.a;
Map mapping = match.b;
algo.appendHTML("Matched as " + beaHTML(pattern));
algo.appendText(renderMappingAsText(mapping));
if (input != null) {
BEAObject matchObj = uniqCI(algo.localConcepts, BEAObject.class, "type", "Match", "input", input, "patternList", patternList, "winningPattern", pattern, "mapping", mapping);
algo.appendHTML("Match saved as: " + beaHTML(matchObj));
}
if (level < recursionLevels) {
algo.appendHTML_raw("");
for (Map.Entry extends String, ? extends String> __18 : _entrySet(mapping)) {
String key = __18.getKey();
String subInput = __18.getValue();
if (!eqic(key, text)) {
algo.appendHTML_raw("");
algo.appendText("Processing sub-Input: " + subInput);
reactInputWithPatternList(algo, null, subInput, patternList, level + 1, recursionLevels);
algo.appendHTML_raw(" ");
}
}
algo.appendHTML_raw(" ");
}
}
}
public int patternSpecificity(BEAObject pattern) {
return countWordsWithoutAngleBracketedAndStars(pattern.text());
}
public List syntacticPatternsSortedBySpecificityDesc() {
return sortedByCalculatedFieldDesc(__42 -> patternSpecificity(__42), mod.beaList("Syntactic Pattern"));
}
public Object executeTextQuery(String s) {
Matches m = new Matches();
if (match3_withIntsAndIDs("all references in field of object ", s, m)) {
Object value = cget(mod.beaGet(m.unq(1)), m.unq(0));
return value instanceof Collection ? instancesOf(BEAObject.class, (Collection) value) : value instanceof BEAObject ? ll((BEAObject) value) : ll();
}
return new QueryNotUnderstood(s);
}
static public class QueryNotUnderstood implements IFieldsToList {
public String s;
public QueryNotUnderstood() {
}
public QueryNotUnderstood(String s) {
this.s = s;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + s + ")";
}
public boolean equals(Object o) {
if (!(o instanceof QueryNotUnderstood))
return false;
QueryNotUnderstood __23 = (QueryNotUnderstood) o;
return eq(s, __23.s);
}
public int hashCode() {
int h = 1528655894;
h = boostHashCombine(h, _hashCode(s));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { s };
}
}
public String beaToHTML(BEAObject o) {
return mod.beaToHTML(o);
}
public String beaHTML(BEAObject o) {
return mod.beaHTML(o);
}
public String beaURL(BEAObject o) {
return mod.beaURL(o);
}
public boolean isSyntacticPattern(BEAObject pat) {
return pat != null && pat.typeIs("Syntactic pattern");
}
public String patternTextWithAngleBracketVars(BEAObject pat) {
String text = pat.text();
return isSyntacticPattern(pat) ? starsToAngleBracketedNumbers(text) : text;
}
public boolean isCommentOrFeedback(BEAObject o) {
return o != null && o.typeIsOneOf("Comment", "Useful", "Feedback");
}
public String feedbackHTML(BEAObject o) {
Collection l = filter(__43 -> isCommentOrFeedback(__43), mod.beaBackRefs(o));
return joinWithBR(map(l, c -> c.typeIs("Comment") ? ahref(beaURL(c), htmlEncode2(c.text())) : beaHTML(c)));
}
public String bestInputURL(String text) {
text = trim(text);
BEAObject input = mod.findInput(text);
return input != null ? beaURL(input) : processInputURL(text);
}
public String bestInputHTML(String text) {
if (empty(text))
return "";
return ahref(bestInputURL(text), span(htmlEncode2(text), "style", "background-color: #ccc"));
}
public String performRewrite(BEAObject rewrite, Map mapping) {
String rewriteText = starsToAngleBracketedNumbers(rewrite.text());
return replaceAngleBracketVars(rewriteText, mapping);
}
public Pair exampleForPatternRewrite(BEAObject pattern, BEAObject rewrite) {
String patText = patternTextWithAngleBracketVars(pattern);
Set vars = collectAngleBracketVars(patText);
Map mapping = mapToValues_ciMap(vars, var -> "$" + var);
return pair(replaceAngleBracketVars(patText, mapping), performRewrite(rewrite, mapping));
}
public class RegExpToPossibleSubInputs extends Algorithm implements IFieldsToList {
public BEAObject input;
public BEAObject regExp;
public RegExpToPossibleSubInputs() {
}
public RegExpToPossibleSubInputs(BEAObject input, BEAObject regExp) {
this.regExp = regExp;
this.input = input;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + input + ", " + regExp + ")";
}
public boolean equals(Object o) {
if (!(o instanceof RegExpToPossibleSubInputs))
return false;
RegExpToPossibleSubInputs __16 = (RegExpToPossibleSubInputs) o;
return eq(input, __16.input) && eq(regExp, __16.regExp);
}
public int hashCode() {
int h = -208954156;
h = boostHashCombine(h, _hashCode(input));
h = boostHashCombine(h, _hashCode(regExp));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { input, regExp };
}
public void run() {
String text = input.text();
String pat = regExp.text();
for (IntRange r : regexpFindRangesIC(pat, text)) appendHTML(beaHTML(csetAndReturn(uniq(localConcepts, BEAObject.class, "type", "Possible Sub-Input", "input", input, "characterRange", r, "text", substring(text, r)), "regExp", regExp, "byAlgorithm", shortName(this))));
}
}
public void appendPossibleRewrite(Algorithm algo, BEAObject input, String text) {
appendPossibleRewrite(algo, input, text, null);
}
public void appendPossibleRewrite(Algorithm algo, BEAObject input, String text, Map moreInfo) {
BEAObject existing = input == null ? null : conceptWhereIC(BEAObject.class, "type", "Rewrite", "input", input, "text", text, "label", "good");
if (existing != null)
algo.appendHTML("Rewrite exists: " + mod.beaLinkHTML(existing));
else if (input != null)
algo.appendHTML(joinWithSpace(map(ll("good", "bad"), label -> hinlinepostform(hhiddenMulti("action", "create", "f_type", "Rewrite", "f_text", text, "f_input", input.id, "metaInfo_input", "concept", "f_label", label, "redirectAfterSave", "") + hhiddenMulti(moreInfo) + hbutton(firstToUpper(label) + " rewrite", "onclick", js_redirectAutoScroll2()), "action", mod.crudLink(BEAObject.class)))));
}
public BEAObject reactFunctionWithInput(Algorithm algo, BEAObject f, BEAObject input) {
String fName = getString("name", f);
if (!isIdentifier(fName))
return null;
if (!isSafeStandardFunction(fName)) {
{
if (algo != null)
algo.addNonMatch(new Runnable() {
public void run() {
try {
algo.appendText("Function " + fName + " not safe");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "algo.appendText(\"Function \" + fName + \" not safe\");";
}
});
}
return null;
}
BEAObject o = cnew(algo.localConcepts, BEAObject.class, "type", "Function Result", "function", f, "functionCalled", fName, "input", input, "calculating", true);
print("Function result: " + o);
try {
Object holder = getStandardFunctionHolder(fName);
Object result = evalWithTimeoutOrFail(10.0, () -> call(holder, fName, input.text()));
if (!(result instanceof List) && isStringCollection(result))
result = asList((Collection) result);
if (result == null)
cset(o, "resultType", "null");
else if (result instanceof String)
cset(o, "resultType", "string", "result", result);
else if (isStringList(result))
cset(o, "resultType", "list of strings", "result", result);
else
cset(o, "result", "other" + appendRoundBracketed(className(result)), "result", shorten(1000, str(result)));
} catch (Throwable e) {
cset(o, "resultType", "error", "error", getStackTrace(e));
}
cset(o, "calculating", null);
return o;
}
public BEAObject convertSyntacticToSemanticMatch(BEAObject match, BEAObject semanticPattern) {
BEAObject syntacticPattern = beaGet("pattern", match);
BEAObject input = beaGet("input", match);
String pat2 = syntacticPattern.text();
String pat1 = semanticPattern.text();
List vars = new ArrayList();
String pat2b = angleBracketVarsToStars(pat1, vars);
String warning = eq(pat2, pat2b) ? null : "Patterns don't match: " + quote(pat2) + " / " + quote(pat2b);
Map mapping = (Map) (cget("mapping", match));
Map mapping2 = mapKeys(mapping, key -> or(_get(vars, parseInt(key) - 1), key));
mapping2 = putKeysFirst(vars, mapping2);
BEAObject match2 = uniqCI(BEAObject.class, "type", "Match", "input", input, "pattern", semanticPattern, "fromSyntacticMatch", match);
cset(match2, "mapping", mapping2);
return match2;
}
public Collection convertSyntacticToSemanticMatches(BEAObject match) {
List out = new ArrayList();
BEAObject syntacticPattern = beaGet("pattern", match);
for (BEAObject semanticPattern : mod.beaList("Pattern", "syntacticPattern", syntacticPattern)) {
try {
out.add(convertSyntacticToSemanticMatch(match, semanticPattern));
} catch (Throwable __e) {
_handleException(__e);
}
}
return out;
}
public Collection convertSyntacticToSemanticMatchesForWholePattern(BEAObject pattern) {
if (pattern.typeIs("Syntactic Pattern"))
return concatMap_lists(__65 -> convertSyntacticToSemanticMatches(__65), mod.beaList("Match", "pattern", pattern));
else {
List out = new ArrayList();
BEAObject syntacticPattern = beaGet("syntacticPattern", pattern);
if (syntacticPattern != null)
for (BEAObject match : mod.beaList("Match", "pattern", syntacticPattern)) out.add(convertSyntacticToSemanticMatch(match, pattern));
return out;
}
}
public BEAObject beaGet(String field, BEAObject o) {
return mod.beaGet(field, o);
}
public Collection beaList(String type, Object... params) {
return mod.beaList(type, params);
}
public int simpleObjectScore(BEAObject o) {
int score = 0;
if (eqic_gen(getOpt("label", o), "good"))
++score;
else if (eqic_gen(getOpt("label", o), "bad"))
--score;
Collection l = findBackRefsWithField(BEAObject.class, "object", o);
score += countWhereCI(l, "type", "Useful");
score -= countWhereCI(l, "type", "Bad");
return score;
}
public List sortedBySimpleObjectScore(int minScore, Collection l) {
return sortedByCalculatedFieldDesc(__44 -> simpleObjectScore(__44), filter(l, o -> simpleObjectScore(o) >= minScore));
}
public BEAObject createPatternListFromUsefulSyntacticPatterns() {
List patterns = sortedBySimpleObjectScore(0, beaList("Syntactic Pattern"));
return mod.autoMigrateToCustomClass(uniqCI(BEAObject.class, "type", "Pattern List", "byFunction", "createPatternListFromUsefulSyntacticPatterns", "patterns", patterns));
}
public Map> algorithms() {
return litorderedmap("Process new input v3", (IF0) () -> new ProcessNewInput_v3(), "Process new input v2", (IF0) () -> new ProcessNewInput_v2(), "Process new input", (IF0) () -> new ProcessNewInput(), "Run pattern", (IF0) () -> new RunPattern(), "Find rewrites for match", (IF0) () -> new FindRewrites(), "Reverse input (test algorithm)", (IF0) () -> new ReverseInput(), "Timeout test", (IF0) () -> new TimeoutTest(), "Syntactic pattern from input", (IF0) () -> new SyntacticPatternFromInput(), "Apply all text functions", (IF0) () -> new ApplyTextFunctions(), "Find Path", (IF0) () -> new FindPath(), "Execute text query", (IF0) () -> new ExecuteTextQuery(), "Make syntactic patterns for all patterns in DB", (IF0) () -> new MakeSyntacticPatterns(), "Input summary", (IF0) () -> new InputSummary(), "Apply pattern list", (IF0) () -> new ApplyPatternList(), "Apply regular expression replacement to all inputs", (IF0) () -> new ApplyRegExpReplacement(), "Match input with all pattern lists", (IF0) () -> new MatchInputWithAllPatternLists(), "Apply algorithm object", (IF0) () -> new ApplyAlgorithmObject(), "Run test cases on code post", (IF0) () -> new RunTestCasesOnCodePost());
}
public void putAlgorithmsInDatabase() {
for (String name : keys(algorithms())) uniq(BEAObject.class, "type", "Classic Query Algorithm", "name", name);
}
}
abstract static public class GazelleBEA extends DynGazelleRocks {
static public boolean _switchableField_mirrorBEAObjects = true;
public boolean mirrorBEAObjects = false;
static public boolean _switchableField_enableAutoRuns = true;
public boolean enableAutoRuns = true;
static public boolean _switchableField_enableNewBEAObjectNotis = true;
public boolean enableNewBEAObjectNotis = true;
static public boolean _switchableField_printAllConceptChanges = true;
public boolean printAllConceptChanges = false;
static public boolean _switchableField_useShadowLogger = true;
public boolean useShadowLogger = false;
static public boolean _switchableField_autoActivateDynamicObjects = true;
public boolean autoActivateDynamicObjects = true;
static public boolean _switchableField_reloadWhenMainLibUpdates = true;
public boolean reloadWhenMainLibUpdates = false;
static public boolean _switchableField_baseSystemVersion = true;
public String baseSystemVersion = "1";
static public boolean _switchableField_backupFrequency = true;
public int backupFrequency = 5;
transient public boolean allObjectsActivated = false;
transient public Throwable startError;
public String activateOnlyTheseIDs;
public String dontActivateTheseIDs;
transient public ReliableSingleThread_Multi rstAutoRuns = dm_rstMulti(this, 1000, __37 -> performAutoRuns(__37));
transient public Q notificationQ;
transient public ReliableSingleThread_Multi rstDistributeNewObject = dm_rstMulti(this, 1000, __38 -> distributeNewObject_impl(__38));
transient public Set newObjectsDistributed = weakSet();
transient public ReliableSingleThread_Multi rstUpdateBEAMirrors = dm_rstMulti(this, 100, c -> c.updateMirrorPost());
transient public ReliableSingleThread_Multi rstAutoActivateDynamicObjects = dm_rstMulti(this, 100, __39 -> autoActivateDynamicObject(__39));
transient public BEACalculations calculations = new BEACalculations(this);
transient public BEACalculations calc = calculations;
transient public int newFieldsToShow = 3;
transient public boolean allowAnonymousInputUpload = true;
static public boolean _switchableField_maxInputLength = true;
public int maxInputLength = 50000;
static public boolean _switchableField_mainDomainWithProtocol = true;
public String mainDomainWithProtocol = "https://bea.gazelle.rocks";
static public boolean _switchableField_verboseQStartsAndStops = true;
public boolean verboseQStartsAndStops = false;
transient public ConceptClassesDependentValue inputsWithoutRewrites;
transient public ConceptClassesDependentValue inputsWithoutMatches;
transient public ConceptClassesDependentValue syntacticPatternsWithoutRewrites;
transient public Set deadClassPaths = syncLinkedHashSet();
transient public x30_pkg.x30_util.BetterThreadLocal beaThreadOwner = new x30_pkg.x30_util.BetterThreadLocal();
public boolean verboseClassLoading = false;
transient public boolean saveAllQsAsInput = true;
transient public boolean moveNavItemsToMisc = false;
transient public boolean additionalCommandsForObjects = true;
transient public boolean exportUsersInVM = false;
transient public boolean quickDBReloadEnabled = false;
public Concepts _getReloadData() {
return db_mainConcepts();
}
public void _setReloadData_early(Object data) {
quickImportMainConcepts(data, () -> quickDBReloadEnabled);
}
public void init() {
super.init();
botName = heading = adminName = "Gazelle";
enableVars = true;
showTalkToBotLink = false;
phoneNumberSpecialInputField = false;
showMetaBotOnEveryPage = false;
}
public Class lookForClass(ClassLoader cl, String name) {
try {
if (!name.startsWith(DynClassName_mainPrefixForVM()))
return null;
if (verboseClassLoading)
print("Looking for class " + name);
DynClassName dcn = DynClassName_parse(name);
if (dcn == null)
dcn = DynClassName_parseOther(name);
if (dcn == null) {
vmBus_send("lookingForClass_noDCNParse", name);
return null;
}
String subPath = vmClassNameToSubPath(dcn.fullClassNameForVM());
File byteCode = dcn.byteCodeFile();
vmBus_send("lookingForClass_haveByteCodeFile", byteCode);
if (classLoaderContainsByteCodePath(cl, byteCode)) {
vmBus_send("lookingForClass_haveByteCodePath", byteCode);
return null;
}
boolean exists = fileExistsInInDirOrZip(byteCode, subPath);
printVars("exists", exists, "subPath", subPath, "byteCode", byteCode);
if (!exists) {
vmBus_send("lookingForClass_subPathNotInByteCode", byteCode, subPath);
throw fail("Class not found: " + subPath + " in " + byteCode);
}
addByteCodePathToClassLoader(cl, byteCode);
assertTrue("Byte code added", classLoaderContainsByteCodePath(cl, byteCode));
vmBus_send("lookingForClass_byteCodePathAdded", byteCode);
return (Class) call(cl, "super_findClass", name);
} catch (Throwable __e) {
_handleException(__e);
}
return null;
}
public void db() {
main.db();
}
public void startDB() {
ClassLoader cl = dm_moduleClassLoader();
setOpt(cl, "verbose", verboseClassLoading);
setFieldToIF1Proxy(cl, "findClass_extension", (IF1) name -> {
vmBus_send("lookingForClass", cl, name);
Class c = lookForClass(cl, name);
vmBus_send("lookingForClass_result", cl, name, c);
return c;
});
Object classFinder = _defaultClassFinder();
db_mainConcepts().classFinder = new F1() {
public Class get(String name) {
try {
AutoCloseable __32 = enter();
try {
print("Deserializing class " + name);
try {
String name2 = dropPrefix(mcName() + "$", name);
String mainPrefix = dotToDollar(DynClassName_mainPrefix());
if (name2.startsWith(mainPrefix)) {
String vmName = DynClassName_parse(name2).fullClassNameForVM();
if (verboseClassLoading)
print("Loading dynamic class " + vmName);
Class c = classLoader_loadClass(module(), vmName);
return c;
}
Class c = (Class) (callF(classFinder, name));
print("c", c);
return c;
} catch (Throwable e) {
printStackTrace(e);
throw rethrow(e);
}
} finally {
_close(__32);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp enter();\r\n print(\"Deserializing class \" + name);\r\n try {\r\n ...";
}
};
db();
Concepts concepts = db_mainConcepts();
concepts.useBackRefsForSearches = true;
concepts.newBackupEveryXMinutes = backupFrequency;
fixConceptIDs();
inputsWithoutRewrites = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Input"), c -> empty(beaBackRefs(c, "Rewrite"))));
inputsWithoutMatches = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Input"), c -> empty(beaBackRefs(c, "Match"))));
syntacticPatternsWithoutRewrites = new ConceptClassesDependentValue(litset(BEAObject.class), () -> countPred(beaList("Syntactic Pattern"), c -> empty(beaBackRefs(c, "Rewrite"))));
if (useShadowLogger) {
ConceptsShadowLogger shadowLogger = new ConceptsShadowLogger(db_mainConcepts());
shadowLogger.install();
shadowLogger.writer = filePrintWriter_append(programFile("shadow.log"));
dm_doEvery(10.0, new Runnable() {
public void run() {
try {
shadowLogger.flush();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "shadowLogger.flush();";
}
});
ownResource(shadowLogger);
}
if (printAllConceptChanges)
printAllConceptChanges();
}
public Map emergencyFlags() {
return (Map) parseEqualsProperties(joinNemptiesWithEmptyLines(loadTextFile(programFile("gazelle-emergency-options.txt")), loadTextFile(javaxDataDir("gazelle-emergency-options.txt"))));
}
public void start() {
try {
start2();
} catch (Throwable e) {
_handleException(e);
startError = e;
}
}
public void start2() {
print("Module ID: " + dm_moduleID());
useBotNameAsModuleName = false;
setOptAllDyn_pcall(module(), pnl("emergencyFlags", emergencyFlags()));
change();
String name = actualMCDollar() + "BEAObject";
print("name", name);
assertEquals(BEAObject.class, callF(defaultDefaultClassFinder(), name));
assertEquals(ConceptWithGlobalID.class, callF(defaultDefaultClassFinder(), mcDollar() + "ConceptWithGlobalID"));
botDisabled = true;
storeBaseClassesInStructure = true;
super.start();
assertSameVerbose("miscMap me", db_mainConcepts().miscMapGet(DynNewBot2.class), this);
assertSameVerbose("beaMod()", main.beaMod(), this);
print("main concepts: " + db_mainConcepts() + ", count: " + db_mainConcepts().countConcepts());
print(renderConceptClassesWithCount(db_mainConcepts()));
print("Inputs: " + n2(beaCount("Input")));
showCRUDToEveryone = true;
dm_onSnippetTranspiled(mainLibID, new Runnable() {
public void run() {
try {
if (reloadWhenMainLibUpdates)
dm_reloadModule();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (reloadWhenMainLibUpdates)\r\n dm_reloadModule();";
}
});
if (!enabled)
return;
if (exportUsersInVM) {
dm_vmBus_answerToMessage("lookupGazelleUser", new F3() {
public Object get(String name, String pw, String salt) {
try {
if (!eq(salt, passwordSalt()))
return null;
User user = conceptWhereCI(User.class, "name", name);
if (user == null)
return null;
if (!eq(getVar(user.passwordMD5), hashPW(pw)))
return null;
return user;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (!eq(salt, passwordSalt())) null;\r\n User user = conceptWhereCI User...";
}
});
}
rstUpdateBEAMirrors.addAll(list(BEAObject.class));
newObjectsDistributed.addAll(list(BEAObject.class));
onIndividualConceptChange_notOnAllChanged(BEAObject.class, o -> {
if (enableAutoRuns)
rstAutoRuns.add(o);
if (enableNewBEAObjectNotis && newObjectsDistributed.add(o))
rstDistributeNewObject.add(o);
});
notificationQ = dm_startQ();
dm_doEvery(5 * 60.0, new Runnable() {
public void run() {
try {
{
AutoCloseable __33 = enter();
try {
print(new ConceptsRefChecker(db_mainConcepts()).runAndFixAll());
} finally {
_close(__33);
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "{ temp enter();\r\n print(ConceptsRefChecker(db_mainConcepts()).runAndFixA...";
}
});
setField("activateOnlyTheseIDs", nemptyLinesLL(loadTextFile(programDir("gazelle-activate-only")), loadTextFile(javaxDataDir("gazelle-activate-only"))));
Set ids = activateOnlyTheseIDs();
Set antiIDs = dontActivateTheseIDs();
print("Object IDs to activate: " + (ids == null ? "ALL" : ids));
if (nempty(antiIDs))
print("Object IDs not to activate: " + (ids == null ? "ALL" : ids));
for (BEAObject bea : list(BEAObject.class)) if ((ids == null || contains(ids, bea.id)) && !contains(antiIDs, bea.id)) {
callActivate(bea);
}
for (BEAObject o : cloneList(beaList("Live WebSocket"))) cdelete(o);
allObjectsActivated = true;
print("All objects activated");
}
public void makeIndices() {
super.makeIndices();
indexConceptClass(BSettings.class);
indexConceptFieldDesc(BEAObject.class, "_modified");
indexConceptFieldCIWithTopTen(BEAObject.class, "type");
indexConceptFieldIC(BEAObject.class, "text");
indexConceptFieldIC(BEAObject.class, "purpose");
}
public boolean isMaster(Req req) {
return req == null ? null : req.masterAuthed;
}
@Override
public List crudClasses(DynGazelleRocks.Req req) {
return listPlus(super.crudClasses(req), BEAObject.class);
}
public Set hiddenCrudClasses() {
Set set = super.hiddenCrudClasses();
addAll(set, Conversation.class, ExecutedStep.class, InputHandled.class);
return set;
}
public String authFormHeading() {
return h3(adminName);
}
transient public IF0 authFormMoreContent;
public String authFormMoreContent() {
return authFormMoreContent != null ? authFormMoreContent.get() : authFormMoreContent_base();
}
final public String authFormMoreContent_fallback(IF0 _f) {
return _f != null ? _f.get() : authFormMoreContent_base();
}
public String authFormMoreContent_base() {
return super.authFormMoreContent();
}
@Override
public void makeFramer(DynGazelleRocks.Req req) {
super.makeFramer(req);
if (!allObjectsActivated)
req.framer.add(p("WARNING: Start failure"));
if (startError != null)
req.framer.add(pre_htmlEncode("WARNING: Start error\n\n" + renderStackTrace(startError)));
req.framer.addInHead(hjs_selectize());
req.framer.addInHead(hjs_selectizeClickable());
req.framer.addInHead(hjs_autoExpandingTextAreas());
}
@Override
public HCRUD_Concepts crudData(Class c, DynGazelleRocks.Req _req) {
Req req = (Req) _req;
HCRUD_Concepts cc = super.crudData(c, req);
if (c == BEAObject.class) {
cc.lsMagic = true;
cc.humanizeFieldNames = false;
cc.convertConceptValuesToRefs = true;
cc.itemName = () -> "BEA Object";
cc.addRenderer("meta_code", new HCRUD_Data.AceEditor(80, 20));
cc.titleForObjectID = id -> beaHTML(beaGet(toLong(id)));
cc.isEditableValue = o -> cc.isEditableValue_base(o) && !eq(shortClassName(o), "MultiSet");
cc.conceptClassForComboBoxSearch = (info, query) -> {
if (endsWith(info, "_nativeValue"))
return Concept.class;
return cc.conceptClassForComboBoxSearch_base(info, query);
};
cc.comboBoxSearchBaseItems = (info, query) -> {
Matches m = new Matches();
printVars("comboBoxSearchBaseItems", "info", info);
if (jMatchStart("type=", info, m)) {
var l = beaList(m.unq(0));
print("Got " + nItems(l));
return cc.comboBoxItems(l);
}
return cc.comboBoxSearchBaseItems_base(info, query);
};
cc.massageItemMapForUpdate = (o, map) -> {
if (!isMaster(req)) {
Object createdByOld = cget("createdBy", o);
if (createdByOld != null || map.get("createdBy") != user(req))
map.remove("createdBy");
}
};
cc.onCreate.add(o -> cset(o, "createdBy", currentUser()));
cc.getObjectForDuplication = id -> {
BEAObject o = beaGet(toLong(id));
Map item = cc.getObjectForDuplication_base(id);
item.put("createdBy", req.auth.user.get());
item.put("meta_createdFrom", o);
item = or((Map) pcallOpt(cget("cleanObjectForDuplication", websiteEnhancersObject()), "cleanObjectForDuplication", o, item), item);
return item;
};
cc.emptyObject = () -> {
Map item = cc.emptyObject_base();
item.put("type", "");
return item;
};
Set deletableRefs = litciset("Match");
cc.objectCanBeDeleted = id -> {
BEAObject o = (BEAObject) (cc.conceptForID(id));
return userCanEditObject(user(req), o) && all(findBackRefs(BEAObject.class, o), x -> contains(deletableRefs, x.type()));
};
cc.actuallyDeleteConcept = o -> {
deleteConcepts(filter(findBackRefs(BEAObject.class, o), o2 -> contains(deletableRefs, o2.type())));
cdelete(o);
};
}
return cc;
}
public boolean newLinkTargetBlank_base(Class c) {
return super.newLinkTargetBlank_base(c) || c == BEAObject.class;
}
@Override
public HCRUD makeCRUD(Class c, DynGazelleRocks.Req req, HTMLFramer1 framer) {
HCRUD crud = super.makeCRUD(c, req, framer);
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
crud.showOnlySelected = true;
crud.showSearchField = true;
if (data.customFilter == null)
crud.descending = true;
crud.cleanItemIDs = true;
if (c == BEAObject.class) {
crud.allowFieldRenaming = true;
var renderValue_old = crud.renderValue;
crud.renderValue = (field, value) -> {
String html = crud.renderValue_fallback(renderValue_old, field, value);
return addShowMoreButton(html);
};
crud.haveSelectizeClickable = true;
crud.cellColumnToolTips = true;
crud.unshownFields = litset("mirrorPost", "globalID");
crud.uneditableFields = litset("log");
crud.showTextFieldsAsAutoExpandingTextAreas = true;
crud.duplicateInNewTab = true;
crud.customizeACEEditor = ace -> {
ace.onKeyDown = "function(event) { " + jquery_submitFormOnCtrlEnter() + " }";
};
HCRUD_Concepts cc = (HCRUD_Concepts) (crud.data);
String typeFilter = req.get("type");
if (nempty(typeFilter))
cc.addCIFilter("type", typeFilter);
crud.renderCmds = map -> {
BEAObject o = getConcept(BEAObject.class, crud.itemIDAsLong(map));
if (o == null)
return "";
List cmds = new ArrayList();
addAll(cmds, allToString(optCast(Collection.class, pcall(o, "cmds"))));
if (fileNotEmpty(javaSourceFileForObject(o)))
cmds.add(targetBlank(baseLink + "/javaSource?id=" + o.id, "Show Java source"));
for (String field : ll("text", "what", "type")) {
String text = getStringOpt(o, field);
if (nempty(text))
cmds.add(targetBlank_noFollow(addParamsToURL(baseLink + "/query", "q", text, "algorithm", "process input"), "Use field " + quote(field) + " as query"));
}
if (o.typeIs("Input")) {
cmds.add(ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Pattern For Input", "f_type", "Pattern", "f_text", getStringOpt("text", o), "f_shouldMatch", o.id, "metaInfo_shouldMatch", "concept"), "Add pattern"));
cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.text(), "algorithm", "Apply all text functions"), "Apply all text functions"));
}
if (o.typeIs("Pattern"))
cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.id, "algorithm", "Run pattern"), "Try-run pattern against all inputs"));
if (o.typeIsOneOf("Pattern", "Syntactic Pattern")) {
cmds.add(ahref(appendParamsToURL(baseLink + "/reactAllInputsWithPattern", "patternID", o.id), "React pattern with all inputs"));
cmds.add(ahref(appendParamsToURL(baseLink + "/convertSyntacticToSemanticMatchesForWholePattern", "patternID", o.id), "Convert all syntactic matches to semantic matches"));
}
if (o.typeIs("Match")) {
cmds.add(ahref(appendParamsToURL(baseLink + "/query", "q", o.id, "algorithm", "Find rewrites for match"), "Find rewrites"));
if (beaTypeIs(beaGet("pattern", o), "Syntactic Pattern"))
cmds.add(ahref(appendParamsToURL(baseLink + "/convertSyntacticToSemanticMatches", "matchID", o.id), "Convert to semantic matches"));
}
cmds.add(targetBlank(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "newField1_name", "inReferenceTo", "newField1_type", "BEAObject", "newField1_conceptValue", o.id), "Reference this"));
cmds.add(ahref(addParamsToURL(baseLink + "/markUseful", "redirect", beaShortURL(o), "objectID", o.id), "Mark useful"));
cmds.add(ahref(addParamsToURL(baseLink + "/markBad", "redirect", beaShortURL(o), "objectID", o.id), "Mark bad"));
cmds.add(addCommentHTML(o));
if (o.typeIsOneOf("Script", "Step in script") || eqic(beforeVerticalBar(o.type()), "Instruction"))
cmds.add(ahref(addParamsToURL(baseLink + "/runInstruction", "instruction", o.id), "Run"));
if (o.typeIs("Function Result")) {
if (eqic(cget("resultType", o), "string"))
cmds.add(ahref(addParamsToURL(baseLink + "/convertResultToInput", "result", o.id), "Convert to input"));
}
if (o.typeIs("Auto Run"))
cmds.add(ahref(addParamsToURL(baseLink + "/performAutoRunOnAllObjects", "autoRun", o.id), "Run on all objects"));
if (o.getClass() != BEAObject.class)
cmds.add(ahref(addParamsToURL(baseLink + "/migrateToBase", "id", o.id), "Migrate to BEAObject"));
cmds.add(ahref(addParamsToURL(baseLink + "/performAutoRuns", "onObject", o.id), "Perform auto runs on this object"));
framer.addInHead(hjs_copyToClipboard());
cmds.add(ahref_onClick(formatFunctionCall("copyToClipboard", jsQuote(o.globalIDStr())), "Copy global ID [" + o.globalIDStr() + "]"));
List items = llNempties(crud.renderCmds_base(map), !o.typeIsOneOf("Input", "Pattern", "Syntactic Pattern") ? null : addRewriteHTML(o), !canAutoMigrate(o) ? null : ahref(addParamsToURL(baseLink + "/autoMigrate", "id", o.id), "Auto-migrate to " + shortClassName(defaultCustomClass(o))));
if (isObjectWithCode(o) && isMasterAuthed(req)) {
String link = baseLink + "/activateDynamicObject?id=" + o.id;
if (!codeHashUpToDate(o))
if (cget("meta_codeHash", o) == null)
items.add(ahref(link, "Compile new code", "title", "Object has not been compiled yet"));
else
items.add(ahref(link, "Compile changed code", "title", "Code has changed afer last compilation"));
else if (compileErrorInObject(o))
items.add("Code error. " + ahref(link, "Compile again", "title", "Object has code errors - maybe recompiling fixes them?"));
else if (o.customCodeLoaded())
items.add(ahref(link, "Compile again", "title", "Custom code is loaded. Click if you want to recompile anyway"));
else
items.add(ahref(link, "Compile & load"));
}
if (additionalCommandsForObjects) {
if (hasMethodNamed(o, "html"))
items.add(targetBlank(beaMod().baseLink + "/beaHTML/" + o.id, "Show HTML"));
if (nempty(getStringOpt("meta_code", o)))
items.add(targetBlank(addParamsToURL(beaMod().baseLink + "/beaHTML/249697", "obj", o.id, "field", "meta_code"), "Show code"));
String codeState = getStringOpt("meta_codeState", o);
if (swic(codeState, "error"))
items.add(targetBlank(addParamsToURL(beaMod().baseLink + "/beaHTML/249697", "obj", o.id, "field", "meta_codeState"), "Show compile error"));
boolean master = beaMod().isMasterAuthed();
if (hasMethod(o, "_activate")) {
boolean active = isTrue(pcallOpt(o, "_active"));
boolean shouldActivate = isTrue(getOpt(o, "meta_shouldActivate"));
if (active != shouldActivate)
items.add("Warning: Object is semi-activated");
else if (active)
items.add("Object is active");
else
items.add("Object is inactive");
if (master) {
if (!active || !shouldActivate)
items.add(ahref(addParamsToURL(beaMod().baseLink + "/activateObject", "id", o.id), "ACTIVATE"));
if (active || shouldActivate)
items.add(ahref(addParamsToURL(beaMod().baseLink + "/deactivateObject", "id", o.id), "DEACTIVATE"));
}
}
if (master) {
List methodCalls = new ArrayList();
for (Method method : methodsSortedByNameIC(allLiveMethodsBelowClass(o, BEAObject.class))) {
Map params = litorderedmap("id", o.id, "name", method.getName());
boolean incomplete = false, problem = false;
var types = method.getParameterTypes();
for (int i = 1; i <= l(types); i++) {
var argType = types[i - 1];
incomplete = true;
if (eq(argType, String.class))
params.put("arg" + i, "putArgHere");
else if (isSubclassOf(argType, BEAObject.class))
params.put("conceptArg" + i, "putArgHere");
else {
params.put("arg" + i, "missingConverterProblem");
problem = true;
}
}
String url = addParamsToURL("/callAnyMethod", params);
String html = method.getName();
if (problem)
html += appendBracketed("probably can't call, need converter");
else if (incomplete)
html += appendBracketed("fill in parameters first");
methodCalls.add(targetBlank(url, html));
}
if (nempty(methodCalls))
items.add(hPopDownButtonWithText("Call a method", methodCalls));
}
}
try {
addAll(items, o.directCmds());
} catch (Throwable __e) {
_handleException(__e);
}
try {
addAll(items, (List) callOpt(getWebsiteEnhancer("commandsForObject"), "commandsFor", o));
} catch (Throwable __e) {
_handleException(__e);
}
items.add(hPopDownButton(cmds));
return joinNemptiesWithVBar(items);
};
cc.massageItemMapForList = (item, map) -> {
BEAObject o = (BEAObject) item;
if (o.typeIs("Input")) {
Collection matches = objectsWhereNotIC(objectsWhereCI(findBackRefs(o, BEAObject.class), "type", "match"), "label", "bad");
((Map) map).put("Best Matches", new HTML(hparagraphs(lmap(__45 -> matchDescHTML(__45), takeFirst(3, matches)))));
}
String idField = crud.idField();
Object id = ((Map) map).get(idField);
if (id instanceof String)
((Map) map).put(idField, new HTML(ahref(beaShortURL(o), id)));
if (o.typeIs("Function Result")) {
Object value = getOpt("result", o);
((Map) map).put("result", new HTML(javaValueToHTML(value)));
}
if (o.typeIs("Match")) {
Map mapping = o.mapping();
if (mapping != null)
((Map) map).put("mapping", new HTML(joinWithBR(map(mapping, (k, v) -> htmlEncode2(k) + "=" + calculations.bestInputHTML(v)))));
}
if (o.getClass() != BEAObject.class)
((Map) map).put("Java Class", dropPrefix(actualMCDollar(), className(o)));
if (eq(req.get("showSimpleObjectScore"), "1"))
((Map) map).put("Simple object score", calculations.simpleObjectScore(o));
o.massageItemMapForList(((Map) map));
};
crud.massageFormMatrix = (map, matrix) -> {
for (int i = 1; i <= newFieldsToShow; i++) {
String nf = "newField" + i;
String key = (nf + "_conceptValue");
BEAObject refValue = beaGet(req.get(key));
String refSelector = crud.renderInput(key, cc.makeConceptsComboBox(key, BEAObject.class), refValue) + hjs("$(\"[name=" + key + "]\").hide()");
String nativeSelector = crud.renderInput((nf + "_nativeValue"), cc.makeConceptsComboBox((nf + "_nativeValue"), Concept.class), null) + hjs("$(\"[name=" + nf + "_nativeValue]\").hide()");
List types = ll("String", "BEAObject", "Bool", "Native");
String toggleVis = "\r\n $(\"[name=" + nf + "_value]\").toggle(value == \"String\" || value == \"Bool\");\r\n $(\"#" + nf + "_refBox\").toggle(value == \"BEAObject\");\r\n $(\"#" + nf + "_nativeSel\").toggle(value == \"Native\");\r\n ";
String type = req.get((nf + "_type"));
String typeSelector = hselect_list(types, type, "name", (nf + "_type"), "onchange", "var value = this.value;" + toggleVis);
if (nempty(type))
typeSelector += hscript("(function(value) {" + toggleVis + "})(" + jsQuote(type) + ")");
matrix.add(ll("Add field: " + htextfield((nf + "_name"), req.get((nf + "_name")), "title", "New field name"), htmlTable2_noHtmlEncode(ll(ll(crud.renderTextField((nf + "_value"), "", 40) + span(refSelector, "id", (nf + "_refBox"), "style", "display: none"), span(nativeSelector, "id", (nf + "_nativeSel"), "style", "display: none"), "Type", typeSelector)), "noHeader", true, "tableParams", litobjectarray("style", "width: 100%"))));
}
};
crud.preprocessUpdateParams = params -> {
params = cloneMap(params);
params = mapValues(params, v -> eq(v, "") ? null : v);
for (int i = 1; i <= max(newFieldsToShow, 10); i++) {
String nf = "newField" + i;
String name = trim(params.get((nf + "_name"))), type = params.get((nf + "_type")), refValue = params.get((nf + "_conceptValue")), nativeValue = params.get((nf + "_nativeValue")), value = params.get((nf + "_value"));
if (eqic(type, "BEAObject")) {
value = refValue;
params.put("metaInfo_" + name, "concept");
} else if (eqic(type, "Native")) {
value = nativeValue;
params.put("metaInfo_" + name, "concept");
} else if (eqic(type, "Bool"))
params.put("metaInfo_" + name, "bool");
if (eq(value, ""))
value = null;
if (nempty(name))
params.put(crud.fieldPrefix + name, value);
}
return params;
};
if (!isMasterAuthed(req))
cc.objectCanBeEdited = id -> userCanEditObject(user(req), (BEAObject) cc.conceptForID(id));
}
return crud;
}
public boolean userCanEditObject(User user, BEAObject o) {
return user != null && (user.isMaster || cget("createdBy", o) == user);
}
@Override
public Object servePossiblyUserlessBotFunction(DynGazelleRocks.Req req, String function, Map data, User user) {
if (eq(function, "beaExport")) {
Collection ids = concatLists(tok_integersAsLongs(urldecode(req.subURI)), tok_integersAsLongs(req.get("ids")));
var objects = map(__46 -> beaGet(__46), ids);
return serveJSON_breakAtLevels(2, "result", map(objects, obj -> litorderedmap("id", obj.id, "gid", str(obj.globalID()), "struct", obj.structureString())));
}
return super.servePossiblyUserlessBotFunction(req, function, data, user);
}
@Override
public Object serveBotFunction(DynGazelleRocks.Req req, String function, Map data, User user) {
if (eq(function, "beaList")) {
long changedAfter = toLong(data.get("changedAfter"));
double pollFor = min(bot_maxPollSeconds, toLong(data.get("pollFor")));
long startTime = sysNow();
if (changedAfter > 0 && changedAfter == now())
sleep(1);
Collection objects;
while (true) {
objects = changedAfter == 0 ? list(BEAObject.class) : conceptsWithFieldGreaterThan_sorted(BEAObject.class, "_modified", changedAfter);
if (nempty(objects) || pollFor == 0 || elapsedSeconds_sysNow(startTime) >= pollFor)
return serveJSON_breakAtLevels(2, "result", map(objects, obj -> litorderedmap("gid", str(obj.globalID()), "struct", obj.structureString())));
sleep(bot_pollInterval);
}
}
return super.serveBotFunction(req, function, data, user);
}
@Override
public Object serveOtherPage2(DynGazelleRocks.Req req) {
return serveOtherPage2((Req) req);
}
public Object serveOtherPage2(Req req) {
{
Object __31 = super.serveOtherPage2(req);
if (__31 != null)
return __31;
}
String uri = dropTrailingSlashIfNemptyAfterwards(req.uri);
Matches m = new Matches();
if (swic_notSame(uri, "/beaCRUD/", m))
return renderBEAObjectTable(req, urldecode(m.rest()));
if (eq(uri, "/inputs"))
return renderBEAObjectTable(req, "input");
if (eq(uri, "/syntacticMatchesTable"))
return hrefresh(baseLink + "/matchesTable?syntacticOnly=1");
if (eq(uri, "/matchesTable")) {
boolean syntacticOnly = eq("1", req.get("syntacticOnly"));
List list = new ArrayList();
for (BEAObject match : beaList("Match")) {
BEAObject input = cgetOpt(BEAObject.class, match, "input");
BEAObject pat = cgetOpt(BEAObject.class, match, "pattern");
if (syntacticOnly && !calculations.isSyntacticPattern(pat))
continue;
{
if (calculations.patternAlwaysMatches(pat))
continue;
}
Map mapping = match.mapping();
if (input == null || pat == null || mapping == null)
continue;
list.add(match);
}
list = sortedByCalculatedFieldDesc(list, match -> conceptID(cgetBEA("input", match)));
HTMLPaginator paginator = new HTMLPaginator();
paginator.processParams(req.params());
paginator.baseLink = addParamsToURL(baseLink, filterKeys(req.params(), p -> eq(p, "syntacticOnly")));
paginator.max = l(list);
req.framer.add(divUnlessEmpty(paginator.renderNav()));
list = subList(list, paginator.visibleRange());
List data = new ArrayList();
for (BEAObject match : list) {
BEAObject input = cgetOpt(BEAObject.class, match, "input");
BEAObject pat = cgetOpt(BEAObject.class, match, "pattern");
Map mapping = match.mapping();
String patText = calculations.patternTextWithAngleBracketVars(pat);
List tok = javaTokWithAngleBrackets(patText);
BitSet bs = new BitSet();
tok = replaceAngleBracketVars(tok, mapping, bs);
for (Pair __26 : bitSetStreaksAndNonStreaks(bs, l(tok))) {
IntRange r = pairA(__26);
boolean b = pairB(__26);
String t = joinSubList(tok, r);
replaceTokens(tok, r, b ? formatSubInput(input, t, "obj" + match.id) : htmlEncode2(t));
}
String boldenedInput = join(tok);
data.add(litorderedmap("Input", aname("obj" + match.id, joinWithBR(ahref(beaURL(input), htmlEncode2_str(call(input, "text"))), boldenedInput)), "Pattern", ahref(beaURL(pat), htmlEncode2(pat.text())), "DB object", beaHTML_justID(match), "Feedback", joinNemptiesWithSpace(calculations.feedbackHTML(match), addCommentHTML(match, "defaultComment", "good match", "redirectAfterSave", req.uriWithParams(), "text", "+"))));
}
req.framer.title = syntacticOnly ? "Syntactic matches table" : "Matches table";
req.framer.add(p());
req.framer.add(htmlTable2_noHtmlEncode(data));
return completeFrame(req);
}
if (eq(uri, "/rewritesTable")) {
List data = new ArrayList();
for (BEAObject input : beaList("Input")) for (BEAObject r : beaBackRefs(input, "Rewrite")) data.add(litorderedmap("Input", input.text(), "Rewrite", tok_dropCurlyBrackets(r.text()), "Rewrite Type", getOpt("rewriteType", r)));
req.framer.title = "Rewrites table";
req.framer.add(p());
req.framer.add(htmlTable2(data));
return completeFrame(req);
}
if (eq(uri, "/patternRewritesTable")) {
List data = new ArrayList();
for (BEAObject pat : beaListAny("Pattern", "Syntactic Pattern")) for (BEAObject r : beaBackRefs(pat, "Rewrite")) if (cget("isRewriteOf", r) == pat) {
Pair example = calculations.exampleForPatternRewrite(pat, r);
data.add(litorderedmap("Pattern", ahref(beaURL(pat), htmlEncode2(pat.text())), "Rewrite", ahref(beaURL(r), htmlEncode2(tok_dropCurlyBrackets(r.text()))), "Example", joinWithBR(htmlEncode2(example.a), htmlEncode2("=> " + example.b)), "Rewrite Type", htmlEncode2_str(getOpt("rewriteType", r)), "Cmds", hPopDownButton(targetBlank(conceptEditLink(r), "Edit"))));
}
req.framer.title = "Pattern rewrites table";
req.framer.add(p());
req.framer.add(htmlTable2_noHtmlEncode(data));
return completeFrame(req);
}
if (eq(uri, "/syntacticPatternsWithoutRewrites")) {
HCRUD crud = makeBEAObjectCRUD(req, "Syntactic Pattern");
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
IF1 prev = data.customFilter;
data.customFilter = list -> {
list = filter(list, c -> empty(beaBackRefs(c, "Rewrite")));
return postProcess(prev, list);
};
crud.customTitle = "Syntactic patterns without rewrites";
return serveCRUD(req, BEAObject.class, crud);
}
if (eq(uri, "/inputsWithoutRewrites")) {
HCRUD crud = makeBEAObjectCRUD(req, "input");
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
IF1 prev = data.customFilter;
data.customFilter = list -> {
list = filter(list, c -> empty(beaBackRefs(c, "Rewrite")));
return postProcess(prev, list);
};
crud.customTitle = "Inputs without rewrites";
return serveCRUD(req, BEAObject.class, crud);
}
if (eq(uri, "/inputsWithRewrites")) {
HCRUD crud = makeBEAObjectCRUD(req, "input");
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
IF1 prev = data.customFilter;
data.customFilter = list -> {
list = filter(list, c -> nempty(beaBackRefs(c, "Rewrite")));
return postProcess(prev, list);
};
crud.customTitle = "Inputs with rewrites";
return serveCRUD(req, BEAObject.class, crud);
}
if (eq(uri, "/inputsWithoutMatches")) {
HCRUD crud = makeBEAObjectCRUD(req, "input");
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
IF1 prev = data.customFilter;
data.customFilter = list -> {
list = filter(list, c -> empty(beaBackRefs(c, "Match")));
return postProcess(prev, list);
};
crud.customTitle = "Inputs without matches";
return serveCRUD(req, BEAObject.class, crud);
}
if (eq(uri, "/patterns"))
return renderBEAObjectTable(req, "pattern");
if (eq(uri, "/syntacticPatterns"))
return renderBEAObjectTable(req, "Syntactic Pattern");
if (eq(uri, "/matches"))
return renderBEAObjectTable(req, "match");
if (eq(uri, "/rewrites"))
return renderBEAObjectTable(req, "rewrite");
if (eq(uri, "/aiTasks"))
return renderBEAObjectTable(req, "AI Task");
if (eq(uri, "/query"))
return calculations.serveQueryPage(req);
if (eq(uri, "/queryHome"))
return calculations.serveQueryPage(req, true);
if (eq(uri, "/saveInput")) {
if (userAgentIsBot(currentUserAgent()))
return "You're a bot";
String text = trim(req.get("text"));
String info = trim(req.get("info"));
String uncleanedText = trim(req.get("uncleanedText"));
if (empty(text))
return subBot_serve500("Input empty");
if (l(text) > maxInputLength)
return subBot_serve500("Input too long");
BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text, "createdBy", user(req));
saveUserAgent(input);
if (nempty(info) || nempty(uncleanedText))
cnew(BEAObject.class, "type", "Input Source", "input", input, "source", info, "uncleanedText", uncleanedText);
return hrefresh(or2(req.get("redirect"), baseLink + "/"));
}
if (eq(uri, "/markUseful")) {
BEAObject o = beaGet("objectID", req);
if (o == null)
return subBot_serve500("Object not found");
uniqCI(BEAObject.class, "type", "Useful", "object", o, "createdBy", user(req));
return hrefresh(or2(req.get("redirect"), baseLink + "/"));
}
if (eq(uri, "/markBad")) {
BEAObject o = beaGet("objectID", req);
if (o == null)
return subBot_serve500("Object not found");
uniqCI(BEAObject.class, "type", "Bad", "object", o, "createdBy", user(req));
return hrefresh(or2(req.get("redirect"), baseLink + "/"));
}
if (eq(uri, "/saveAnswer")) {
String text = trim(req.get("text"));
String rewriteType = or2(trim(req.get("rewriteType")), "Suggested Answer");
long inputID = toLong(req.get("inputID"));
BEAObject input = beaGet(inputID);
if (input == null)
return subBot_serve500("Input not found");
if (empty(text))
return subBot_serve500("Text empty");
if (l(text) > maxInputLength)
return subBot_serve500("Text too long");
uniqCI(BEAObject.class, "type", "Rewrite", "text", text, "isRewriteOf", input, "rewriteType", rewriteType, "createdBy", user(req));
return hrefresh(or2(req.get("redirect"), baseLink + "/"));
}
if (eq(uri, "/javaSource")) {
BEAObject o = beaGet("id", req);
return serveText(loadTextFile(javaSourceFileForObject(o)));
}
if (startsWith(uri, "/beaHTML/", m)) {
req.noSpam();
String rest = m.rest();
int i = smartIndexOf(rest, "/");
BEAObject o = beaGet(takeFirst(i, rest));
req.subURI = substring(rest, i + 1);
req.makers.add(o);
IF0 result = call_optional(o, "html", req);
if (result != null)
return result.get();
result = call_optional(o, "html", req.webRequest);
if (result != null)
return result.get();
return call(o, "html");
}
if (!inMasterMode(req))
return null;
if (eq(uri, "/uploadInputs"))
return serveUploadTexts(req, "Input");
if (eq(uri, "/uploadPatterns"))
return serveUploadTexts(req, "Pattern");
if (eq(uri, "/analyzeInput"))
return calculations.serveAnalyzeInput(req);
if (eq(uri, "/allBEATypes")) {
return h2_title("All object types") + ul(renderObjectTypes());
}
if (eq(uri, "/storeMatch")) {
BEAObject pattern = beaGet(req.get("pattern"));
BEAObject input = beaGet(req.get("input"));
String label = req.get("label");
BEAObject match = calculations.reactInputWithPattern(input, pattern);
if (match == null)
return "Couldn't match";
cset(match, "label", label);
return hrefresh(or2(req.get("redirect"), beaObjectURL(match)));
}
if (eq(uri, "/saveSyntacticPattern") || eq(uri, "/savePattern")) {
String type = cic(uri, "syntactic") ? "Syntactic Pattern" : "Pattern";
String text = req.get("text");
BEAObject fromInput = beaGet(req.get("fromInput"));
BEAObject pat = uniqCI(BEAObject.class, "type", type, "text", text, "createdBy", user(req));
csetIfUnset(pat, "fromInput", fromInput);
if (fromInput != null)
calculations.reactInputWithPattern(fromInput, pat);
return hrefresh(or2(req.get("redirect"), baseLink + "/"));
}
if (eq(uri, "/runInstruction")) {
BEAObject o = beaGet(req.get("instruction"));
runInstruction(o);
return hrefresh(beaObjectURL(o));
}
if (eq(uri, "/convertResultToInput")) {
BEAObject result = beaGet(req.get("result"));
if (result == null)
return subBot_serve500("Object not found");
String text = unquote(getString("result", result));
if (l(text) > maxInputLength)
return subBot_serve500("Input too long");
BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text);
uniqCI(BEAObject.class, "type", "Input Source", "input", input, "source", result);
return hrefresh(beaShortURL(input));
}
if (eq(uri, "/setWordType")) {
BEAObject r = beaGet(req.get("resultID"));
String wordType = assertNempty(req.get("wordType"));
List result = assertStringList(cget("result", r));
for (String s : result) uniqCI(BEAObject.class, "type", "Word type", "word", s, "wordType", wordType);
return "OK";
}
if (eq(uri, "/reload")) {
dm_reloadModuleIn(3);
return "Reloading module in 3";
}
if (eq(uri, "/performAutoRuns")) {
BEAObject o = beaGet(req.get("onObject"));
if (o == null)
return "Object not found";
rstAutoRuns.add(o);
return hrefresh(beaURL(o));
}
if (eq(uri, "/reactAllInputsWithAllSyntacticPatterns")) {
return str(returnTimed(new Runnable() {
public void run() {
try {
calculations.reactAllInputsWithAllSyntacticPatterns();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "calculations.reactAllInputsWithAllSyntacticPatterns();";
}
}));
}
if (eq(uri, "/reactAllInputsWithPattern")) {
BEAObject pat = beaGet(req.get("patternID"));
if (pat == null)
return "Pattern not found";
return str(returnTimed(new Runnable() {
public void run() {
try {
calculations.reactAllInputsWithPattern(pat);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "calculations.reactAllInputsWithPattern(pat);";
}
}));
}
if (eq(uri, "/storeSubInput")) {
BEAObject input = beaGet(req.get("input"));
if (input == null)
return "Input not found";
String text = req.get("text");
String type = eqic(req.get("label"), "good") ? "Sub-Input" : "Bad Sub-Input";
BEAObject o = uniqCI(BEAObject.class, "type", type, "input", input, "text", text, "createdBy", currentUser());
return hrefresh(or2(req.get("redirect"), beaURL(o)));
}
if (eq(uri, "/performAutoRunOnAllObjects")) {
BEAObject autoRun = beaGet("autoRun", req);
performAutoRunOnAllObjects(autoRun);
return "OK";
}
if (eq(uri, "/autoMigrate")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
String url = beaURL(o);
return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(autoMigrateToCustomClass(o)) + hrefresh(1.0, url);
}
if (eq(uri, "/migrateToBase")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
String url = beaURL(o);
return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(autoMigrateToBase(o)) + hrefresh(1.0, url);
}
if (eq(uri, "/convertSyntacticToSemanticMatches")) {
BEAObject match = beaGet("matchID", req);
if (match == null)
return "Match not found";
return ul_htmlEncode2(calculations.convertSyntacticToSemanticMatches(match));
}
if (eq(uri, "/convertSyntacticToSemanticMatchesForWholePattern")) {
BEAObject pat = beaGet("patternID", req);
if (pat == null)
return "Pattern not found";
return ul_htmlEncode2(calculations.convertSyntacticToSemanticMatchesForWholePattern(pat));
}
if (eq(uri, "/createPatternListFromUsefulSyntacticPatterns"))
return hrefresh(beaURL(calc.createPatternListFromUsefulSyntacticPatterns()));
if (eq(uri, "/createConceptShadows"))
return createConceptShadows();
if (eq(uri, "/compareConceptShadows")) {
if (conceptShadows == null)
return createConceptShadows();
List newShadows = allConceptShadows();
List> diff = diffConceptShadows(conceptShadows, newShadows);
return subBot_serveText(nDiffs(diff) + ":\n\n" + pnlToString(diff));
}
if (eq(uri, "/includeScript")) {
String snippetID = req.get("id");
Object wired = hotwire(snippetID);
return "Wired: " + wired;
}
if (eq(uri, "/dependents")) {
BEAObject o = beaGet("id", req);
return ul(lmap(__47 -> htmlEncode2_str(__47), objectWithDependents(o)));
}
if (eq(uri, "/prototypeUsers")) {
BEAObject o = beaGet("id", req);
return ul(lmap(__48 -> htmlEncode2_str(__48), prototypeUsers(o)));
}
if (eq(uri, "/activateObject")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
cset(o, "meta_shouldActivate", true);
callActivate(o);
return "Object activated." + hrefresh(1.0, beaURL(o));
}
if (eq(uri, "/deactivateObject")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
cset(o, "meta_shouldActivate", false);
callDeactivate(o);
return "Object deactivated." + hrefresh(1.0, beaURL(o));
}
if (eq(uri, "/reactivateDynamicObject")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
long id = o.id;
reactivateAndMigratePrototypeUsers(o);
return "OK" + hrefresh(1.0, beaURL(id));
}
if (eq(uri, "/activateDynamicObject")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
compileAndLoadObject(o);
o = beaGet("id", req);
String url = or2(req.get("redirect"), beaURL(o));
return hsansserif() + "Migrated " + beaHTML(o) + " to " + className(o) + hrefresh(1.0, url);
}
if (eq(uri, "/callAnyMethod")) {
BEAObject o = beaGet("id", req);
if (o == null)
return "Object not found";
String name = req.get("name");
boolean showPrints = eq("1", req.get("showPrints"));
List args = new ArrayList();
for (Map.Entry extends String, ? extends String> __27 : _entrySet(req.params())) {
String key = __27.getKey();
String val = __27.getValue();
List groups = regexpExtractGroups("^(arg|conceptArg)(\\d+)$", key);
if (groups != null) {
int idx = parseInt(second(groups));
String type = first(groups);
Object arg = eq(type, "conceptArg") ? getConcept(parseLong(val)) : val;
listSet(args, idx - 1, arg);
}
}
String arg = req.get("arg");
if (arg != null)
listSet(args, 0, arg);
String result = hijackPrintPlusResult_text(() -> {
try {
return call(o, name, toObjectArray(args));
} catch (Throwable e) {
printStackTrace(e);
return null;
}
});
return serveText("Result of " + o + " . " + name + "(" + joinWithComma(args) + "):\n" + result);
}
if (eq(uri, "/download"))
return subBot_serveFileWithName("gazelle-database." + ymd_minus_hms() + ".gz", conceptsFile());
if (eq(uri, "/errorSource"))
return subBot_serveText(loadTextFile(transpilerErrorSourceFile()));
if (eq(uri, "/changeUserPassword")) {
String name = req.get("name"), newPW = req.get("newPW");
if (empty(name))
return "Need 'name' parameter (user name)";
if (empty(newPW))
return "Need 'newPW' parameter";
User user = conceptWhereCI(User.class, "name", name);
cset(user, "passwordMD5", new SecretValue(hashPW(newPW)));
return "Password for " + htmlEncode2(user) + " updated!";
}
return null;
}
transient public List conceptShadows;
public Object createConceptShadows() {
long _startTime_28 = sysNow();
String profile = profileThisThreadToString(new Runnable() {
public void run() {
try {
conceptShadows = allConceptShadows();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "conceptShadows = allConceptShadows();";
}
});
done2_always("Make shadows", _startTime_28);
return subBot_serveText(n2(conceptShadows, "shadow") + " made in " + lastTiming_formatted() + "\n\n" + profile);
}
public HCRUD makeBEAObjectCRUD(Req req, String type) {
HCRUD crud = makeCRUD(BEAObject.class, req);
crud.baseLink = req.uri();
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
data.itemName = () -> firstToUpper(type);
data.addCIFilter("type", eqic(type, "(no type)") ? null : type);
if (eqicOneOf(type, "Input", "Pattern", "AI Task")) {
IF0> prev = data.emptyObject;
data.emptyObject = () -> {
Map item = data.emptyObject_fallback(prev);
item.put("text", "");
return item;
};
}
return crud;
}
public Object renderBEAObjectTable(Req req, String type) {
HCRUD crud = makeBEAObjectCRUD(req, type);
return serveCRUD(req, BEAObject.class, crud);
}
public Object serveUploadTexts(Req req, String type) {
String inputs = req.get("text");
List output = new ArrayList();
if (nempty(inputs)) {
for (String text : tlft(inputs)) {
Pair p = uniqCI2_sync(BEAObject.class, "type", type, "text", text);
if (cget("uploadedBy", p.a) == null)
cset(p.a, "uploadedBy", req.auth.user);
output.add(type + " " + (p.b ? "added" : "exists") + " (ID " + p.a.id + "): " + text);
}
}
return h2("Upload " + plural(type)) + hpostform(p(plural(type) + " (one per line):") + p(htextarea(inputs, "name", "text")) + pIfNempty(htmlEncode_nlToBR(lines(output))) + hsubmit("Upload " + plural(type)));
}
public Collection beaObjectsOfType(String type) {
return conceptsWhereCI(BEAObject.class, "type", type);
}
public void reactAllInputsWithSomePatterns() {
calculations.reactAllInputsWithSomePatterns();
}
transient public IF0 navDiv;
public String navDiv() {
return navDiv != null ? navDiv.get() : navDiv_base();
}
final public String navDiv_fallback(IF0 _f) {
return _f != null ? _f.get() : navDiv_base();
}
public String navDiv_base() {
return div_vbar(newNavLinks(), "style", "margin-bottom: 0.5em");
}
transient public IF0> newNavLinks;
public List newNavLinks() {
return newNavLinks != null ? newNavLinks.get() : newNavLinks_base();
}
final public List newNavLinks_fallback(IF0> _f) {
return _f != null ? _f.get() : newNavLinks_base();
}
public List newNavLinks_base() {
HCRUD crud = makeCRUD(BEAObject.class, currentReq());
int inputsWithoutRewrites = this.inputsWithoutRewrites.get();
int inputsWithoutMatches = this.inputsWithoutMatches.get();
int syntacticPatternsWithoutRewrites = this.syntacticPatternsWithoutRewrites.get();
String allObjectTypesLink = ahref(baseLink + "/allBEATypes", "All object types");
return ll(ahref(baseLink + "/query", "Query"), ahref(baseLink + "/newSearch", span_title("New BEA-based searched in development", "New Search (dev.)")), beaNavLink("Input", crud), beaNavLink("Pattern", crud), beaNavLink("Syntactic Pattern", crud), ahref(baseLink + "/syntacticPatternsWithoutRewrites", n2(syntacticPatternsWithoutRewrites) + " Syntactic patterns w/o rewrites"), beaNavLink("Match", crud), beaNavLink("Rewrite", crud), beaNavLink("AI Task", crud), ahref(baseLink + "/inputsWithoutMatches", n2(inputsWithoutMatches) + " Inputs w/o matches"), ahref(baseLink + "/inputsWithoutRewrites", n2(inputsWithoutRewrites) + " Inputs w/o rewrites"), inlineSwappable("navDiv_allObjectTypes", this, () -> allObjectTypesLink + " " + hPopDownButton(listPlus(renderObjectTypes(10), allObjectTypesLink))), new HTMLPopDownButton(ahref(baseLink + "/stats", "Stats"), !isMasterAuthed() ? null : ahref(baseLink + "/download", "DB download"), !isMasterAuthed() ? null : ahref(baseLink + "/refchecker", "Reference checker"), ahref(baseLink + "/inputsWithRewrites", "Inputs with rewrites"), ahref(baseLink + "/rewritesTable", "Rewrites table"), ahref(baseLink + "/patternRewritesTable", "Pattern rewrites table"), ahref(baseLink + "/matchesTable", "Matches table"), ahref(baseLink + "/matchesTable?syntacticOnly=1", "Syntactic matches table"), ahref("https://gazelle.rocks/htmlBot/238410", "Classic Gazelle")).width(350).height(500).html());
}
public String beaNavLink(String type, HCRUD crud) {
return beaNavLink(type, crud, beaCount(type));
}
public String beaNavLink(String type, HCRUD crud, int count) {
String plural = firstToLower(plural(type));
String link = baseLink + "/" + camelCase(plural);
return ahref(link, n2(count) + " " + firstToUpper(plural)) + (!crud.actuallyAllowCreate() ? "" : " " + ahref(addParamToURL(link, "cmd", "new"), "+"));
}
public String beaObjectURL(BEAObject o) {
return conceptLink(o, currentReq());
}
public String matchDescHTML(BEAObject m) {
try {
BEAObject pat = cget("pattern", m);
Map mapping = (Map) (cget("mapping", m));
return ahref_undecorated(crudLink(m), htmlEncode2(quote(getString("text", pat))) + " with " + renderEqualsCommaProperties(mapping));
} catch (Throwable __e) {
_handleException(__e);
}
return htmlEncode2(str(m));
}
public Collection beaList() {
return list(BEAObject.class);
}
public Collection beaList(String type, Object... params) {
return conceptsWhereCI(BEAObject.class, paramsPlus_inFront(params, "type", type));
}
public Collection beaListAny(String... types) {
return concatLists(lmap(__49 -> beaList(__49), litciset(types)));
}
public Collection beaListAny(Collection types) {
return concatLists(lmap(__50 -> beaList(__50), asCISet(types)));
}
public BEAObject beaGet(long id) {
return getConceptOpt(BEAObject.class, id);
}
public BEAObject beaGet(String id) {
return beaGet(parseFirstLong(id));
}
public boolean beaTypeIs(BEAObject o, String type) {
return o != null && o.typeIs(type);
}
public BEAObject beaGet(String key, Req req) {
return beaGet(req.get(key));
}
public BEAObject beaGet(String field, BEAObject o) {
return cgetBEA(field, o);
}
public BEAObject cgetBEA(String field, BEAObject o) {
return (BEAObject) cget(field, o);
}
public BEAObject beaGet(BEAObject o, String field) {
return cgetBEA(o, field);
}
public BEAObject cgetBEA(BEAObject o, String field) {
return cgetBEA(field, o);
}
public String beaToHTML(BEAObject o) {
return beaLinkHTML(o);
}
public String beaHTML(BEAObject o) {
return beaLinkHTML(o);
}
public String beaLinkHTML(BEAObject o) {
return o == null ? null : ahref(conceptLink(o), htmlEncode2_nlToBr(str(o)));
}
public String beaHTML_targetBlank(BEAObject o) {
return o == null ? null : targetBlank(conceptLink(o), htmlEncode2_nlToBr(str(o)));
}
public String beaHTML_justID(BEAObject o) {
return o == null ? null : ahref(beaShortURL(o), o.id);
}
public String beaFullURL(BEAObject o) {
return o == null ? null : mainDomainWithProtocol + beaURL(o);
}
public String beaURL(long id) {
return baseLink + "/" + id;
}
public String beaURL(BEAObject o) {
return beaShortURL(o);
}
public String beaShortURL(BEAObject o) {
return o == null ? null : baseLink + "/" + o.id;
}
public Collection beaBackRefs(BEAObject o, String type) {
return objectsWhereCI(findBackRefs(BEAObject.class, o), "type", type);
}
public Collection beaBackRefs(BEAObject o) {
return findBackRefs(BEAObject.class, o);
}
transient public IF1 serveDefaultPage;
@Override
public Object serveDefaultPage(DynGazelleRocks.Req req) {
return serveDefaultPage != null ? serveDefaultPage.get(req) : serveDefaultPage_base(req);
}
final public Object serveDefaultPage_fallback(IF1 _f, DynGazelleRocks.Req req) {
return _f != null ? _f.get(req) : serveDefaultPage_base(req);
}
public Object serveDefaultPage_base(DynGazelleRocks.Req req) {
HTMLFramer1 framer = req.framer;
framer.add(centerGazelleLogo());
return completeFrame(req);
}
public String centerGazelleLogo() {
return hcenter3(hsnippetimg_scaleToWidth(200, "#1102967", 200, 110, "title", "Gazelle"), "style", "margin-top: 100px");
}
public String html_loggedIn() {
User user = user(currentReq());
return user == null ? ahref(baseLink + "/", "Log in") : "Logged in as " + htmlEncode2(user.name);
}
transient public IVF1 distributeNewObject_impl;
public void distributeNewObject_impl(BEAObject o) {
if (distributeNewObject_impl != null)
distributeNewObject_impl.get(o);
else
distributeNewObject_impl_base(o);
}
final public void distributeNewObject_impl_fallback(IVF1 _f, BEAObject o) {
if (_f != null)
_f.get(o);
else
distributeNewObject_impl_base(o);
}
public void distributeNewObject_impl_base(BEAObject o) {
if (newObjectIsWorthNotification(o))
distributeNewObject_impl_noCheck(o);
}
transient public IF1 newObjectIsWorthNotification;
public boolean newObjectIsWorthNotification(BEAObject o) {
return newObjectIsWorthNotification != null ? newObjectIsWorthNotification.get(o) : newObjectIsWorthNotification_base(o);
}
final public boolean newObjectIsWorthNotification_fallback(IF1 _f, BEAObject o) {
return _f != null ? _f.get(o) : newObjectIsWorthNotification_base(o);
}
public boolean newObjectIsWorthNotification_base(BEAObject o) {
return !o.typeIsOneOf("Match", "Live WebSocket");
}
transient public IVF1 distributeNewObject_impl_noCheck;
public void distributeNewObject_impl_noCheck(BEAObject o) {
if (distributeNewObject_impl_noCheck != null)
distributeNewObject_impl_noCheck.get(o);
else
distributeNewObject_impl_noCheck_base(o);
}
final public void distributeNewObject_impl_noCheck_fallback(IVF1 _f, BEAObject o) {
if (_f != null)
_f.get(o);
else
distributeNewObject_impl_noCheck_base(o);
}
public void distributeNewObject_impl_noCheck_base(BEAObject o) {
distributeNotification("New object: " + o);
}
public void performAutoRuns(BEAObject o) {
AutoCloseable __34 = enter();
try {
for (BEAObject autoRun : beaList("Auto Run")) {
if (!isTrue(getOpt("enabled", autoRun))) {
print("Not enabled: " + autoRun);
continue;
}
performAutoRunOnObject(autoRun, o);
}
} finally {
_close(__34);
}
}
public void performAutoRunOnAllObjects(BEAObject autoRun) {
for (BEAObject o : list(BEAObject.class)) performAutoRunOnObject(autoRun, o);
}
public void performAutoRunOnObject(BEAObject autoRun, BEAObject o) {
ping();
String type = getString("onChangedObjectOfType", autoRun);
if (!o.typeIs(type))
return;
print("Running " + autoRun);
BEAObject procedure = (BEAObject) (cget("procedure", autoRun));
String internalCode = getString("internalCode", procedure);
printVars_str("internalCode", internalCode, "o", o);
if (eqic(internalCode, "convertInputToPattern")) {
String text = o.text();
if (!containsAngleBracketVars(text)) {
print("No angle bracket vars");
return;
}
BEAObject p = uniqCI_returnIfNew(BEAObject.class, "type", "Pattern", "text", text);
cset(p, "fromInput", o, "byProcedure", procedure, "byAutoRun", autoRun);
print("p", p);
} else if (eqic(internalCode, "convertInputToSyntacticPattern")) {
String text = o.text();
if (!containsStars(text)) {
print("No stars");
return;
}
BEAObject p = uniqCI_returnIfNew(BEAObject.class, "type", "Syntactic Pattern", "text", text);
cset(p, "fromInput", o, "byProcedure", procedure, "byAutoRun", autoRun);
print("p", p);
} else if (eqic(internalCode, "dropPunctuationFromPattern")) {
String text = o.text();
String text2 = dropPunctuation(text);
if (eq(text, text2))
return;
BEAObject p = uniqCI(BEAObject.class, "type", o.type(), "text", text2);
cset(o, "withoutPunctuation", p);
} else if (eqic(internalCode, "makeSyntacticPattern")) {
print("sp", calculations.makeSyntacticPattern(o));
} else if (eqic(internalCode, "runFunctionOnInput")) {
print("runFunctionOnInput");
BEAObject function = beaGet(o, "function");
BEAObject input = beaGet(o, "input");
if (function == null || input == null) {
print("Missing parameters");
return;
}
if (cget("result", o) != null) {
print("Has result");
return;
}
BEAObject result = calculations.reactFunctionWithInput(calculations.new BackEndAlgorithm(), function, input);
print("result", result);
if (result != null) {
cset(result, "request", o);
cset(o, "result", result);
}
} else
print("Unknown internal code");
}
public BEAObject findInput(String text) {
return conceptWhereIC(BEAObject.class, "type", "Input", "text", text);
}
public String addRewriteHTML(BEAObject o) {
return ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Rewrite", "f_type", "Rewrite", "f_text", getStringOpt("text", o), "f_isRewriteOf", o.id, "metaInfo_isRewriteOf", "concept"), "Add Rewrite");
}
@Override
public Object serveIntegerLink(DynGazelleRocks.Req req, long id) {
BEAObject o = getConceptOpt(BEAObject.class, id);
if (o != null)
return htitle(str(o)) + hrefresh(conceptLink_long(o));
return super.serveIntegerLink(req, id);
}
public void distributeTestNotification() {
distributeNotification("It is " + localTimeWithSeconds());
}
public void distributeNotification(String text) {
notificationQ.add(new Runnable() {
public void run() {
try {
String jsCode = "window.createNotification({ theme: 'success', showDuration: 3000 })(" + jsonEncodeMap("message", text) + ");";
sendJavaScriptToAllWebSockets(jsCode);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "/*for (User user)\r\n if (nemptyAfterTrim(user.notificationSetting))\r\n ...";
}
});
}
public void sendJavaScriptToAllWebSockets(String jsCode) {
for (Pair p : syncMapToPairs(webSockets)) {
pcall(p.a, "send", jsonEncodeMap("eval", jsCode));
}
}
public void runInstruction(BEAObject o) {
if (o == null)
return;
try {
BEAObject instruction = o;
if (o.typeIs("Step in script"))
instruction = (BEAObject) cget(o, "instruction");
if (instruction.typeIs("Instruction | List objects by type")) {
saveInstructionResult(o, beaList(getString("typeToList", instruction)));
return;
}
if (instruction.typeIs("Instruction | List object types")) {
saveInstructionResult(o, distinctCIFieldValuesOfConcepts(BEAObject.class, "type"));
return;
}
if (instruction.typeIs("Instruction | Filter list by text starting with")) {
BEAObject scriptRun = cgetBEA("scriptRun", o);
if (scriptRun == null)
throw fail("Need to be run as part of script");
List steps = scriptRunSteps(scriptRun);
int idx = indexOf(steps, o);
if (idx < 0)
throw fail("Step not found in script run");
List list = firstNotNull(map(reversed(takeFirst(steps, idx)), step -> optCast(List.class, cget("data", cgetBEA("result", step)))));
String prefix = getString("prefix", instruction);
List filtered = filter(list, obj -> swic(obj.text(), prefix));
saveInstructionResult(o, filtered);
return;
}
if (instruction.typeIs("Script")) {
BEAObject script = instruction;
BEAObject scriptRun = cnew(BEAObject.class, "type", "Script Run", "script", script);
int i = 0;
List steps = new ArrayList();
while ((instruction = (BEAObject) cget(instruction, "step" + (++i))) != null) {
BEAObject step = cnew(BEAObject.class, "type", "Step in script", "step", i, "scriptRun", scriptRun, "instruction", instruction);
steps.add(step);
}
cset(scriptRun, "steps", steps);
return;
}
cnew(BEAObject.class, "type", "Instruction Error", "instruction", o, "error", "Unknown instruction type");
} catch (Throwable e) {
cnew(BEAObject.class, "type", "Instruction Error", "instruction", o, "error", getStackTrace(e));
}
}
public BEAObject saveInstructionResult(BEAObject instruction, Object data) {
BEAObject result = cnew(BEAObject.class, "type", "Instruction Result", "instruction", instruction, "data", data);
cset(instruction, "result", result);
return result;
}
public List scriptRunSteps(BEAObject scriptRun) {
return (List) cget("steps", scriptRun);
}
public String addCommentHTML(BEAObject o, Object... __) {
String redirectAfterSave = (String) (optPar("redirectAfterSave", __));
String defaultComment = (String) (optPar("defaultComment", __));
String text = optPar("text", __, "Add comment");
return ahref(addParamsToURL(crudLink(BEAObject.class), "cmd", "new", "title", "Add Comment", "f_type", "Comment", "f_on", o.id, "f_text", unnull(defaultComment), "redirectAfterSave", redirectAfterSave, "autofocus", "f_text", "metaInfo_on", "concept"), text);
}
public String formatSubInput(BEAObject input, String text, String anchor) {
String redirect = addAnchorToURL(currentReq.get().uriWithParams(), anchor);
int goodCount = countConceptsCI(BEAObject.class, "type", "Sub-Input", "input", input, "text", text);
int badCount = countConceptsCI(BEAObject.class, "type", "Bad Sub-Input", "input", input, "text", text);
return calculations.bestInputHTML(text) + " " + small(joinNemptiesWithSpace(ahref(addParamsToURL(baseLink + "/storeSubInput", "label", "good", "text", text, "input", input.id, "redirect", redirect), unicode_thumbsUp()), goodCount == 0 ? "" : n2(goodCount), ahref(addParamsToURL(baseLink + "/storeSubInput", "label", "bad", "text", text, "input", input.id, "redirect", redirect), unicode_thumbsDown()), badCount == 0 ? "" : n2(badCount)));
}
public List renderObjectTypes() {
return renderObjectTypes(Integer.MAX_VALUE);
}
public List renderObjectTypes(int max) {
MultiSet ms = distinctCIFieldValuesOfConcepts_multiSet(BEAObject.class, "type");
return mapPairs(takeFirst(max, multiSetToPairsByPopularity(ms)), (type, count) -> {
String _type = or2(type, "(no type)");
return n2(count) + " " + ahref(baseLink + "/beaCRUD/" + urlencode(_type), htmlEncode2(_type));
});
}
public BEAObject autoMigrateToBase(BEAObject o) {
return migrateToClass(o, BEAObject.class);
}
public BEAObject autoMigrateToCustomClass(BEAObject o) {
return migrateToClass(o, defaultCustomClass(o));
}
public BEAObject migrateToClass(BEAObject o, Class extends BEAObject> targetClass) {
if (o == null || o._concepts != db_mainConcepts())
return null;
if (targetClass != null && targetClass != _getClass(o)) {
BEAObject newObject = unlistedCopyToClass_withConverter_pcall(targetClass, o);
beaCallOpt(newObject, "_fixAfterMigration", o);
return replaceConceptAndUpdateRefs(o, newObject);
}
return o;
}
public void setCodeState(BEAObject o, long timestamp, String codeHash, Object state) {
if (empty(state))
state = null;
cset(o, "meta_codeState", state);
}
public String codeForObject(BEAObject o) {
return getStringOpt("meta_code", o);
}
public String actualCodeHash(BEAObject o) {
return md5OrNull(codeForObject(o));
}
public boolean codeHashUpToDate(BEAObject o) {
return eq(actualCodeHash(o), getStringOpt("meta_codeHash", o));
}
public boolean compileErrorInObject(BEAObject o) {
return swic(getStringOpt("meta_codeState", o), "error.");
}
public boolean isDependentOn(BEAObject a, BEAObject b) {
return contains(optCast(Concept.RefL.class, getOpt("meta_dependsOnCode", a)), b);
}
public Collection objectWithDependents(BEAObject o) {
return stepAllAndGet(new TransitiveHull<>(x -> filter(y -> isDependentOn(y, x), list(BEAObject.class)), o));
}
public void compileAndLoadObject(BEAObject o) {
dm_mediumRefreshTranspiler();
Collection withDependents = objectWithDependents(o);
print("Dependents for " + o + ": " + withDependents);
for (BEAObject x : withDependents) compileAndLoadObject_withoutDependents(x);
}
public Class protoClass(BEAObject o) {
BEAObject proto = cget("meta_prototype", o);
Class protoClass = null;
if (proto != null) {
if (!isActivatedDynamicObject(proto))
throw fail("Prototype not activated: " + proto);
protoClass = proto.getClass();
}
return protoClass;
}
public String setCodeHash(BEAObject o) {
String code = codeForObject(o);
String codeHash = empty(code) ? null : md5(code);
cset(o, "meta_codeHash", codeHash);
return codeHash;
}
public void compileAndLoadObject_withoutDependents(BEAObject o) {
try {
print("compileAndLoadObject_withoutDependents", o);
assertSame(db_mainConcepts(), o._concepts);
ClassLoader cl = dm_moduleClassLoader();
long timestamp = now();
setCodeState(o, timestamp, null, "Compiling");
String codeHash = null;
transpileAndCompileForHotwiring_src.set(null);
try {
Class protoClass = protoClass(o);
codeHash = setCodeHash(o);
String code = codeForObject(o);
if (empty(code)) {
if (protoClass != null) {
o = migrateToClass(o, protoClass);
setCodeState(o, timestamp, null, "Migrated to proto class " + shortClassName(protoClass));
callActivate(o);
} else {
o = autoMigrateToBase(o);
setCodeState(o, timestamp, null, null);
}
return;
}
actualCompile(o);
reactivateAndMigratePrototypeUsers(o);
print("Done compiling");
} catch (Throwable e) {
cset(o, "meta_javaClass", null);
setCodeState(o, timestamp, codeHash, "Error. " + exceptionToStringShort(e));
throw rethrow(e);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void setCodeHashAndActualCompile(BEAObject o) {
setCodeHash(o);
actualCompile(o);
}
public void actualCompile(BEAObject o) {
Class protoClass = protoClass(o);
cset(o, "meta_codeSafety", null);
DynClassName dcn = new DynClassName(o.id, aGlobalID(), o.id);
cset(o, "meta_javaClass", dcn.fullClassName());
String code = codeForObject(o);
List tok = javaTok(code);
String baseClass = "BEAObject";
List implementedInterfaces = new ArrayList();
for (int i : jfindAll(tok, "implements", (_tok, nIdx) -> {
String left = get(_tok, nIdx - 1);
return !(isIdentifier(left) || eq(left, ">"));
})) {
int iSemi = tok_findEndOfStatement(tok, i) - 1;
List tokWhat = subList(tok, i + 1, iSemi);
String className;
if (nCodeTokens(tokWhat) == 3 && eq(tokWhat.get(3), "from")) {
className = tokWhat.get(1);
className = "B" + tokWhat.get(5) + "." + className;
} else
className = join(dropFirstAndLast(tokWhat));
className = expandShortClassRef(className);
implementedInterfaces.add(className);
clearTokens(tok, i, iSemi + 2);
}
int tokIdx;
if ((tokIdx = jfind_any(tok, "extends ;", "extends .;", "extends ..;")) > 0) {
int j = indexOf(tok, ";", tokIdx);
baseClass = joinSubList(tok, tokIdx + 2, j - 1);
baseClass = expandShortClassRef(baseClass);
clearTokens(tok, tokIdx, j + 2);
}
if ((tokIdx = jfind(tok, "extends from *;")) > 0) {
String className = tok.get(tokIdx + 2);
baseClass = expandShortClassRef("B" + parseFirstLong_regexp(tok.get(tokIdx + 6)) + "." + className);
int j = indexOf(tok, ";", tokIdx);
clearTokens(tok, tokIdx, j + 2);
}
if ((tokIdx = jfind(tok, "extends <> from ;")) > 0) {
String className = tok.get(tokIdx + 2);
int j = indexOf(tok, ";", tokIdx);
baseClass = expandShortClassRef("B" + tok.get(j - 2) + "." + className) + joinSubList(tok, tokIdx + 4, j - 5);
clearTokens(tok, tokIdx, j + 2);
}
List imports = new ArrayList();
while ((tokIdx = jfind(tok, "import from ;")) > 0) {
String className = tok.get(tokIdx + 2);
String name = expandShortClassRef("B" + tok.get(tokIdx + 6) + "." + className);
imports.add("import " + name + ";");
int j = indexOf(tok, ";", tokIdx);
clearTokens(tok, tokIdx, j + 2);
}
String global = getGlobalCode(tok);
code = join(tok);
String src = lines(imports) + "mainPackage " + dcn.makePackageName() + "\n" + "mainClassName " + dcn.makeMainClassName() + "\n" + "concept " + dcn.makeBEAClassName() + " extends " + (protoClass == null ? baseClass : protoClass.getName().replace("$", ".")) + (empty(implementedInterfaces) ? "" : " implements " + joinWithComma(implementedInterfaces)) + " {\n" + code + "\n}\n" + global + "\n" + customCodePostlude();
ClassLoader cl = dm_moduleClassLoader();
var files = filesFromClassLoader(cl);
print("Compiling with " + n2(files, "byte code path"));
javaCompileToJar_localLibraries.set(files);
File bytecode;
List libs = new ArrayList();
try {
bytecode = transpileAndCompileForHotwiring(src, libs);
libs.remove(str(parseSnippetID(mainLibID)));
print("libs", libs);
} finally {
String javaSrc = transpileAndCompileForHotwiring_src.get();
saveTextFile(javaSourceFileForObject(o), javaSrc);
List dependencies = new ArrayList();
for (String id : tok_identifiers(javaTok(javaSrc))) {
long objID = regexpToLongIC("^b_?(\\d+)", id);
if (objID != 0 && objID != o.id)
dependencies.add(getConceptOrMarkMissingObject(BEAObject.class, objID));
}
cset(o, "meta_libraries", nullIfEmpty(joinWithSpace(libs)));
cset(o, "meta_dependsOnCode", nullIfEmpty(dependencies));
}
renameFileVerbose(bytecode, dcn.byteCodeFile());
cset(o, "meta_javaClass", dcn.fullClassName());
}
public void reactivateAndMigratePrototypeUsers(BEAObject o) {
var p = reactivateDynamicObject(o);
if (p == null)
throw fail("Activation of " + o.id + " failed. " + getOpt("meta_codeState", o));
File deadPath = byteCodePathForClass(o);
print("New dead class path: " + deadPath + " (total: " + n2(deadClassPaths) + ")");
deadClassPaths.add(deadPath);
o = p.a;
assertNotNull("Activated object", o);
String codeHash = getStringOpt("meta_codeHash", o);
long timestamp = now();
setCodeState(o, timestamp, codeHash, "Custom code loaded");
print("Custom code loaded");
migratePrototypeUsers(o);
}
public String expandShortClassRef(String name) {
List groups = regexpGroups("^B(\\d+)(\\..+)$", name);
if (groups != null) {
long baseID = parseLong(first(groups));
BEAObject baseObj = beaGet(baseID);
name = mainClassNameForObject(baseObj) + second(groups);
if (empty(name))
throw fail("Referenced object doesn't have a Java class: " + baseID);
}
return name;
}
public void migratePrototypeUsers(BEAObject o) {
for (BEAObject derivative : prototypeUsers(o)) {
try {
print("Migrating prototype user " + derivative + " of " + o + " to new base class " + o.getClass());
migrateToClass(derivative, o.getClass());
} catch (Throwable __e) {
_handleException(__e);
}
}
}
public boolean basedOnUnactivatedPrototype(BEAObject o) {
BEAObject proto = optCast(BEAObject.class, cget("meta_prototype", o));
return proto != null && !isActivatedDynamicObject(proto);
}
public Collection prototypeUsers(BEAObject o) {
TransitiveHull th = new TransitiveHull<>(x -> filter(conceptsWhere(BEAObject.class, "meta_prototype", x), d -> empty(codeForObject(d))), o);
return setMinus_inPlace(stepAllAndGet(th), o);
}
public Pair reactivateDynamicObject(BEAObject o) {
try {
return reactivateDynamicObject_impl(o);
} catch (Throwable e) {
_handleException(e);
cset(o, "meta_javaClass", null);
cset(o, "meta_codeState", exceptionToStringShort(e));
return null;
}
}
public boolean isActivatedDynamicObject(BEAObject o) {
return startsWith(className(o), packagePrefix());
}
public Pair reactivateDynamicObject_impl(BEAObject o) {
try {
assertNotNull(o);
assertSame(db_mainConcepts(), o._concepts);
DynClassName dcn = dcnForObject(o);
if (dcn == null) {
cset(o, "meta_codeState", null);
return pair(o, false);
}
File byteCode = dcn.byteCodeFile();
loadObjectsLibraries(o);
dm_addByteCodePathToModuleClassLoader(byteCode);
String fullName = dcn.fullClassNameForVM();
print("fullName", fullName);
ClassLoader cl = dm_moduleClassLoader();
Class targetClass = cl.loadClass(fullName);
print("targetClass", targetClass);
assertNotNull("Class not found: " + fullName, targetClass);
o = migrateToClass(o, targetClass);
assertNotNull("autoMigrated", o);
callActivate(o);
cset(o, "meta_codeState", "[" + formatGMTWithMilliseconds_24() + "] " + "Custom code reloaded");
return pair(o, true);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public File javaSourceFileForObject(BEAObject o) {
return programFile("BEA Java Sources/" + o.id + ".java");
}
public File byteCodeFile(DynClassName name) {
return name == null ? null : programFile("Object ByteCode/" + name.objectID + "-" + name.globalID + ".jar");
}
public DynClassName dcnForObject(BEAObject o) {
String javaClassName = getString("meta_javaClass", o);
return DynClassName_parse(javaClassName);
}
public File byteCodeFileForObject(BEAObject o) {
DynClassName dcn = dcnForObject(o);
return dcn == null ? null : dcn.byteCodeFile();
}
public BEAObject autoMigrateUnlistedOrKeep(BEAObject o) {
return canAutoMigrate(o) ? unlistedCopyToClass_withConverter(defaultCustomClass(o), o) : o;
}
public boolean canAutoMigrate(BEAObject o) {
return o != null && !eqOneOf(defaultCustomClass(o), _getClass(o), null);
}
public Class extends BEAObject> defaultCustomClass(BEAObject o) {
if (o == null)
return null;
BEAObject entry = conceptWhereCI(BEAObject.class, "type", "Auto Custom Class", "forType", o.type());
if (entry == null)
return null;
String className = getString("toClassName", entry);
Class c = findClassThroughDefaultClassFinder(className);
return c;
}
public String queryLink(String algorithm, String q) {
return addParamsToURL(baseLink + "/query", "algorithm", algorithm, "q", q);
}
public String currentUserAgent() {
Req req = currentReq();
if (req == null)
return null;
return mapGet(req.webRequest.headers(), "user-agent");
}
public void saveUserAgent(BEAObject input) {
String userAgent = currentUserAgent();
if (nempty(userAgent) && !userAgentIsBot(userAgent))
uniqCI2(BEAObject.class, "type", "Input Source", "input", input, "userAgent", userAgent);
}
public boolean isObjectWithCode(BEAObject o) {
return o != null && o.hasCustomCode();
}
public boolean createdByMasterUser(BEAObject o) {
User user = optCast(User.class, cget("createdBy", o));
return user != null && user.isMaster;
}
public void autoActivateDynamicObject(BEAObject o) {
if (!autoActivateDynamicObjects)
return;
String code = codeForObject(o);
if (empty(code))
return;
if (!createdByMasterUser(o))
return;
String codeState = getString("meta_codeState", o);
String time = leadingAngleBracketStuff(codeState);
long timestamp = empty(time) ? 0 : parseDateWithMillisecondsGMT(time);
if (o._modified <= timestamp)
return;
String hash = getString("meta_codeHash", o);
if (eq(hash, md5(code)))
return;
print("Auto-activating dynamic object: " + o);
compileAndLoadObject(o);
sleepSeconds(1);
}
public String customCodePostlude() {
return "!include early #1031282\n\n";
}
public String makeJavaClassName(BEAObject o) {
return aGlobalID();
}
public String packagePrefix() {
return "dyn.b_";
}
public String makePackageName(BEAObject o) {
return packagePrefix() + o.id;
}
public BEAObject websiteEnhancersObject() {
Collection l = beaList("Live Website Enhancers");
if (l(l) > 1)
warn("Multiple Live Website Enhancers: " + l);
return first(l);
}
public BEAObject getWebsiteEnhancer(String key) {
return beaGet(websiteEnhancersObject(), key);
}
public String newLinkForCRUD(HCRUD crud, Class c) {
if (c == User.class)
return baseLink + "/register";
else
return super.newLinkForCRUD(crud, c);
}
public String callHTMLFixer(Object caller, String html) {
BEAObject fixer = beaGet("htmlFixer", websiteEnhancersObject());
return or((String) callOpt(fixer, "fixHTML", html, caller), html);
}
@Override
public Object html3(DynGazelleRocks.Req req) {
return html3((Req) req);
}
public Object html3(Req req) {
assertSame(realMC(), mc());
assertSame(main.beaMod(), me());
vmBus_send("logMethodCall", this, "html3", req);
vmBus_send("html3", this, req);
BHTTPRequest reified = null;
if (reifyHTTPRequests())
reified = cnew(BHTTPRequest.class, "type", "Live HTTP Request", "req", req, "uri", req.uri(), "ip", req.webRequest.clientIP(), "user", user(req));
long time = sysNow();
try {
return html4(req);
} finally {
time = sysNow() - time;
if (reified != null)
cset(reified, "type", "Past HTTP Request", "processingTime", time);
}
}
public Object html4(Req req) {
if (saveAllQsAsInput && !cic(req.uri(), "/live") && user(req) != null) {
String text = trim(req.get("q"));
if (nempty(text)) {
BEAObject input = uniqCI(BEAObject.class, "type", "Input", "text", text);
uniqCI(BEAObject.class, "type", "Input Source", "input", input, "source", "Web Request (q parameter)");
}
}
Object response = html5(req);
if (response instanceof String)
response = routeThroughAll(pagePostProcessors, ((String) response));
return response;
}
transient public List> pagePostProcessors = syncL();
public Object html5(Req req) {
String uri = req.uri();
for (BEAObject rewrite : filter(__51 -> createdByMasterUser(__51), beaList("Live URL Rewrite"))) {
try {
String input = getString("input", rewrite);
vmBus_send("testingURLRewrite", rewrite, uri);
if (eq(uri, input)) {
vmBus_send("applyingURLRewrite", rewrite, uri);
String output = getString("output", rewrite);
return hrefresh(output);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
return super.html3(req);
}
public void cleanMeUp_deactivateBEAObjects() {
Collection objects = filter(beaList(), o -> hasMethod(o, "_deactivate"));
print("Deactivating " + nObjects(objects) + " for shutdown");
for (BEAObject bea : objects) pcallOpt(bea, "_deactivate");
if (nempty(objects))
print("Done");
}
public DynClassName DynClassName_parse(String className) {
className = replace(className, "$", ".");
List groups = regexpFirstGroups("^dyn\\.b_(\\d+)_([a-z]+)\\.B(\\d+)\\$?(.*)", className);
if (verboseClassLoading)
printVars("DynClassName_parse", "className", className, "groups", groups);
if (groups == null)
return null;
return new DynClassName(parseLong(first(groups)), second(groups), parseLong(third(groups)), fourth(groups));
}
public DynClassName DynClassName_parseOther(String className) {
className = replace(className, "$", ".");
List groups = regexpFirstGroups("^dyn\\.b_(\\d+)_([a-z]+)\\.(.*)", className);
if (verboseClassLoading)
printVars("DynClassName_parseOther", "className", className, "groups", groups);
if (groups == null)
return null;
return new DynClassName(parseLong(first(groups)), second(groups), 0, third(groups));
}
public String DynClassName_mainPrefix() {
return "dyn.";
}
public String DynClassName_mainPrefixForVM() {
return "dyn.";
}
public class DynClassName {
public long compileBaseObjectID;
public String globalID;
public long objectID;
public String innerClass;
public DynClassName(long compileBaseObjectID, String globalID, long objectID) {
this.objectID = objectID;
this.globalID = globalID;
this.compileBaseObjectID = compileBaseObjectID;
}
public DynClassName(long compileBaseObjectID, String globalID, long objectID, String innerClass) {
this.innerClass = innerClass;
this.objectID = objectID;
this.globalID = globalID;
this.compileBaseObjectID = compileBaseObjectID;
}
public String makePackageName() {
return dropDotSuffix(DynClassName_mainPrefix());
}
public String makeMainClassName() {
return "b_" + compileBaseObjectID + "_" + globalID;
}
public String makeBEAClassName() {
return joinNempties("$", objectID == 0 ? "" : "B" + objectID, innerClass);
}
public String fullClassName() {
return joinWithDot(makePackageName(), makeMainClassName(), makeBEAClassName());
}
public String fullClassNameForVM() {
return makePackageName() + "." + makeMainClassName() + "$" + makeBEAClassName();
}
public File byteCodeFile() {
return programFile("Object ByteCode/" + baseSystemVersion + "/" + compileBaseObjectID + "/" + globalID + ".jar");
}
}
public String mainClassNameForObject(BEAObject o) {
if (o == null)
return null;
String fullBaseClass = getString("meta_javaClass", o);
return takeFirst(fullBaseClass, lastIndexOf(fullBaseClass, "."));
}
public void loadObjectsLibraries(BEAObject o) {
List libs = splitAtSpace_trim(getString("meta_libraries", o));
if (addLibrariesToClassLoader(dm_moduleClassLoader(), libs))
print("Loaded libs for " + o + ": " + libs);
}
public void callActivate(BEAObject bea) {
if (getBoolOpt("meta_shouldActivate", bea, true)) {
loadObjectsLibraries(bea);
pcallOpt(bea, "_activate");
}
}
public void callDeactivate(BEAObject bea) {
pcallOpt(bea, "_deactivate");
}
public void onNewWebSocket(WebSocketInfo ws) {
super.onNewWebSocket(ws);
Req req = (Req) (ws.req);
String uri = ws.uri;
BEAObject reifiedWebSocket = null;
if (webSocketsToBEA()) {
long _startTime_29 = sysNow();
var webRequest = req == null ? null : req.webRequest;
var cookie = cookieFromWebRequest(webRequest);
User user = user(req);
reifiedWebSocket = cnew(webSocketClass, "webSocketInfo", ws, "type", "Live WebSocket", "uri", uri, "user", user);
ws.dbRepresentation = reifiedWebSocket;
ws.eval(replaceDollarVars("$(\".webSocketPlaceholder\").html($html);", "html", jsQuote(beaHTML(reifiedWebSocket))));
done2_always("Reify WebSocket", _startTime_29);
}
Matches m = new Matches();
if (startsWith(uri, "/beaHTML/", m)) {
BEAObject handler = beaGet(m.rest());
if (handler != null) {
print("Have WebSocket " + reifiedWebSocket + "/" + ws + " at " + uri + " for " + handler);
if (!handler._isAlive()) {
print("HAndler not alive!?");
return;
}
cset(reifiedWebSocket, "handler", handler);
beaPcall(handler, "useWebSocket", ws);
}
}
}
transient public Class extends BWebSocket> webSocketClass = BWebSocket.class;
public void onWebSocketClose(WebSocketInfo ws) {
super.onWebSocketClose(ws);
cdelete((Concept) ws.dbRepresentation);
}
transient public TimedCache webSocketsToBEA_cache = new TimedCache<>(10.0, () -> webSocketsToBEA_load());
public boolean webSocketsToBEA() {
return webSocketsToBEA_cache.get();
}
public Boolean webSocketsToBEA_load() {
return getBoolOpt("webSocketsToBEA", liveGazelleSettings());
}
transient public TimedCache reifyHTTPRequests_cache = new TimedCache<>(10.0, () -> reifyHTTPRequests_load());
public boolean reifyHTTPRequests() {
return reifyHTTPRequests_cache.get();
}
public Boolean reifyHTTPRequests_load() {
return getBoolOpt("reifyHTTPRequests", liveGazelleSettings());
}
public BSettings gazelleSettings() {
return conceptWhere(BSettings.class);
}
public BEAObject liveGazelleSettings() {
return first(filter(__52 -> createdByMasterUser(__52), beaList("Live Gazelle Settings")));
}
public Object withFrame(String html) {
return serveWithNavigation(html);
}
public Object serveWithNavigation(String html) {
var framer = framer();
framer.add(html);
return completeFrame();
}
@Override
public Object completeFrame_base(DynGazelleRocks.Req req) {
if (nempty(((Req) req).makers))
((Req) req).framer.addNavItem(hPopDownButtonWithText("Page by", map(((Req) req).makers, o -> {
if (o instanceof BEAObject)
return beaHTML_targetBlank(((BEAObject) o));
return htmlEncode2(shortenStr(o, 40));
})));
return super.completeFrame_base(((Req) req));
}
public List> renderStats_base() {
return listPlusItems_inPlace(super.renderStats_base(), ll("Live / dead class paths", n2(classLoaderPathsCount(dm_moduleClassLoader())) + " / " + n2(deadClassPaths)));
}
transient public IVF2 makeNavItems;
@Override
public void makeNavItems(DynGazelleRocks.Req req, HTMLFramer1 framer) {
if (makeNavItems != null)
makeNavItems.get(req, framer);
else
makeNavItems_base(req, framer);
}
final public void makeNavItems_fallback(IVF2 _f, DynGazelleRocks.Req req, HTMLFramer1 framer) {
if (_f != null)
_f.get(req, framer);
else
makeNavItems_base(req, framer);
}
public void makeNavItems_base(DynGazelleRocks.Req req, HTMLFramer1 framer) {
super.makeNavItems(req, framer);
if (moveNavItemsToMisc) {
var navItems = cloneList(framer.navItems);
framer.clearNavItems();
String webSocketPlaceholder = span("", "class", "webSocketPlaceholder");
framer.addNavItem(hPopDownButtonWithText("Misc", map(navItems, ni -> framer.renderNavItem(ni))) + " " + webSocketPlaceholder);
}
if (findConcept(CMissingObject.class) != null)
framer.addNavItem(makeClassNavItem(CMissingObject.class, req));
}
transient public int showMoreThreshold = 500;
transient public int showMoreHeight = 250;
transient public IF1 addShowMoreButton;
public String addShowMoreButton(String html) {
return addShowMoreButton != null ? addShowMoreButton.get(html) : addShowMoreButton_base(html);
}
final public String addShowMoreButton_fallback(IF1 _f, String html) {
return _f != null ? _f.get(html) : addShowMoreButton_base(html);
}
public String addShowMoreButton_base(String html) {
if (l(html) < showMoreThreshold)
return html;
return new HDivWithVerticalExpandButton(showMoreHeight, html).html();
}
public boolean deleteQsWhenEmpty() {
BSettings settings = gazelleSettings();
return settings != null && settings.deleteQsWhenEmpty;
}
public Set activateOnlyTheseIDs() {
if (empty(activateOnlyTheseIDs))
return null;
return mapToLinkedHashSet(__66 -> parseLong(__66), tok_integers(activateOnlyTheseIDs));
}
public Set dontActivateTheseIDs() {
if (empty(dontActivateTheseIDs))
return null;
return mapToLinkedHashSet(__67 -> parseLong(__67), tok_integers(dontActivateTheseIDs));
}
public GazelleBEA beaMod() {
return this;
}
public Object beaCall(BEAObject c, String method, Object... args) {
return cCall(c, method, args);
}
public Object beaCallOpt(BEAObject c, String method, Object... args) {
return cCallOpt(c, method, args);
}
public Object beaPcall(BEAObject c, String method, Object... args) {
return cPcall(c, method, args);
}
public Object beaCall(Concept.Ref ref, String method, Object... args) {
return cCall(ref, method, args);
}
public Object beaPcall(Concept.Ref ref, String method, Object... args) {
return cPcall(ref, method, args);
}
public Object beaCall(long id, String method, Object... args) {
return cCall(beaMod().beaGet(id), method, args);
}
public Object beaPcall(long id, String method, Object... args) {
return cPcall(beaMod().beaGet(id), method, args);
}
public Object beaCallOpt(long id, String method, Object... args) {
return cCallOpt(beaMod().beaGet(id), method, args);
}
public A beaGet(Class c, String key, GazelleBEA.Req req) {
return optCast(c, beaGet(key, req));
}
public String beaHTMLURL(BEAObject o) {
return o == null ? null : beaMod().baseLink + "/beaHTML/" + o.id;
}
public String beaHTML(Object o) {
if (o instanceof BEAObject)
return beaHTML(((BEAObject) o));
return htmlEncode2(o);
}
public BEAObject beaGetOpt(long id) {
return getConceptOpt(BEAObject.class, id);
}
static public Collection beaDeleteType(String type) {
return deleteConceptsWhereIC(BEAObject.class, "type", type);
}
public int beaCount(String type) {
return countConceptsWhereCI(BEAObject.class, "type", type);
}
public BEAObject beaNew(Object... __) {
__ = prependParamIfOddCount("type", __);
return cnew(BEAObject.class, __);
}
public String getGlobalCode(List tok) {
Var global = new Var<>("");
int idx;
while ((idx = jfind_any(tok, "global {", "exports {")) >= 0) {
int j = findEndOfBracketPart(tok, idx + 2);
global.set(joinSubList(tok, idx + 3, j - 1));
clearTokens(tok, idx, j + 1);
}
return global.get();
}
public String getGlobalCode(BEAObject o) {
return getGlobalCode(javaTok(codeForObject(o)));
}
public AutoCloseable beaEnter(BEAObject o) {
if (o == null)
return null;
return combineAutoCloseables(tempSetTL(beaThreadOwner, o), enter());
}
public JComponent visualize() {
JComponent _c = super.visualize();
addControls();
return _c;
}
public void addControls() {
}
transient public IF1 beaObjectToString_long;
public String beaObjectToString_long(BEAObject o) {
return beaObjectToString_long != null ? beaObjectToString_long.get(o) : beaObjectToString_long_base(o);
}
final public String beaObjectToString_long_fallback(IF1 _f, BEAObject o) {
return _f != null ? _f.get(o) : beaObjectToString_long_base(o);
}
public String beaObjectToString_long_base(BEAObject o) {
return beaObjectToString_long_static(o);
}
static public String beaObjectToString_long_static(BEAObject o) {
if (o == null)
return "null";
String type = strOrNull(cget("type", o));
String s = or2(type, "(no type)");
s += " " + o.id;
s += appendBracketed(strOrNull(getOpt("label", o)));
if (eqic(type, "Match"))
s += " " + getOpt("mapping", o);
boolean enabled = eq(true, getOpt("enabled", o));
if (enabled)
s += " [enabled]";
String purpose = getStringOpt("purpose", o);
if (nempty(purpose))
s += " " + quote(purpose);
String text = or2(o.text(), getStringOpt("name", o), getStringOpt("internalCode", o));
if (text != null)
s += " " + quote(text);
Object fc = getOpt("functionCalled", o);
if (fc != null)
s += " " + fc;
Object result = getOpt("result", o);
if (result != null)
s += " = " + shorten_str(result);
return s;
}
public boolean useErrorHandling() {
return false;
}
public User findOrCreateUserForLogin(String name, String pw) {
{
User u = super.findOrCreateUserForLogin(name, pw);
if (u != null)
return u;
}
Object u = vmBus_query("lookupGazelleUser", name, pw, passwordSalt());
if (u == null)
return null;
String contact = getString("contact", u);
var passwordMD5 = new SecretValue(hashPW(pw));
if (passwordMD5 == null)
return null;
boolean isMaster = getBoolOpt("isMaster", u);
return cnew(User.class, "name", name, "contact", contact, "passwordMD5", passwordMD5, "isMaster", isMaster, "copiedFromMainDB", true);
}
public String conceptLink(Concept c) {
if (c instanceof BEAObject)
return beaShortURL(((BEAObject) c));
return super.conceptLink(c);
}
public String conceptLink_long(Concept c) {
return super.conceptLink(c);
}
public Req newReq() {
return new Req();
}
public Req currentReq() {
return (Req) currentReq.get();
}
public class Req extends DynGazelleRocks.Req {
public Set makers = syncCompactSet();
public void add(Object html) {
framer.add(html);
}
}
}
static public class BEAObject extends ConceptWithGlobalID {
public UserPost mirrorPost() {
return (UserPost) cget("mirrorPost", this);
}
public void change() {
super.change();
var mod = beaMod();
if (mod != null) {
mod.rstUpdateBEAMirrors.add(this);
if (mod.autoActivateDynamicObjects)
mod.rstAutoActivateDynamicObjects.add(this);
}
}
public void delete() {
cdelete(mirrorPost());
pcallOpt(this, "_deactivate");
super.delete();
}
public void updateMirrorPost() {
GazelleBEA mod = beaMod();
if (isDeleted() || !mod.mirrorBEAObjects)
return;
if (mirrorPost() == null)
cset(this, "mirrorPost", cnew(UserPost.class, "type", "BEA Object", "creator", mod.internalUser(), "botInfo", "BEA Mirror Bot"));
String text = structureString();
cset(mirrorPost(), "title", str(this), "text", text);
}
public String structureString() {
String text = "Error";
try {
structure_Data data = new structure_Data() {
public structure_ClassInfo newClass(Class c) {
structure_ClassInfo info = super.newClass(c);
if (c == Concept.Ref.class) {
info.special = true;
info.serializeObject = o -> {
Concept cc = (Concept) (deref((Concept.Ref) o));
if (cc != null)
append("CRef(id=" + cc.id + ", c=" + quote(dynShortClassName(cc)) + ")", 6);
else
append("CRef", 1);
};
}
return info;
}
public void setFields(structure_ClassInfo info, List fields) {
if (isSubclassOf(info.c, BEAObject.class)) {
removeAll(fields, getField(BEAObject.class, "refs"), getField(BEAObject.class, "backRefs"));
}
super.setFields(info, fields);
}
};
String struct = structure(this, data);
struct = structure_convertTokenMarkersToExplicit(struct);
struct = dropLoadableUtilsPackageFromStruct(struct);
text = indentStructureString_firstLevels(1, struct);
} catch (Throwable __e) {
_handleException(__e);
}
return text;
}
public String toString() {
return shorten(toString_long());
}
public String toString_long() {
var mod = beaMod();
if (mod != null)
return mod.beaObjectToString_long(this);
return "[NO MODULE] " + mod.beaObjectToString_long_static(this);
}
public boolean _isAlive() {
return !_conceptsDefunctOrUnregistered();
}
public boolean hasCustomCode() {
return cget("meta_code", this) != null || cget("meta_prototype", this) != null;
}
public boolean customCodeLoaded() {
String className = getStringOpt("meta_javaClass", this);
return className != null && eq(replace(className(this), "$", "."), className);
}
public String type() {
return getStringOpt("type", this);
}
public boolean typeIs(String type) {
return eqic(type(), type);
}
public boolean typeIsAny(String... types) {
return typeIsOneOf(types);
}
public boolean typeIsOneOf(String... types) {
return eqicOneOf(type(), types);
}
public String text() {
return getStringOpt("text", this);
}
public BEAObject input() {
return (BEAObject) cget("input", this);
}
public BEAObject isRewriteOf() {
return (BEAObject) cget("isRewriteOf", this);
}
public String inputText() {
BEAObject input = or(input(), isRewriteOf());
return input == null ? null : input.text();
}
public Map mapping() {
return keysAndValuesToString(cgetOpt(Map.class, this, "mapping"));
}
public List directCmds() {
return ll();
}
public Collection allObjects() {
return list(_concepts, BEAObject.class);
}
public String baseLink() {
return beaMod().baseLink;
}
public BEAObject beaGet(String field, BEAObject o) {
return beaMod().beaGet(field, o);
}
public BEAObject beaGet(long id) {
return beaMod().beaGet(id);
}
public BEAObject beaGet(String field) {
return beaMod().beaGet(field, this);
}
public Object beaCall(BEAObject c, String method, Object... args) {
return cCall(c, method, args);
}
public Object beaCallOpt(BEAObject c, String method, Object... args) {
return cCallOpt(c, method, args);
}
public Object beaPcall(BEAObject c, String method, Object... args) {
return cPcall(c, method, args);
}
public Object beaCall(Concept.Ref ref, String method, Object... args) {
return cCall(ref, method, args);
}
public Object beaPcall(Concept.Ref ref, String method, Object... args) {
return cPcall(ref, method, args);
}
public Object beaCall(long id, String method, Object... args) {
return cCall(beaMod().beaGet(id), method, args);
}
public Object beaPcall(long id, String method, Object... args) {
return cPcall(beaMod().beaGet(id), method, args);
}
public Object beaCallOpt(long id, String method, Object... args) {
return cCallOpt(beaMod().beaGet(id), method, args);
}
public A beaGet(Class c, String key, GazelleBEA.Req req) {
return optCast(c, beaGet(key, req));
}
public String beaHTMLURL(BEAObject o) {
return o == null ? null : beaMod().baseLink + "/beaHTML/" + o.id;
}
public String beaHTML(Object o) {
if (o instanceof BEAObject)
return beaHTML(((BEAObject) o));
return htmlEncode2(o);
}
public BEAObject beaGetOpt(long id) {
return getConceptOpt(BEAObject.class, id);
}
static public Collection beaDeleteType(String type) {
return deleteConceptsWhereIC(BEAObject.class, "type", type);
}
public int beaCount(String type) {
return countConceptsWhereCI(BEAObject.class, "type", type);
}
public BEAObject beaNew(Object... __) {
__ = prependParamIfOddCount("type", __);
return cnew(BEAObject.class, __);
}
public gazelle.main.GazelleBEA beaMod() {
return _concepts == null ? main.beaMod() : (GazelleBEA) _concepts.miscMapGet(DynNewBot2.class);
}
public Collection beaAll() {
return beaList();
}
public Collection beaList() {
return beaMod().beaList();
}
public Collection beaListAny(String... types) {
return beaMod().beaListAny(types);
}
public Collection beaList(String type, Object... params) {
return beaMod().beaList(type, params);
}
public String beaHTML(BEAObject o) {
return beaMod().beaHTML(o);
}
public String beaURL(BEAObject o) {
return beaShortURL(o);
}
public String beaShortURL(BEAObject o) {
return beaMod().beaURL(o);
}
public String fixHtml(String html) {
return fixHTML(html);
}
public String htmlFixer(String html) {
return fixHTML(html);
}
public String htmlFix(String html) {
return fixHTML(html);
}
public String fixHTML(String html) {
return beaMod().callHTMLFixer(this, html);
}
public boolean createdByMasterUser(BEAObject o) {
return beaMod().createdByMasterUser(o);
}
public String myURI() {
return beaMod().baseLink + "/beaHTML/" + id;
}
public void massageItemMapForList(Map map) {
}
public BEAObject beaGet(String key, GazelleBEA.Req req) {
return beaMod().beaGet(key, req);
}
public BEAObject me() {
return this;
}
public Object completeFrame(GazelleBEA.Req req) {
return beaMod().completeFrame(req);
}
}
static public class BEARegExp extends BEAObject {
static final public String _fieldOrder = "text caseInsensitive";
public String text;
public boolean caseInsensitive = true;
public boolean valid() {
return nempty(text);
}
public java.util.regex.Pattern compile() {
return compileRegexpPossiblyIC_unicodeCase(text, caseInsensitive);
}
}
static public class BEARegExpReplacement extends BEARegExp {
public String replacement;
public String apply(String text) {
try {
return regexpReplace_directWithRefs(compile().matcher(text), unnull(replacement));
} catch (Throwable e) {
throw fail(format_quoted("Was searching * in * ", this.text, text));
}
}
public List directCmds() {
return listPlus(super.directCmds(), !valid() ? "Note: not valid" : targetBlank(beaMod().queryLink("Apply regular expression replacement to all inputs", str(id)), "Apply to all inputs"));
}
}
static public class BEAPatternList extends BEAObject {
public RefL patterns = new RefL();
public String toString() {
return super.toString() + ": " + nPatterns(patterns);
}
}
static public GazelleBEA beaMod() {
return (GazelleBEA) dm_current_mandatory();
}
static public JavaXClassLoader hotwire_makeClassLoader(List files) {
ClassLoader cl = myClassLoader();
return new JavaXClassLoaderWithParent2(null, files, cl, ll());
}
static public class BWebSocket extends BEAObject {
static final public String _fieldOrder = "webSocketInfo screenShot onScreenShotChanged";
transient public GazelleBEA.WebSocketInfo webSocketInfo;
transient public WithTimestamp screenShot;
transient public Set onScreenShotChanged = syncLinkedHashSet();
public void sendJavaScript(String js) {
if (empty(js))
return;
Object ws = getWeakRef(webSocketInfo.webSocket);
call(ws, "send", jsonEncode(litorderedmap("eval", js)));
}
public void setScreenShot(WithTimestamp screenShot) {
this.screenShot = screenShot;
vmBus_send("screenShotChanged", this, screenShot);
print("Listeners: " + cloneList(onScreenShotChanged));
pcallFAll(onScreenShotChanged);
}
}
static public class BWithResources extends BEAObject {
static final public String _fieldOrder = "resources q log activated meta_shouldActivate";
transient public CloseablesHolder resources = new CloseablesHolder();
transient public Q q = startQ();
public List> log;
transient public boolean activated = false;
public boolean meta_shouldActivate = true;
public AutoCloseable enter() {
return beaMod().beaEnter(this);
}
public void _handleException(Throwable e) {
beaPrint(getStackTrace(e));
}
public boolean _active() {
return activated;
}
final public void _activate() {
addToQ(new Runnable() {
public void run() {
try {
if (activated)
return;
activated = true;
_activateImpl();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (activated) return;\r\n activated = true;\r\n _activateImpl();";
}
});
}
public void _activateImpl() {
}
public void _deactivate() {
addToQ(new Runnable() {
public void run() {
try {
_deactivateImpl();
resources.close();
activated = false;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "_deactivateImpl();\r\n resources.close();\r\n activated = false;";
}
});
}
public void _deactivateImpl() {
}
public void delete() {
_deactivate();
waitForQToEmpty(q());
super.delete();
}
public void addResource(AutoCloseable r) {
resources.add(r);
}
public void clearBEAPrintLog() {
inQ(new Runnable() {
public void run() {
try {
log = null;
change();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "log = null;\r\n change();";
}
});
}
public int maxBeaPrintLength() {
return 10000;
}
public void beaPrint(Object o) {
beaPrint("", o);
}
public void beaPrint(String s, Object o) {
AutoCloseable __35 = enter();
try {
inQ(new Runnable() {
public void run() {
try {
String text = combinePrintParameters(s, o);
text = shorten(maxBeaPrintLength(), text);
if (log == null)
log = new ArrayList();
synchronized (log) {
truncateListFromStart(log, maxLogSize() - 1);
printIndent(id + "|", text);
log.add(new WithTimestamp(text));
}
change();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "String text = combinePrintParameters(s, o);\r\n text = shorten(maxBeaPrint...";
}
});
} finally {
_close(__35);
}
}
public int maxLogSize() {
return getIntOpt("maxLogSize", this, 10);
}
public BWithResources me() {
return this;
}
public void inQ(Runnable r) {
if (r == null)
return;
if (isInQ(q))
r.run();
else
addToQ(r);
}
public void addToQ(Runnable r) {
if (r == null)
return;
getQ().add(new Runnable() {
public void run() {
try {
AutoCloseable __36 = enter();
try {
try {
r.run();
} catch (Throwable e) {
beaPrint(getStackTrace(e));
}
} finally {
_close(__36);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp enter(); \r\n try {\r\n r.run();\r\n } catch (Throwable e) {\r...";
}
});
}
public Q q() {
return getQ();
}
public Q getQ() {
return q;
}
}
static public class BSettings extends Concept {
public boolean deleteQsWhenEmpty = false;
}
static public class BHTTPRequest extends BEAObject {
transient public GazelleBEA.Req req;
}
static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static volatile public Concepts mainConcepts;
static public Concepts db_mainConcepts() {
if (mainConcepts == null)
mainConcepts = newConceptsWithClassFinder(getDBProgramID());
return mainConcepts;
}
static public void cleanMeUp_concepts() {
if (db_mainConcepts() != null)
db_mainConcepts().cleanMeUp();
}
static public String unnullForIteration(String s) {
return s == null ? "" : s;
}
static public Collection unnullForIteration(Collection l) {
return l == null ? immutableEmptyList() : l;
}
static public List unnullForIteration(List l) {
return l == null ? immutableEmptyList() : l;
}
static public int[] unnullForIteration(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnullForIteration(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnullForIteration(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public Map unnullForIteration(Map l) {
return l == null ? immutableEmptyMap() : l;
}
static public Iterable unnullForIteration(Iterable i) {
return i == null ? immutableEmptyList() : i;
}
static public A[] unnullForIteration(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnullForIteration(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnullForIteration(Pt p) {
return p == null ? new Pt() : p;
}
static public Pair unnullForIteration(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public long unnullForIteration(Long l) {
return l == null ? 0L : l;
}
static public Map flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_first(String pat, String input) {
return grabValueAndCancel(new VF1>>() {
public void get(VF1> onMatch) {
try {
flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_iterate(pat, input, onMatch);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_iterate(pat, input, o...";
}
});
}
static public String appendSquareBracketed(String b) {
return empty(b) ? "" : "" + " [" + b + "]";
}
static public String appendSquareBracketed(String a, String b) {
return empty(b) ? a : a + appendSquareBracketed(b);
}
static public String jquery_submitFormOnCtrlEnter() {
return "if ((event.keyCode == 10 || event.keyCode == 13) && event.ctrlKey) $(this).closest('form').submit();";
}
static public String hjs_handleScrollToAnchor() {
return hjs("\r\n $(window).on(\"load\", function() {\r\n var anchor = window.location.hash.substr(1);\r\n var match = anchor.match(/^scrollTo(\\d+)$/);\r\n if (match) {\r\n var y = parseInt(match[1]);\r\n console.log(\"Scrolling to \" + y);\r\n window.scrollTo(0, y);\r\n }\r\n });\r\n ");
}
static public boolean userAgentIsBot(String userAgent) {
return cic(userAgent, "bot") || cic(userAgent, "crawler");
}
static public String js_redirectAutoScroll2() {
return "$(\"input[name=redirect], input[name=redirectAfterSave]\").val(window.location.toString().replace(/(#.+?)$/, \"\") + (window.scrollY == 0 ? \"\" : \"#scrollTo\" + Math.round(window.scrollY)));";
}
static public String hSingleRowTable_withSpacing(Object... elements) {
return hSingleRowTable_withSpacing(10, elements);
}
static public String hSingleRowTable_withSpacing(int spacing, Object... elements) {
return tag("table", tr(join(" ", map(new F1() {
public String get(Object x) {
try {
return td_top(x);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "td_top(x)";
}
}, nonNulls(elements)))));
}
static public String targetBlank_noFollow(String link, Object contents, Object... params) {
return tag("a", contents, paramsPlus(params, "href", link, "target", "_blank", "rel", "nofollow"));
}
static public String tok_dropCurlyBrackets(String s) {
return join(tok_dropCurlyBrackets(javaTok(s)));
}
static public List tok_dropCurlyBrackets(List tok) {
for (int i = 1; i < l(tok); i += 2) {
while (eqGetOneOf(tok, i, "{", "}")) {
tokAppend(tok, i - 1, tok.get(i + 1));
removeSubList(tok, i, i + 2);
}
}
return tok;
}
static public Map mapToKey(Iterable l, IF1 f) {
return mapToKeys(l, f);
}
static public Map mapToKey(IF1 f, Iterable l) {
return mapToKeys(f, l);
}
static public List wideningListCast(Class c, List l) {
return (List) l;
}
static public Collection wideningListCast(Class c, Collection