Warning : session_start(): open(/var/lib/php/sessions/sess_m29gk3vkqg1cc3mdc0of8cdon8, 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 java.util.function.*;
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 java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import com.microsoft.playwright.*;
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.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 loadableUtils.utils;
import loadableUtils.utils.CloseablesHolder;
import loadableUtils.utils.UploadedImage;
import loadableUtils.utils.UploadedFile;
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.format3;
import static loadableUtils.utils.struct;
import static loadableUtils.utils.structure;
import static loadableUtils.utils.cset;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.rethrow;
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.IConceptCounter;
import loadableUtils.utils.IFieldIndex;
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.HTML;
import static loadableUtils.utils.startsWithOneOf;
import static loadableUtils.utils.appendParamsToURL;
import static loadableUtils.utils.litset;
import static loadableUtils.utils.printStackTrace;
import static loadableUtils.utils.replacePrefix;
import static loadableUtils.utils.loadJQuery2;
import static loadableUtils.utils.cget;
import static loadableUtils.utils.javaTok;
import static loadableUtils.utils.getConcept;
import static loadableUtils.utils.addPrefix;
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.addParamToURL;
import static loadableUtils.utils.match2;
import static loadableUtils.utils.trueOrNull;
import static loadableUtils.utils.callMain;
import static loadableUtils.utils.empty;
import static loadableUtils.utils.containsAngleBracketVars;
import static loadableUtils.utils.list;
import static loadableUtils.utils.hasMethod;
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.addSlash;
import static loadableUtils.utils.charAt;
import static loadableUtils.utils.conceptWhere;
import static loadableUtils.utils.getSnippetTitles;
import static loadableUtils.utils.dropTrailingSlash;
import static loadableUtils.utils.getOuterClass;
import static loadableUtils.utils.cloneList;
import static loadableUtils.utils.hstyle_sourceCodeLikeInRepo;
import static loadableUtils.utils.ping;
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.tok_tokenBeforeLonelyReturnValue;
import static loadableUtils.utils.eqOneOf;
import static loadableUtils.utils.joinWithBR;
import static loadableUtils.utils.javaxDataDir;
import static loadableUtils.utils.substring;
import static loadableUtils.utils.cleanUp;
import static loadableUtils.utils.mapPutInRange;
import static loadableUtils.utils.getConceptOpt;
import static loadableUtils.utils.hhtml;
import static loadableUtils.utils.appendBracketed;
import static loadableUtils.utils.js_evalOnWebSocketMessage;
import static loadableUtils.utils.aGlobalID;
import static loadableUtils.utils.synchroWeakHashSet;
import static loadableUtils.utils.toDouble;
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.dottedSpan;
import static loadableUtils.utils.pnl;
import static loadableUtils.utils.hPopDownButton;
import static loadableUtils.utils.hcenter3;
import static loadableUtils.utils.shortName;
import static loadableUtils.utils.camelCase;
import static loadableUtils.utils.subBot_noCacheHeaders;
import static loadableUtils.utils.instancesOf;
import static loadableUtils.utils.swic;
import static loadableUtils.utils.unnull;
import static loadableUtils.utils.joinWithComma;
import static loadableUtils.utils.conceptsWithFieldGreaterThan_sorted;
import static loadableUtils.utils.replaceDollarVars;
import static loadableUtils.utils.postPage;
import static loadableUtils.utils.subList;
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.psI;
import static loadableUtils.utils.warn;
import static loadableUtils.utils.isStringList;
import static loadableUtils.utils.plural;
import static loadableUtils.utils.addIfNotNull;
import static loadableUtils.utils.distinctCIFieldValuesOfConcepts;
import static loadableUtils.utils.startQ;
import static loadableUtils.utils.filterKeys;
import static loadableUtils.utils.htmlencode;
import static loadableUtils.utils.pair;
import static loadableUtils.utils.hbutton;
import static loadableUtils.utils.parseInt;
import static loadableUtils.utils.hbuttonLink;
import static loadableUtils.utils.lastIndexOf;
import static loadableUtils.utils.parseFirstLong;
import static loadableUtils.utils.vmBus_timerStarted;
import static loadableUtils.utils.litciset;
import static loadableUtils.utils.joinWithSpace;
import static loadableUtils.utils.printIndent;
import static loadableUtils.utils.put;
import static loadableUtils.utils.fileNotEmpty;
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.isSnippetID;
import static loadableUtils.utils.hjs_copyToClipboard;
import static loadableUtils.utils.codeTokens;
import static loadableUtils.utils.listPlus;
import static loadableUtils.utils.jreplace;
import static loadableUtils.utils.fromSingleQuoteIdentifier;
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.makePostData;
import static loadableUtils.utils.dynamize_noEncode;
import static loadableUtils.utils.minutes;
import static loadableUtils.utils.wrapInDiv;
import static loadableUtils.utils.hjs;
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.parseLongOpt;
import static loadableUtils.utils.toObjectArray;
import static loadableUtils.utils.loadTextFile;
import static loadableUtils.utils.mapValues;
import static loadableUtils.utils.hbody;
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.isSingleQuoteIdentifier;
import static loadableUtils.utils.javaTokWithAngleBrackets;
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.htitle_h2;
import static loadableUtils.utils.htitle_h1;
import static loadableUtils.utils.stdFunctions_cached;
import static loadableUtils.utils.domain;
import static loadableUtils.utils.subBot_serve404;
import static loadableUtils.utils.hreconnectingWebSockets;
import static loadableUtils.utils.hscript;
import static loadableUtils.utils.exceptionToStringShort;
import static loadableUtils.utils.toString;
import static loadableUtils.utils.div;
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.dropLoadableUtilsPackageFromStruct;
import static loadableUtils.utils.hashCode;
import static loadableUtils.utils.shortClassName;
import static loadableUtils.utils.postProcess;
import static loadableUtils.utils.htextfield;
import static loadableUtils.utils.hhidden;
import static loadableUtils.utils.print;
import static loadableUtils.utils.mapPairs;
import static loadableUtils.utils.lock;
import static loadableUtils.utils.firstToLower;
import static loadableUtils.utils.simpleSpacesTrim_javaTok;
import static loadableUtils.utils.hpostform;
import static loadableUtils.utils.litlist;
import static loadableUtils.utils.toMS;
import static loadableUtils.utils.cancelTimer;
import static loadableUtils.utils.map;
import static loadableUtils.utils.isStringCollection;
import static loadableUtils.utils.max;
import static loadableUtils.utils.addParamsToURL;
import static loadableUtils.utils.md5;
import static loadableUtils.utils.javaValueToHTML;
import static loadableUtils.utils.isTrue_getOpt;
import static loadableUtils.utils.htmlEncode_quote;
import static loadableUtils.utils.indexConceptFieldIC;
import static loadableUtils.utils.hotwire_makeClassLoader;
import static loadableUtils.utils.deref;
import static loadableUtils.utils.dbBot;
import static loadableUtils.utils.putAll;
import static loadableUtils.utils.sourceCodeToHTML_noEncode;
import static loadableUtils.utils.dropSuffix;
import static loadableUtils.utils.subBot_serveWithContentType;
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.isURL;
import static loadableUtils.utils.elapsedSeconds_sysNow;
import static loadableUtils.utils.pairsA;
import static loadableUtils.utils.swic_notSame;
import static loadableUtils.utils.hstyle;
import static loadableUtils.utils.uncurly;
import static loadableUtils.utils.min;
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.himgsnippet;
import static loadableUtils.utils.jsQuote;
import static loadableUtils.utils.htmlEncode2_nlToBr;
import static loadableUtils.utils.ymd_minus_hms;
import static loadableUtils.utils.hsnippetimg_scaleToWidth;
import static loadableUtils.utils.evalWithTimeout;
import static loadableUtils.utils.lookupPossiblyCI;
import static loadableUtils.utils.strOrNull;
import static loadableUtils.utils._close;
import static loadableUtils.utils.starsToAngleBracketedNumbers;
import static loadableUtils.utils.countPred;
import static loadableUtils.utils.jsonDecodeMap;
import static loadableUtils.utils._entrySet;
import static loadableUtils.utils.first;
import static loadableUtils.utils.span;
import static loadableUtils.utils.litorderedmap;
import static loadableUtils.utils.tok_subListWithoutBorderNTokens;
import static loadableUtils.utils.multiSetToPairsByPopularity;
import static loadableUtils.utils.mapPut;
import static loadableUtils.utils.objectToMap;
import static loadableUtils.utils.hsnippetimg;
import static loadableUtils.utils.renderEqualsCommaProperties;
import static loadableUtils.utils.hjs_autoExpandingTextAreas;
import static loadableUtils.utils.hmobilefix;
import static loadableUtils.utils.dropDollarPrefix;
import static loadableUtils.utils.printVars_str;
import static loadableUtils.utils.hotwire;
import static loadableUtils.utils.round;
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.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.subBot_serveRedirect;
import static loadableUtils.utils.uniquifyCI;
import static loadableUtils.utils.close;
import static loadableUtils.utils.ewicOneOf;
import static loadableUtils.utils.standardClassesMap;
import static loadableUtils.utils.conceptWhereIC;
import static loadableUtils.utils.swing;
import static loadableUtils.utils.stdFunctions_uncached;
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.hcss;
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.lines;
import static loadableUtils.utils.unquote;
import static loadableUtils.utils.tok_expandIfQuoted;
import static loadableUtils.utils.nempty;
import static loadableUtils.utils.serveText;
import static loadableUtils.utils.sortByConceptID;
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.hrefresh;
import static loadableUtils.utils.countConceptsWhereIC;
import static loadableUtils.utils.beforeVerticalBar;
import static loadableUtils.utils.isIdentifier;
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.uniq;
import static loadableUtils.utils.collect;
import static loadableUtils.utils.scanForComponents;
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.optCast;
import static loadableUtils.utils.reversed;
import static loadableUtils.utils.done2_always;
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.replaceAngleBracketVars;
import static loadableUtils.utils.litobjectarray;
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.cdelete;
import static loadableUtils.utils.now;
import static loadableUtils.utils.csetIfUnset;
import static loadableUtils.utils.hsubmit;
import static loadableUtils.utils.eqicOneOf;
import static loadableUtils.utils.htitle;
import static loadableUtils.utils.htmlEncode2;
import static loadableUtils.utils.hdiv;
import static loadableUtils.utils.dropLeadingSlash;
import static loadableUtils.utils.optPar;
import static loadableUtils.utils.allPlus;
import static loadableUtils.utils.h1_title;
import static loadableUtils.utils.javaTokC;
import static loadableUtils.utils.callFAll;
import static loadableUtils.utils.match3_withIntsAndIDs;
import static loadableUtils.utils.getClass;
import static loadableUtils.utils.containsKey;
import static loadableUtils.utils.jsonEncode;
import static loadableUtils.utils.joinNemptiesWithVBar;
import static loadableUtils.utils.mapGet;
import static loadableUtils.utils.parseSnippetID;
import static loadableUtils.utils.firstToUpper;
import static loadableUtils.utils.asList;
import static loadableUtils.utils.neatMechListURL;
import static loadableUtils.utils.endsWith;
import static loadableUtils.utils.listSet;
import static loadableUtils.utils.hfulltag;
import static loadableUtils.utils.allBackRefs;
import static loadableUtils.utils.vmBus_send;
import static loadableUtils.utils.serveJSON;
import static loadableUtils.utils.set;
import static loadableUtils.utils.hselect_list;
import static loadableUtils.utils.sfu;
import static loadableUtils.utils.getStackTrace;
import static loadableUtils.utils.javax;
import static loadableUtils.utils.isQuoted;
import static loadableUtils.utils.hhiddenMulti;
import static loadableUtils.utils.isFalse;
import static loadableUtils.utils.eq;
import static loadableUtils.utils.hinlinepostform;
import static loadableUtils.utils.hform;
import static loadableUtils.utils.h1;
import static loadableUtils.utils.h2;
import static loadableUtils.utils.h3;
import static loadableUtils.utils.random;
import static loadableUtils.utils.md5OrNull;
import static loadableUtils.utils.pcallFAll;
import static loadableUtils.utils.getString;
import static loadableUtils.utils.conceptsFile;
import static loadableUtils.utils.urlencode;
import static loadableUtils.utils.hr;
import static loadableUtils.utils.join;
import static loadableUtils.utils.fsI;
import static loadableUtils.utils.clamp;
import static loadableUtils.utils.binaryMimeType;
import static loadableUtils.utils.stringTree2_javaTok;
import static loadableUtils.utils.lmap;
import static loadableUtils.utils.ahref_undecorated;
import static loadableUtils.utils.replaceDollarVars_dyn;
import static loadableUtils.utils.change;
import static loadableUtils.utils.assertEquals;
import static loadableUtils.utils.tlft;
import static loadableUtils.utils.dm_startQ;
import static loadableUtils.utils.ll;
import static loadableUtils.utils.n2;
import static loadableUtils.utils.second;
import static loadableUtils.utils.replaceTokens;
import static loadableUtils.utils.takeFirst;
import static loadableUtils.utils.hparagraphs;
import static loadableUtils.utils.jsonEncode_breakAtLevel1;
import static loadableUtils.utils.keys;
import static loadableUtils.utils.uniqCI2_sync;
import static loadableUtils.utils.smartIndexOf;
import static loadableUtils.utils.parseDouble;
import static loadableUtils.utils.ol;
import static loadableUtils.utils.or;
import static loadableUtils.utils.dropPunctuation;
import static loadableUtils.utils.rtrim;
import static loadableUtils.utils.iterator;
import static loadableUtils.utils.putMultipleKeys;
import static loadableUtils.utils.assertNotNull;
import static loadableUtils.utils.str;
import static loadableUtils.utils.tempInterceptPrint;
import static loadableUtils.utils.printWithIndent;
import static loadableUtils.utils.hfullcenter;
import static loadableUtils.utils.appendRoundBracketed;
import static loadableUtils.utils.getMainClass;
import static loadableUtils.utils.asCISet;
import static loadableUtils.utils.th;
import static loadableUtils.utils.syncMapToPairs;
import static loadableUtils.utils.tt;
import static loadableUtils.utils.dm_moduleID;
import static loadableUtils.utils.doublePut;
import static loadableUtils.utils.conceptIDOrNull;
import static loadableUtils.utils.ul;
import static loadableUtils.utils.programDir;
import static loadableUtils.utils.or2;
import static loadableUtils.utils._get;
import static loadableUtils.utils.div_alignRight;
import static loadableUtils.utils.gazelle_allSyntacticPatternsFromInput;
import static loadableUtils.utils.eqGet;
import static loadableUtils.utils.ul_htmlEncode;
import static loadableUtils.utils.eqic;
import static loadableUtils.utils.hpre_htmlencode;
import static loadableUtils.utils.pairA;
import static loadableUtils.utils._handleException;
import static loadableUtils.utils.longSnippetLink;
import static loadableUtils.utils.pairB;
import static loadableUtils.utils.htitledSectionWithDiv;
import static loadableUtils.utils.urldecode;
import static loadableUtils.utils.dropPrefix;
import static loadableUtils.utils.getClientIPFromHeaders;
import static loadableUtils.utils.allToString;
import static loadableUtils.utils.filter;
import static loadableUtils.utils.getWeakRef;
import static loadableUtils.utils.doLater;
import static loadableUtils.utils.ensureDBNotRunning;
import static loadableUtils.utils.findBackRefs;
import static loadableUtils.utils.htmlEncode_nlToBR;
import static loadableUtils.utils.tok_findEndOfStatement;
import static loadableUtils.utils.stringTreeLeafValue2;
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.isInQ;
import static loadableUtils.utils.countTokens;
import static loadableUtils.utils.unicode_smallDownPointingTriangle;
import static loadableUtils.utils.renderVars;
import static loadableUtils.utils.ahref_possiblyTargetBlank;
import static loadableUtils.utils.sysNow;
import static loadableUtils.utils.countConcepts;
import static loadableUtils.utils.hPopDownButtonWithText;
import static loadableUtils.utils.getAll;
import static loadableUtils.utils.hjavascript_src_snippet;
import static loadableUtils.utils.countWordsWithoutAngleBracketedAndStars;
import static loadableUtils.utils.startsWith;
import loadableUtils.utils.Scorer;
import loadableUtils.utils.ConceptsRefChecker;
import loadableUtils.utils.ConceptFieldIndexDesc;
import loadableUtils.utils.IWebRequest;
import loadableUtils.utils.Flag;
import loadableUtils.utils.StringBufferWithMaxSize;
import loadableUtils.utils.IFieldsToList;
import loadableUtils.utils.DynNewBot2;
import loadableUtils.utils.DynGazelleRocks;
import loadableUtils.utils.ConceptWithGlobalID;
import loadableUtils.utils.Timestamp;
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.StringTree2;
import loadableUtils.utils.IntRange;
import loadableUtils.utils.FieldIndicator;
import loadableUtils.utils.JavaXClassLoaderWithParent2;
import loadableUtils.utils.HDivWithVerticalExpandButton;
import loadableUtils.utils.CMissingObject;
import loadableUtils.utils.ConceptsShadowLogger;
import loadableUtils.utils.ConceptClassesDependentValue;
import loadableUtils.utils.ConceptShadow;
import loadableUtils.utils.HTMLPopDownButton;
import loadableUtils.utils.TransitiveHull;
import loadableUtils.utils.CreatedDeletedChanged;
import loadableUtils.utils.HTMLPaginator;
import static loadableUtils.utils.parseEqualsProperties;
import static loadableUtils.utils.nItems;
import static loadableUtils.utils.prependParamIfOddCount;
import static loadableUtils.utils.objectsWhereNotIC;
import static loadableUtils.utils._className;
import static loadableUtils.utils.replaceConceptAndUpdateRefs;
import static loadableUtils.utils.afterDollar;
import static loadableUtils.utils.collectAngleBracketVars;
import static loadableUtils.utils.regexpToLongIC;
import static loadableUtils.utils.countWhereCI;
import static loadableUtils.utils.regexpReplace_directWithRefs;
import static loadableUtils.utils.regexpExtractGroups;
import static loadableUtils.utils.rcallOpt;
import static loadableUtils.utils.htmlEncode2_str;
import static loadableUtils.utils.vmClassNameToSubPath;
import static loadableUtils.utils.unicode_thumbsUp;
import static loadableUtils.utils.lastTiming_formatted;
import static loadableUtils.utils.putKeysFirst;
import static loadableUtils.utils.diffConceptShadows;
import static loadableUtils.utils.addByteCodePathToClassLoader;
import static loadableUtils.utils.allConceptShadows;
import static loadableUtils.utils.hasMethodNamed;
import static loadableUtils.utils.indexConceptFieldCIWithTopTen;
import static loadableUtils.utils.startsWithAny;
import static loadableUtils.utils.assertSame;
import static loadableUtils.utils.byteCodePathForClass;
import static loadableUtils.utils.fourth;
import static loadableUtils.utils.shorten_str;
import static loadableUtils.utils.combinePrintParameters;
import static loadableUtils.utils.format_quoted;
import static loadableUtils.utils.unnullForIteration;
import static loadableUtils.utils.mapToLinkedHashSet;
import static loadableUtils.utils.js_redirectAutoScroll2;
import static loadableUtils.utils.pcall;
import static loadableUtils.utils.dm_mediumRefreshTranspiler;
import static loadableUtils.utils.compileRegexpPossiblyIC_unicodeCase;
import static loadableUtils.utils.getBoolOpt;
import static loadableUtils.utils.printVars;
import static loadableUtils.utils.profileThisThreadToString;
import static loadableUtils.utils.getStandardFunctionHolder;
import static loadableUtils.utils.renderConceptClassesWithCount;
import static loadableUtils.utils.tok_integers;
import static loadableUtils.utils.fileExistsInInDirOrZip;
import static loadableUtils.utils.formatGMTWithMilliseconds_24;
import static loadableUtils.utils.subBot_serveFileWithName;
import static loadableUtils.utils.joinNemptiesWithEmptyLines;
import static loadableUtils.utils.findBackRefsWithField;
import static loadableUtils.utils.filesFromClassLoader;
import static loadableUtils.utils.leadingAngleBracketStuff;
import static loadableUtils.utils.jquery_submitFormOnCtrlEnter;
import static loadableUtils.utils.nDiffs;
import static loadableUtils.utils.fixHTML;
import static loadableUtils.utils.dm_reloadModule;
import static loadableUtils.utils.concatMap_lists;
import static loadableUtils.utils.findConcept;
import static loadableUtils.utils.hijackPrintPlusResult_text;
import static loadableUtils.utils.indexConceptClass;
import static loadableUtils.utils.regexpFindRangesIC;
import static loadableUtils.utils.cCall;
import static loadableUtils.utils.toCIMap;
import static loadableUtils.utils.nPatterns;
import static loadableUtils.utils.containsStars;
import static loadableUtils.utils.assertNempty;
import static loadableUtils.utils.call_optional;
import static loadableUtils.utils.distinctCIFieldValuesOfConcepts_multiSet;
import static loadableUtils.utils.transpilerErrorSourceFile;
import static loadableUtils.utils.combineAutoCloseables;
import static loadableUtils.utils.jfind_any;
import static loadableUtils.utils.hjs_handleScrollToAnchor;
import static loadableUtils.utils.unicode_thumbsDown;
import static loadableUtils.utils.id;
import static loadableUtils.utils.unlistedCopyToClass_withConverter;
import static loadableUtils.utils.returnTimed;
import static loadableUtils.utils.cgetOpt;
import static loadableUtils.utils.dropDotSuffix;
import static loadableUtils.utils.classLoaderPathsCount;
import static loadableUtils.utils.csetAndReturn;
import static loadableUtils.utils.htmlDecode_dropTags;
import static loadableUtils.utils.dm_reloadModuleIn;
import static loadableUtils.utils.appendSquareBracketed;
import static loadableUtils.utils.truncateListFromStart;
import static loadableUtils.utils.getAny;
import static loadableUtils.utils.joinWithDot;
import static loadableUtils.utils.ul_htmlEncode2;
import static loadableUtils.utils.wideningListCast;
import static loadableUtils.utils.dm_moduleClassLoader;
import static loadableUtils.utils.hSingleRowTable_withSpacing;
import static loadableUtils.utils.transpileAndCompileForHotwiring;
import static loadableUtils.utils.transpileAndCompileForHotwiring_src;
import static loadableUtils.utils.printAllConceptChanges;
import static loadableUtils.utils.setMinus_inPlace;
import static loadableUtils.utils.tok_dropCurlyBrackets;
import static loadableUtils.utils.classLoader_loadClass;
import static loadableUtils.utils.getConceptOrMarkMissingObject;
import static loadableUtils.utils.keysAndValuesToString;
import static loadableUtils.utils.dm_addByteCodePathToModuleClassLoader;
import static loadableUtils.utils.flexMatchAngleBracketVarsIC_honorPunctuation_noBrackets_first;
import static loadableUtils.utils.regexpFirstGroups;
import static loadableUtils.utils.dm_rstMulti;
import static loadableUtils.utils.syncLinkedHashSet;
import static loadableUtils.utils.listPlusItems_inPlace;
import static loadableUtils.utils.cCallOpt;
import static loadableUtils.utils.find;
import static loadableUtils.utils.subBot_serveText;
import static loadableUtils.utils.mapToValues_ciMap;
import static loadableUtils.utils.tok_identifiers;
import static loadableUtils.utils.get2;
import static loadableUtils.utils.cPcall;
import static loadableUtils.utils.renameFileVerbose;
import static loadableUtils.utils.jMatchStart;
import static loadableUtils.utils.llNempties;
import static loadableUtils.utils.getIntOpt;
import static loadableUtils.utils.bitSetStreaksAndNonStreaks;
import static loadableUtils.utils.classLoaderContainsByteCodePath;
import static loadableUtils.utils.quickImportMainConcepts;
import static loadableUtils.utils.dotToDollar;
import static loadableUtils.utils.dm_onSnippetTranspiled;
import static loadableUtils.utils.assertStringList;
import static loadableUtils.utils.stepAllAndGet;
import static loadableUtils.utils.nObjects;
import static loadableUtils.utils.setFieldToIF1Proxy;
import static loadableUtils.utils.aname;
import static loadableUtils.utils.mapToKey;
import static loadableUtils.utils.regexpGroups;
import static loadableUtils.utils.filePrintWriter_append;
import static loadableUtils.utils.parseDateWithMillisecondsGMT;
import loadableUtils.utils.TimedCache;
import loadableUtils.utils.JS;
import static loadableUtils.utils.hcenter;
import static loadableUtils.utils.hlinkButton;
import static loadableUtils.utils.parseFirstLong_regexp;
import static loadableUtils.utils.makeAbsoluteURL;
import static loadableUtils.utils.shortClassName_dropNumberPrefix;
import static loadableUtils.utils.dm_vmBus_answerToMessage;
import static loadableUtils.utils.pre_htmlEncode;
import static loadableUtils.utils.methodsSortedByNameIC;
import static loadableUtils.utils.unlistedCopyToClass_withConverter_pcall;
import static loadableUtils.utils.addFilenameHeader;
import static loadableUtils.utils.isIntegerOrIdentifier;
import static loadableUtils.utils.splitAtSpace_trim;
import static loadableUtils.utils.userAgentIsBot;
import static loadableUtils.utils.deleteConceptsWhereIC;
import static loadableUtils.utils.linesLL;
import static loadableUtils.utils.hjs_selectizeClickable;
import static loadableUtils.utils.routeThroughAll;
import static loadableUtils.utils.eqOrEqic;
import static loadableUtils.utils.nemptyLinesLL;
import static loadableUtils.utils.syncCompactSet;
import static loadableUtils.utils.getMigration;
import static loadableUtils.utils.ahref_noFollow;
import static loadableUtils.utils.actualMCDollar;
import static loadableUtils.utils.inlineSwappable;
import static loadableUtils.utils.startsWith_addingSlash;
import static loadableUtils.utils.waitForQToEmpty;
import static loadableUtils.utils.tok_integersAsLongs;
import static loadableUtils.utils.snippetURL;
import static loadableUtils.utils.inQ;
import static loadableUtils.utils.addLibrariesToClassLoader;
import static loadableUtils.utils.trailingLong_regexp;
import static loadableUtils.utils.addSlashSuffix;
import static loadableUtils.utils.renderStackTrace;
import static loadableUtils.utils.isTrueOpt;
import static loadableUtils.utils.dynShortClassName;
import static loadableUtils.utils.structure_convertTokenMarkersToExplicit;
import static loadableUtils.utils.shortenStr;
import static loadableUtils.utils.fixConceptIDs;
import static loadableUtils.utils.nCodeTokens;
import static loadableUtils.utils.targetBlank_noFollow;
import static loadableUtils.utils.withoutInstancesOf;
import static loadableUtils.utils.assertSameVerbose;
import static loadableUtils.utils.getInnerClass;
import static loadableUtils.utils.realMC;
import static loadableUtils.utils.getProgramURL;
import static loadableUtils.utils.allLiveMethodsBelowClass;
import static loadableUtils.utils.dateWithSecondsUTC;
import loadableUtils.utils.F3;
import loadableUtils.utils.ConceptFieldIndexCI_certainValues;
import loadableUtils.utils.User;
import loadableUtils.utils.UserPost;
import loadableUtils.utils.Conversation;
import loadableUtils.utils.ExecutedStep;
import loadableUtils.utils.InputHandled;
import loadableUtils.utils.AuthedDialogID;
import loadableUtils.utils.UploadedSound;
import static loadableUtils.utils.passwordSalt;
public class main {
static public List _stickyLibs_1032268 = ll("#1400501");
static public Map _renameClasses = litmap("GazelleBEA", "GazelleBEAMainServer");
static public class GazelleBEAMainServer extends GazelleBEA {
public void init() {
super.init();
runRefChecker = false;
exportUsersInVM = true;
exportUsersGlobally = true;
}
@Override
public Object serveDefaultPage(DynGazelleRocks.Req req) {
if (ewicOneOf(req.uri(), ".css", ".js"))
return serve404Page();
String uri = req.uri();
if (startsWith(addSlash(uri), "/kb/"))
return "Knowledge base missing :(";
return hrefresh(addParamsToURL("https://gazelle.rocks/kb" + uri, req.params()));
}
public Object serve404Page() {
if (startsWith(currentReq().uri, "/crud/"))
return hredirect(baseLink + "/login");
else
return subBot_serve404("Resource not found, please try the " + ahref("/", "home page"));
}
}
static public boolean _moduleClass_GazelleBEAMainServer = true;
static {
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 __23 = mod.enter();
try {
AutoCloseable __24 = 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(__24);
}
} finally {
_close(__23);
}
} 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() {
try {
} catch (Exception __e) {
throw rethrow(__e);
}
}
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() {
try {
appendText(reversed(q));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void runLiveMode() {
run();
}
}
public class TimeoutTest extends Algorithm {
public void run() {
try {
sleepSeconds(120);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class RunPattern extends Algorithm {
public void run() {
try {
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);
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public String renderMappingAsText(Map mapping) {
return indent(formatDoubleArrowMap_horizontallyAligned(mapping));
}
public class FindRewrites extends Algorithm {
public void run() {
try {
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);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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() {
try {
BEAObject input = handleInput(this, q = trim(q), false);
for (BEAObject pattern : mod.beaListAny("Pattern", "Syntactic Pattern")) {
checkPattern(this, input, q, pattern);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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() {
try {
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);
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class ProcessNewInput_v3 extends Algorithm {
public void run() {
try {
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());
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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() {
try {
for (BEAObject p : mod.beaList("Pattern")) {
appendText(p + " => " + makeSyntacticPattern(p));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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() {
try {
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> __21 : _entrySet(mapping)) {
String key = __21.getKey();
String val = __21.getValue();
row.put("Argument " + key, htmlEncode2(val));
}
data.add(row);
}
appendHTML(htmlTable2_noHtmlEncode(data));
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class ApplyTextFunctions extends Algorithm {
public void run() {
try {
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) {
pcallFail(__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));
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class FindPath extends Algorithm {
public BreadthFirstPathFinder_withLinkType pathFinder = new BreadthFirstPathFinder_withLinkType();
public BEAObject start, dest;
public void run() {
try {
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));
})));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class ExecuteTextQuery extends Algorithm {
public void run() {
try {
saveInput(q = trim(q));
appendHTML(h3("Result"));
appendHTML(htmlEncode2(strOrEmpty(executeTextQuery(q))));
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class InputSummary extends Algorithm {
public void run() {
try {
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 __19 : iterateWithIndex1(rewrites)) {
int i = pairA(__19);
BEAObject r = pairB(__19);
appendHTML("Rewrite " + i + ": " + ahref(mod.beaURL(r), tok_dropCurlyBrackets(r.text())));
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class ApplyPatternList extends Algorithm {
public String additionalInputs() {
return hselect("patternListID", mapToKey(__52 -> conceptID(__52), mod.beaList("Pattern List")), req.get("patternListID"));
}
public void run() {
try {
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);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public class ApplyAlgorithmObject extends Algorithm {
public String additionalInputs() {
return hselect("algorithmID", mapToKey(__53 -> conceptID(__53), 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() {
try {
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"));
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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() {
try {
BEAObject input = saveInput(q);
for (BEAObject patternList : sortedByConceptIDDesc(beaList("Pattern List"))) reactInputWithPatternList(this, input, q, patternList, 1, 2);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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(__54 -> conceptID(__54), conceptsWhereIC(UserPost.class, "type", "JavaX Code (HTML Bot)")), req.get("algorithmID"));
}
public void run() {
try {
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));
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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> __20 : _entrySet(mapping)) {
String key = __20.getKey();
String subInput = __20.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(__55 -> patternSpecificity(__55), 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 __25 = (QueryNotUnderstood) o;
return eq(s, __25.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(__56 -> isCommentOrFeedback(__56), 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 __18 = (RegExpToPossibleSubInputs) o;
return eq(input, __18.input) && eq(regExp, __18.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() {
try {
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))));
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
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) {
pcallFail(__e);
}
}
return out;
}
public Collection convertSyntacticToSemanticMatchesForWholePattern(BEAObject pattern) {
if (pattern.typeIs("Syntactic Pattern"))
return concatMap_lists(__57 -> convertSyntacticToSemanticMatches(__57), 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(__58 -> simpleObjectScore(__58), 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;
static public boolean _switchableField_gazelleServerGlobalID = true;
public String gazelleServerGlobalID = aGlobalID();
transient public boolean allObjectsActivated = false;
transient public Throwable startError;
static public boolean _switchableField_activateOnlyTheseIDs = true;
public String activateOnlyTheseIDs;
static public boolean _switchableField_dontActivateTheseIDs = true;
public String dontActivateTheseIDs;
transient public ReliableSingleThread_Multi rstAutoRuns = dm_rstMulti(this, 1000, __42 -> performAutoRuns(__42));
transient public Q notificationQ;
transient public ReliableSingleThread_Multi rstDistributeNewObject = dm_rstMulti(this, 1000, __43 -> distributeNewObject_impl(__43));
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, __44 -> autoActivateDynamicObject(__44));
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_grabUsersFromDomain = true;
public String grabUsersFromDomain = "https://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();
static public boolean _switchableField_beaHomePageID = true;
public long beaHomePageID;
public boolean verboseClassLoading = false;
transient public boolean saveAllQsAsInput = true;
transient public boolean moveNavItemsToMisc = false;
transient public boolean additionalCommandsForObjects = true;
transient public boolean exportUsersInVM, exportUsersGlobally;
transient public boolean sourceIsPublic = true;
transient public boolean makeAnonymousUsers = true;
transient public boolean showInputAndPatternNavItems = true;
transient public IConceptCounter beaModifiedIndex;
transient public boolean showInputCounts = false;
transient public ConceptFieldIndexCI_certainValues serviceIndex;
transient public boolean runRefChecker = true;
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;
showDeliveredDomains = false;
showCRUDToEveryone = true;
}
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) {
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) {
pcallFail(__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;
});
String mainPrefix = dotToDollar(DynClassName_mainPrefix());
Object classFinder = _defaultClassFinder();
db_mainConcepts().classFinder = new F1() {
public Class get(String name) {
try {
AutoCloseable __34 = enter();
try {
print("Deserializing class " + name);
try {
String name2 = dropPrefix(mcName() + "$", name);
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(__34);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp enter();\r\n //ret syncGetOrCreate(classesCache, name, () -> {\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) {
printStackTrace(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")));
dm_onSnippetTranspiled(mainLibID, new Runnable() {
public void run() {
try {
if (reloadWhenMainLibUpdates) {
setField("reloadWhenMainLibUpdates", false);
dm_reloadModule();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (reloadWhenMainLibUpdates) {\r\n setField(reloadWhenMainLibUpdates ...";
}
});
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();
if (runRefChecker)
dm_doEvery(60 * 60.0, new Runnable() {
public void run() {
try {
{
AutoCloseable __35 = enter();
try {
print(new ConceptsRefChecker(db_mainConcepts()).runAndFixAll());
} finally {
_close(__35);
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "{ temp enter();\r\n print(ConceptsRefChecker(db_mainConcepts()).runAndFi...";
}
});
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);
}
cleanReifiedWebSockets();
allObjectsActivated = true;
print("All objects activated");
}
public void makeIndices() {
super.makeIndices();
indexConceptClass(BSettings.class);
beaModifiedIndex = (IConceptCounter) indexConceptFieldDesc_v2(BEAObject.class, "_modified");
indexConceptFieldCIWithTopTen(BEAObject.class, "type");
indexConceptFieldIC(BEAObject.class, "text");
indexConceptFieldIC(BEAObject.class, "purpose");
serviceIndex = new ConceptFieldIndexCI_certainValues(BEAObject.class, "meta_isService") {
public boolean isApplicableValue(Object o) {
return o != null;
}
};
}
public boolean isMaster(Req req) {
return req == null ? null : req.masterAuthed;
}
@Override
public List crudClasses(DynGazelleRocks.Req req) {
var l = super.crudClasses(req);
l.add(BEAObject.class);
if (masterAuthed(req))
l.add(AuthedDialogID.class);
return l;
}
public Set hiddenCrudClasses() {
Set set = super.hiddenCrudClasses();
set.remove(UploadedSound.class);
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() {
String html = p(html_loggedIn(false));
HTMLFramer1 framer = new HTMLFramer1();
if (anonymousUserWarning(currentReq(), framer))
html += lines(framer.contents);
return html + super.authFormMoreContent();
}
public HTMLFramer1 newFramerInstance() {
return new BEAHTMLFramer();
}
@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 == UploadedSound.class || c == UploadedFile.class || c == UploadedImage.class) {
cc.onCreate.add(o -> cset(o, "createdBy", currentUser()));
cc.emptyConcept = () -> {
Concept ccc = cc.emptyConcept_base();
cset(ccc, "isPublic", true);
return (A) ccc;
};
}
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) -> {
cc.massageItemMapForUpdate_base(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;
}
public HCRUD makeCRUDBase(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)
customizeBEACrud(crud, req, framer);
return crud;
}
@Override
public HCRUD makeCRUD(Class c, DynGazelleRocks.Req req, HTMLFramer1 framer) {
HCRUD crud = makeCRUDBase(c, req, framer);
if (c == BEAObject.class)
optimizeBEACrud(crud);
return crud;
}
public void customizeBEACrud(HCRUD crud, DynGazelleRocks.Req req, HTMLFramer1 framer) {
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
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", "meta_dependsOnCode");
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_noFollow(addParamsToURL(baseLink + "/markUseful", "redirect", beaShortURL(o), "objectID", o.id), "Mark useful"));
cmds.add(ahref_noFollow(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_gen(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 (o.canRenderHTML())
items.add(targetBlank(beaMod().baseLink + "/beaHTML/" + o.id, "Show HTML"));
if (nempty(getStringOpt("meta_code", o)))
items.add(targetBlank(addParamsToURL(beaMod().baseLink + "/get-field", "obj", o.id, "field", "meta_code", "enhance", "JavaX"), "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) {
pcallFail(__e);
}
try {
addAll(items, (List) callOpt(getWebsiteEnhancer("commandsForObject"), "commandsFor", o));
} catch (Throwable __e) {
pcallFail(__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(__59 -> matchDescHTML(__59), 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));
}
public void optimizeBEACrud(HCRUD crud) {
HCRUD_Concepts data = (HCRUD_Concepts) (crud.data);
if (empty(data.filters) && empty(data.ciFilters)) {
crud.sortByField = "_modified";
crud.descending = true;
data.listConcepts_firstStep = () -> (List) cloneList(beaModifiedIndex.allConcepts());
data.defaultSortField = () -> pair("_modified", true);
data.defaultSort = __45 -> id(__45);
}
}
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(__60 -> beaGet(__60), 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) {
{
var __33 = super.serveOtherPage2(req);
if (__33 != null)
return __33;
}
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 __28 : bitSetStreaksAndNonStreaks(bs, l(tok))) {
IntRange r = pairA(__28);
boolean b = pairB(__28);
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 = makeBEATypeCrud(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 = makeBEATypeCrud(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 = makeBEATypeCrud(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 = makeBEATypeCrud(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)) {
String rest = m.rest();
int i = smartIndexOf(rest, "/");
BEAObject o = beaGet(takeFirst(i, rest));
String subURI = substring(rest, i + 1);
return serveBEAHTML(req, o, subURI);
}
if (eq(uri, "/is-a-gazelle"))
return "yes";
if (eq(uri, "/gazelle-server-id"))
return gazelleServerGlobalID;
if (eq(uri, "/get-field")) {
BEAObject obj = beaGet("obj", req);
String field = req.get("field");
String value = str(cget(field, obj));
if (eqic(req.get("enhance"), "JavaX")) {
JavaXHyperlinker hl = new JavaXHyperlinker();
hl.targetBlank = true;
hl.addExplainer(ph -> {
if (eq(ph.token, "from") && isInteger(ph.next))
ph.link(ph.cIdx + 2, beaURL(parseLong(ph.next)));
});
String html = hl.codeToHTML(value);
return htitle_h1(beaHTML(obj) + "." + htmlEncode2(field)) + div(sourceCodeToHTML_noEncode(html), "style", hstyle_sourceCodeLikeInRepo());
}
return serveText(value);
}
if (sourceIsPublic || masterAuthed(req))
if (eqicOneOf(uri, "/source", "/sources", "/src", "sourceCode", "/code"))
return "You will be redirected to my source code..." + hrefresh(3.0, snippetURL(programID()));
BEAForward forward = findBEAShortURL(uri);
if (forward != null)
return serveBEAHTML(req, forward.object, forward.subURI);
if (exportUsersGlobally && eq(uri, "/lookup-user")) {
String name = req == null ? null : req.get("name");
String passwordMD5 = req == null ? null : req.get("passwordMD5");
String salt = req == null ? null : req.get("salt");
print("lookup-user called from " + req.webRequest.clientIP() + ", name: " + name);
if (!eq(salt, passwordSalt()))
return serveJSON(litorderedmap("error", "Bad salt"));
if (empty(name))
return serveJSON(litorderedmap("error", "No name"));
User user = conceptWhereCI(User.class, "name", name);
if (user == null)
return serveJSON(litorderedmap("error", "User not found"));
if (!eq(getVar(user.passwordMD5), passwordMD5))
return serveJSON(litorderedmap("error", "Bad pw"));
return serveJSON(litorderedmap("userID", user.id, "contact", getString("contact", user), "isMaster", getBoolOpt("isMaster", user)));
}
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(__61 -> htmlEncode2_str(__61), objectWithDependents(o)));
}
if (eq(uri, "/prototypeUsers")) {
BEAObject o = beaGet("id", req);
return ul(lmap(__62 -> htmlEncode2_str(__62), 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> __29 : _entrySet(req.params())) {
String key = __29.getKey();
String val = __29.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;
}
public class BEAForward implements IFieldsToList {
public BEAObject object;
public String subURI;
public BEAForward() {
}
public BEAForward(BEAObject object, String subURI) {
this.subURI = subURI;
this.object = object;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + object + ", " + subURI + ")";
}
public Object[] _fieldsToList() {
return new Object[] { object, subURI };
}
}
public Collection beaShortURLObjects() {
return filter(__63 -> createdByMasterUser(__63), beaList("BEA Short URL"));
}
public Collection masterObjects(Collection l) {
return filter(__64 -> createdByMasterUser(__64), l);
}
public boolean isBEAShortURLObject(BEAObject o) {
return o != null && o.typeIs("BEA Short URL") && createdByMasterUser(o);
}
public BEAForward findBEAShortURL(String uri) {
Matches m = new Matches();
String uriWithSlash = addSlashSuffix(uri);
for (BEAObject o : beaShortURLObjects()) {
try {
String uriToTest = getStringOpt("uri", o);
if (startsWith_addingSlash(uriWithSlash, uriToTest, m)) {
BEAObject o2 = (BEAObject) (cget("object", o));
if (o2 != null) {
String subURI = m.rest();
if (l(uriWithSlash) > l(uri))
subURI = dropSlashSuffix(subURI);
return new BEAForward(o2, subURI);
}
}
} catch (Throwable __e) {
pcallFail(__e);
}
}
return null;
}
transient public List conceptShadows;
public Object createConceptShadows() {
long _startTime_30 = 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_30);
return subBot_serveText(n2(conceptShadows, "shadow") + " made in " + lastTiming_formatted() + "\n\n" + profile);
}
public HCRUD makeBEATypeCrud(Req req, String type) {
return makeBEATypeCrud(req, type, req.framer);
}
public HCRUD makeBEATypeCrud(Req req, String type, HTMLFramer1 framer) {
HCRUD crud = makeCRUDBase(BEAObject.class, req, framer);
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;
};
}
optimizeBEACrud(crud);
return crud;
}
public Object renderBEAObjectTable(Req req, String type) {
HCRUD crud = makeBEATypeCrud(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() {
Req req = currentReq();
HCRUD crud = makeCRUD(BEAObject.class, req);
String allObjectTypesLink = ahref(baseLink + "/allBEATypes", "All object types");
BEAHTMLFramer framer = (BEAHTMLFramer) (req.framer);
framer.unnamedPopDownButton.addAll(ahref(baseLink + "/stats", "Stats"), !isMasterAuthed() ? null : ahref(baseLink + "/download", "DB download"), targetBlank(getProgramURL(), "Source code"), !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"));
List items = new ArrayList();
if (showInputAndPatternNavItems)
addAll(items, 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", (showInputCounts ? n2(syntacticPatternsWithoutRewrites.get()) + " " : "") + "Syntactic patterns w/o rewrites"), beaNavLink("Match", crud), beaNavLink("Rewrite", crud), beaNavLink("AI Task", crud), ahref(baseLink + "/inputsWithoutMatches", (showInputCounts ? n2(inputsWithoutMatches.get()) + " " : "") + "Inputs w/o matches"), ahref(baseLink + "/inputsWithoutRewrites", (showInputCounts ? n2(inputsWithoutRewrites.get()) + " " : "") + "Inputs w/o rewrites"));
addAll(items, inlineSwappable("navDiv_allObjectTypes", this, () -> allObjectTypesLink + " " + hPopDownButton(listPlus(renderObjectTypes(10), allObjectTypesLink))), framer.unnamedPopDownButton.width(350).height(500).html());
return items;
}
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 = (BEAObject) (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) {
pcallFail(__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(__65 -> beaList(__65), litciset(types)));
}
public Collection beaListAny(Collection types) {
return concatLists(lmap(__66 -> beaList(__66), 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));
}
final public BEAObject beaGet(String field, BEAObject o) {
return cgetBEA(field, o);
}
public BEAObject cgetBEA(String field, BEAObject o) {
return (BEAObject) cget(field, o);
}
final public BEAObject beaGet(BEAObject o, String field) {
return cgetBEA(o, field);
}
public BEAObject cgetBEA(BEAObject o, String field) {
return cgetBEA(field, o);
}
final public String beaToHTML(BEAObject o) {
return beaLinkHTML(o);
}
final public String beaHTML(BEAObject o) {
return beaLinkHTML(o);
}
public String beaLinkHTML(BEAObject o) {
return beaLinkHTML(o, false);
}
final public String beaToHTML(BEAObject o, boolean targetBlank) {
return beaLinkHTML(o, targetBlank);
}
final public String beaHTML(BEAObject o, boolean targetBlank) {
return beaLinkHTML(o, targetBlank);
}
public String beaLinkHTML(BEAObject o, boolean targetBlank) {
return o == null ? null : ahref_targetBlankIf(targetBlank, 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;
}
final 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() {
return html_loggedIn(true);
}
public String html_loggedIn(boolean offerLogInLink) {
User user = user(currentReq());
return user == null ? (offerLogInLink ? ahref(baseLink + "/login", "Log in") : "Not logged 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.id != 0 && !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 __36 = enter();
try {
for (BEAObject autoRun : beaList("Auto Run")) {
if (!isTrue(getOpt("enabled", autoRun))) {
print("Not enabled: " + autoRun);
continue;
}
performAutoRunOnObject(autoRun, o);
}
} finally {
_close(__36);
}
}
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_noFollow(addParamsToURL(baseLink + "/storeSubInput", "label", "good", "text", text, "input", input.id, "redirect", redirect), unicode_thumbsUp()), goodCount == 0 ? "" : n2(goodCount), ahref_noFollow(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);
callOpt(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 BEAObject compileAndLoadObject(BEAObject o) {
dm_mediumRefreshTranspiler();
Collection withDependents = objectWithDependents(o);
withDependents = filter(withDependents, x -> x == o || !isFalse(getBoolOpt("meta_shouldActivate", x)));
print("Dependents for " + o + ": " + withDependents);
for (BEAObject x : withDependents) compileAndLoadObject_withoutDependents(x);
return (BEAObject) getMigration(o);
}
static public class UseClassDecl implements IFieldsToList {
static final public String _fieldOrder = "objID innerClassName";
public long objID;
public String innerClassName;
public UseClassDecl() {
}
public UseClassDecl(long objID, String innerClassName) {
this.innerClassName = innerClassName;
this.objID = objID;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + objID + ", " + innerClassName + ")";
}
public boolean equals(Object o) {
if (!(o instanceof UseClassDecl))
return false;
UseClassDecl __48 = (UseClassDecl) o;
return objID == __48.objID && eq(innerClassName, __48.innerClassName);
}
public int hashCode() {
int h = 1216910491;
h = boostHashCombine(h, _hashCode(objID));
h = boostHashCombine(h, _hashCode(innerClassName));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { objID, innerClassName };
}
}
public UseClassDecl parseUseClassDecl(String useClass) {
List tok = javaTokC(useClass);
if (l(tok) == 3 && eqGet(tok, 1, ".") && isIdentifier(tok.get(2)) && isIntegerOrIdentifier(tok.get(0))) {
String innerClassName = tok.get(2);
long objID = trailingLong_regexp(first(tok));
return new UseClassDecl(objID, innerClassName);
}
return null;
}
public Class protoClass(BEAObject o) {
BEAObject proto = (BEAObject) (cget("meta_prototype", o));
String useClass = (String) (cget("meta_useClass", o));
if (nempty(useClass)) {
UseClassDecl uc = parseUseClassDecl(useClass);
if (uc != null) {
String innerClassName = uc.innerClassName;
long objID = uc.objID;
proto = beaGet(objID);
if (proto == null)
throw fail("useClass invalid reference: " + objID + " not found");
if (!usesLiveCustomCode(proto))
throw fail("Prototype is not custom or not loaded: " + proto);
Class protoClass = proto.getClass();
Class outerClass = getOuterClass(protoClass, _defaultClassFinder());
printVars("id", o.id, "useClass", useClass, "innerClassName", innerClassName, "protoClass", protoClass, "outerClass", outerClass);
Class innerClass = getInnerClass(outerClass, innerClassName, _defaultClassFinder());
printVars("innerClass", innerClass);
if (innerClass == null)
throw fail("Inner class not found: " + outerClass + " . " + innerClassName);
cset(o, "meta_dependsOnCode", ll(proto));
return innerClass;
} else
throw fail("meta_useClass has invalid syntax: " + useClass);
}
Class protoClass = null;
if (proto != null) {
if (!usesLiveCustomCode(proto))
throw fail("Prototype is not custom or not loaded: " + 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 .;", "extends ..;")) > 0) {
int j = indexOf(tok, ";", tokIdx);
baseClass = joinSubList(tok, tokIdx + 2, j - 1);
baseClass = expandShortClassRef(baseClass);
clearTokens(tok, tokIdx, j + 2);
}
jreplace(tok, "extends <.>", "extends $2<" + dcn.middleClassName() + ".$5>");
if ((tokIdx = jfind_any(tok, "extends from *;", "extends <> from *;", "extends <.> from *;")) > 0) {
int iFrom = indexOf(tok, tokIdx, "from");
String className = joinSubList(tok, tokIdx + 2, iFrom - 1);
baseClass = expandShortClassRef("B" + parseFirstLong_regexp(tok.get(iFrom + 2)) + "." + className);
int j = indexOf(tok, ";", iFrom);
clearTokens(tok, tokIdx, j + 2);
}
List imports = new ArrayList();
while ((tokIdx = jfind_any(tok, "import from ;", "import from ;", "import static from ;", "import static from ;")) > 0) {
int i = tokIdx + 2;
if (eqGet(tok, i, "static"))
i += 2;
int iStart = i;
String className = tok.get(i);
String bClass = addPrefix("B", tok.get(i += 4));
String name = expandShortClassRef(bClass + "." + className);
imports.add(joinSubList(tok, tokIdx, iStart - 1) + " " + 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 = concatLists(filesFromClassLoader(cl), filesFromClassLoader(getVirtualParent(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);
LinkedHashSet dependencies = new LinkedHashSet();
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(asList(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) {
pcallFail(__e);
}
}
}
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) {
printStackTrace(e);
cset(o, "meta_javaClass", null);
cset(o, "meta_codeState", exceptionToStringShort(e));
return null;
}
}
public boolean usesLiveCustomCode(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() {
return userAgent(currentReq());
}
public String userAgent(Req req) {
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(__67 -> createdByMasterUser(__67), beaList("Live URL Rewrite"))) {
try {
String input = getString("input", rewrite);
boolean ci = isTrueOpt("caseInsensitive", rewrite);
vmBus_send("testingURLRewrite", rewrite, uri);
if (eqOrEqic(ci, uri, input)) {
vmBus_send("applyingURLRewrite", rewrite, uri);
String output = getString("output", rewrite);
return hrefresh(appendParamsToURL(output, req.params()));
}
} catch (Throwable __e) {
pcallFail(__e);
}
}
return super.html3(req);
}
@Override
public Object serveOtherPage(DynGazelleRocks.Req req) {
return serveOtherPage((Req) req);
}
public Object serveOtherPage(Req req) {
if (eq(req.uri, "/login"))
return serveAuthForm(null);
if (startsWith_addingSlash(req.uri, "/myLoginData"))
return serveMyLoginData(req);
return super.serveOtherPage(req);
}
public void cleanMeUp_deactivateBEAObjects() {
Collection objects = filter(beaList(), o -> hasMethod(o, "_deactivate"));
print("Deactivating " + nObjects(objects) + " for shutdown");
for (BEAObject bea : objects) callDeactivate(bea);
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 new DynClassName(parseLong(first(groups)), second(groups), parseLong(third(groups)), fourth(groups));
return DynClassName_parseOther(className);
}
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 new DynClassName(parseLong(first(groups)), second(groups), 0, third(groups));
return null;
}
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 middleClassName() {
return objectID == 0 ? "" : "B" + objectID;
}
public String makePackageName() {
return dropDotSuffix(DynClassName_mainPrefix());
}
public String makeMainClassName() {
return "b_" + compileBaseObjectID + "_" + globalID;
}
public String makeBEAClassName() {
return joinNempties("$", middleClassName(), 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_31 = 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("if (typeof $ !== \"undefined\") $(\".webSocketPlaceholder\").html($html);", "html", jsQuote(beaHTML(reifiedWebSocket))));
done2_always("Reify WebSocket", _startTime_31);
}
onNewWebSocket2(ws);
BEAForward forward = null;
if (eq(uri, "/")) {
BEAObject o = beaGet(beaHomePageID);
if (o != null)
forward = new BEAForward(o, dropLeadingSlash(uri));
}
if (forward == null) {
Matches m = new Matches();
if (startsWith(uri, "/beaHTML/", m)) {
BEAObject handler = beaGet(m.rest());
if (handler != null)
forward = new BEAForward(handler, afterSlash(m.rest()));
} else
forward = findBEAShortURL(uri);
}
printVars("onNewWebSocket", "uri", uri, "forward", forward);
if (forward != null) {
var handler = forward.object;
req.subURI = forward.subURI;
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 IVF1 onNewWebSocket2;
public void onNewWebSocket2(WebSocketInfo ws) {
if (onNewWebSocket2 != null)
onNewWebSocket2.get(ws);
else
onNewWebSocket2_base(ws);
}
final public void onNewWebSocket2_fallback(IVF1 _f, WebSocketInfo ws) {
if (_f != null)
_f.get(ws);
else
onNewWebSocket2_base(ws);
}
public void onNewWebSocket2_base(WebSocketInfo ws) {
}
transient public Class extends BWebSocket> webSocketClass = BWebSocket.class;
public void onWebSocketClose(WebSocketInfo ws) {
AutoCloseable __37 = enter();
try {
super.onWebSocketClose(ws);
retireReifiedWebSocket((BWebSocket) ws.dbRepresentation);
} finally {
_close(__37);
}
}
public void retireReifiedWebSocket(BWebSocket ws) {
if (!keepReifiedWebSockets())
cdelete(ws);
else
cset(ws, "type", "Closed WebSocket");
}
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 keepReifiedWebSockets_cache = new TimedCache<>(10.0, () -> keepReifiedWebSockets_load());
public boolean keepReifiedWebSockets() {
return keepReifiedWebSockets_cache.get();
}
public Boolean keepReifiedWebSockets_load() {
return getBoolOpt("keepReifiedWebSockets", 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(__68 -> createdByMasterUser(__68), beaList("Live Gazelle Settings")));
}
final 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) {
((Req) req).framer.addNavItems(pageBy_navItems(((Req) req).makers));
return super.completeFrame_base((Req) req);
}
public List pageBy_navItems(Object... makers) {
return pageBy_navItems(asList(makers));
}
public List pageBy_navItems(Collection makers) {
makers = nonNulls(makers);
if (empty(makers))
return ll();
List beas = instancesOf(BEAObject.class, makers);
List nonBEAs = nonInstancesOf(BEAObject.class, makers);
return concatLists(map(beas, o -> targetBlank(beaURL(o), repS(2, html_gazelle_madeByIcon()), "title", "Page made by: " + o)), empty(nonBEAs) ? ll() : ll(new HPopDownButton(empty(beas) ? "Page by" : "Page also by", map(makers, o -> {
if (o instanceof BEAObject)
return beaHTML_targetBlank((BEAObject) o);
return htmlEncode2(shortenStr(o, 40));
})).html()));
}
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);
String webSocketPlaceholder = span("", "class", "webSocketPlaceholder");
if (moveNavItemsToMisc) {
var navItems = cloneList(framer.navItems);
framer.clearNavItems();
framer.addNavItem(hPopDownButtonWithText("Misc", map(navItems, ni -> framer.renderNavItem(ni))) + " " + webSocketPlaceholder);
} else
framer.addNavItem(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(__69 -> parseLong(__69), tok_integers(activateOnlyTheseIDs));
}
public Set dontActivateTheseIDs() {
if (empty(dontActivateTheseIDs))
return null;
return mapToLinkedHashSet(__70 -> parseLong(__70), 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 : o.myURI();
}
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) {
String global = "";
int idx;
while ((idx = jfind_any(tok, "global {", "exports {")) >= 0) {
int j = findEndOfBracketPart(tok, idx + 2);
global = joinSubList(tok, idx + 3, j - 1);
clearTokens(tok, idx, j + 1);
}
return global;
}
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(o.typeForToString());
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;
}
if (empty(grabUsersFromDomain))
return null;
try {
var passwordMD5 = new SecretValue(hashPW(pw));
String url = addSlashSuffix(grabUsersFromDomain) + "lookup-user";
Map map = jsonDecodeMap(postPage(url, "name", name, "passwordMD5", passwordMD5, "salt", passwordSalt()));
print("Got map? " + (map != null));
String error = (String) (mapGet(map, "error"));
if (nempty(error)) {
print("error", error);
return null;
}
if (map != null)
return cnew(User.class, "name", name, "contact", (String) map.get("contact"), "passwordMD5", passwordMD5, "isMaster", isTrue(map.get("isMaster")), "copiedFromMainDB", true);
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
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 String conceptToHTML_targetBlank(Concept c) {
return c == null ? "" : targetBlank(conceptLink(c), htmlEncode2(c));
}
public Req newReq() {
return new Req();
}
public class Req extends DynGazelleRocks.Req {
public Set makers = syncCompactSet();
public Timestamp started = new Timestamp();
public void add(Object html) {
framer.add(html);
}
public boolean debug() {
return eq(get("debug"), "1");
}
public BEAHTMLFramer framer() {
return (BEAHTMLFramer) framer;
}
}
transient public IF0 serveHomePage;
@Override
public Object serveHomePage() {
return serveHomePage != null ? serveHomePage.get() : serveHomePage_base();
}
final public Object serveHomePage_fallback(IF0 _f) {
return _f != null ? _f.get() : serveHomePage_base();
}
public Object serveHomePage_base() {
BEAObject o = beaGet(beaHomePageID);
if (o != null) {
Req req = currentReq();
return serveBEAHTML(req, o, dropLeadingSlash(req.uri()));
}
return super.serveHomePage();
}
public Req currentReq() {
return (Req) super.currentReq();
}
public void cleanReifiedWebSockets() {
AutoCloseable __38 = enter();
try {
for (BWebSocket o : instancesOf(BWebSocket.class, cloneList(beaList("Live WebSocket")))) if (o.webSocket() == null)
retireReifiedWebSocket(o);
} finally {
_close(__38);
}
}
public Class extends Concept> defaultCRUDClass() {
return BEAObject.class;
}
public Object serveFavIcon() {
Object response = super.serveFavIcon();
print("serveFavIcon: " + response);
return response;
}
public boolean alwaysShowLogInLink() {
return true;
}
public String logInLink() {
return baseLink + "/login";
}
public String defaultRedirectAfterLogin() {
return baseLink + "/crud/BEAObject";
}
@Override
public void fillReqAuthFromCookie(DynGazelleRocks.Req req, String cookie, AuthedDialogID auth) {
super.fillReqAuthFromCookie(req, cookie, auth);
if (makeAnonymousUsers && auth != null && auth.user.get() == null) {
String pw = aGlobalID();
User userObj = cnew(User.class, "passwordMD5", new SecretValue(hashPW(pw)), "password", new SecretValue(pw));
cset(userObj, "name", "guest" + userObj.id);
cset(auth, "user", userObj);
vmBus_send("userCreated", userObj);
}
}
public boolean userHasData(User user) {
try {
Collection refs = allBackRefs(user);
refs = withoutInstancesOf(AuthedDialogID.class, refs);
refs = withoutInstancesOf(BWebSocket.class, refs);
pnl("USERDATA", refs);
return nempty(refs);
} catch (Throwable __e) {
pcallFail(__e);
}
return true;
}
public boolean anonymousUserWarning(Req req, HTMLFramer1 framer) {
User user = user(req);
if (print("confirm", empty(req.get("confirmLogout"))) && print("isAnonymousUser", isAnonymousUser(user)) && print("userHasData", userHasData(user))) {
framer.add(h2("Anonymous User Warning"));
framer.add(p("You are currently logged in as anonymous user " + b(htmlEncode2(user)) + " and seem to have some data stored on the server. Do you want to download your login data before logging out?"));
framer.add(p(joinWithSpace(hlinkButton(baseLink + "/myLoginData", "Download Login Data"), hlinkButton(baseLink + req.uri + "?logout=1&confirmLogout=1", "Just log me out"))));
return true;
}
return false;
}
@Override
public Object handleLogout(DynGazelleRocks.Req req) {
print("handleLogout " + user((Req) req));
if (anonymousUserWarning(((Req) req), framer((Req) req)))
return completeFrame((Req) req);
print("Actual logout");
return super.handleLogout((Req) req);
}
public boolean isAnonymousUser(User user) {
return cget("password", user) != null;
}
public Object serveMyLoginData(Req req) {
User user = user(req);
SecretValue pw = (SecretValue) (cget("password", user));
boolean isAnon = pw != null;
if (!isAnon) {
req.framer.add(p("You are not an anonymous user. Only anonymous users can download their login data."));
return beaMod().completeFrame(req);
}
if (eq(req.uri(), "/myLoginData/download")) {
String host = mapGet(req.headers(), "host");
String text = jsonEncode_breakAtLevel1(litorderedmap("site", host, "user", user.name, "password", pw.get(), "date", dateWithSecondsUTC(), "ip", getClientIPFromHeaders(req.headers())));
String filename = "my-login-at-" + host + ".txt";
return subBot_noCacheHeaders(addFilenameHeader(filename, subBot_serveWithContentType(text, binaryMimeType())));
}
req.framer.add(hcenter(linesLL(h1(req.framer.htmlTitle("Download Login Data")), p("You are currently logged in as an anonymous user and are able to upload data to the site. In order to access, modify or delete this data later, you should definitely download your login data now. Otherwise you risk losing this data and/or being unable to delete it."), p(hbuttonLink(baseLink + "/myLoginData/download", "Download my login data")))));
return completeFrame(req);
}
public HTMLFramer1 framer(Req req) {
if (req.framer == null)
makeFramer(req);
return req.framer;
}
public boolean userCanSeeObject(User user, Object o) {
if (user == null)
return false;
if (user.isMaster)
return true;
o = derefRef(o);
if (user == o)
return true;
if (o instanceof Concept) {
if (cget("createdBy", (Concept) o) == user)
return true;
if (isTrueOpt("isPublic", (Concept) o))
return true;
}
return false;
}
@Override
public File uploadsBaseDir() {
return programFile("uploads");
}
public class BEAHTMLFramer extends HTMLFramer1 {
public HTMLPopDownButton unnamedPopDownButton = new HTMLPopDownButton();
}
public String makeAbsoluteURL(Req req, String url) {
return loadableUtils.utils.makeAbsoluteURL((req.isHttps() ? "https://" : "http://") + req.domain(), url);
}
public Object serveBEAHTML(Req req, BEAObject o, String subURI) {
req.noSpam();
req.subURI = subURI;
req.makers.add(o);
framer(req).title = str(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");
}
public String optBeaHTML(Object o) {
return optBeaHTML(o, false);
}
public String optBeaHTML(Object o, boolean targetBlank) {
if (o instanceof BEAObject)
return beaHTML(((BEAObject) o), targetBlank);
return htmlEncode2(str(o));
}
public String beaHTML_preferRendered(BEAObject o) {
return beaHTML_preferRendered(o, false);
}
public String beaHTML_preferRendered(BEAObject o, boolean targetBlank) {
if (o != null && o.canRenderHTML())
return targetBlankIf(targetBlank, o.myUri(), htmlEncode2_nlToBr(str(o)));
return beaHTML(o, targetBlank);
}
public boolean checkCookie(String cookie, String domain) {
print("checkCookie " + takeFirst(4, cookie));
AuthedDialogID auth = authObject(cookie);
if (auth == null)
return false;
Req req = new Req();
fillReqAuthFromCookie(req, cookie, auth);
return masterAuthed(req);
}
public boolean masterAuthed(WebSocketInfo ws) {
return masterAuthed(ws == null ? null : ws.req);
}
public String redirectToLoginURL(Req req) {
return addParamsToURL(baseLink + "/login", "redirect", req.uri());
}
public Object redirectToLogin(Req req) {
return subBot_serveRedirect(redirectToLoginURL(req));
}
public String redirectUnlessMasterAuthed(WebSocketInfo ws) {
if (masterAuthed(ws))
return null;
return hrefresh(redirectToLoginURL((Req) ws.req));
}
public String redirectToLogin_hrefresh(Req req) {
return hrefresh(addParamsToURL(baseLink + "/login", "redirect", req.uri()));
}
@Override
public Object html(IWebRequest request) {
AutoCloseable __39 = enter();
try {
boolean profile = eq(request.get("_profile"), "1");
if (profile) {
return subBot_serveText(profileThisThreadToString(() -> {
super.html(request);
}));
}
return super.html(request);
} finally {
_close(__39);
}
}
public A findService(Class type) {
if (type == null)
return null;
String name = shortClassName(type);
return (A) findService(name);
}
public BEAObject findService(String name) {
if (empty(name))
return null;
var services = cloneList(serviceIndex.getAll(name));
if (l(services) > 1)
warn("Duplicate service " + name + ": " + joinWithSlash(services));
return first(services);
}
public String beaAttribution(BEAObject o) {
return o == null ? null : html_gazelle_madeByIcon(beaURL(o));
}
public File beaDataDir(BEAObject o) {
if (o == null)
return null;
long id = o.id;
return id == 0 ? null : programFile("BEA Data " + id);
}
public String beaTypeCRUDURL(String type) {
return baseLink + "/beaCRUD/" + urlencode(type);
}
@Override
public Object serveCRUD(DynNewBot2.Req req) {
if (eq(req.uri(), "/crud/BEA"))
return hrefresh(baseLink + "/crud/BEAObject");
return super.serveCRUD(req);
}
public Collection