Administration
Speicherdienst
Anmelden
Hilfe
Skript
Name des Skripts
Skript
/* * This JavaScript program returns test data for the development and test * environment in the same format as the "SAP-Link" DataProvider does in * production. * * It can be run through ScriptDataProvider. */ // For compatibility with Java7/Java8 (Rhino vs. Nashorn) if (typeof importClass != "function") { load("nashorn:mozilla_compat.js"); } importClass(Packages.java.lang.Byte); importClass(Packages.java.util.Arrays); importClass(Packages.java.math.BigDecimal); importClass(Packages.de.devbrain.bw.app.universaldata.meta.identifier.PlainIdentifier); importClass(Packages.de.devbrain.bw.app.universaldata.data.FieldDef); importClass(Packages.de.devbrain.bw.app.universaldata.data.RecordDef); importClass(Packages.de.devbrain.bw.app.universaldata.type.string.VarCharType); importClass(Packages.de.devbrain.bw.app.universaldata.type.BigDecimalType); importClass(Packages.de.devbrain.bw.app.universaldata.type.ByteArrayType); importClass(Packages.de.devbrain.bw.app.universaldata.type.temporal.DateOnlyType); importClass(Packages.de.devbrain.bw.app.universaldata.type.string.StringType); importClass(Packages.de.devbrain.bw.app.universaldata.provider.DataProvider); var INFO_FIELDS = Arrays.asList([ new FieldDef( new PlainIdentifier("BELNR", "Belegnummer", "Belegnummer eines Buchhaltungsbeleges", false), new VarCharType(10)), new FieldDef( new PlainIdentifier("GJAHR", "Geschäftsjahr", false), BigDecimalType.INSTANCE), new FieldDef( new PlainIdentifier("BLDAT", "Rechnungsdatum", "Belegdatum im Beleg", true), DateOnlyType.INSTANCE), new FieldDef( new PlainIdentifier("XBLNR", "Rechnungsnummer", true), new VarCharType(16)), new FieldDef( new PlainIdentifier("BKTXT", "ITEMS-Auftragsnummer", false), new VarCharType(25)), new FieldDef( new PlainIdentifier("AUGDT", "Datum des Ausgleichs", true), DateOnlyType.INSTANCE), new FieldDef( new PlainIdentifier("AUGBL", "Ausgleichsbeleg", "Belegnummer des Ausgleichsbelegs", false), new VarCharType(10)), new FieldDef( new PlainIdentifier("DMBTR", "Betrag (brutto)", "Betrag in Hauswährung", true), BigDecimalType.INSTANCE), new FieldDef( new PlainIdentifier("ZUONR", "Zuordnungsnummer", false), new VarCharType(18)), new FieldDef( new PlainIdentifier("SAKNR", "Sachkonto", "Nummer des Sachkontos", true), new VarCharType(10)), new FieldDef( new PlainIdentifier("KOSTL", "Kostenstelle", true), new VarCharType(10)), new FieldDef( new PlainIdentifier("AUFNR", "Auftragsnummer", true), new VarCharType(12)), new FieldDef( new PlainIdentifier("ANLN1", "Anlagen-Hauptnummer", false), new VarCharType(12)), new FieldDef( new PlainIdentifier("ANLN2", "Anlagenunternummer", false), new VarCharType(4)), new FieldDef( new PlainIdentifier("LIFNR", "Kontonummer", "Kontonummer des Lieferanten bzw. Kreditors", false), new VarCharType(10)), new FieldDef( new PlainIdentifier("FISTL", "Drittmittel", true), new VarCharType(16)) ]); function Z_FI_GET_ACCDOC_INFO(orderId) { var row = createInfoRow(orderId); var javaRow = convertArray(row, "java.io.Serializable"); return new DataProvider.Result(javaRow, new RecordDef(INFO_FIELDS)); } function createInfoRow(orderId) { return [ "Bel: " + orderId, new BigDecimal("2013"), Packages.java.sql.Date.valueOf("2013-12-23"), "" + orderId, "" + orderId, null, null, new BigDecimal("1234.56"), "Zuordnung", "Sachkonto", "active", "" + orderId, "-", null, "00998877", "active"]; } var ARCH_FIELDS = Arrays.asList([ new FieldDef( new PlainIdentifier("EX_DATA", "Binärdaten"), ByteArrayType.OCTET_STREAM), new FieldDef( new PlainIdentifier("EX_EXTENSION", "Dateiextension (z.B. pdf, tif)"), StringType.INSTANCE) ]); function Z_FI_GET_ACCDOC_ARCH(IM_BELNR, IM_GJAHR) { var contents = "Dies ist der Dateiinhalt der Binärdatei für Belegnummer " + IM_BELNR + " und Geschäftsjahr " + IM_GJAHR; var row = [stringToByteArray(contents), "tif"]; return new DataProvider.Result( convertArray(row, "java.io.Serializable"), new RecordDef(ARCH_FIELDS)); } function stringToByteArray(string) { var result = java.lang.reflect.Array.newInstance(Byte.TYPE, string.length); for (var x = 0; x < string.length; ++x) { var charCode = string.charCodeAt(x); result[x] = charCode <= 127 ? charCode : -256 + charCode; } return result; } /** * Rhino in the version distributed with OpenJDK 1.6.0_30 cannot convert * native JavaScript arrays to Java arrays; later versions can. * * This method explicitly converts the given native array to a Java array of * the class with the given (fully qualified) name. */ function convertArray(array, type) { var javaClass = java.lang.Class.forName(type); var result = java.lang.reflect.Array.newInstance(javaClass, array.length); for (var i = 0; i < array.length; i++) { /* * Nashorn (JDK-1.8) creates objects of class * jdk.nashorn.internal.runtime.ConsString for string literals, which * cannot be cast or converted to java.io.Serializable, and thus cannot * be stored in the returned array (assuming that type == * "java.io.Serializable"). It seems that when invoking Java methods, * those objects are automatically converted to java.lang.String, but * here, Nashorn isn't intelligent enough. Therefore, this hack checks * whether the input value is a JavaScript string, and if it is, converts * it explicitly to a Java String. * * All of this is not required for Rhino (JDK-1.7), which is intelligent * enough to handle this on its own. */ var source = array[i]; result[i] = typeof source == "string" ? new java.lang.String(source) : source; } return result; }