diff --git a/README.md b/README.md index 8cf5f13..87af50e 100644 --- a/README.md +++ b/README.md @@ -23,5 +23,6 @@ Any content with fixed position will be repeated on every page in the generated ## Usage - Place the widget on the page - Put your content in the header, body and footer drop zones +- If you only need a header **or** a footer, leave the unused drop zone empty and set the property to only use what you need - When the PDF is generated the header and footer are repeated on each page diff --git a/src/DocumentLayoutWidget.editorConfig.js b/src/DocumentLayoutWidget.editorConfig.js index 3b17b22..40fcec1 100644 --- a/src/DocumentLayoutWidget.editorConfig.js +++ b/src/DocumentLayoutWidget.editorConfig.js @@ -1,3 +1,5 @@ +import { hidePropertyIn } from "@mendix/pluggable-widgets-tools"; + /** * @typedef Property * @type {object} @@ -48,33 +50,61 @@ */ export function getProperties(values, defaultProperties, target) { // Do the values manipulation here to control the visibility of properties in Studio and Studio Pro conditionally. - /* Example - if (values.myProperty === "custom") { - delete defaultProperties.properties.myOtherProperty; + if (values.headerFooter === "header") { + hidePropertyIn(defaultProperties, values, "footerContent"); + hidePropertyIn(defaultProperties, values, "footerHeight"); + } + if (values.headerFooter === "footer") { + hidePropertyIn(defaultProperties, values, "headerContent"); + hidePropertyIn(defaultProperties, values, "headerHeight"); } - */ return defaultProperties; } -// /** -// * @param {Object} values -// * @returns {Problem[]} returns a list of problems. -// */ -// export function check(values) { -// /** @type {Problem[]} */ -// const errors = []; -// // Add errors to the above array to throw errors in Studio and Studio Pro. -// /* Example -// if (values.myProperty !== "custom") { -// errors.push({ -// property: `myProperty`, -// message: `The value of 'myProperty' is different of 'custom'.`, -// url: "https://github.com/myrepo/mywidget" -// }); -// } -// */ -// return errors; -// } +/** + * @param {Object} values + * @returns {Problem[]} returns a list of problems. + */ +export function check(values) { + /** @type {Problem[]} */ + const errors = []; + + const headerHeightValue = values.headerHeight ? Number(values.headerHeight) : 0; + if (values.headerFooter === "both" || values.headerFooter === "header") { + if (!values.headerHeight || headerHeightValue <= 0) { + errors.push({ + property: "headerHeight", + message: "Header height must be set and positive" + }); + } + + if (!values.headerContent || values.headerContent.widgetCount === 0) { + errors.push({ + property: "headerContent", + message: "Place content in the header dropzone" + }); + } + } + + const footerHeightValue = values.footerHeight ? Number(values.footerHeight) : 0; + if (values.headerFooter === "both" || values.headerFooter === "footer") { + if (!values.footerHeight || footerHeightValue <= 0) { + errors.push({ + property: "footerHeight", + message: "Footer height must be set and positive" + }); + } + + if (!values.footerContent || values.footerContent.widgetCount === 0) { + errors.push({ + property: "footerContent", + message: "Place content in the footer dropzone" + }); + } + } + + return errors; +} // /** // * @param {object} values diff --git a/src/DocumentLayoutWidget.jsx b/src/DocumentLayoutWidget.jsx index 4583516..ab6a117 100644 --- a/src/DocumentLayoutWidget.jsx +++ b/src/DocumentLayoutWidget.jsx @@ -2,7 +2,7 @@ import "./ui/DocumentLayoutWidget.css"; import { createElement } from "react"; export function DocumentLayoutWidget(props) { - const { headerContent, bodyContent, footerContent, headerHeight, footerHeight } = props; + const { headerFooter, headerContent, bodyContent, footerContent, headerHeight, footerHeight } = props; const className = "document-layout-widget " + props.class; @@ -27,15 +27,17 @@ export function DocumentLayoutWidget(props) { return (
- - - - - + {(headerFooter === "header" || headerFooter === "both") && ( + + + + + + )} - - - - - + {(headerFooter === "footer" || headerFooter === "both") && ( + + + + + + )}
-
-   -
-
+
+   +
+
@@ -43,22 +45,28 @@ export function DocumentLayoutWidget(props) {
-
-   -
-
+
+   +
+
-
- {headerContent} -
-
- {footerContent} -
+ {(headerFooter === "header" || headerFooter === "both") && ( +
+ {headerContent} +
+ )} + {(headerFooter === "footer" || headerFooter === "both") && ( +
+ {footerContent} +
+ )}
); } diff --git a/src/DocumentLayoutWidget.xml b/src/DocumentLayoutWidget.xml index 018e605..556e568 100644 --- a/src/DocumentLayoutWidget.xml +++ b/src/DocumentLayoutWidget.xml @@ -8,7 +8,16 @@ Document generation - + + Header/Footer + + + Both + Header + Footer + + + Header content @@ -16,7 +25,7 @@ Body content - + Footer content diff --git a/test/TestDocLayoutWidget.mpr b/test/TestDocLayoutWidget.mpr index 4bc6026..3bc949b 100644 Binary files a/test/TestDocLayoutWidget.mpr and b/test/TestDocLayoutWidget.mpr differ diff --git a/test/javasource/communitycommons/DateTime.java b/test/javasource/communitycommons/DateTime.java new file mode 100644 index 0000000..d030469 --- /dev/null +++ b/test/javasource/communitycommons/DateTime.java @@ -0,0 +1,65 @@ +package communitycommons; + +import communitycommons.proxies.DatePartSelector; +import static communitycommons.proxies.DatePartSelector.day; +import static communitycommons.proxies.DatePartSelector.month; +import static communitycommons.proxies.DatePartSelector.year; +import java.util.Date; + +import java.time.LocalDate; +import java.time.Period; +import java.time.ZoneId; +import java.util.Calendar; + +public class DateTime { + + /** + * @author mwe + * @author res + * @param firstDate The begin of the period + * @param compareDate The end of the period + * @return The period between the firstDate in the system default timezone, and the compareDate in the system + * default timezone as a Java Period + * + * Code is based on http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java + * + * Adjusted to Java 8 APIs (April, 2019) + */ + public static Period periodBetween(Date firstDate, Date compareDate) { + return Period.between(toLocalDate(firstDate), toLocalDate(compareDate)); + } + + private static LocalDate toLocalDate(Date someDate) { + return someDate.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + } + + public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) { + Calendar newDate = Calendar.getInstance(); + newDate.setTime(date); + int value = -1; + switch (selectorObj) { + case year: + value = newDate.get(Calendar.YEAR); + break; + case month: + value = newDate.get(Calendar.MONTH) + 1; + break; // Return starts at 0 + case day: + value = newDate.get(Calendar.DAY_OF_MONTH); + break; + default: + break; + } + return value; + } + + public static long dateTimeToLong(Date date) { + return date.getTime(); + } + + public static Date longToDateTime(Long value) { + return new Date(value); + } +} diff --git a/test/javasource/communitycommons/ImmutablePair.java b/test/javasource/communitycommons/ImmutablePair.java new file mode 100644 index 0000000..c787a53 --- /dev/null +++ b/test/javasource/communitycommons/ImmutablePair.java @@ -0,0 +1,58 @@ +package communitycommons; + +import org.apache.commons.lang3.builder.HashCodeBuilder; + + +public class ImmutablePair +{ + public static ImmutablePair of(T left, U right) { + return new ImmutablePair(left, right); + } + + private final T left; + private final U right; + + private ImmutablePair(T left, U right) { + if (left == null) + throw new IllegalArgumentException("Left is NULL"); + if (right == null) + throw new IllegalArgumentException("Right is NULL"); + + this.left = left; + this.right = right; + } + + public T getLeft() { + return left; + } + + public U getRight() { + return right; + } + + @Override + public String toString() { + return "<" + left.toString()+ "," + right.toString() + ">"; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ImmutablePair)) + return false; + + if (this == other) + return true; + + ImmutablePair o = (ImmutablePair) other; + return left.equals(o.getLeft()) && right.equals(o.getRight()); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(19, 85) + .append(left) + .append(right) + .toHashCode(); + } + +} diff --git a/test/javasource/communitycommons/Logging.java b/test/javasource/communitycommons/Logging.java new file mode 100644 index 0000000..dfbf47e --- /dev/null +++ b/test/javasource/communitycommons/Logging.java @@ -0,0 +1,90 @@ +package communitycommons; + +import com.mendix.core.Core; +import com.mendix.logging.ILogNode; +import communitycommons.proxies.LogLevel; +import communitycommons.proxies.LogNodes; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class Logging { + + private static Map timers = new HashMap(); + + public static void trace(String lognode, String message) { + log(lognode, LogLevel.Trace, message, null); + } + + public static void info(String lognode, String message) { + log(lognode, LogLevel.Info, message, null); + } + + public static void debug(String lognode, String message) { + log(lognode, LogLevel.Debug, message, null); + } + + public static void warn(String lognode, String message, Throwable e) { + log(lognode, LogLevel.Warning, message, e); + } + + public static void warn(String lognode, String message) { + warn(lognode, message, null); + } + + public static void error(String lognode, String message, Throwable e) { + log(lognode, LogLevel.Error, message, e); + } + + public static void error(String lognode, String message) { + error(lognode, message, null); + } + + public static void critical(String lognode, String message, Throwable e) { + log(lognode, LogLevel.Critical, message, e); + } + + public static void log(String lognode, LogLevel loglevel, String message, Throwable e) { + ILogNode logger = createLogNode(lognode); + switch (loglevel) { + case Critical: + logger.critical(message, e); + break; + case Warning: + logger.warn(message, e); + break; + case Debug: + logger.debug(message); + break; + case Error: + logger.error(message, e); + break; + case Info: + logger.info(message); + break; + case Trace: + logger.trace(message); + break; + } + } + + public static Long measureEnd(String timerName, LogLevel loglevel, + String message) { + Long cur = new Date().getTime(); + if (!timers.containsKey(timerName)) { + throw new IllegalArgumentException(String.format("Timer with key %s not found", timerName)); + } + Long timeTaken = cur - timers.get(timerName); + String time = String.format("%d", timeTaken); + log(LogNodes.CommunityCommons.name(), loglevel, "Timer " + timerName + " finished in " + time + " ms. " + message, null); + return timeTaken; + } + + public static void measureStart(String timerName) { + timers.put(timerName, new Date().getTime()); + } + + public static ILogNode createLogNode(String logNode) { + return Core.getLogger(logNode); + } +} diff --git a/test/javasource/communitycommons/Misc.java b/test/javasource/communitycommons/Misc.java new file mode 100644 index 0000000..fffc18d --- /dev/null +++ b/test/javasource/communitycommons/Misc.java @@ -0,0 +1,736 @@ +package communitycommons; + +import com.mendix.core.Core; +import com.mendix.core.CoreException; +import com.mendix.core.conf.RuntimeVersion; +import com.mendix.core.objectmanagement.member.MendixBoolean; +import com.mendix.integration.WebserviceException; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.systemwideinterfaces.core.ISession; +import com.mendix.systemwideinterfaces.core.IUser; +import communitycommons.proxies.LogNodes; +import static communitycommons.proxies.constants.Constants.getMergeMultiplePdfs_MaxAtOnce; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; +import org.apache.commons.io.IOUtils; +import org.apache.pdfbox.multipdf.Overlay; +import org.apache.pdfbox.multipdf.PDFMergerUtility; +import org.apache.pdfbox.pdmodel.PDDocument; +import system.proxies.FileDocument; +import system.proxies.Language; + +public class Misc { + + private static final String LOGNODE = LogNodes.CommunityCommons.name(); + private static boolean UNDER_TEST = false; + + static { + try { + // if this succeeds, we have a runtime + Logging.createLogNode(LOGNODE); + } catch (NullPointerException npe) { + UNDER_TEST = true; + } + } + + public abstract static class IterateCallback { + + boolean start = false; + boolean stop = false; + private Iterator mapIter; + + public abstract void hit(T1 key, T2 value) throws Exception; + + public void exit() { + stop = true; + } + + public void remove() { + mapIter.remove(); + } + + synchronized void runOn(Map map) throws Exception { + if (start) { + throw new IllegalMonitorStateException(); + } + start = true; + + try { + this.mapIter = map.keySet().iterator(); + + while (mapIter.hasNext()) { + T1 key = mapIter.next(); + T2 value = map.get(key); + + hit(key, value); + + if (stop) { + break; + } + } + } finally { + //reset state to allow reuse, even when exceptions occur + mapIter = null; + stop = false; + start = false; + } + } + } + + /** + * + * @param Any Java enumeration, such as a proxy class for a Mendix enumeration + * @param enumClass For instance: LogLevel.class + * @param value The value to look up in the enumeration + * @return An Optional of the requested enumeration. Will have the requested value if found, + * Optional.empty() otherwise. + */ + public static > Optional enumFromString(final Class enumClass, final String value) { + try { + if (value != null) { + return Optional.of(E.valueOf(enumClass, value)); + } + } catch (IllegalArgumentException iae) { + if (!UNDER_TEST) { + Logging.warn(LOGNODE, String.format("No enumeration with value %s found", value)); + } + } + return Optional.empty(); + } + + /** + * Because you cannot remove items from a map while iteration, this function is introduced. In + * the callback, you can use this.remove() or this.exit() to either remove or break the loop. + * Use return; to continue + * + * @throws Exception + */ + public static void iterateMap(Map map, IterateCallback callback) throws Exception { + //http://marxsoftware.blogspot.com/2008/04/removing-entry-from-java-map-during.html + if (map == null || callback == null) { + throw new IllegalArgumentException(); + } + + callback.runOn(map); + } + + public static String getApplicationURL() { + final String applicationURL = UNDER_TEST ? "http://localhost:8080/" : Core.getConfiguration().getApplicationRootUrl(); + return StringUtils.removeEnd(applicationURL, "/"); + } + + public static String getRuntimeVersion() { + RuntimeVersion runtimeVersion = RuntimeVersion.getInstance(); + return runtimeVersion.toString(); + } + + public static String getModelVersion() { + return Core.getModelVersion(); + } + + public static void throwException(String message) throws UserThrownException { + throw new UserThrownException(message); + } + + public static void throwWebserviceException(String faultstring) throws WebserviceException { + throw new WebserviceException(WebserviceException.clientFaultCode, faultstring); + } + + public static String retrieveURL(String url, String postdata) throws Exception { + // Send data, appname + URLConnection conn = new URL(url).openConnection(); + + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (postdata != null) { + try ( + OutputStream os = conn.getOutputStream()) { + IOUtils.copy(new ByteArrayInputStream(postdata.getBytes(StandardCharsets.UTF_8)), os); + } + } + + String result; + try ( + InputStream is = conn.getInputStream()) { + // Get the response + result = IOUtils.toString(is, StandardCharsets.UTF_8); + } + + return result; + } + + public static Boolean duplicateFileDocument(IContext context, IMendixObject toClone, IMendixObject target) throws Exception { + if (toClone == null || target == null) { + throw new Exception("No file to clone or to clone into provided"); + } + + MendixBoolean hasContents = (MendixBoolean) toClone.getMember(context, FileDocument.MemberNames.HasContents.toString()); + if (!hasContents.getValue(context)) { + return false; + } + + try ( + InputStream inputStream = Core.getFileDocumentContent(context, toClone)) { + Core.storeFileDocumentContent(context, target, (String) toClone.getValue(context, system.proxies.FileDocument.MemberNames.Name.toString()), inputStream); + } + + return true; + } + + public static Boolean duplicateImage(IContext context, IMendixObject toClone, IMendixObject target, int thumbWidth, int thumbHeight) throws Exception { + if (toClone == null || target == null) { + throw new Exception("No file to clone or to clone into provided"); + } + + MendixBoolean hasContents = (MendixBoolean) toClone.getMember(context, FileDocument.MemberNames.HasContents.toString()); + if (!hasContents.getValue(context)) { + return false; + } + + try ( + InputStream inputStream = Core.getImage(context, toClone, false)) { + Core.storeImageDocumentContent(context, target, inputStream, thumbWidth, thumbHeight); + + } + + return true; + } + + public static Boolean storeURLToFileDocument(IContext context, String url, IMendixObject __document, String filename) throws IOException { + if (__document == null || url == null || filename == null) { + throw new IllegalArgumentException("No document, filename or URL provided"); + } + + final int MAX_REMOTE_FILESIZE = 1024 * 1024 * 200; //maximum of 200 MB + try { + URL imageUrl = new URL(url); + URLConnection connection = imageUrl.openConnection(); + //we connect in 20 seconds or not at all + connection.setConnectTimeout(20000); + connection.setReadTimeout(20000); + connection.connect(); + + int contentLength = connection.getContentLength(); + + //check on forehand the size of the remote file, we don't want to kill the server by providing a 3 terabyte image. + Logging.trace(LOGNODE, String.format("Remote filesize: %d", contentLength)); + + if (contentLength > MAX_REMOTE_FILESIZE) { //maximum of 200 mb + throw new IllegalArgumentException(String.format("Wrong filesize of remote url: %d (max: %d)", contentLength, MAX_REMOTE_FILESIZE)); + } + + InputStream fileContentIS; + try (InputStream connectionInputStream = connection.getInputStream()) { + if (contentLength >= 0) { + fileContentIS = connectionInputStream; + } else { // contentLength is negative or unknown + Logging.trace(LOGNODE, String.format("Unknown content length; limiting to %d", MAX_REMOTE_FILESIZE)); + byte[] outBytes = new byte[MAX_REMOTE_FILESIZE]; + int actualLength = IOUtils.read(connectionInputStream, outBytes, 0, MAX_REMOTE_FILESIZE); + fileContentIS = new ByteArrayInputStream(Arrays.copyOf(outBytes, actualLength)); + } + Core.storeFileDocumentContent(context, __document, filename, fileContentIS); + } + } catch (IOException ioe) { + Logging.error(LOGNODE, String.format("A problem occurred while reading from URL %s: %s", url, ioe.getMessage())); + throw ioe; + } + + return true; + } + + public static Long getFileSize(IContext context, IMendixObject document) { + final int BUFFER_SIZE = 4096; + long size = 0; + + if (context != null) { + byte[] buffer = new byte[BUFFER_SIZE]; + + try ( + InputStream inputStream = Core.getFileDocumentContent(context, document)) { + int i; + while ((i = inputStream.read(buffer)) != -1) { + size += i; + } + } catch (IOException e) { + Logging.error(LOGNODE, "Couldn't determine filesize of FileDocument '" + document.getId()); + } + } + + return size; + } + + public static void delay(long delaytime) throws InterruptedException { + Thread.sleep(delaytime); + } + + public static IContext getContextFor(IContext context, String username, boolean sudoContext) { + if (username == null || username.isEmpty()) { + throw new RuntimeException("Assertion: No username provided"); + } + + if (username.equals(context.getSession().getUserName())) { + return context; + } else { // when it is a scheduled event, then get the right session. + ISession session = getSessionFor(context, username); + + IContext c = session.createContext(); + if (sudoContext) { + return c.createSudoClone(); + } + + return c; + } + } + + private static ISession getSessionFor(IContext context, String username) { + ISession session = Core.getActiveSession(username); + + if (session == null) { + IContext newContext = context.getSession().createContext().createSudoClone(); + newContext.startTransaction(); + try { + session = initializeSessionForUser(newContext, username); + } catch (CoreException e) { + newContext.rollbackTransaction(); + + throw new RuntimeException("Failed to initialize session for user: " + username + ": " + e.getMessage(), e); + } finally { + newContext.endTransaction(); + } + } + + return session; + } + + private static ISession initializeSessionForUser(IContext context, String username) throws CoreException { + IUser user = Core.getUser(context, username); + + if (user == null) { + throw new RuntimeException("Assertion: user with username '" + username + "' does not exist"); + } + + return Core.initializeSession(user, null); + } + + public static Object executeMicroflowAsUser(IContext context, + String microflowName, String username, Boolean sudoContext, Object... args) throws Exception { + + if (context == null) { + throw new Exception("Assertion: No context provided"); + } + if (microflowName == null || microflowName.isEmpty()) { + throw new Exception("Assertion: No context provided"); + } + if (!Core.getMicroflowNames().contains(microflowName)) { + throw new Exception("Assertion: microflow not found: " + microflowName); + } + if (args.length % 2 != 0) { + throw new Exception("Assertion: odd number of dynamic arguments provided, please name every argument: " + args.length); + } + + Map params = new LinkedHashMap(); + for (int i = 0; i < args.length; i += 2) { + if (args[i] != null) { + params.put(args[i].toString(), args[i + 1]); + } + } + + IContext c = getContextFor(context, username, sudoContext); + + return Core.microflowCall(microflowName).withParams(params).execute(c); + } + + //MWE: based on: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Executor.html + static class MFSerialExecutor { + + private static MFSerialExecutor _instance = new MFSerialExecutor(); + + private final AtomicLong tasknr = new AtomicLong(); + private final ExecutorService executor; + + public static MFSerialExecutor instance() { + return _instance; + } + + private MFSerialExecutor() { + executor = Executors.newSingleThreadExecutor(new ThreadFactory() { + + //Default thread factory takes care of setting the proper thread context + private final ThreadFactory defaultFactory = Executors.defaultThreadFactory(); + + @Override + public Thread newThread(Runnable runnable) { + Thread t = defaultFactory.newThread(runnable); + t.setPriority(Thread.MIN_PRIORITY); + t.setName("CommunityCommons background pool executor thread"); + return t; + } + + }); + } + + public void execute(final Runnable command) { + if (command == null) { + throw new NullPointerException("command"); + } + + final long currenttasknr = tasknr.incrementAndGet(); + Logging.debug(LOGNODE, "[RunMicroflowAsyncInQueue] Scheduling task #" + currenttasknr); + + executor.submit(new Runnable() { + @Override + public void run() { + Logging.debug(LOGNODE, "[RunMicroflowAsyncInQueue] Running task #" + currenttasknr); + try { + command.run(); + } catch (RuntimeException e) { + Logging.error(LOGNODE, "[RunMicroflowAsyncInQueue] Execution of task #" + currenttasknr + " failed: " + e.getMessage(), e); + throw e; //single thread executor will continue, even if an exception is thrown. + } + Logging.debug(LOGNODE, "[RunMicroflowAsyncInQueue] Completed task #" + currenttasknr + ". Tasks left: " + (tasknr.get() - currenttasknr)); + } + }); + } + } + + public static Boolean runMicroflowAsyncInQueue(final String microflowName) { + MFSerialExecutor.instance().execute(new Runnable() { + @Override + public void run() { + try { + Future future = Core.executeAsync(Core.createSystemContext(), microflowName, true, new HashMap<>()); //MWE: somehow, it only works with system context... well thats OK for now. + future.get(); + } catch (CoreException | InterruptedException | ExecutionException e) { + throw new RuntimeException("Failed to run Async: " + microflowName + ": " + e.getMessage(), e); + } + } + }); + return true; + } + + public static Boolean runMicroflowInBackground(final IContext context, final String microflowName, + final IMendixObject paramObject) { + + MFSerialExecutor.instance().execute(new Runnable() { + + @Override + public void run() { + try { + IContext c = Core.createSystemContext(); + if (paramObject != null) { + Core.executeAsync(c, microflowName, true, paramObject).get(); //MWE: somehow, it only works with system context... well thats OK for now. + } else { + Core.executeAsync(c, microflowName, true, new HashMap<>()).get(); //MWE: somehow, it only works with system context... well thats OK for now. + } + } catch (CoreException | InterruptedException | ExecutionException e) { + throw new RuntimeException("Failed to run Async: " + microflowName + ": " + e.getMessage(), e); + } + + } + + }); + return true; + } + + private interface IBatchItemHandler { + + void exec(IContext context, IMendixObject obj) throws Exception; + + } + + private static class BatchState { + + private int state = 0; //-1 = error, 1 = done. + private final IBatchItemHandler callback; + + public BatchState(IBatchItemHandler callback) { + this.callback = callback; + } + + public void setState(int state) { + this.state = state; + } + + public int getState() { + return state; + } + + public void handle(IContext context, IMendixObject obj) throws Exception { + callback.exec(context, obj); + } + } + + public static Boolean executeMicroflowInBatches(String xpath, final String microflow, int batchsize, boolean waitUntilFinished, boolean asc) throws CoreException, InterruptedException { + Logging.debug(LOGNODE, "[ExecuteInBatches] Starting microflow batch '" + microflow + "..."); + + return executeInBatches(xpath, new BatchState(new IBatchItemHandler() { + + @Override + public void exec(IContext context, IMendixObject obj) throws Exception { + Core.executeAsync(context, microflow, true, obj).get(); + } + + }), batchsize, waitUntilFinished, asc); + } + + public static Boolean recommitInBatches(String xpath, int batchsize, + boolean waitUntilFinished, Boolean asc) throws CoreException, InterruptedException { + Logging.debug(LOGNODE, "[ExecuteInBatches] Starting recommit batch..."); + + return executeInBatches(xpath, new BatchState(new IBatchItemHandler() { + + @Override + public void exec(IContext context, IMendixObject obj) throws Exception { + Core.commit(context, obj); + } + + }), batchsize, waitUntilFinished, asc); + } + + public static Boolean executeInBatches(String xpathRaw, BatchState batchState, int batchsize, boolean waitUntilFinished, boolean asc) throws CoreException, InterruptedException { + String xpath = xpathRaw.startsWith("//") ? xpathRaw : "//" + xpathRaw; + + long count = Core.retrieveXPathQueryAggregate(Core.createSystemContext(), "count(" + xpath + ")"); + int loop = (int) Math.ceil(((float) count) / ((float) batchsize)); + + Logging.debug(LOGNODE, + "[ExecuteInBatches] Starting batch on ~ " + count + " objects divided over ~ " + loop + " batches. " + + (waitUntilFinished ? "Waiting until the batch has finished..." : "") + ); + + executeInBatchesHelper(xpath, batchsize, 0, batchState, count, asc); + + if (waitUntilFinished) { + while (batchState.getState() == 0) { + Thread.sleep(5000); + } + if (batchState.getState() == 1) { + Logging.debug(LOGNODE, "[ExecuteInBatches] Successfully finished batch"); + return true; + } + Logging.error(LOGNODE, "[ExecuteInBatches] Failed to finish batch. Please check the application log for more details."); + return false; + } + + return true; + } + + static void executeInBatchesHelper(final String xpath, final int batchsize, final long last, final BatchState batchState, final long count, final boolean asc) { + MFSerialExecutor.instance().execute(new Runnable() { + + @Override + public void run() { + try { + Thread.sleep(200); + IContext c = Core.createSystemContext(); + + List objects = Core.retrieveXPathQuery(c, xpath + (last > 0 ? "[id " + (asc ? "> " : "< ") + last + "]" : ""), + batchsize, + 0, + new HashMap() { + { + put("id", asc ? "asc" : "desc"); + } + } + ); + + //no new objects found :) + if (objects.isEmpty()) { + Logging.debug(LOGNODE, "[ExecuteInBatches] Succesfully finished batch on ~" + count + " objects."); + batchState.setState(1); + } else { + + //process objects + for (IMendixObject obj : objects) { + batchState.handle(c, obj); + } + + //invoke next batch + executeInBatchesHelper(xpath, batchsize, objects.get(objects.size() - 1).getId().toLong(), batchState, count, asc); + } + } catch (Exception e) { + batchState.setState(-1); + throw new RuntimeException("[ExecuteInBatches] Failed to run in batch: " + e.getMessage(), e); + } + } + + }); + } + + /** + * Tests if two objects are equal with throwing unecessary null pointer exceptions. + * + * This is almost the most stupid function ever, since it should be part of Java itself. + * + * @param left + * @param right + * @return + * @deprecated Native Java function Objects.equals() is available since Java 7 + */ + @Deprecated + public static boolean objectsAreEqual(Object left, Object right) { + if (left == null && right == null) { + return true; + } + if (left == null || right == null) { + return false; + } + return left.equals(right); + } + + /** + * Get the default language + * + * @param context + * @return The default language + * @throws CoreException + */ + public static Language getDefaultLanguage(IContext context) throws CoreException { + String languageCode = Core.getDefaultLanguage().getCode(); + List languageList = Language.load(context, "[Code = '" + languageCode + "']"); + if (languageList == null || languageList.isEmpty()) { + throw new RuntimeException("No language found for default language constant value " + languageCode); + } + return languageList.get(0); + } + + public static boolean mergePDF(IContext context, List documents, IMendixObject mergedDocument) throws IOException { + if (getMergeMultiplePdfs_MaxAtOnce() <= 0 || documents.size() <= getMergeMultiplePdfs_MaxAtOnce()) { + + List sources = new ArrayList<>(); + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + PDFMergerUtility mergePdf = new PDFMergerUtility(); + + for (FileDocument file : documents) { + InputStream content = Core.getFileDocumentContent(context, file.getMendixObject()); + sources.add(content); + } + mergePdf.addSources(sources); + mergePdf.setDestinationStream(out); + mergePdf.mergeDocuments(null); + + Core.storeFileDocumentContent(context, mergedDocument, new ByteArrayInputStream(out.toByteArray())); + + out.reset(); + documents.clear(); + } catch (IOException e) { + throw new RuntimeException("Failed to merge documents" + e.getMessage(), e); + } finally { // We cannot use try-with-resources because streams would be prematurely closed + for (InputStream is : sources) { + is.close(); + } + } + + return true; + } else { + throw new IllegalArgumentException("MergeMultiplePDFs: you cannot merge more than " + getMergeMultiplePdfs_MaxAtOnce() + + " PDF files at once. You are trying to merge " + documents.size() + " PDF files."); + } + } + + /** + * Overlay a generated PDF document with another PDF (containing the company stationary for + * example) + * + * @param context + * @param generatedDocumentMendixObject The document to overlay + * @param overlayMendixObject The document containing the overlay + * @param onTopOfContent if true, puts overlay position in the foreground, otherwise in the + * background + * @return boolean + * @throws IOException + */ + public static boolean overlayPdf(IContext context, IMendixObject generatedDocumentMendixObject, IMendixObject overlayMendixObject, boolean onTopOfContent) throws IOException { + Logging.trace(LOGNODE, "Retrieve generated document"); + try ( + PDDocument inputDoc = PDDocument.load(Core.getFileDocumentContent(context, generatedDocumentMendixObject)); + PDDocument overlayDoc = PDDocument.load(Core.getFileDocumentContent(context, overlayMendixObject)); + ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + Logging.trace(LOGNODE, "Overlay PDF start, retrieve overlay PDF"); + + Logging.trace(LOGNODE, "Perform overlay"); + Overlay overlay = new Overlay(); + overlay.setInputPDF(inputDoc); + overlay.setDefaultOverlayPDF(overlayDoc); + if (onTopOfContent == true) { + overlay.setOverlayPosition(Overlay.Position.FOREGROUND); + } else { + overlay.setOverlayPosition(Overlay.Position.BACKGROUND); + } + + Logging.trace(LOGNODE, "Save result in output stream"); + + overlay.overlay(new HashMap<>()).save(baos); + + Logging.trace(LOGNODE, "Duplicate result in input stream"); + try (InputStream overlayedContent = new ByteArrayInputStream(baos.toByteArray())) { + Logging.trace(LOGNODE, "Store result in original document"); + Core.storeFileDocumentContent(context, generatedDocumentMendixObject, overlayedContent); + } + } + + Logging.trace(LOGNODE, "Overlay PDF end"); + return true; + } + + /** + * Get the Cloud Foundry Instance Index (0 for leader and >0 for slave) + * + * @return CF_INSTANCE_INDEX environment variable if available, otherwise -1 + */ + public static long getCFInstanceIndex() { + long cfInstanceIndex = -1L; + + try { + cfInstanceIndex = Long.parseLong(System.getenv("CF_INSTANCE_INDEX")); + } catch (SecurityException securityException) { + Logging.info(LOGNODE, "GetCFInstanceIndex: Could not access environment variable CF_INSTANCE_INDEX, permission denied. Value of -1 is returned."); + } catch (NumberFormatException numberFormatException) { + Logging.info(LOGNODE, "GetCFInstanceIndex: Could not parse value of environment variable CF_INSTANCE_INDEX as Long. Value of -1 is returned."); + } catch (NullPointerException nullPointerException) { + Logging.info(LOGNODE, "GetCFInstanceIndex: Could not find value for environment variable CF_INSTANCE_INDEX. This could indicate a local deployment is running. Value of -1 is returned."); + } + + return cfInstanceIndex; + } + + /** + * Returns the top n items of a List + * + * @param the type of the list elements + * @param objects the list to take the top n items from + * @param top the number of items to take + * @return the sublist of
objects
with max + *
top
elements + */ + public static List listTop(List objects, int top) { + return objects.stream() + .limit(top) + .collect(Collectors.toList()); + } +} diff --git a/test/javasource/communitycommons/ORM.java b/test/javasource/communitycommons/ORM.java new file mode 100644 index 0000000..f666e32 --- /dev/null +++ b/test/javasource/communitycommons/ORM.java @@ -0,0 +1,355 @@ +package communitycommons; + +import com.mendix.core.Core; +import com.mendix.core.CoreException; +import com.mendix.core.objectmanagement.member.MendixAutoNumber; +import com.mendix.core.objectmanagement.member.MendixDateTime; +import com.mendix.core.objectmanagement.member.MendixEnum; +import com.mendix.core.objectmanagement.member.MendixObjectReference; +import com.mendix.core.objectmanagement.member.MendixObjectReferenceSet; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixIdentifier; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.systemwideinterfaces.core.IMendixObject.ObjectState; +import com.mendix.systemwideinterfaces.core.IMendixObjectMember; +import com.mendix.systemwideinterfaces.core.IMendixObjectMember.MemberState; +import com.mendix.systemwideinterfaces.core.meta.IMetaAssociation; +import com.mendix.systemwideinterfaces.core.meta.IMetaAssociation.AssociationType; +import com.mendix.systemwideinterfaces.core.meta.IMetaEnumValue; +import com.mendix.systemwideinterfaces.core.meta.IMetaEnumeration; +import com.mendix.systemwideinterfaces.core.meta.IMetaObject; +import com.mendix.systemwideinterfaces.core.meta.IMetaPrimitive; +import com.mendix.systemwideinterfaces.core.meta.IMetaPrimitive.PrimitiveType; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import system.proxies.FileDocument; + +public class ORM { + + public static Long getGUID(IMendixObject item) { + return item.getId().toLong(); + } + + public static String getOriginalValueAsString(IContext context, IMendixObject item, + String member) { + return String.valueOf(item.getMember(context, member).getOriginalValue(context)); + } + + public static boolean objectHasChanged(IMendixObject anyobject) { + if (anyobject == null) { + throw new IllegalArgumentException("The provided object is empty"); + } + return anyobject.isChanged(); + } + + /** + * checks whether a certain member of an object has changed. If the objects itself is still new, + * we consider to be changes as well. + * + * @param item + * @param member + * @param context + * @return + */ + public static boolean memberHasChanged(IContext context, IMendixObject item, String member) { + if (item == null) { + throw new IllegalArgumentException("The provided object is empty"); + } + if (!item.hasMember(member)) { + throw new IllegalArgumentException("Unknown member: " + member); + } + return item.getMember(context, member).getState() == MemberState.CHANGED || item.getState() != ObjectState.NORMAL; + } + + public static void deepClone(IContext c, IMendixObject source, IMendixObject target, String membersToSkip, String membersToKeep, String reverseAssociations, String excludeEntities, String excludeModules) throws CoreException { + List toskip = Arrays.asList((membersToSkip + ",createdDate,changedDate").split(",")); + List tokeep = Arrays.asList((membersToKeep + ",System.owner,System.changedBy").split(",")); + List revAssoc = Arrays.asList(reverseAssociations.split(",")); + List skipEntities = Arrays.asList(excludeEntities.split(",")); + List skipModules = Arrays.asList(excludeModules.split(",")); + Map mappedIDs = new HashMap(); + duplicate(c, source, target, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedIDs); + } + + private static void duplicate(IContext ctx, IMendixObject src, IMendixObject tar, + List toskip, List tokeep, List revAssoc, + List skipEntities, List skipModules, + Map mappedObjects) throws CoreException { + mappedObjects.put(src.getId(), tar.getId()); + + Map> members = src.getMembers(ctx); + String type = src.getType() + "/"; + + for (var entry : members.entrySet()) { + String key = entry.getKey(); + if (!toskip.contains(key) && !toskip.contains(type + key)) { + IMendixObjectMember m = entry.getValue(); + if (m.isVirtual() || m instanceof MendixAutoNumber) { + continue; + } + + boolean keep = tokeep.contains(key) || tokeep.contains(type + key); + + if (m instanceof MendixObjectReference && !keep && m.getValue(ctx) != null) { + IMendixObject o = Core.retrieveId(ctx, ((MendixObjectReference) m).getValue(ctx)); + IMendixIdentifier refObj = getCloneOfObject(ctx, o, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedObjects); + tar.setValue(ctx, key, refObj); + } else if (m instanceof MendixObjectReferenceSet && !keep && m.getValue(ctx) != null) { + MendixObjectReferenceSet rs = (MendixObjectReferenceSet) m; + List res = new ArrayList(); + for (IMendixIdentifier item : rs.getValue(ctx)) { + IMendixObject o = Core.retrieveId(ctx, item); + IMendixIdentifier refObj = getCloneOfObject(ctx, o, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedObjects); + res.add(refObj); + } + tar.setValue(ctx, key, res); + } else if (m instanceof MendixAutoNumber) //skip autonumbers! Ticket 14893 + { + // do nothing + } else if ("__UUID__".equals(key) && (isFileDocument(src) || isFileDocument(tar))) { + // do nothing + } else { + tar.setValue(ctx, key, m.getValue(ctx)); + } + } + } + Core.commitWithoutEvents(ctx, tar); + duplicateReverseAssociations(ctx, src, tar, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedObjects); + } + + private static IMendixIdentifier getCloneOfObject(IContext ctx, IMendixObject src, + List toskip, List tokeep, List revAssoc, + List skipEntities, List skipModules, + Map mappedObjects) throws CoreException { + String objType = src.getMetaObject().getName(); + String modName = src.getMetaObject().getModuleName(); + + // if object is already being cloned, return ref to clone + if (mappedObjects.containsKey(src.getId())) { + return mappedObjects.get(src.getId()); + // if object should be skipped based on module or entity, return source object + } else if (skipEntities.contains(objType) || skipModules.contains(modName)) { + return src.getId(); + // if not already being cloned, create clone + } else { + IMendixObject clone = Core.instantiate(ctx, src.getType()); + duplicate(ctx, src, clone, toskip, tokeep, revAssoc, skipEntities, skipModules, mappedObjects); + return clone.getId(); + } + } + + private static void duplicateReverseAssociations(IContext ctx, IMendixObject src, IMendixObject tar, + List toskip, List tokeep, List revAssocs, + List skipEntities, List skipModules, + Map mappedObjects) throws CoreException { + for (String fullAssocName : revAssocs) { + String[] parts = fullAssocName.split("/"); + + if (parts.length != 1 && parts.length != 3) //specifying entity has no meaning anymore, but remain backward compatible. + { + throw new IllegalArgumentException("Reverse association is not defined correctly, please mention the relation name only: '" + fullAssocName + "'"); + } + + String assocname = parts.length == 3 ? parts[1] : parts[0]; //support length 3 for backward compatibility + + IMetaAssociation massoc = src.getMetaObject().getDeclaredMetaAssociationChild(assocname); + + if (massoc != null) { + IMetaObject relationParent = massoc.getParent(); + // if the parent is in the exclude list, we can't clone the parent, and setting the + // references to the newly cloned target object will screw up the source data. + if (skipEntities.contains(relationParent.getName()) || skipModules.contains(relationParent.getModuleName())) { + throw new IllegalArgumentException("A reverse reference has been specified that starts at an entity in the exclude list, this is not possible to clone: '" + fullAssocName + "'"); + } + + //MWE: what to do with reverse reference sets? -> to avoid spam creating objects on + //reverse references, do not support referenceset (todo: we could keep a map of converted guids and reuse that!) + if (massoc.getType() == AssociationType.REFERENCESET) { + throw new IllegalArgumentException("It is not possible to clone reverse referencesets: '" + fullAssocName + "'"); + } + + List objs = Core.createXPathQuery(String.format("//%s[%s=$value]", relationParent.getName(), assocname)) + .setVariable("value", src) + .execute(ctx); + + for (IMendixObject obj : objs) { + @SuppressWarnings("unused") // object is unused on purpose + IMendixIdentifier refObj = getCloneOfObject(ctx, obj, toskip, tokeep, revAssocs, skipEntities, skipModules, mappedObjects); + // setting reference explicitly is not necessary, this has been done in the + // duplicate() call. + } + } + } + } + + public static Boolean commitWithoutEvents(IContext context, IMendixObject subject) throws CoreException { + Core.commitWithoutEvents(context, subject); + return true; + } + + public static String getValueOfPath(IContext context, IMendixObject substitute, String fullpath, String datetimeformat) throws Exception { + String[] path = fullpath.split("/"); + if (path.length == 1) { + IMendixObjectMember member = substitute.getMember(context, path[0]); + + //special case, see ticket 9135, format datetime. + if (member instanceof MendixDateTime) { + Date time = ((MendixDateTime) member).getValue(context); + if (time == null) { + return ""; + } + String f = datetimeformat != null && !datetimeformat.isEmpty() ? datetimeformat : "EEE dd MMM yyyy, HH:mm"; + return new SimpleDateFormat(f).format(time); + } + + if (member instanceof MendixEnum) { + String value = member.parseValueToString(context); + if (value == null || value.isEmpty()) { + return ""; + } + + IMetaEnumeration enumeration = ((MendixEnum) member).getEnumeration(); + IMetaEnumValue evalue = enumeration.getEnumValues().get(value); + return Core.getInternationalizedString(context, evalue.getI18NCaptionKey()); + } + //default + return member.parseValueToString(context); + } else if (path.length == 0) { + throw new Exception("communitycommons.ORM.getValueOfPath: Unexpected end of path."); + } else { + IMendixObjectMember member = substitute.getMember(context, path[0]); + if (member instanceof MendixObjectReference) { + MendixObjectReference ref = (MendixObjectReference) member; + IMendixIdentifier id = ref.getValue(context); + if (id == null) { + return ""; + } + IMendixObject obj = Core.retrieveId(context, id); + if (obj == null) { + return ""; + } + return getValueOfPath(context, obj, fullpath.substring(fullpath.indexOf("/") + 1), datetimeformat); + } else if (member instanceof MendixObjectReferenceSet) { + MendixObjectReferenceSet ref = (MendixObjectReferenceSet) member; + List ids = ref.getValue(context); + if (ids == null) { + return ""; + } + StringBuilder res = new StringBuilder(); + for (IMendixIdentifier id : ids) { + if (id == null) { + continue; + } + IMendixObject obj = Core.retrieveId(context, id); + if (obj == null) { + continue; + } + res.append(", "); + res.append(getValueOfPath(context, obj, fullpath.substring(fullpath.indexOf("/") + 1), datetimeformat)); + } + return res.length() > 1 ? res.toString().substring(2) : ""; + } else { + throw new Exception("communitycommons.ORM.getValueOfPath: Not a valid reference: '" + path[0] + "' in '" + fullpath + "'"); + } + } + } + + private static boolean isFileDocument(IMendixObject object) { + return Core.isSubClassOf(Core.getMetaObject(FileDocument.entityName), object.getMetaObject()); + } + + public static Boolean cloneObject(IContext c, IMendixObject source, + IMendixObject target, Boolean withAssociations) { + Map> members = source.getMembers(c); + + for (var entry : members.entrySet()) { + IMendixObjectMember m = entry.getValue(); + if (m.isVirtual()) { + continue; + } + if (m instanceof MendixAutoNumber) { + continue; + } + if ("__UUID__".equals(m.getName()) && (isFileDocument(source) || isFileDocument(target))) { + continue; + } + if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet) && !(m instanceof MendixAutoNumber)))) { + target.setValue(c, entry.getKey(), m.getValue(c)); + } + } + return true; + } + + public static IMendixObject firstWhere(IContext c, String entityName, + Object member, String value) throws CoreException { + List items = Core.retrieveXPathQuery(c, String.format("//%s[%s = '%s']", entityName, member, value), 1, 0, new HashMap()); + if (items == null || items.size() == 0) { + return null; + } + return items.get(0); + } + + public static IMendixObject getLastChangedByUser(IContext context, + IMendixObject thing) throws CoreException { + if (thing == null || !thing.hasChangedByAttribute()) { + return null; + } + + IMendixIdentifier itemId = thing.getChangedBy(context); + if (itemId == null) { + return null; + } + + return Core.retrieveId(context, itemId); + } + + public static IMendixObject getCreatedByUser(IContext context, + IMendixObject thing) throws CoreException { + if (thing == null || !thing.hasOwnerAttribute()) { + return null; + } + + IMendixIdentifier itemId = thing.getOwner(context); + if (itemId == null) { + return null; + } + + return Core.retrieveId(context, itemId); + } + + public static void commitSilent(IContext c, IMendixObject mendixObject) { + try { + Core.commit(c, mendixObject); + } catch (CoreException e) { + throw new RuntimeException(e); + } + } + + public static void copyAttributes(IContext context, IMendixObject source, IMendixObject target) { + if (source == null) { + throw new IllegalStateException("source is null"); + } + if (target == null) { + throw new IllegalStateException("target is null"); + } + + for (IMetaPrimitive e : target.getMetaObject().getMetaPrimitives()) { + if (!source.hasMember(e.getName())) { + continue; + } + if (e.isVirtual() || e.getType() == PrimitiveType.AutoNumber) { + continue; + } + if ("__UUID__".equals(e.getName()) && (isFileDocument(source) || isFileDocument(target))) { + continue; + } + + target.setValue(context, e.getName(), source.getValue(context, e.getName())); + } + } +} diff --git a/test/javasource/communitycommons/StringUtils.java b/test/javasource/communitycommons/StringUtils.java new file mode 100644 index 0000000..8caf671 --- /dev/null +++ b/test/javasource/communitycommons/StringUtils.java @@ -0,0 +1,483 @@ +package communitycommons; + +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.proxies.SanitizerPolicy; + +import static communitycommons.proxies.SanitizerPolicy.BLOCKS; +import static communitycommons.proxies.SanitizerPolicy.FORMATTING; +import static communitycommons.proxies.SanitizerPolicy.IMAGES; +import static communitycommons.proxies.SanitizerPolicy.LINKS; +import static communitycommons.proxies.SanitizerPolicy.STYLES; +import static communitycommons.proxies.SanitizerPolicy.TABLES; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.*; +import java.text.Normalizer; +import java.util.*; +import java.util.AbstractMap.SimpleEntry; +import java.util.function.Function; +import java.util.regex.MatchResult; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.parser.ParserDelegator; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.owasp.html.PolicyFactory; +import org.owasp.html.Sanitizers; +import system.proxies.FileDocument; + +public class StringUtils { + + private static final Random RANDOM = new SecureRandom(); + + private static final String UPPERCASE_ALPHA = stringRange('A', 'Z'); + private static final String LOWERCASE_ALPHA = stringRange('a', 'z'); + private static final String DIGITS = stringRange('0', '9'); + private static final String SPECIAL = stringRange('!', '/'); + private static final String ALPHANUMERIC = UPPERCASE_ALPHA + LOWERCASE_ALPHA + DIGITS; + + static final Map SANITIZER_POLICIES = + Map.ofEntries( + new SimpleEntry<>(BLOCKS.name(), Sanitizers.BLOCKS), + new SimpleEntry<>(FORMATTING.name(), Sanitizers.FORMATTING), + new SimpleEntry<>(IMAGES.name(), Sanitizers.IMAGES), + new SimpleEntry<>(LINKS.name(), Sanitizers.LINKS), + new SimpleEntry<>(STYLES.name(), Sanitizers.STYLES), + new SimpleEntry<>(TABLES.name(), Sanitizers.TABLES) + ); + + public static final String HASH_ALGORITHM = "SHA-256"; + + public static String hash(String value, int length) throws NoSuchAlgorithmException, DigestException { + byte[] inBytes = value.getBytes(StandardCharsets.UTF_8); + byte[] outBytes = new byte[length]; + + MessageDigest alg = MessageDigest.getInstance(HASH_ALGORITHM); + alg.update(inBytes); + + alg.digest(outBytes, 0, length); + + StringBuilder hexString = new StringBuilder(); + for (int i = 0; i < outBytes.length; i++) { + String hex = Integer.toHexString(0xff & outBytes[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + + return hexString.toString(); + } + + /** + * The default replaceAll microflow function doesn't support capture variables such as $1, $2 + * etc. so for that reason we do not deprecate this method. + * + * @param haystack The string to replace patterns in + * @param needleRegex The regular expression pattern + * @param replacement The string that should come in place of the pattern matches. + * @return The resulting string, where all matches have been replaced by the replacement. + */ + public static String regexReplaceAll(String haystack, String needleRegex, + String replacement) { + Pattern pattern = Pattern.compile(needleRegex); + Matcher matcher = pattern.matcher(haystack); + return matcher.replaceAll(replacement); + } + + public static String leftPad(String value, Long amount, String fillCharacter) { + if (fillCharacter == null || fillCharacter.length() == 0) { + return org.apache.commons.lang3.StringUtils.leftPad(value, amount.intValue(), " "); + } + return org.apache.commons.lang3.StringUtils.leftPad(value, amount.intValue(), fillCharacter); + } + + public static String rightPad(String value, Long amount, String fillCharacter) { + if (fillCharacter == null || fillCharacter.length() == 0) { + return org.apache.commons.lang3.StringUtils.rightPad(value, amount.intValue(), " "); + } + return org.apache.commons.lang3.StringUtils.rightPad(value, amount.intValue(), fillCharacter); + } + + public static String randomString(int length) { + return randomStringFromCharArray(length, ALPHANUMERIC.toCharArray()); + } + + public static String substituteTemplate(final IContext context, String template, + final IMendixObject substitute, final boolean HTMLEncode, final String datetimeformat) { + return regexReplaceAll(template, "\\{(@)?([\\w./]+)\\}", (MatchResult match) -> { + String value; + String path = match.group(2); + if (match.group(1) != null) { + value = String.valueOf(Core.getConfiguration().getConstantValue(path)); + } else { + try { + value = ORM.getValueOfPath(context, substitute, path, datetimeformat); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return HTMLEncode ? HTMLEncode(value) : value; + }); + } + + public static String regexReplaceAll(String source, String regexString, Function replaceFunction) { + if (source == null || source.trim().isEmpty()) // avoid NPE's, save CPU + { + return ""; + } + + StringBuffer resultString = new StringBuffer(); + Pattern regex = Pattern.compile(regexString); + Matcher regexMatcher = regex.matcher(source); + + while (regexMatcher.find()) { + MatchResult match = regexMatcher.toMatchResult(); + String value = replaceFunction.apply(match); + regexMatcher.appendReplacement(resultString, Matcher.quoteReplacement(value)); + } + regexMatcher.appendTail(resultString); + + return resultString.toString(); + } + + public static String HTMLEncode(String value) { + return StringEscapeUtils.escapeHtml4(value); + } + + public static String randomHash() { + return UUID.randomUUID().toString(); + } + + public static String base64Decode(String encoded) { + if (encoded == null) { + return null; + } + return new String(Base64.getDecoder().decode(encoded.getBytes())); + } + + public static void base64DecodeToFile(IContext context, String encoded, FileDocument targetFile) throws Exception { + if (targetFile == null) { + throw new IllegalArgumentException("Source file is null"); + } + if (encoded == null) { + throw new IllegalArgumentException("Source data is null"); + } + + byte[] decoded = Base64.getDecoder().decode(encoded.getBytes()); + + try (ByteArrayInputStream bais = new ByteArrayInputStream(decoded)) { + Core.storeFileDocumentContent(context, targetFile.getMendixObject(), bais); + } + } + + public static String base64Encode(String value) { + if (value == null) { + return null; + } + return Base64.getEncoder().encodeToString(value.getBytes()); + } + + public static String base64EncodeFile(IContext context, FileDocument file) throws IOException { + if (file == null) { + throw new IllegalArgumentException("Source file is null"); + } + if (!file.getHasContents()) { + throw new IllegalArgumentException("Source file has no contents!"); + } + + try (InputStream f = Core.getFileDocumentContent(context, file.getMendixObject())) { + return Base64.getEncoder().encodeToString(IOUtils.toByteArray(f)); + } + } + + public static String stringFromFile(IContext context, FileDocument source) throws IOException { + return stringFromFile(context, source, StandardCharsets.UTF_8); + } + + public static String stringFromFile(IContext context, FileDocument source, Charset charset) throws IOException { + if (source == null) { + return null; + } + try (InputStream f = Core.getFileDocumentContent(context, source.getMendixObject())) { + return IOUtils.toString(f, charset); + } + } + + public static void stringToFile(IContext context, String value, FileDocument destination) throws IOException { + stringToFile(context, value, destination, StandardCharsets.UTF_8); + } + + public static void stringToFile(IContext context, String value, FileDocument destination, Charset charset) throws IOException { + if (destination == null) { + throw new IllegalArgumentException("Destination file is null"); + } + if (value == null) { + throw new IllegalArgumentException("Value to write is null"); + } + + try (InputStream is = IOUtils.toInputStream(value, charset)) { + Core.storeFileDocumentContent(context, destination.getMendixObject(), is); + } + } + + public static String HTMLToPlainText(String html) throws IOException { + if (html == null) { + return ""; + } + final StringBuilder result = new StringBuilder(); + + HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback() { + @Override + public void handleText(char[] data, int pos) { + result.append(data); //TODO: needds to be html entity decode? + } + + @Override + public void handleComment(char[] data, int pos) { + //Do nothing + } + + @Override + public void handleError(String errorMsg, int pos) { + //Do nothing + } + + @Override + public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet a, int pos) { + if (tag == HTML.Tag.BR) { + result.append("\r\n"); + } + } + + @Override + public void handleEndTag(HTML.Tag tag, int pos) { + if (tag == HTML.Tag.P) { + result.append("\r\n"); + } + } + }; + + new ParserDelegator().parse(new StringReader(html), callback, true); + + return result.toString(); + } + + /** + * Returns a random strong password containing a specified minimum number of digits, uppercase + * and special characters. + * + * @param minLen Minimum length + * @param maxLen Maximum length + * @param noOfCAPSAlpha Number of capitals + * @param noOfDigits Number of digits + * @param noOfSplChars Number of special characters + * @return + */ + public static String randomStrongPassword(int minLen, int maxLen, int noOfCAPSAlpha, int noOfDigits, int noOfSplChars) { + if (minLen > maxLen) { + throw new IllegalArgumentException("Min. Length > Max. Length!"); + } + if ((noOfCAPSAlpha + noOfDigits + noOfSplChars) > minLen) { + throw new IllegalArgumentException("Min. Length should be atleast sum of (CAPS, DIGITS, SPL CHARS) Length!"); + } + return generateCommonLangPassword(minLen, maxLen, noOfCAPSAlpha, noOfDigits, noOfSplChars); + } + + // See https://www.baeldung.com/java-generate-secure-password + // Implementation inspired by https://github.com/eugenp/tutorials/tree/master/core-java-modules/core-java-string-apis (under MIT license) + private static String generateCommonLangPassword(int minLen, int maxLen, int noOfCapsAlpha, int noOfDigits, int noOfSplChars) { + String upperCaseLetters = randomStringFromCharArray(noOfCapsAlpha, UPPERCASE_ALPHA.toCharArray()); + String numbers = randomStringFromCharArray(noOfDigits, DIGITS.toCharArray()); + String specialChar = randomStringFromCharArray(noOfSplChars, SPECIAL.toCharArray()); + + final int fixedNumber = noOfCapsAlpha + noOfDigits + noOfSplChars; + final int lowerBound = minLen - fixedNumber; + final int upperBound = maxLen - fixedNumber; + String totalChars = randomStringFromCharArray(lowerBound, upperBound, ALPHANUMERIC.toCharArray()); + + String combinedChars = upperCaseLetters + .concat(numbers) + .concat(specialChar) + .concat(totalChars); + List pwdChars = combinedChars.chars() + .mapToObj(c -> (char) c) + .collect(Collectors.toList()); + Collections.shuffle(pwdChars); + String password = pwdChars.stream() + .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append) + .toString(); + return password; + } + + /** + * Generate a secure random string using the given array of characters, of which the resulting + * string will be composed of. + * + * @param count The length of the random string. + * @param allowedChars The characters used for constructing the random string. + * @return A random string. + * @throws IllegalArgumentException if count is negative or allowedChars is null or empty. + */ + private static String randomStringFromCharArray(int count, final char[] allowedChars) { + if (count == 0) + return ""; + if (count < 0) + throw new IllegalArgumentException("The requested length for the random string was negative: " + count); + if (allowedChars == null) + throw new IllegalArgumentException("The char array 'allowedChars' cannot be null."); + if (allowedChars.length == 0) + throw new IllegalArgumentException("The char array 'allowedChars' cannot be empty."); + + StringBuilder builder = new StringBuilder(); + + while (count-- > 0) { + int index = RANDOM.nextInt(allowedChars.length); + builder.append(allowedChars[index]); + } + + return builder.toString(); + } + + /** + * Generate a random string with a random length between minLengthBound and maxLengthBound (inclusive), + * using the given set of allowed characters. + * + * @param minLengthBound The lower bound for the random length of the string. + * @param maxLengthBound The upper bound for the random length of the string. + * @param allowedChars An array of characters of which the resulting string will be made up of. + * @return A random string with a length between minLengthBound and maxLengthBound. + * @throws IllegalArgumentException if minLengthBound is larger than maxLengthBound. + */ + private static String randomStringFromCharArray(int minLengthBound, int maxLengthBound, final char[] allowedChars) { + if (minLengthBound == maxLengthBound) + return randomStringFromCharArray(minLengthBound, allowedChars); + if (minLengthBound > maxLengthBound) + throw new IllegalArgumentException("The minimum bound (" + minLengthBound + ") was larger than the maximum bound (" + maxLengthBound + "."); + final int randomLength = minLengthBound + RANDOM.nextInt(maxLengthBound - minLengthBound + 1); // add one to make the range inclusive. + return randomStringFromCharArray(randomLength, allowedChars); + } + + /** + * Produces a 'range' string starting from the begin character up to + * the end character (inclusive range). For example, for the range (a-z), + * this method will generate the lowercase alphabet. + * + * @param begin The starting point of the string. + * @param end The ending point of the string. + * @return A string from begin to end (inclusive range). + * @throws IllegalArgumentException if the begin character has a higher code point than the end character. + */ + private static String stringRange(char begin, char end) { + if (begin > end) { + throw new IllegalArgumentException("The 'begin' character cannot be larger than the 'end' character."); + } + + StringBuilder builder = new StringBuilder(); + while (begin <= end) + builder.append(begin++); + return builder.toString(); + } + + private static byte[] generateHmacSha256Bytes(String key, String valueToEncrypt) throws UnsupportedEncodingException, IllegalStateException, InvalidKeyException, NoSuchAlgorithmException { + SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256"); + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(secretKey); + mac.update(valueToEncrypt.getBytes("UTF-8")); + byte[] hmacData = mac.doFinal(); + + return hmacData; + } + + public static String generateHmacSha256(String key, String valueToEncrypt) { + try { + byte[] hash = generateHmacSha256Bytes(key, valueToEncrypt); + StringBuilder result = new StringBuilder(); + for (byte b : hash) { + result.append(String.format("%02x", b)); + } + return result.toString(); + } catch (UnsupportedEncodingException | IllegalStateException | InvalidKeyException | NoSuchAlgorithmException e) { + throw new RuntimeException("CommunityCommons::generateHmacSha256::Unable to encode: " + e.getMessage(), e); + } + } + + public static String generateHmacSha256Hash(String key, String valueToEncrypt) { + try { + return Base64.getEncoder().encodeToString(generateHmacSha256Bytes(key, valueToEncrypt)); + } catch (UnsupportedEncodingException | IllegalStateException | InvalidKeyException | NoSuchAlgorithmException e) { + throw new RuntimeException("CommunityCommons::generateHmacSha256Hash::Unable to encode: " + e.getMessage(), e); + } + } + + public static String escapeHTML(String input) { + return input.replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'");// notice this one: for xml "'" would be "'" (http://blogs.msdn.com/b/kirillosenkov/archive/2010/03/19/apos-is-in-xml-in-html-use-39.aspx) + // OWASP also advises to escape "/" but give no convincing reason why: https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet + } + + public static String regexQuote(String unquotedLiteral) { + return Pattern.quote(unquotedLiteral); + } + + public static String substringBefore(String str, String separator) { + return org.apache.commons.lang3.StringUtils.substringBefore(str, separator); + } + + public static String substringBeforeLast(String str, String separator) { + return org.apache.commons.lang3.StringUtils.substringBeforeLast(str, separator); + } + + public static String substringAfter(String str, String separator) { + return org.apache.commons.lang3.StringUtils.substringAfter(str, separator); + } + + public static String substringAfterLast(String str, String separator) { + return org.apache.commons.lang3.StringUtils.substringAfterLast(str, separator); + } + + public static String removeEnd(String str, String toRemove) { + return org.apache.commons.lang3.StringUtils.removeEnd(str, toRemove); + } + + public static String sanitizeHTML(String html, List policyParams) { + PolicyFactory policyFactory = null; + + for (SanitizerPolicy param : policyParams) { + policyFactory = (policyFactory == null) ? SANITIZER_POLICIES.get(param.name()) : policyFactory.and(SANITIZER_POLICIES.get(param.name())); + } + + return sanitizeHTML(html, policyFactory); + } + + public static String sanitizeHTML(String html, PolicyFactory policyFactory) { + return policyFactory.sanitize(html); + } + + public static String stringSimplify(String value) { + String normalized = Normalizer.normalize(value, Normalizer.Form.NFD); + return normalized.replaceAll("\\p{M}", ""); // removes all characters in Unicode Mark category + } + + public static Boolean isStringSimplified(String value) { + return Normalizer.isNormalized(value, Normalizer.Form.NFD); + } +} diff --git a/test/javasource/communitycommons/UserThrownException.java b/test/javasource/communitycommons/UserThrownException.java new file mode 100644 index 0000000..5c67787 --- /dev/null +++ b/test/javasource/communitycommons/UserThrownException.java @@ -0,0 +1,15 @@ +package communitycommons; + +public class UserThrownException extends Exception +{ + /** + * + */ + private static final long serialVersionUID = -55911261625752858L; + + public UserThrownException(String arg0) + { + super(arg0); + } + +} diff --git a/test/javasource/communitycommons/XPath.java b/test/javasource/communitycommons/XPath.java new file mode 100644 index 0000000..800d1e1 --- /dev/null +++ b/test/javasource/communitycommons/XPath.java @@ -0,0 +1,838 @@ +package communitycommons; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.translate.AggregateTranslator; +import org.apache.commons.text.translate.CharSequenceTranslator; +import org.apache.commons.text.translate.EntityArrays; +import org.apache.commons.text.translate.LookupTranslator; + +import com.mendix.core.Core; +import com.mendix.core.CoreException; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixIdentifier; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +public class XPath +{ + /** Build in tokens, see: https://world.mendix.com/display/refguide3/XPath+Keywords+and+System+Variables + * + */ + + public static final String CurrentUser = "[%CurrentUser%]"; + public static final String CurrentObject = "[%CurrentObject%]"; + + public static final String CurrentDateTime = "[%CurrentDateTime%]"; + public static final String BeginOfCurrentDay = "[%BeginOfCurrentDay%]"; + public static final String EndOfCurrentDay = "[%EndOfCurrentDay%]"; + public static final String BeginOfCurrentHour = "[%BeginOfCurrentHour%]"; + public static final String EndOfCurrentHour = "[%EndOfCurrentHour%]"; + public static final String BeginOfCurrentMinute = "[%BeginOfCurrentMinute%]"; + public static final String EndOfCurrentMinute = "[%EndOfCurrentMinute%]"; + public static final String BeginOfCurrentMonth = "[%BeginOfCurrentMonth%]"; + public static final String EndOfCurrentMonth = "[%EndOfCurrentMonth%]"; + public static final String BeginOfCurrentWeek = "[%BeginOfCurrentWeek%]"; + public static final String EndOfCurrentWeek = "[%EndOfCurrentWeek%]"; + + public static final String DayLength = "[%DayLength%]"; + public static final String HourLength = "[%HourLength%]"; + public static final String MinuteLength = "[%MinuteLength%]"; + public static final String SecondLength = "[%SecondLength%]"; + public static final String WeekLength = "[%WeekLength%]"; + public static final String YearLength = "[%YearLength%]"; + public static final String ID = "id"; + + /** End builtin tokens */ + + private String entity; + private int offset = 0; + private int limit = -1; + private LinkedHashMap sorting = new LinkedHashMap(); //important, linked map! + private LinkedList closeStack = new LinkedList(); + private StringBuilder builder = new StringBuilder(); + private IContext context; + private Class proxyClass; + private boolean requiresBinOp = false; //state property, indicates whether and 'and' needs to be inserted before the next constraint + + public static XPath create(IContext c, String entityType) { + XPath res = new XPath(c, IMendixObject.class); + + res.entity = entityType; + + return res; + } + + public static XPath create(IContext c, Class proxyClass) { + return new XPath(c, proxyClass); + } + + private XPath(IContext c, Class proxyClass) { + try + { + if (proxyClass != IMendixObject.class) + this.entity = (String) proxyClass.getMethod("getType").invoke(null); + } + catch (Exception e) + { + throw new IllegalArgumentException("Failed to determine entity type of proxy class. Did you provide a valid proxy class? '" + proxyClass.getName() + "'"); + } + + this.proxyClass = proxyClass; + this.context = c; + } + + private XPath autoInsertAnd() { + if (requiresBinOp) + and(); + return this; + } + + private XPath requireBinOp(boolean requires) { + requiresBinOp = requires; + return this; + } + + public XPath offset(int offset2) { + if (offset2 < 0) + throw new IllegalArgumentException("Offset should not be negative"); + this.offset = offset2; + return this; + } + + public XPath limit(int limit2) { + if (limit2 < -1 || limit2 == 0) + throw new IllegalArgumentException("Limit should be larger than zero or -1. "); + + this.limit = limit2; + return this; + } + + public XPath addSortingAsc(Object... sortparts) { + assertOdd(sortparts); + sorting.put(StringUtils.join(sortparts, '/'), "asc"); + return this; + } + + public XPath addSortingDesc(Object... sortparts) { + sorting.put(StringUtils.join(sortparts, "/"), "desc"); + return this; + } + + public XPath eq(Object attr, Object valuecomparison) { + return compare(attr, "=", valuecomparison); + } + + public XPath eq(Object... pathAndValue) { + assertEven(pathAndValue); + return compare(Arrays.copyOfRange(pathAndValue, 0, pathAndValue.length -1), "=", pathAndValue[pathAndValue.length -1 ]); + } + + public XPath equalsIgnoreCase(Object attr, String value) { + //(contains(Name, $email) and length(Name) = length($email) + return + subconstraint() + .contains(attr, value) + .and() + .append(" length(" + attr + ") = ").append(value == null ? "0" : valueToXPathValue(value.length())) + .close(); + } + + public XPath notEq(Object attr, Object valuecomparison) { + return compare(attr, "!=", valuecomparison); + } + + public XPath notEq(Object... pathAndValue) { + assertEven(pathAndValue); + return compare(Arrays.copyOfRange(pathAndValue, 0, pathAndValue.length -1), "!=", pathAndValue[pathAndValue.length -1 ]); + } + + public XPath contains(Object attr, String value) + { + autoInsertAnd().append(" contains(").append(String.valueOf(attr)).append(",").append(valueToXPathValue(value)).append(") "); + return this.requireBinOp(true); + } + + public XPath compare(Object attr, String operator, Object value) { + return compare(new Object[] {attr}, operator, value); + } + + public XPath compare(Object[] path, String operator, Object value) { + assertOdd(path); + autoInsertAnd().append(StringUtils.join(path, '/')).append(" ").append(operator).append(" ").append(valueToXPathValue(value)); + return this.requireBinOp(true); + } + + public XPath hasReference(Object... path) + { + assertEven(path); //Reference + entity type + autoInsertAnd().append(StringUtils.join(path, '/')); + return this.requireBinOp(true); + } + + public XPath subconstraint(Object... path) { + assertEven(path); + autoInsertAnd().append(StringUtils.join(path, '/')).append("["); + closeStack.push("]"); + return this.requireBinOp(false); + } + + public XPath subconstraint() { + autoInsertAnd().append("("); + closeStack.push(")"); + return this.requireBinOp(false); + } + + public XPath addConstraint() + { + if (!closeStack.isEmpty() && !closeStack.peek().equals("]")) + throw new IllegalStateException("Cannot add a constraint while in the middle of something else.."); + + return append("][").requireBinOp(false); + } + + public XPath close() { + if (closeStack.isEmpty()) + throw new IllegalStateException("XPathbuilder close stack is empty!"); + append(closeStack.pop()); + return requireBinOp(true); + //MWE: note that a close does not necessary require a binary operator, for example with two subsequent block([bla][boe]) constraints, + //but openening a binary constraint reset the flag, so that should be no issue + } + + public XPath or() { + if (!requiresBinOp) + throw new IllegalStateException("Received 'or' but no binary operator was expected"); + return append(" or ").requireBinOp(false); + } + + public XPath and() { + if (!requiresBinOp) + throw new IllegalStateException("Received 'and' but no binary operator was expected"); + return append(" and ").requireBinOp(false); + } + + public XPath not() { + autoInsertAnd(); + closeStack.push(")"); + return append(" not(").requireBinOp(false); + } + + private void assertOdd(Object[] stuff) { + if (stuff == null || stuff.length == 0 || stuff.length % 2 == 0) + throw new IllegalArgumentException("Expected an odd number of xpath path parts"); + } + + private void assertEven(Object[] stuff) { + if (stuff == null || stuff.length == 0 || stuff.length % 2 == 1) + throw new IllegalArgumentException("Expected an even number of xpath path parts"); + } + + public XPath append(String s) { + builder.append(s); + return this; + } + + public String getXPath() { + + if (builder.length() > 0) + return "//" + this.entity + "[" + builder.toString() + "]"; + return "//" + this.entity; + } + + public XPath gt(Object attr, Object valuecomparison) { + return compare(attr,">=", valuecomparison); + } + + public XPath gt(Object... pathAndValue) { + assertEven(pathAndValue); + return compare(Arrays.copyOfRange(pathAndValue, 0, pathAndValue.length -1), ">=", pathAndValue[pathAndValue.length -1 ]); + } + + private void assertEmptyStack() throws IllegalStateException + { + if (!closeStack.isEmpty()) + throw new IllegalStateException("Invalid xpath expression, not all items where closed"); + } + + public long count( ) throws CoreException { + assertEmptyStack(); + + return Core.retrieveXPathQueryAggregate(context, "count(" + getXPath() +")"); + } + + + public IMendixObject firstMendixObject() throws CoreException { + assertEmptyStack(); + + List result = Core.retrieveXPathQuery(context, getXPath(), 1, offset, sorting); + if (result.isEmpty()) + return null; + return result.get(0); + } + + public T first() throws CoreException { + return createProxy(context, proxyClass, firstMendixObject()); + } + + + /** + * Given a set of attribute names and values, tries to find the first object that matches all conditions, or creates one + * + * @param keysAndValues + * @return + * @throws CoreException + */ + public T findOrCreateNoCommit(Object... keysAndValues) throws CoreException + { + T res = findFirst(keysAndValues); + + return res != null ? res : constructInstance(false, keysAndValues); + } + + + public T findOrCreate(Object... keysAndValues) throws CoreException { + T res = findFirst(keysAndValues); + + return res != null ? res : constructInstance(true, keysAndValues); + + } + + public T findOrCreateSynchronized(Object... keysAndValues) throws CoreException, InterruptedException { + T res = findFirst(keysAndValues); + + if (res != null) { + return res; + } else { + synchronized (Core.getMetaObject(entity)) { + IContext synchronizedContext = context.getSession().createContext().createSudoClone(); + try { + synchronizedContext.startTransaction(); + res = createProxy(synchronizedContext, proxyClass, XPath.create(synchronizedContext, entity).findOrCreate(keysAndValues)); + synchronizedContext.endTransaction(); + return res; + } catch (CoreException e) { + if (synchronizedContext.isInTransaction()) { + synchronizedContext.rollbackTransaction(); + } + throw e; + } + } + } + } + + public T findFirst(Object... keysAndValues) + throws IllegalStateException, CoreException + { + if (builder.length() > 0) + throw new IllegalStateException("FindFirst can only be used on XPath which do not have constraints already"); + + assertEven(keysAndValues); + for(int i = 0; i < keysAndValues.length; i+= 2) + eq(keysAndValues[i], keysAndValues[i + 1]); + + T res = this.first(); + return res; + } + + + /** + * Creates one instance of the type of this XPath query, and initializes the provided attributes to the provided values. + * @param keysAndValues AttributeName, AttributeValue, AttributeName2, AttributeValue2... list. + * @return + * @throws CoreException + */ + public T constructInstance(boolean autoCommit, Object... keysAndValues) throws CoreException + { + assertEven(keysAndValues); + IMendixObject newObj = Core.instantiate(context, this.entity); + + for(int i = 0; i < keysAndValues.length; i+= 2) + newObj.setValue(context, String.valueOf(keysAndValues[i]), toMemberValue(keysAndValues[i + 1])); + + if (autoCommit) + Core.commit(context, newObj); + + return createProxy(context, proxyClass, newObj); + } + + /** + * Given a current collection of primitive values, checks if for each value in the collection an object in the database exists. + * It creates a new object if needed, and removes any superfluos objects in the database that are no longer in the collection. + * + * @param currentCollection The collection that act as reference for the objects that should be in this database in the end. + * @param comparisonAttribute The attribute that should store the value as decribed in the collection + * @param autoDelete Automatically remove any superfluous objects form the database + * @param keysAndValues Constraints that should hold for the set of objects that are deleted or created. Objects outside this constraint are not processed. + * + * @return A pair of lists. The first list contains the newly created objects, the second list contains the objects that (should be or are) removed. + * @throws CoreException + */ + public ImmutablePair, List> syncDatabaseWithCollection(Collection currentCollection, Object comparisonAttribute, boolean autoDelete, Object... keysAndValues) throws CoreException { + if (builder.length() > 0) + throw new IllegalStateException("syncDatabaseWithCollection can only be used on XPath which do not have constraints already"); + + + List added = new ArrayList(); + List removed = new ArrayList(); + + Set col = new HashSet(currentCollection); + + for(int i = 0; i < keysAndValues.length; i+= 2) + eq(keysAndValues[i], keysAndValues[i + 1]); + + for(IMendixObject existingItem : this.allMendixObjects()) { + //Item is still available + if (col.remove(existingItem.getValue(context, String.valueOf(comparisonAttribute)))) + continue; + + //No longer available + removed.add(createProxy(context, this.proxyClass, existingItem)); + if (autoDelete) + Core.delete(context, existingItem); + } + + //Some items where not found in the database + for(U value : col) { + + //In apache lang3, this would just be: ArrayUtils.addAll(keysAndValues, comparisonAttribute, value) + Object[] args = new Object[keysAndValues.length + 2]; + for(int i = 0; i < keysAndValues.length; i++) + args[i] = keysAndValues[i]; + args[keysAndValues.length] = comparisonAttribute; + args[keysAndValues.length + 1] = value; + + T newItem = constructInstance(true, args); + added.add(newItem); + } + + //Oké, stupid, Pair is also only available in apache lang3, so lets use a simple pair implementation for now + return ImmutablePair.of(added, removed); + } + + public T firstOrWait(long timeoutMSecs) throws CoreException, InterruptedException + { + IMendixObject result = null; + + long start = System.currentTimeMillis(); + int sleepamount = 200; + int loopcount = 0; + + while (result == null) { + loopcount += 1; + result = firstMendixObject(); + + long now = System.currentTimeMillis(); + + if (start + timeoutMSecs < now) //Time expired + break; + + if (loopcount % 5 == 0) + sleepamount *= 1.5; + + //not expired, wait a bit + if (result == null) + Thread.sleep(sleepamount); + } + + return createProxy(context, proxyClass, result); + } + + + public List allMendixObjects() throws CoreException { + assertEmptyStack(); + + return Core.retrieveXPathQuery(context, getXPath(), limit, offset, sorting); + } + + public List all() throws CoreException { + List res = new ArrayList(); + for(IMendixObject o : allMendixObjects()) + res.add(createProxy(context, proxyClass, o)); + + return res; + } + + @Override + public String toString() { + return getXPath(); + } + + + /** + * + * + * Static utility functions + * + * + */ + + //cache for proxy constructors. Reflection is slow, so reuse as much as possible + private static Map initializers = new HashMap(); + + public static List createProxyList(IContext c, Class proxieClass, List objects) { + List res = new ArrayList(); + if (objects == null || objects.size() == 0) + return res; + + for(IMendixObject o : objects) + res.add(createProxy(c, proxieClass, o)); + + return res; + } + + public static T createProxy(IContext c, Class proxieClass, IMendixObject object) { + //Borrowed from nl.mweststrate.pages.MxQ package + + if (object == null) + return null; + + if (c == null || proxieClass == null) + throw new IllegalArgumentException("[CreateProxy] No context or proxieClass provided. "); + + //jeuj, we expect IMendixObject's. Thats nice.. + if (proxieClass == IMendixObject.class) + return proxieClass.cast(object); //.. since we can do a direct cast + + try { + String entityType = object.getType(); + + if (!initializers.containsKey(entityType)) { + + String[] entType = object.getType().split("\\."); + Class realClass = Class.forName(entType[0].toLowerCase()+".proxies."+entType[1]); + + initializers.put(entityType, realClass.getMethod("initialize", IContext.class, IMendixObject.class)); + } + + //find constructor + Method m = initializers.get(entityType); + + //create proxy object + Object result = m.invoke(null, c, object); + + //cast, but check first is needed because the actual type might be a subclass of the requested type + if (!proxieClass.isAssignableFrom(result.getClass())) + throw new IllegalArgumentException("The type of the object ('" + object.getType() + "') is not (a subclass) of '" + proxieClass.getName()+"'"); + + T proxie = proxieClass.cast(result); + return proxie; + } + catch (Exception e) { + throw new RuntimeException("Unable to instantiate proxie: " + e.getMessage(), e); + } + } + + public static String valueToXPathValue(Object value) + { + if (value == null) + return "NULL"; + + //Complex objects + if (value instanceof IMendixIdentifier) + return "'" + String.valueOf(((IMendixIdentifier) value).toLong()) + "'"; + if (value instanceof IMendixObject) + return valueToXPathValue(((IMendixObject)value).getId()); + if (value instanceof List) + throw new IllegalArgumentException("List based values are not supported!"); + + //Primitives + if (value instanceof Date) + return String.valueOf(((Date) value).getTime()); + if (value instanceof Long || value instanceof Integer) + return String.valueOf(value); + if (value instanceof Double || value instanceof Float) { + //make sure xpath understands our number formatting + NumberFormat format = NumberFormat.getNumberInstance(Locale.ENGLISH); + format.setMaximumFractionDigits(10); + format.setGroupingUsed(false); + return format.format(value); + } + if (value instanceof Boolean) { + return value.toString() + "()"; //xpath boolean, you know.. + } + if (value instanceof String) { + return "'" + ESCAPE_XML.translate(String.valueOf(value)) + "'"; + } + + //Object, assume its a proxy and deproxiefy + try + { + IMendixObject mo = proxyToMendixObject(value); + return valueToXPathValue(mo); + } + catch (NoSuchMethodException e) + { + //This is O.K. just not a proxy object... + } + catch (Exception e) { + throw new RuntimeException("Failed to retrieve MendixObject from proxy: " + e.getMessage(), e); + } + + //assume some string representation + return "'" + ESCAPE_XML.translate(String.valueOf(value)) + "'"; + } + + public static IMendixObject proxyToMendixObject(Object value) + throws NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException + { + Method m = value.getClass().getMethod("getMendixObject"); + IMendixObject mo = (IMendixObject) m.invoke(value); + return mo; + } + + public static List proxyListToMendixObjectList( + List objects) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException + { + ArrayList res = new ArrayList(objects.size()); + for(T i : objects) + res.add(proxyToMendixObject(i)); + return res; + } + + public static Object toMemberValue(Object value) + { + if (value == null) + return null; + + //Complex objects + if (value instanceof IMendixIdentifier) + return value; + if (value instanceof IMendixObject) + return ((IMendixObject)value).getId(); + + if (value instanceof List) + throw new IllegalArgumentException("List based values are not supported!"); + + //Primitives + if ( value instanceof Date + || value instanceof Long + || value instanceof Integer + || value instanceof Double + || value instanceof Float + || value instanceof Boolean + || value instanceof String) { + return value; + } + + if (value.getClass().isEnum()) + return value.toString(); + + //Object, assume its a proxy and deproxiefy + try + { + Method m = value.getClass().getMethod("getMendixObject"); + IMendixObject mo = (IMendixObject) m.invoke(value); + return toMemberValue(mo); + } + catch (NoSuchMethodException e) + { + //This is O.K. just not a proxy object... + } + catch (Exception e) { + throw new RuntimeException("Failed to convert object to IMendixMember compatible value '" + value + "': " + e.getMessage(), e); + } + + throw new RuntimeException("Failed to convert object to IMendixMember compatible value: " + value); + } + + public static interface IBatchProcessor { + public void onItem(T item, long offset, long total) throws Exception; + } + + private static final class ParallelJobRunner implements Callable + { + private final XPath self; + private final IBatchProcessor batchProcessor; + private final IMendixObject item; + private long index; + private long count; + + ParallelJobRunner(XPath self, IBatchProcessor batchProcessor, IMendixObject item, long index, long count) + { + this.self = self; + this.batchProcessor = batchProcessor; + this.item = item; + this.index = index; + this.count = count; + } + + @Override + public Boolean call() + { + try + { + batchProcessor.onItem(XPath.createProxy(Core.createSystemContext(), self.proxyClass, item), index, count); //mwe: hmm, many contexts.. + return true; + } + catch (Exception e) + { + throw new RuntimeException(String.format("Failed to execute batch on '%s' offset %d: %s", self.toString(), self.offset, e.getMessage()), e); + } + } + } + + + /** + * Retreives all items in this xpath query in batches of a limited size. + * Not that this function does not start a new transaction for all the batches, + * rather, it just limits the number of objects being retrieved and kept in memory at the same time. + * + * So it only batches the retrieve process, not the optional manipulations done in the onItem method. + * @param batchsize + * @param batchProcessor + * @throws CoreException + */ + public void batch(int batchsize, IBatchProcessor batchProcessor) throws CoreException + { + if (this.sorting.isEmpty()) + this.addSortingAsc(XPath.ID); + + long count = this.count(); + + int baseoffset = this.offset; + int baselimit = this.limit; + + boolean useBaseLimit = baselimit > -1; + + this.offset(baseoffset); + List data; + + long i = 0; + + do { + int newlimit = useBaseLimit ? Math.min(batchsize, baseoffset + baselimit - this.offset) : batchsize; + if (newlimit == 0) + break; //where done, no more data is needed + + this.limit(newlimit); + data = this.all(); + + for(T item : data) { + i += 1; + try + { + batchProcessor.onItem(item, i, Math.max(i, count)); + } + catch (Exception e) + { + throw new RuntimeException(String.format("Failed to execute batch on '%s' offset %d: %s", this.toString(), this.offset, e.getMessage()), e); + } + } + + this.offset(this.offset + data.size()); + } while(data.size() > 0); + } + + /** + * Batch with parallelization. + * + * IMPORTANT NOTE: DO NOT USE THE CONTEXT OF THE XPATH OBJECT ITSELF INSIDE THE BATCH PROCESSOR! + * + * Instead, use: Item.getContext(); !! + * + * + * @param batchsize + * @param threads + * @param batchProcessor + * @throws CoreException + * @throws InterruptedException + * @throws ExecutionException + */ + public void batch(int batchsize, int threads, final IBatchProcessor batchProcessor) + throws CoreException, InterruptedException, ExecutionException + { + if (this.sorting.isEmpty()) + this.addSortingAsc(XPath.ID); + + ExecutorService pool = Executors.newFixedThreadPool(threads); + + final long count = this.count(); + + final XPath self = this; + + int progress = 0; + List> futures = new ArrayList>(batchsize); //no need to synchronize + + this.offset(0); + this.limit(batchsize); + + List data = this.allMendixObjects(); + + while (data.size() > 0) + { + + for (final IMendixObject item : data) + { + futures.add(pool.submit(new ParallelJobRunner(self, batchProcessor, item, progress, count))); + progress += 1; + } + + while (!futures.isEmpty()) + futures.remove(0).get(); //wait for all futures before proceeding to next iteration + + this.offset(this.offset + data.size()); + data = this.allMendixObjects(); + } + + if (pool.shutdownNow().size() > 0) + throw new IllegalStateException("Not all tasks where finished!"); + + } + + public static Class getProxyClassForEntityName(String entityname) + { + { + String [] parts = entityname.split("\\."); + try + { + return Class.forName(parts[0].toLowerCase() + ".proxies." + parts[1]); + } + catch (ClassNotFoundException e) + { + throw new RuntimeException("Cannot find class for entity: " + entityname + ": " + e.getMessage(), e); + } + } + } + + public boolean deleteAll() throws CoreException + { + this.limit(1000); + List objs = allMendixObjects(); + while (!objs.isEmpty()) { + if (!Core.delete(context, objs.toArray(new IMendixObject[objs.size()]))) + return false; //TODO: throw? + + objs = allMendixObjects(); + } + return true; + } + + // Implement our own ESCAPE_XML because the original got deprecated and we originally translated only a very small + // subset of characters. + private static final CharSequenceTranslator ESCAPE_XML = + new AggregateTranslator( + new LookupTranslator(EntityArrays.BASIC_ESCAPE), + new LookupTranslator(EntityArrays.APOS_ESCAPE) + ); +} diff --git a/test/javasource/communitycommons/actions/Base64Decode.java b/test/javasource/communitycommons/actions/Base64Decode.java new file mode 100644 index 0000000..7639705 --- /dev/null +++ b/test/javasource/communitycommons/actions/Base64Decode.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Converts a base64 encoded string to the plain, original string + */ +public class Base64Decode extends CustomJavaAction +{ + private java.lang.String encoded; + + public Base64Decode(IContext context, java.lang.String encoded) + { + super(context); + this.encoded = encoded; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.base64Decode(encoded); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Base64Decode"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Base64DecodeToFile.java b/test/javasource/communitycommons/actions/Base64DecodeToFile.java new file mode 100644 index 0000000..de771b8 --- /dev/null +++ b/test/javasource/communitycommons/actions/Base64DecodeToFile.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Stores an base 64 encoded string plain in the provided target file document + * + * Note that targetFile will be committed. + */ +public class Base64DecodeToFile extends CustomJavaAction +{ + private java.lang.String encoded; + private IMendixObject __targetFile; + private system.proxies.FileDocument targetFile; + + public Base64DecodeToFile(IContext context, java.lang.String encoded, IMendixObject targetFile) + { + super(context); + this.encoded = encoded; + this.__targetFile = targetFile; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.targetFile = this.__targetFile == null ? null : system.proxies.FileDocument.initialize(getContext(), __targetFile); + + // BEGIN USER CODE + StringUtils.base64DecodeToFile(getContext(), encoded, targetFile); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Base64DecodeToFile"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Base64Encode.java b/test/javasource/communitycommons/actions/Base64Encode.java new file mode 100644 index 0000000..bd7b3c0 --- /dev/null +++ b/test/javasource/communitycommons/actions/Base64Encode.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Converts a plain string to a base64 encoded string + */ +public class Base64Encode extends CustomJavaAction +{ + private java.lang.String value; + + public Base64Encode(IContext context, java.lang.String value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.base64Encode(value); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Base64Encode"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Base64EncodeFile.java b/test/javasource/communitycommons/actions/Base64EncodeFile.java new file mode 100644 index 0000000..8ea7d35 --- /dev/null +++ b/test/javasource/communitycommons/actions/Base64EncodeFile.java @@ -0,0 +1,53 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Converts an unencoded file to a base 64 encoded string. + */ +public class Base64EncodeFile extends CustomJavaAction +{ + private IMendixObject __file; + private system.proxies.FileDocument file; + + public Base64EncodeFile(IContext context, IMendixObject file) + { + super(context); + this.__file = file; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + this.file = this.__file == null ? null : system.proxies.FileDocument.initialize(getContext(), __file); + + // BEGIN USER CODE + return StringUtils.base64EncodeFile(getContext(), file); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Base64EncodeFile"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Clone.java b/test/javasource/communitycommons/actions/Clone.java new file mode 100644 index 0000000..a069edc --- /dev/null +++ b/test/javasource/communitycommons/actions/Clone.java @@ -0,0 +1,60 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Clones objects + * + * - Source: the original object to copy + * - Target: the object to copy it into (should be of the same type, or a specialization) + * - includeAssociations: whether to clone associations. + * + * If associated objects need to be cloned as well, use deepClone, this function only copies the references, not the reffered objects. Target is not committed automatically. + */ +public class Clone extends CustomJavaAction +{ + private IMendixObject source; + private IMendixObject target; + private java.lang.Boolean withAssociations; + + public Clone(IContext context, IMendixObject source, IMendixObject target, java.lang.Boolean withAssociations) + { + super(context); + this.source = source; + this.target = target; + this.withAssociations = withAssociations; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.cloneObject(this.getContext(), source, target, withAssociations); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Clone"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/CreateLogNode.java b/test/javasource/communitycommons/actions/CreateLogNode.java new file mode 100644 index 0000000..94fe4e4 --- /dev/null +++ b/test/javasource/communitycommons/actions/CreateLogNode.java @@ -0,0 +1,50 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Logging; + +/** + * Initializes a log node for later use. Useful to set logging to a more detailed log level before the first time a certain log action is executed. + */ +public class CreateLogNode extends CustomJavaAction +{ + private java.lang.String logNodeParameter; + + public CreateLogNode(IContext context, java.lang.String logNodeParameter) + { + super(context); + this.logNodeParameter = logNodeParameter; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + Logging.createLogNode(logNodeParameter); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "CreateLogNode"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/DateTimeToLong.java b/test/javasource/communitycommons/actions/DateTimeToLong.java new file mode 100644 index 0000000..a6834e6 --- /dev/null +++ b/test/javasource/communitycommons/actions/DateTimeToLong.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.DateTime; + +/** + * Converts a DateTime to a Unix timestamps. (Milliseconds since 1-1-1970) + */ +public class DateTimeToLong extends CustomJavaAction +{ + private java.util.Date dateObject; + + public DateTimeToLong(IContext context, java.util.Date dateObject) + { + super(context); + this.dateObject = dateObject; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + return DateTime.dateTimeToLong(dateObject); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "DateTimeToLong"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/DeepClone.java b/test/javasource/communitycommons/actions/DeepClone.java new file mode 100644 index 0000000..2a78848 --- /dev/null +++ b/test/javasource/communitycommons/actions/DeepClone.java @@ -0,0 +1,87 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Clones objects, their associations and even referred objects. + * + * - Source: the original object to copy + * - Target: the object to copy it into (should be of the same type, or a specialization) + * - MembersToSkip: members which should not be set at all + * - MembersToKeep: references which should be set, but not cloned. (so source and target will refer to exactly the same object). If an association is not part of this property, it will be cloned. + * - ReverseAssociations: 1 - 0 assications which refer to target, which will be cloned as well. Only the reference name itself needs to be mentioned. + * - excludeEntities: entities that will not be cloned. references to these entities will refer to the same object as the source did. + * - excludeModules: modules that will have none of their enities cloned. Behaves similar to excludeEntities. + * + * members format: or or , where objecttype is the concrete type of the object being cloned. + * + * reverseAssociation: + * + * + * membersToSkip by automatically contains createdDate and changedDate. + * membersToKeep by automatically contains System.owner and System.changedBy + * + * Note that DeepClone does commit all objects, where Clone does not. + */ +public class DeepClone extends CustomJavaAction +{ + private IMendixObject source; + private IMendixObject target; + private java.lang.String membersToSkip; + private java.lang.String membersToKeep; + private java.lang.String reverseAssociations; + private java.lang.String excludeEntities; + private java.lang.String excludeModules; + + public DeepClone(IContext context, IMendixObject source, IMendixObject target, java.lang.String membersToSkip, java.lang.String membersToKeep, java.lang.String reverseAssociations, java.lang.String excludeEntities, java.lang.String excludeModules) + { + super(context); + this.source = source; + this.target = target; + this.membersToSkip = membersToSkip; + this.membersToKeep = membersToKeep; + this.reverseAssociations = reverseAssociations; + this.excludeEntities = excludeEntities; + this.excludeModules = excludeModules; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + java.lang.String membersToSkip = this.membersToSkip == null ? "" : this.membersToSkip; + java.lang.String membersToKeep = this.membersToKeep == null ? "" : this.membersToKeep; + java.lang.String reverseAssociations = this.reverseAssociations == null ? "" : this.reverseAssociations; + java.lang.String excludeEntities = this.excludeEntities == null ? "" : this.excludeEntities; + java.lang.String excludeModules = this.excludeModules == null ? "" : this.excludeModules; + + ORM.deepClone(getContext(), source, target, membersToSkip, membersToKeep, reverseAssociations, excludeEntities, excludeModules); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "DeepClone"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Delay.java b/test/javasource/communitycommons/actions/Delay.java new file mode 100644 index 0000000..d5e4f84 --- /dev/null +++ b/test/javasource/communitycommons/actions/Delay.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Causes this request to sleep for a while. Useful to prevent brute force attacks or to simulate latency delays. + * + * Delaytime : time in ms + */ +public class Delay extends CustomJavaAction +{ + private java.lang.Long delaytime; + + public Delay(IContext context, java.lang.Long delaytime) + { + super(context); + this.delaytime = delaytime; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + Misc.delay(delaytime); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Delay"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/DuplicateFileDocument.java b/test/javasource/communitycommons/actions/DuplicateFileDocument.java new file mode 100644 index 0000000..1b5f5a0 --- /dev/null +++ b/test/javasource/communitycommons/actions/DuplicateFileDocument.java @@ -0,0 +1,63 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Clones the contents of one file document into another. + * - fileToClone : the source file + * - cloneTarget : an initialized file document, in which the file will be stored. + * + * Returns true if copied, returns file if the source had no contents, throws exception in any other case. + * Pre condition: HasContents of the 'fileToClone' need to be set to true, otherwise the action will not copy anything. + */ +public class DuplicateFileDocument extends CustomJavaAction +{ + private IMendixObject __fileToClone; + private system.proxies.FileDocument fileToClone; + private IMendixObject __cloneTarget; + private system.proxies.FileDocument cloneTarget; + + public DuplicateFileDocument(IContext context, IMendixObject fileToClone, IMendixObject cloneTarget) + { + super(context); + this.__fileToClone = fileToClone; + this.__cloneTarget = cloneTarget; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.fileToClone = this.__fileToClone == null ? null : system.proxies.FileDocument.initialize(getContext(), __fileToClone); + + this.cloneTarget = this.__cloneTarget == null ? null : system.proxies.FileDocument.initialize(getContext(), __cloneTarget); + + // BEGIN USER CODE + return Misc.duplicateFileDocument(this.getContext(), fileToClone.getMendixObject(), cloneTarget.getMendixObject()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "DuplicateFileDocument"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/DuplicateImageDocument.java b/test/javasource/communitycommons/actions/DuplicateImageDocument.java new file mode 100644 index 0000000..a82b575 --- /dev/null +++ b/test/javasource/communitycommons/actions/DuplicateImageDocument.java @@ -0,0 +1,67 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Clones the contents of one image document into another, and generates a thumbnail as well. + * - fileToClone : the source file + * - cloneTarget : an initialized file document, in which the file will be stored. + * + * Returns true if copied, returns file if the source had no contents, throws exception in any other case. + * Pre condition: HasContents of the 'fileToClone' need to be set to true, otherwise the action will not copy anything. + */ +public class DuplicateImageDocument extends CustomJavaAction +{ + private IMendixObject __fileToClone; + private system.proxies.Image fileToClone; + private IMendixObject __cloneTarget; + private system.proxies.Image cloneTarget; + private java.lang.Long thumbWidth; + private java.lang.Long thumbHeight; + + public DuplicateImageDocument(IContext context, IMendixObject fileToClone, IMendixObject cloneTarget, java.lang.Long thumbWidth, java.lang.Long thumbHeight) + { + super(context); + this.__fileToClone = fileToClone; + this.__cloneTarget = cloneTarget; + this.thumbWidth = thumbWidth; + this.thumbHeight = thumbHeight; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.fileToClone = this.__fileToClone == null ? null : system.proxies.Image.initialize(getContext(), __fileToClone); + + this.cloneTarget = this.__cloneTarget == null ? null : system.proxies.Image.initialize(getContext(), __cloneTarget); + + // BEGIN USER CODE + return Misc.duplicateImage(this.getContext(), fileToClone.getMendixObject(), cloneTarget.getMendixObject(), thumbWidth.intValue(), thumbHeight.intValue()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "DuplicateImageDocument"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/EndTransaction.java b/test/javasource/communitycommons/actions/EndTransaction.java new file mode 100644 index 0000000..3e19698 --- /dev/null +++ b/test/javasource/communitycommons/actions/EndTransaction.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Commit the transaction, this will end this transaction or remove a save point from the queue if the transaction is nested + */ +public class EndTransaction extends CustomJavaAction +{ + public EndTransaction(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + getContext().endTransaction(); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "EndTransaction"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/EnumerationFromString.java b/test/javasource/communitycommons/actions/EnumerationFromString.java new file mode 100644 index 0000000..3d0fd65 --- /dev/null +++ b/test/javasource/communitycommons/actions/EnumerationFromString.java @@ -0,0 +1,56 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; +import communitycommons.proxies.LogLevel; +import java.util.Optional; + +/** + * Use this Java action as a template for your own String-to-Enumeration conversions. + * Studio Pro requires specifying the exact Enumeration to return in the definition of a Java action so we cannot provide a generic implementation. + * This implementation will throw a NoSuchElementException if an invalid toConvert parameter is given, so remember to handle this error gracefully. + */ +public class EnumerationFromString extends CustomJavaAction +{ + private java.lang.String toConvert; + + public EnumerationFromString(IContext context, java.lang.String toConvert) + { + super(context); + this.toConvert = toConvert; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + + // Replace LogLevel.class by the proxy class for your Enumeration + Optional result = Misc.enumFromString(LogLevel.class, toConvert); + return result.orElseThrow().name(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "EnumerationFromString"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/EscapeHTML.java b/test/javasource/communitycommons/actions/EscapeHTML.java new file mode 100644 index 0000000..9bdc999 --- /dev/null +++ b/test/javasource/communitycommons/actions/EscapeHTML.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Given a, escapes it to html codes, for example + * + * "< Joe & John >" will be converted to + * "< Joe & John >" + */ +public class EscapeHTML extends CustomJavaAction +{ + private java.lang.String rawString; + + public EscapeHTML(IContext context, java.lang.String rawString) + { + super(context); + this.rawString = rawString; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.escapeHTML(rawString); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "EscapeHTML"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/FileDocumentFromFile.java b/test/javasource/communitycommons/actions/FileDocumentFromFile.java new file mode 100644 index 0000000..2d58091 --- /dev/null +++ b/test/javasource/communitycommons/actions/FileDocumentFromFile.java @@ -0,0 +1,64 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.io.File; +import java.io.FileInputStream; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Loads a file from the local (server) storage and stores it inside a FileDocument. + */ +public class FileDocumentFromFile extends CustomJavaAction +{ + private java.lang.String file; + private IMendixObject __fileDocument; + private system.proxies.FileDocument fileDocument; + + public FileDocumentFromFile(IContext context, java.lang.String file, IMendixObject fileDocument) + { + super(context); + this.file = file; + this.__fileDocument = fileDocument; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.fileDocument = this.__fileDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __fileDocument); + + // BEGIN USER CODE + try ( + FileInputStream fis = new FileInputStream(new File(this.file)) + ) { + Core.storeFileDocumentContent(getContext(), fileDocument.getMendixObject(), + this.file, fis); + } + + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "FileDocumentFromFile"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/FileFromFileDocument.java b/test/javasource/communitycommons/actions/FileFromFileDocument.java new file mode 100644 index 0000000..c043775 --- /dev/null +++ b/test/javasource/communitycommons/actions/FileFromFileDocument.java @@ -0,0 +1,68 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import org.apache.commons.io.IOUtils; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Reads contents from a FileDocument and stores it in a file on the local (server) storage. + */ +public class FileFromFileDocument extends CustomJavaAction +{ + private java.lang.String targetFile; + private IMendixObject __fileDocument; + private system.proxies.FileDocument fileDocument; + + public FileFromFileDocument(IContext context, java.lang.String targetFile, IMendixObject fileDocument) + { + super(context); + this.targetFile = targetFile; + this.__fileDocument = fileDocument; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.fileDocument = this.__fileDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __fileDocument); + + // BEGIN USER CODE + File output = new File(targetFile); + + try ( + FileOutputStream fos = new FileOutputStream(output); + InputStream is = Core.getFileDocumentContent(getContext(), fileDocument.getMendixObject()); + ) { + IOUtils.copy(is, fos); + } + + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "FileFromFileDocument"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GenerateHMAC_SHA256.java b/test/javasource/communitycommons/actions/GenerateHMAC_SHA256.java new file mode 100644 index 0000000..3e0618a --- /dev/null +++ b/test/javasource/communitycommons/actions/GenerateHMAC_SHA256.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Generates and asymmetric hexadecimal hash using the HMAC_SHA256 hash algorithm + */ +public class GenerateHMAC_SHA256 extends CustomJavaAction +{ + private java.lang.String key; + private java.lang.String valueToEncrypt; + + public GenerateHMAC_SHA256(IContext context, java.lang.String key, java.lang.String valueToEncrypt) + { + super(context); + this.key = key; + this.valueToEncrypt = valueToEncrypt; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.generateHmacSha256(key, valueToEncrypt); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GenerateHMAC_SHA256"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GenerateHMAC_SHA256_hash.java b/test/javasource/communitycommons/actions/GenerateHMAC_SHA256_hash.java new file mode 100644 index 0000000..6822ad2 --- /dev/null +++ b/test/javasource/communitycommons/actions/GenerateHMAC_SHA256_hash.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Generates an asymmetric hash using the HMAC_SHA256 hash algorithm + */ +public class GenerateHMAC_SHA256_hash extends CustomJavaAction +{ + private java.lang.String key; + private java.lang.String valueToEncrypt; + + public GenerateHMAC_SHA256_hash(IContext context, java.lang.String key, java.lang.String valueToEncrypt) + { + super(context); + this.key = key; + this.valueToEncrypt = valueToEncrypt; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.generateHmacSha256Hash(key, valueToEncrypt); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GenerateHMAC_SHA256_hash"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetApplicationUrl.java b/test/javasource/communitycommons/actions/GetApplicationUrl.java new file mode 100644 index 0000000..e81b0cf --- /dev/null +++ b/test/javasource/communitycommons/actions/GetApplicationUrl.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the runtime URL of this application. + */ +public class GetApplicationUrl extends CustomJavaAction +{ + public GetApplicationUrl(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.getApplicationURL(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetApplicationUrl"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetCFInstanceIndex.java b/test/javasource/communitycommons/actions/GetCFInstanceIndex.java new file mode 100644 index 0000000..8c28f71 --- /dev/null +++ b/test/javasource/communitycommons/actions/GetCFInstanceIndex.java @@ -0,0 +1,50 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Returns the Cloud Foundry Instance Index that is set during deployment of the application in a Cloud native environment. Based on the Cloud Foundry Instance Index, Mendix determines what is the leader instance (index 0 executes scheduled events, db sync, session management etc.) or slave instance. + * + * Returns 0 for the leader instance, 1 or higher for slave instances or -1 when the environment variable could not be read (when running locally or on premise). When -1 is returned, it will probably be the leader in the cluster. + * + * Make sure emulate cloud security is disabled. Otherwise, the policy restrictions will prevent the method to be executed. Action is tested in Mendix Cloud on 19-12-2018. + */ +public class GetCFInstanceIndex extends CustomJavaAction +{ + public GetCFInstanceIndex(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.getCFInstanceIndex(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetCFInstanceIndex"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetDefaultLanguage.java b/test/javasource/communitycommons/actions/GetDefaultLanguage.java new file mode 100644 index 0000000..ef6b761 --- /dev/null +++ b/test/javasource/communitycommons/actions/GetDefaultLanguage.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import system.proxies.Language; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; + +/** + * Get default language + */ +public class GetDefaultLanguage extends CustomJavaAction +{ + public GetDefaultLanguage(IContext context) + { + super(context); + } + + @java.lang.Override + public IMendixObject executeAction() throws Exception + { + // BEGIN USER CODE + Language defaultLanguage = Misc.getDefaultLanguage(getContext()); + return defaultLanguage.getMendixObject(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetDefaultLanguage"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetFileContentsFromResource.java b/test/javasource/communitycommons/actions/GetFileContentsFromResource.java new file mode 100644 index 0000000..1b42477 --- /dev/null +++ b/test/javasource/communitycommons/actions/GetFileContentsFromResource.java @@ -0,0 +1,66 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.io.File; +import java.io.FileInputStream; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Set the contents of a FileDocument with the contents of a file which is a resource. + */ +public class GetFileContentsFromResource extends CustomJavaAction +{ + private java.lang.String filename; + private IMendixObject __fileDocument; + private system.proxies.FileDocument fileDocument; + + public GetFileContentsFromResource(IContext context, java.lang.String filename, IMendixObject fileDocument) + { + super(context); + this.filename = filename; + this.__fileDocument = fileDocument; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.fileDocument = this.__fileDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __fileDocument); + + // BEGIN USER CODE + File myFile = new File(Core.getConfiguration().getResourcesPath() + + File.separator + filename); + + try ( + FileInputStream fis = new FileInputStream(myFile) + ) { + Core.storeFileDocumentContent(getContext(), fileDocument.getMendixObject(), filename, fis); + } + + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetFileContentsFromResource"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetImageDimensions.java b/test/javasource/communitycommons/actions/GetImageDimensions.java new file mode 100644 index 0000000..582997a --- /dev/null +++ b/test/javasource/communitycommons/actions/GetImageDimensions.java @@ -0,0 +1,61 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.webui.CustomJavaAction; +import communitycommons.proxies.ImageDimensions; +import java.io.InputStream; + +public class GetImageDimensions extends CustomJavaAction +{ + private IMendixObject __ImageParameter; + private system.proxies.Image ImageParameter; + + public GetImageDimensions(IContext context, IMendixObject ImageParameter) + { + super(context); + this.__ImageParameter = ImageParameter; + } + + @java.lang.Override + public IMendixObject executeAction() throws Exception + { + this.ImageParameter = this.__ImageParameter == null ? null : system.proxies.Image.initialize(getContext(), __ImageParameter); + + // BEGIN USER CODE + ImageDimensions imageDimensions = new ImageDimensions(getContext()); + try (InputStream inputStream = Core.getImage(getContext(), this.ImageParameter.getMendixObject(), false)) { + BufferedImage bimg = ImageIO.read(inputStream); + imageDimensions.setHeight(bimg.getHeight()); + imageDimensions.setWidth(bimg.getWidth()); + } + + return imageDimensions.getMendixObject(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetImageDimensions"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetIntFromDateTime.java b/test/javasource/communitycommons/actions/GetIntFromDateTime.java new file mode 100644 index 0000000..b5c1bde --- /dev/null +++ b/test/javasource/communitycommons/actions/GetIntFromDateTime.java @@ -0,0 +1,56 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.DateTime; + +/** + * Converts a datetime to an integer based on the selector used. + * + * Selectors available are: + * - year (returns f. ex. 1980) + * - month (returns 1-12) + * - day (returns 1-31) + */ +public class GetIntFromDateTime extends CustomJavaAction +{ + private java.util.Date dateObj; + private communitycommons.proxies.DatePartSelector selectorObj; + + public GetIntFromDateTime(IContext context, java.util.Date dateObj, java.lang.String selectorObj) + { + super(context); + this.dateObj = dateObj; + this.selectorObj = selectorObj == null ? null : communitycommons.proxies.DatePartSelector.valueOf(selectorObj); + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + return DateTime.dateTimeToInteger(dateObj, selectorObj); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetIntFromDateTime"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetModelVersion.java b/test/javasource/communitycommons/actions/GetModelVersion.java new file mode 100644 index 0000000..ab6c666 --- /dev/null +++ b/test/javasource/communitycommons/actions/GetModelVersion.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Returns the model version of the deployed application. + */ +public class GetModelVersion extends CustomJavaAction +{ + public GetModelVersion(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.getModelVersion(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetModelVersion"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/GetRuntimeVersion.java b/test/javasource/communitycommons/actions/GetRuntimeVersion.java new file mode 100644 index 0000000..9692542 --- /dev/null +++ b/test/javasource/communitycommons/actions/GetRuntimeVersion.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the runtime version of this application. + */ +public class GetRuntimeVersion extends CustomJavaAction +{ + public GetRuntimeVersion(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.getRuntimeVersion(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "GetRuntimeVersion"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/HTMLEncode.java b/test/javasource/communitycommons/actions/HTMLEncode.java new file mode 100644 index 0000000..c18e84f --- /dev/null +++ b/test/javasource/communitycommons/actions/HTMLEncode.java @@ -0,0 +1,54 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Encodes a string to HTML Entities, so that they can be displayed in the browser without breaking any layout. + * + * This is useful for special widgets which allow HTML to be rendered properly, including special characters as '<' and '&'. + * For example '<' will be encoded as '<' and '&' will be encoded as '&' + * + * Returns the encoded string. + */ +public class HTMLEncode extends CustomJavaAction +{ + private java.lang.String value; + + public HTMLEncode(IContext context, java.lang.String value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.HTMLEncode(value); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "HTMLEncode"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/HTMLToPlainText.java b/test/javasource/communitycommons/actions/HTMLToPlainText.java new file mode 100644 index 0000000..8976462 --- /dev/null +++ b/test/javasource/communitycommons/actions/HTMLToPlainText.java @@ -0,0 +1,50 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Use this function to convert HTML text to plain text. + * It will preserve linebreaks but strip all other markup. including html entity decoding. + */ +public class HTMLToPlainText extends CustomJavaAction +{ + private java.lang.String html; + + public HTMLToPlainText(IContext context, java.lang.String html) + { + super(context); + this.html = html; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.HTMLToPlainText(html); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "HTMLToPlainText"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/Hash.java b/test/javasource/communitycommons/actions/Hash.java new file mode 100644 index 0000000..2d7d2ba --- /dev/null +++ b/test/javasource/communitycommons/actions/Hash.java @@ -0,0 +1,56 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Hashes a value using the SHA-256 hash algorithm. + * + * - value : the value to hash + * - length : the desired length of the hash. + * + * Returns a SHA-256 hash of 'value', with length 'length' + */ +public class Hash extends CustomJavaAction +{ + private java.lang.String value; + private java.lang.Long length; + + public Hash(IContext context, java.lang.String value, java.lang.Long length) + { + super(context); + this.value = value; + this.length = length; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.hash(value, length.intValue()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "Hash"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/IsInDevelopment.java b/test/javasource/communitycommons/actions/IsInDevelopment.java new file mode 100644 index 0000000..0a58533 --- /dev/null +++ b/test/javasource/communitycommons/actions/IsInDevelopment.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns true if the environment is a development environment. Calls Core.getConfiguration().isInDevelopment(). + */ +public class IsInDevelopment extends CustomJavaAction +{ + public IsInDevelopment(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Core.getConfiguration().isInDevelopment(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "IsInDevelopment"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/IsStringSimplified.java b/test/javasource/communitycommons/actions/IsStringSimplified.java new file mode 100644 index 0000000..8e26989 --- /dev/null +++ b/test/javasource/communitycommons/actions/IsStringSimplified.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * True if a string can be simplified by the removal of diacritics. + */ +public class IsStringSimplified extends CustomJavaAction +{ + private java.lang.String value; + + public IsStringSimplified(IContext context, java.lang.String value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.isStringSimplified(this.value); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "IsStringSimplified"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/ListTop.java b/test/javasource/communitycommons/actions/ListTop.java new file mode 100644 index 0000000..9a835cc --- /dev/null +++ b/test/javasource/communitycommons/actions/ListTop.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Takes the top n items of a given list and returns the resulting list. + */ +public class ListTop extends CustomJavaAction> +{ + private java.util.List ObjectList; + private java.lang.Long Top; + + public ListTop(IContext context, java.util.List ObjectList, java.lang.Long Top) + { + super(context); + this.ObjectList = ObjectList; + this.Top = Top; + } + + @java.lang.Override + public java.util.List executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.listTop(ObjectList, Top.intValue()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "ListTop"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/LongToDateTime.java b/test/javasource/communitycommons/actions/LongToDateTime.java new file mode 100644 index 0000000..5a1f916 --- /dev/null +++ b/test/javasource/communitycommons/actions/LongToDateTime.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.DateTime; + +/** + * Converts a Unix timestamp to a dateTime object + */ +public class LongToDateTime extends CustomJavaAction +{ + private java.lang.Long value; + + public LongToDateTime(IContext context, java.lang.Long value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.util.Date executeAction() throws Exception + { + // BEGIN USER CODE + return DateTime.longToDateTime(value); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "LongToDateTime"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/MergeMultiplePdfs.java b/test/javasource/communitycommons/actions/MergeMultiplePdfs.java new file mode 100644 index 0000000..7a8e614 --- /dev/null +++ b/test/javasource/communitycommons/actions/MergeMultiplePdfs.java @@ -0,0 +1,62 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Restricted to 10 files at once for Mendix Cloud v4 compatibility. If you need to merge more than 10 files at once merge recursively instead or change the MergeMultiplePdfs_MaxAtOnce constant. + */ +public class MergeMultiplePdfs extends CustomJavaAction +{ + private java.util.List __FilesToMerge; + private java.util.List FilesToMerge; + private IMendixObject __MergedDocument; + private system.proxies.FileDocument MergedDocument; + + public MergeMultiplePdfs(IContext context, java.util.List FilesToMerge, IMendixObject MergedDocument) + { + super(context); + this.__FilesToMerge = FilesToMerge; + this.__MergedDocument = MergedDocument; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.FilesToMerge = java.util.Optional.ofNullable(this.__FilesToMerge) + .orElse(java.util.Collections.emptyList()) + .stream() + .map(__FilesToMergeElement -> system.proxies.FileDocument.initialize(getContext(), __FilesToMergeElement)) + .collect(java.util.stream.Collectors.toList()); + + this.MergedDocument = this.__MergedDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __MergedDocument); + + // BEGIN USER CODE + return Misc.mergePDF(this.getContext(), this.FilesToMerge, this.MergedDocument.getMendixObject()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "MergeMultiplePdfs"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/MonthsBetween.java b/test/javasource/communitycommons/actions/MonthsBetween.java new file mode 100644 index 0000000..0d14a78 --- /dev/null +++ b/test/javasource/communitycommons/actions/MonthsBetween.java @@ -0,0 +1,63 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.DateTime; +import communitycommons.Logging; +import communitycommons.proxies.LogLevel; +import communitycommons.proxies.LogNodes; +import java.util.Date; + +/** + * Calculates the number of months between two dates. + * - dateTime : the original (oldest) dateTime + * - compareDate: the second date. If EMPTY, the current datetime will be used. Effectively this means that the age of the dateTime is calculated. + */ +public class MonthsBetween extends CustomJavaAction +{ + private java.util.Date date1; + private java.util.Date date2; + + public MonthsBetween(IContext context, java.util.Date date1, java.util.Date date2) + { + super(context); + this.date1 = date1; + this.date2 = date2; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + try { + return DateTime.periodBetween(date1, date2 == null ? new Date() : date2).toTotalMonths(); + } catch (Exception e) { + + Logging.log(LogNodes.CommunityCommons.name(), LogLevel.Warning, "DateTime calculation error, returning -1", e); + return -1L; + } + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "MonthsBetween"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/OverlayPdfDocument.java b/test/javasource/communitycommons/actions/OverlayPdfDocument.java new file mode 100644 index 0000000..da88542 --- /dev/null +++ b/test/javasource/communitycommons/actions/OverlayPdfDocument.java @@ -0,0 +1,60 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; + +/** + * Overlay a generated PDF document with another PDF (containing the company stationary for example) + */ +public class OverlayPdfDocument extends CustomJavaAction +{ + private IMendixObject __generatedDocument; + private system.proxies.FileDocument generatedDocument; + private IMendixObject __overlay; + private system.proxies.FileDocument overlay; + private java.lang.Boolean onTopOfContent; + + public OverlayPdfDocument(IContext context, IMendixObject generatedDocument, IMendixObject overlay, java.lang.Boolean onTopOfContent) + { + super(context); + this.__generatedDocument = generatedDocument; + this.__overlay = overlay; + this.onTopOfContent = onTopOfContent; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.generatedDocument = this.__generatedDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), __generatedDocument); + + this.overlay = this.__overlay == null ? null : system.proxies.FileDocument.initialize(getContext(), __overlay); + + // BEGIN USER CODE + return Misc.overlayPdf(getContext(), __generatedDocument, __overlay, onTopOfContent); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "OverlayPdfDocument"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/ParseDateTimeWithTimezone.java b/test/javasource/communitycommons/actions/ParseDateTimeWithTimezone.java new file mode 100644 index 0000000..7465b40 --- /dev/null +++ b/test/javasource/communitycommons/actions/ParseDateTimeWithTimezone.java @@ -0,0 +1,72 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.text.SimpleDateFormat; +import java.util.TimeZone; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Logging; +import communitycommons.proxies.LogLevel; +import communitycommons.proxies.LogNodes; +import java.text.ParseException; + +/** + * This method parses a date from a string with a given pattern according to a specific timezone. + * The timezone has to be a valid timezone id http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html (e.g. one of https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/) + */ +public class ParseDateTimeWithTimezone extends CustomJavaAction +{ + private java.lang.String date; + private java.lang.String pattern; + private java.lang.String timeZone; + private java.util.Date defaultValue; + + public ParseDateTimeWithTimezone(IContext context, java.lang.String date, java.lang.String pattern, java.lang.String timeZone, java.util.Date defaultValue) + { + super(context); + this.date = date; + this.pattern = pattern; + this.timeZone = timeZone; + this.defaultValue = defaultValue; + } + + @java.lang.Override + public java.util.Date executeAction() throws Exception + { + // BEGIN USER CODE + if (date == null || date.trim().equals("")) { + return defaultValue; + } + + try { + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); + return sdf.parse(date); + } catch (ParseException e) { + Logging.log(LogNodes.CommunityCommons.name(), LogLevel.Warning, "Unable to parse date " + date, e); + return defaultValue; + } + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "ParseDateTimeWithTimezone"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RandomHash.java b/test/javasource/communitycommons/actions/RandomHash.java new file mode 100644 index 0000000..5fedacb --- /dev/null +++ b/test/javasource/communitycommons/actions/RandomHash.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Generates a random hash, perfectly to use as random but unique identifier + */ +public class RandomHash extends CustomJavaAction +{ + public RandomHash(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.randomHash(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RandomHash"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RandomString.java b/test/javasource/communitycommons/actions/RandomString.java new file mode 100644 index 0000000..0b1e219 --- /dev/null +++ b/test/javasource/communitycommons/actions/RandomString.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Generates a random alphanumeric string of the desired length. + */ +public class RandomString extends CustomJavaAction +{ + private java.lang.Long length; + + public RandomString(IContext context, java.lang.Long length) + { + super(context); + this.length = length; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.randomString(length.intValue()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RandomString"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RandomStrongPassword.java b/test/javasource/communitycommons/actions/RandomStrongPassword.java new file mode 100644 index 0000000..886aefe --- /dev/null +++ b/test/javasource/communitycommons/actions/RandomStrongPassword.java @@ -0,0 +1,65 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Returns a random strong password containing a specified minimum number of digits, uppercase and special characters. + * + * Note:Minimumlength should be equal or larger than NrOfCapitalizedCharacters, NrOfDigits and NrOfSpecialCharacters + */ +public class RandomStrongPassword extends CustomJavaAction +{ + private java.lang.Long MinLength; + private java.lang.Long MaxLength; + private java.lang.Long NrOfCapitalizedCharacters; + private java.lang.Long NrOfDigits; + private java.lang.Long NrOfSpecialCharacters; + + public RandomStrongPassword(IContext context, java.lang.Long MinLength, java.lang.Long MaxLength, java.lang.Long NrOfCapitalizedCharacters, java.lang.Long NrOfDigits, java.lang.Long NrOfSpecialCharacters) + { + super(context); + this.MinLength = MinLength; + this.MaxLength = MaxLength; + this.NrOfCapitalizedCharacters = NrOfCapitalizedCharacters; + this.NrOfDigits = NrOfDigits; + this.NrOfSpecialCharacters = NrOfSpecialCharacters; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.randomStrongPassword(safeLongToInt(this.MinLength), safeLongToInt(this.MaxLength), safeLongToInt(this.NrOfCapitalizedCharacters), safeLongToInt(NrOfDigits), safeLongToInt(NrOfSpecialCharacters)); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RandomStrongPassword"; + } + + // BEGIN EXTRA CODE + public static int safeLongToInt(long l) { + if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { + throw new IllegalArgumentException(l + " cannot be cast to int without changing its value."); + } + return (int) l; + } + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RegexQuote.java b/test/javasource/communitycommons/actions/RegexQuote.java new file mode 100644 index 0000000..edd4251 --- /dev/null +++ b/test/javasource/communitycommons/actions/RegexQuote.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Escapes a string value so that it can be used literally with Mendix build-in regex replacement functions. (Otherwise the dollar sign would be interpreted as back reference to a match for example). + */ +public class RegexQuote extends CustomJavaAction +{ + private java.lang.String unquotedLiteral; + + public RegexQuote(IContext context, java.lang.String unquotedLiteral) + { + super(context); + this.unquotedLiteral = unquotedLiteral; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.regexQuote(unquotedLiteral); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RegexQuote"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RegexReplaceAll.java b/test/javasource/communitycommons/actions/RegexReplaceAll.java new file mode 100644 index 0000000..3a82d5f --- /dev/null +++ b/test/javasource/communitycommons/actions/RegexReplaceAll.java @@ -0,0 +1,59 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Performs a regular expression. Similar to the replaceAll microflow function, but supports more advanced usages such as capture variables. + * + * For the regexp specification see: + * https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html + * + * A decent regexp tester can be found at: + * http://www.fileformat.info/tool/regex.htm + */ +public class RegexReplaceAll extends CustomJavaAction +{ + private java.lang.String haystack; + private java.lang.String needleRegex; + private java.lang.String replacement; + + public RegexReplaceAll(IContext context, java.lang.String haystack, java.lang.String needleRegex, java.lang.String replacement) + { + super(context); + this.haystack = haystack; + this.needleRegex = needleRegex; + this.replacement = replacement; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.regexReplaceAll(haystack, needleRegex, replacement); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RegexReplaceAll"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RemoveEnd.java b/test/javasource/communitycommons/actions/RemoveEnd.java new file mode 100644 index 0000000..665b824 --- /dev/null +++ b/test/javasource/communitycommons/actions/RemoveEnd.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Removes a string (if present) from the end of an input string, + */ +public class RemoveEnd extends CustomJavaAction +{ + private java.lang.String input; + private java.lang.String toRemove; + + public RemoveEnd(IContext context, java.lang.String input, java.lang.String toRemove) + { + super(context); + this.input = input; + this.toRemove = toRemove; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.removeEnd(input, toRemove); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RemoveEnd"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/RunMicroflowAsyncInQueue.java b/test/javasource/communitycommons/actions/RunMicroflowAsyncInQueue.java new file mode 100644 index 0000000..ae18ee4 --- /dev/null +++ b/test/javasource/communitycommons/actions/RunMicroflowAsyncInQueue.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Runs a microflow asynchronous, that is, this action immediately returns but schedules the microflow to be run in the near future. The queue guarantees a first come first serve order of the microflows, and only one action is served at a time. + * + * The microflow is run with system rights in its own transaction, and is very useful to run heavy microflows on the background. + */ +public class RunMicroflowAsyncInQueue extends CustomJavaAction +{ + private java.lang.String microflow; + + public RunMicroflowAsyncInQueue(IContext context, java.lang.String microflow) + { + super(context); + this.microflow = microflow; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.runMicroflowAsyncInQueue(microflow); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "RunMicroflowAsyncInQueue"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StartTransaction.java b/test/javasource/communitycommons/actions/StartTransaction.java new file mode 100644 index 0000000..addafa2 --- /dev/null +++ b/test/javasource/communitycommons/actions/StartTransaction.java @@ -0,0 +1,46 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Start a transaction, if a transaction is already started for this context, a savepoint will be added + */ +public class StartTransaction extends CustomJavaAction +{ + public StartTransaction(IContext context) + { + super(context); + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + getContext().startTransaction(); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StartTransaction"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringFromFile.java b/test/javasource/communitycommons/actions/StringFromFile.java new file mode 100644 index 0000000..7a4c489 --- /dev/null +++ b/test/javasource/communitycommons/actions/StringFromFile.java @@ -0,0 +1,60 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Reads the contents form the provided file document, using the specified encoding, and returns it as string. + */ +public class StringFromFile extends CustomJavaAction +{ + private IMendixObject __source; + private system.proxies.FileDocument source; + private communitycommons.proxies.StandardEncodings encoding; + + public StringFromFile(IContext context, IMendixObject source, java.lang.String encoding) + { + super(context); + this.__source = source; + this.encoding = encoding == null ? null : communitycommons.proxies.StandardEncodings.valueOf(encoding); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + this.source = this.__source == null ? null : system.proxies.FileDocument.initialize(getContext(), __source); + + // BEGIN USER CODE + Charset charset = StandardCharsets.UTF_8; + if (this.encoding != null) + charset = Charset.forName(this.encoding.name().replace('_', '-')); + return StringUtils.stringFromFile(getContext(), source, charset); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringFromFile"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringLeftPad.java b/test/javasource/communitycommons/actions/StringLeftPad.java new file mode 100644 index 0000000..72dc488 --- /dev/null +++ b/test/javasource/communitycommons/actions/StringLeftPad.java @@ -0,0 +1,59 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Pads a string on the left to a certain length. + * value : the original value + * amount: the desired length of the resulting string. + * fillCharacter: the character to pad with. (or space if empty) + * + * For example + * StringLeftPad("hello", 8, "-") returns "---hello" + * StringLeftPad("hello", 2, "-") returns "hello" + */ +public class StringLeftPad extends CustomJavaAction +{ + private java.lang.String value; + private java.lang.Long amount; + private java.lang.String fillCharacter; + + public StringLeftPad(IContext context, java.lang.String value, java.lang.Long amount, java.lang.String fillCharacter) + { + super(context); + this.value = value; + this.amount = amount; + this.fillCharacter = fillCharacter; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return communitycommons.StringUtils.leftPad(value, amount, fillCharacter); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringLeftPad"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringRightPad.java b/test/javasource/communitycommons/actions/StringRightPad.java new file mode 100644 index 0000000..7cf0cf8 --- /dev/null +++ b/test/javasource/communitycommons/actions/StringRightPad.java @@ -0,0 +1,59 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Pads a string on the right to a certain length. + * value : the original value + * amount: the desired length of the resulting string. + * fillCharacter: the character to pad with. (or space if empty) + * + * For example + * StringRightPad("hello", 8, "-") returns "hello---" + * StringLeftpad("hello", 2, "-") returns "hello" + */ +public class StringRightPad extends CustomJavaAction +{ + private java.lang.String value; + private java.lang.Long amount; + private java.lang.String fillCharacter; + + public StringRightPad(IContext context, java.lang.String value, java.lang.Long amount, java.lang.String fillCharacter) + { + super(context); + this.value = value; + this.amount = amount; + this.fillCharacter = fillCharacter; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return communitycommons.StringUtils.rightPad(value, amount, fillCharacter); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringRightPad"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringSimplify.java b/test/javasource/communitycommons/actions/StringSimplify.java new file mode 100644 index 0000000..44983cb --- /dev/null +++ b/test/javasource/communitycommons/actions/StringSimplify.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Remove diacritics from a string. + */ +public class StringSimplify extends CustomJavaAction +{ + private java.lang.String value; + + public StringSimplify(IContext context, java.lang.String value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.stringSimplify(this.value); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringSimplify"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringSplit.java b/test/javasource/communitycommons/actions/StringSplit.java new file mode 100644 index 0000000..43cfe8c --- /dev/null +++ b/test/javasource/communitycommons/actions/StringSplit.java @@ -0,0 +1,62 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import java.util.ArrayList; +import java.util.List; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.webui.CustomJavaAction; +import communitycommons.proxies.SplitItem; + +public class StringSplit extends CustomJavaAction> +{ + private java.lang.String inputString; + private java.lang.String splitParameter; + + public StringSplit(IContext context, java.lang.String inputString, java.lang.String splitParameter) + { + super(context); + this.inputString = inputString; + this.splitParameter = splitParameter; + } + + @java.lang.Override + public java.util.List executeAction() throws Exception + { + // BEGIN USER CODE + List returnList = new ArrayList(); + String[] parts = this.inputString.split(this.splitParameter); + Integer index = 0; + for (String part : parts) { + IMendixObject splitPart = Core.instantiate(getContext(), SplitItem.getType()); + splitPart.setValue(getContext(), SplitItem.MemberNames.Value.toString(), part); + splitPart.setValue(getContext(), SplitItem.MemberNames.Index.toString(), index); + returnList.add(splitPart); + index = index + 1; + } + return returnList; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringSplit"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringToFile.java b/test/javasource/communitycommons/actions/StringToFile.java new file mode 100644 index 0000000..cb87fe7 --- /dev/null +++ b/test/javasource/communitycommons/actions/StringToFile.java @@ -0,0 +1,64 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Stores a string into the provided FileDocument, using the specified encoding. + * Note that destination will be committed. + */ +public class StringToFile extends CustomJavaAction +{ + private java.lang.String value; + private IMendixObject __destination; + private system.proxies.FileDocument destination; + private communitycommons.proxies.StandardEncodings encoding; + + public StringToFile(IContext context, java.lang.String value, IMendixObject destination, java.lang.String encoding) + { + super(context); + this.value = value; + this.__destination = destination; + this.encoding = encoding == null ? null : communitycommons.proxies.StandardEncodings.valueOf(encoding); + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.destination = this.__destination == null ? null : system.proxies.FileDocument.initialize(getContext(), __destination); + + // BEGIN USER CODE + Charset charset = StandardCharsets.UTF_8; + if (this.encoding != null) + charset = Charset.forName(this.encoding.name().replace('_', '-')); + StringUtils.stringToFile(getContext(), value, destination, charset); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringToFile"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/StringTrim.java b/test/javasource/communitycommons/actions/StringTrim.java new file mode 100644 index 0000000..fc4f3ee --- /dev/null +++ b/test/javasource/communitycommons/actions/StringTrim.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Left and right trims a string (that is; removes all surrounding whitespace characters such as tabs, spaces and returns). + * Returns the empty string if value is the empty value. Returns the trimmed string otherwise. + */ +public class StringTrim extends CustomJavaAction +{ + private java.lang.String value; + + public StringTrim(IContext context, java.lang.String value) + { + super(context); + this.value = value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + if (this.value == null) + return ""; + return this.value.trim(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "StringTrim"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstituteTemplate.java b/test/javasource/communitycommons/actions/SubstituteTemplate.java new file mode 100644 index 0000000..2950755 --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstituteTemplate.java @@ -0,0 +1,69 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Given an object and a template, substitutes all fields in the template. Supports attributes, references, referencesets and constants. + * + * The general field syntax is '{fieldname}'. + * + * Fieldname can be a member of the example object, an attribute which need to be retrieved over an reference(set) or a project constant. All paths are relative from the provided substitute obect. An example template: + * ------------------ + * Dear {EmailOrName}, + * + * {System.changedBy/FullName} has invited you to join the project {Module.MemberShip_Project/Name}. + * Sign up is free and can be done here: + * {@Module.PublicURL}link/Signup + * ------------------------- + * + * useHTMLEncoding identifies whether HTMLEncode is applied to the values before substituting. + * + * datetimeformat identifies a format string which is applied to date/time based attributes. Can be left empty. Defaults to "EEE dd MMM yyyy, HH:mm" + */ +public class SubstituteTemplate extends CustomJavaAction +{ + private java.lang.String template; + private IMendixObject substitute; + private java.lang.Boolean useHTMLEncoding; + + public SubstituteTemplate(IContext context, java.lang.String template, IMendixObject substitute, java.lang.Boolean useHTMLEncoding) + { + super(context); + this.template = template; + this.substitute = substitute; + this.useHTMLEncoding = useHTMLEncoding; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substituteTemplate(this.getContext(), template, substitute, useHTMLEncoding, null); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstituteTemplate"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstituteTemplate2.java b/test/javasource/communitycommons/actions/SubstituteTemplate2.java new file mode 100644 index 0000000..98195c4 --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstituteTemplate2.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.StringUtils; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Identical to SubstituteTemplate, but adds an datetimeformat argument + * + * DateTimeFormat identifies a format string which is applied to date/time based attributes. Can be left empty. Defaults to "EEE dd MMM yyyy, HH:mm" + */ +public class SubstituteTemplate2 extends CustomJavaAction +{ + private java.lang.String template; + private IMendixObject substitute; + private java.lang.Boolean useHTMLEncoding; + private java.lang.String datetimeformat; + + public SubstituteTemplate2(IContext context, java.lang.String template, IMendixObject substitute, java.lang.Boolean useHTMLEncoding, java.lang.String datetimeformat) + { + super(context); + this.template = template; + this.substitute = substitute; + this.useHTMLEncoding = useHTMLEncoding; + this.datetimeformat = datetimeformat; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substituteTemplate(this.getContext(), template, substitute, useHTMLEncoding, this.datetimeformat); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstituteTemplate2"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstringAfter.java b/test/javasource/communitycommons/actions/SubstringAfter.java new file mode 100644 index 0000000..71e1acb --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstringAfter.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Gets the substring after the first occurrence of a separator. + */ +public class SubstringAfter extends CustomJavaAction +{ + private java.lang.String str; + private java.lang.String separator; + + public SubstringAfter(IContext context, java.lang.String str, java.lang.String separator) + { + super(context); + this.str = str; + this.separator = separator; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substringAfter(str, separator); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstringAfter"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstringAfterLast.java b/test/javasource/communitycommons/actions/SubstringAfterLast.java new file mode 100644 index 0000000..fc65f13 --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstringAfterLast.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Gets the substring after the last occurrence of a separator. + */ +public class SubstringAfterLast extends CustomJavaAction +{ + private java.lang.String str; + private java.lang.String separator; + + public SubstringAfterLast(IContext context, java.lang.String str, java.lang.String separator) + { + super(context); + this.str = str; + this.separator = separator; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substringAfterLast(str, separator); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstringAfterLast"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstringBefore.java b/test/javasource/communitycommons/actions/SubstringBefore.java new file mode 100644 index 0000000..010fc39 --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstringBefore.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Gets the substring before the first occurrence of a separator. + */ +public class SubstringBefore extends CustomJavaAction +{ + private java.lang.String str; + private java.lang.String separator; + + public SubstringBefore(IContext context, java.lang.String str, java.lang.String separator) + { + super(context); + this.str = str; + this.separator = separator; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substringBefore(str, separator); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstringBefore"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/SubstringBeforeLast.java b/test/javasource/communitycommons/actions/SubstringBeforeLast.java new file mode 100644 index 0000000..98ca31a --- /dev/null +++ b/test/javasource/communitycommons/actions/SubstringBeforeLast.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.StringUtils; + +/** + * Gets the substring before the last occurrence of a separator. + */ +public class SubstringBeforeLast extends CustomJavaAction +{ + private java.lang.String str; + private java.lang.String separator; + + public SubstringBeforeLast(IContext context, java.lang.String str, java.lang.String separator) + { + super(context); + this.str = str; + this.separator = separator; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return StringUtils.substringBeforeLast(str, separator); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "SubstringBeforeLast"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/ThrowException.java b/test/javasource/communitycommons/actions/ThrowException.java new file mode 100644 index 0000000..f4e9608 --- /dev/null +++ b/test/javasource/communitycommons/actions/ThrowException.java @@ -0,0 +1,54 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * This action always throws an exception (of type communityutils.UserThrownError), which is, in combination with custom error handling, quite useful to end a microflow prematurely or to bail out to the calling action/ microflow. + * + * The message of the last thrown error can be inspected by using the variable $lasterrormessage + * + * Example usuage: In general, if an Event (before commit especially) returns false, it should call this action and then return true instead. If an Before commit returns false, the object will not be committed, but there is no easy way for the calling Microflow/ action to detect this! An exception on the other hand, will be noticed. + */ +public class ThrowException extends CustomJavaAction +{ + private java.lang.String message; + + public ThrowException(IContext context, java.lang.String message) + { + super(context); + this.message = message; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + Misc.throwException(message); + return null; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "ThrowException"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/ThrowWebserviceException.java b/test/javasource/communitycommons/actions/ThrowWebserviceException.java new file mode 100644 index 0000000..a27a5ed --- /dev/null +++ b/test/javasource/communitycommons/actions/ThrowWebserviceException.java @@ -0,0 +1,54 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * (Behavior has changed since version 3.2. The exception is now properly propagated to the cient). + * + * Throws an exception. This is very useful if the microflow is called by a webservice. If you throw this kind of exceptions, an fault message will be generated in the output, instead of an '501 Internal server' error. + * + * If debug level of community commons is set to 'debug' the errors will be locally visible as well, otherwise not. Throwing a webservice exception states that the webservice invocation was incorrect, not the webservice implementation. + */ +public class ThrowWebserviceException extends CustomJavaAction +{ + private java.lang.String faultstring; + + public ThrowWebserviceException(IContext context, java.lang.String faultstring) + { + super(context); + this.faultstring = faultstring; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + Misc.throwWebserviceException(faultstring); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "ThrowWebserviceException"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/TimeMeasureEnd.java b/test/javasource/communitycommons/actions/TimeMeasureEnd.java new file mode 100644 index 0000000..540d647 --- /dev/null +++ b/test/javasource/communitycommons/actions/TimeMeasureEnd.java @@ -0,0 +1,56 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Logging; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * End timing something, and print the result to the log. + * - TimerName. Should correspond to the TimerName used with TimeMeasureStart. + * - LogLevel. The loglevel used to print the result. + * - The message to be printed in the log. + */ +public class TimeMeasureEnd extends CustomJavaAction +{ + private java.lang.String TimerName; + private communitycommons.proxies.LogLevel Loglevel; + private java.lang.String message; + + public TimeMeasureEnd(IContext context, java.lang.String TimerName, java.lang.String Loglevel, java.lang.String message) + { + super(context); + this.TimerName = TimerName; + this.Loglevel = Loglevel == null ? null : communitycommons.proxies.LogLevel.valueOf(Loglevel); + this.message = message; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + return Logging.measureEnd(TimerName, Loglevel, message); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "TimeMeasureEnd"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/TimeMeasureStart.java b/test/javasource/communitycommons/actions/TimeMeasureStart.java new file mode 100644 index 0000000..b8ff5d9 --- /dev/null +++ b/test/javasource/communitycommons/actions/TimeMeasureStart.java @@ -0,0 +1,53 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Logging; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Start timing something, and print the result to the log. + * - TimerName. Should correspond to the TimerName used in TimeMeasureEnd. + * + * Note that multiple timers can run at once. Existing timers can be restarted using this function as well. + */ +public class TimeMeasureStart extends CustomJavaAction +{ + private java.lang.String TimerName; + + public TimeMeasureStart(IContext context, java.lang.String TimerName) + { + super(context); + this.TimerName = TimerName; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + Logging.measureStart(TimerName); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "TimeMeasureStart"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/XSSSanitize.java b/test/javasource/communitycommons/actions/XSSSanitize.java new file mode 100644 index 0000000..ab4a47b --- /dev/null +++ b/test/javasource/communitycommons/actions/XSSSanitize.java @@ -0,0 +1,95 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.MendixRuntimeException; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.proxies.SanitizerPolicy; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.commons.lang3.StringUtils; + +/** + * Removes all potential dangerous HTML from a string so that it can be safely displayed in a browser. + * + * This function should be applied to all HTML which is displayed in the browser, and can be entered by (untrusted) users. + * + * - HTML: The html to sanitize + * - policy1... policy6: one or more values of SanitizerPolicy. You may leave these policy parameters empty if you don't want to allow additional elements. + * + * BLOCKS: Allows common block elements including

,

, etc. + * FORMATTING: Allows common formatting elements including , , etc. + * IMAGES: Allows elements from HTTP, HTTPS, and relative sources. + * LINKS: Allows HTTP, HTTPS, MAILTO and relative links + * STYLES: Allows certain safe CSS properties in style="..." attributes. + * TABLES: Allows commons table elements. + * + * For more information, visit: + * + * http://javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/20180219.1 + */ +public class XSSSanitize extends CustomJavaAction +{ + private java.lang.String html; + private communitycommons.proxies.SanitizerPolicy policy1; + private communitycommons.proxies.SanitizerPolicy policy2; + private communitycommons.proxies.SanitizerPolicy policy3; + private communitycommons.proxies.SanitizerPolicy policy4; + private communitycommons.proxies.SanitizerPolicy policy5; + private communitycommons.proxies.SanitizerPolicy policy6; + + public XSSSanitize(IContext context, java.lang.String html, java.lang.String policy1, java.lang.String policy2, java.lang.String policy3, java.lang.String policy4, java.lang.String policy5, java.lang.String policy6) + { + super(context); + this.html = html; + this.policy1 = policy1 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy1); + this.policy2 = policy2 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy2); + this.policy3 = policy3 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy3); + this.policy4 = policy4 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy4); + this.policy5 = policy5 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy5); + this.policy6 = policy6 == null ? null : communitycommons.proxies.SanitizerPolicy.valueOf(policy6); + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + if (StringUtils.isEmpty(html)) { + return ""; + } + + List policyParams = Stream.of(policy1, policy2, policy3, policy4, policy5, policy6) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + if (policyParams.isEmpty()) { + throw new MendixRuntimeException("At least one policy is required"); + } + + return communitycommons.StringUtils.sanitizeHTML(html, policyParams); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "XSSSanitize"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/YearsBetween.java b/test/javasource/communitycommons/actions/YearsBetween.java new file mode 100644 index 0000000..a54a38a --- /dev/null +++ b/test/javasource/communitycommons/actions/YearsBetween.java @@ -0,0 +1,63 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.DateTime; +import communitycommons.Logging; +import communitycommons.proxies.LogLevel; +import communitycommons.proxies.LogNodes; +import java.util.Date; + +/** + * Calculates the number of years between two dates. + * - dateTime : the original (oldest) dateTime + * - compareDate: the second date. If EMPTY, the current datetime will be used. Effectively this means that the age of the dateTime is calculated. + */ +public class YearsBetween extends CustomJavaAction +{ + private java.util.Date dateTime; + private java.util.Date compareDate; + + public YearsBetween(IContext context, java.util.Date dateTime, java.util.Date compareDate) + { + super(context); + this.dateTime = dateTime; + this.compareDate = compareDate; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + try { + return Long.valueOf(DateTime.periodBetween(this.dateTime, compareDate == null ? new Date() : compareDate) + .getYears()); + } catch (Exception e) { + Logging.log(LogNodes.CommunityCommons.name(), LogLevel.Warning, "DateTime calculation error, returning -1", e); + return -1L; + } + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "YearsBetween"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/commitInSeparateDatabaseTransaction.java b/test/javasource/communitycommons/actions/commitInSeparateDatabaseTransaction.java new file mode 100644 index 0000000..368747b --- /dev/null +++ b/test/javasource/communitycommons/actions/commitInSeparateDatabaseTransaction.java @@ -0,0 +1,55 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.ISession; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * This function commits an object in a seperate context and transaction, making sure it gets persisted in the database (regarding which exception happens after invocation). + */ +public class commitInSeparateDatabaseTransaction extends CustomJavaAction +{ + private IMendixObject mxObject; + + public commitInSeparateDatabaseTransaction(IContext context, IMendixObject mxObject) + { + super(context); + this.mxObject = mxObject; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + ISession session = getContext().getSession(); + IContext newContext = session.createContext(); + Core.commit(newContext, mxObject); + newContext.endTransaction(); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "commitInSeparateDatabaseTransaction"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/commitWithoutEvents.java b/test/javasource/communitycommons/actions/commitWithoutEvents.java new file mode 100644 index 0000000..110042e --- /dev/null +++ b/test/javasource/communitycommons/actions/commitWithoutEvents.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Commits an object, but without events. + * + * N.B. This function is not very useful when called from the model, but it is useful when called from custom Java code. + */ +public class commitWithoutEvents extends CustomJavaAction +{ + private IMendixObject subject; + + public commitWithoutEvents(IContext context, IMendixObject subject) + { + super(context); + this.subject = subject; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.commitWithoutEvents(this.getContext(), subject); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "commitWithoutEvents"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/copyAttributes.java b/test/javasource/communitycommons/actions/copyAttributes.java new file mode 100644 index 0000000..8aefd59 --- /dev/null +++ b/test/javasource/communitycommons/actions/copyAttributes.java @@ -0,0 +1,55 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; + +/** + * Copies all common primitive attributes from source to target, which are not necessarily of the same type. This is useful to, for example, translate database object into view objects. + * + * Note that no automatic type conversion is done. + */ +public class copyAttributes extends CustomJavaAction +{ + private IMendixObject source; + private IMendixObject target; + + public copyAttributes(IContext context, IMendixObject source, IMendixObject target) + { + super(context); + this.source = source; + this.target = target; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + ORM.copyAttributes(getContext(), source, target); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "copyAttributes"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/deleteAll.java b/test/javasource/communitycommons/actions/deleteAll.java new file mode 100644 index 0000000..237d0be --- /dev/null +++ b/test/javasource/communitycommons/actions/deleteAll.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.XPath; + +/** + * Removes ALL instances of a certain domain object type using batches. + */ +public class deleteAll extends CustomJavaAction +{ + private java.lang.String entityType; + + public deleteAll(IContext context, java.lang.String entityType) + { + super(context); + this.entityType = entityType; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return XPath.create(this.getContext(), entityType).deleteAll(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "deleteAll"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeMicroflowAsUser.java b/test/javasource/communitycommons/actions/executeMicroflowAsUser.java new file mode 100644 index 0000000..2c10fe3 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeMicroflowAsUser.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Executes the given microflow as if the $currentuser is the provided user (delegation). Use sudoContext to determine if 'apply entity access' should be used + * + * - microflowName: the fully qualified microflow name, 'CommunityCommons.CreateUserIfNotExists' + * - username: The user that should be used to execute the microflow + * - sudoContext: whether entity access should be applied. + */ +public class executeMicroflowAsUser extends CustomJavaAction +{ + private java.lang.String microflow; + private java.lang.String username; + private java.lang.Boolean sudoContext; + + public executeMicroflowAsUser(IContext context, java.lang.String microflow, java.lang.String username, java.lang.Boolean sudoContext) + { + super(context); + this.microflow = microflow; + this.username = username; + this.sudoContext = sudoContext; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflow, username, sudoContext); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeMicroflowAsUser"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeMicroflowAsUser_1.java b/test/javasource/communitycommons/actions/executeMicroflowAsUser_1.java new file mode 100644 index 0000000..2bfcd4c --- /dev/null +++ b/test/javasource/communitycommons/actions/executeMicroflowAsUser_1.java @@ -0,0 +1,59 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Identical to executeMicroflowAsUser, but takes 1 argument + */ +public class executeMicroflowAsUser_1 extends CustomJavaAction +{ + private java.lang.String microflow; + private java.lang.String username; + private java.lang.Boolean sudoContext; + private java.lang.String arg1name; + private IMendixObject arg1value; + + public executeMicroflowAsUser_1(IContext context, java.lang.String microflow, java.lang.String username, java.lang.Boolean sudoContext, java.lang.String arg1name, IMendixObject arg1value) + { + super(context); + this.microflow = microflow; + this.username = username; + this.sudoContext = sudoContext; + this.arg1name = arg1name; + this.arg1value = arg1value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflow, username, sudoContext, arg1name, arg1value); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeMicroflowAsUser_1"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeMicroflowAsUser_2.java b/test/javasource/communitycommons/actions/executeMicroflowAsUser_2.java new file mode 100644 index 0000000..93b1a12 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeMicroflowAsUser_2.java @@ -0,0 +1,63 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Identical to executeMicroflowAsUser, but takes 2 arguments + */ +public class executeMicroflowAsUser_2 extends CustomJavaAction +{ + private java.lang.String microflow; + private java.lang.String username; + private java.lang.Boolean sudoContext; + private java.lang.String arg1name; + private IMendixObject arg1value; + private java.lang.String arg2name; + private IMendixObject arg2value; + + public executeMicroflowAsUser_2(IContext context, java.lang.String microflow, java.lang.String username, java.lang.Boolean sudoContext, java.lang.String arg1name, IMendixObject arg1value, java.lang.String arg2name, IMendixObject arg2value) + { + super(context); + this.microflow = microflow; + this.username = username; + this.sudoContext = sudoContext; + this.arg1name = arg1name; + this.arg1value = arg1value; + this.arg2name = arg2name; + this.arg2value = arg2value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflow, username, sudoContext, arg1name, arg1value, arg2name, arg2value); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeMicroflowAsUser_2"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeMicroflowInBackground.java b/test/javasource/communitycommons/actions/executeMicroflowInBackground.java new file mode 100644 index 0000000..061747b --- /dev/null +++ b/test/javasource/communitycommons/actions/executeMicroflowInBackground.java @@ -0,0 +1,64 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * This action allows an microflow to be executed independently from this microflow. + * This function is identical to "RunMicroflowAsyncInQueue", except that it takes one argument which will be passed to the microflow being called. + * + * This might be useful to model for example your own batching system, or to run a microflow in its own (system) transaction. The microflow is delayed for at least 200ms and then run with low priority in a system context. Since the microflow run in its own transaction, it is not affected with rollbacks (due to exceptions) or commits in this microflow. + * + * Invocations to this method are guaranteed to be run in FIFO order, only one microflow is run at a time. + * + * Note that since the microflow is run as system transaction, $currentUser is not available and no security restrictions are applied. + * + * - The microflowname specifies the fully qualified name of the microflow (case sensitive) e.g.: 'MyFirstModule.MyFirstMicroflow'. + * - The context object specifies an argument that should be passed to the microflow if applicable. Currently only zero or one argument are supported. Note that editing this object in both microflows might lead to unexpected behavior. + * + * Returns true if scheduled successfully. + */ +public class executeMicroflowInBackground extends CustomJavaAction +{ + private java.lang.String microflow; + private IMendixObject contextObject; + + public executeMicroflowInBackground(IContext context, java.lang.String microflow, IMendixObject contextObject) + { + super(context); + this.microflow = microflow; + this.contextObject = contextObject; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.runMicroflowInBackground(getContext(), microflow, contextObject); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeMicroflowInBackground"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeMicroflowInBatches.java b/test/javasource/communitycommons/actions/executeMicroflowInBatches.java new file mode 100644 index 0000000..2b21d24 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeMicroflowInBatches.java @@ -0,0 +1,72 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Invokes a microflow in batches. The microflow is invoked for each individual item returned by the xpath query. + * + * The objects will be processed in small batches (based on the batchsize), which makes this function very useful to process large amounts of objects without using much memory. All defaut behavior such as commit events are applied as defined in your microflow. + * + * Parameters: + * - xpath: Fully qualified xpath query that indicates the set of objects the microflow should be invoked on. For example: + * '//System.User[Active = true()]' + * - microflow: The microflow that should be invoked. Should accept one argument of the same type as the xpath. For example: + * 'MyFirstModule.UpdateBirthday' + * - batchsize: The amount of objects that should be processed in a single transaction. When in doubt, 1 is fine, but larger batches (for example; 100) will be faster due to less overhead. + * - waitUntilFinished: Whether this call should block (wait) until all objects are + * processed. + * + * Returns true if the batch has successfully started, or, if waitUntilFinished is true, returns true if the batch succeeded completely. + * + * Note, if new objects are added to the dataset while the batch is still running, those objects will be processed as well. + */ +public class executeMicroflowInBatches extends CustomJavaAction +{ + private java.lang.String xpath; + private java.lang.String microflow; + private java.lang.Long batchsize; + private java.lang.Boolean waitUntilFinished; + private java.lang.Boolean ascending; + + public executeMicroflowInBatches(IContext context, java.lang.String xpath, java.lang.String microflow, java.lang.Long batchsize, java.lang.Boolean waitUntilFinished, java.lang.Boolean ascending) + { + super(context); + this.xpath = xpath; + this.microflow = microflow; + this.batchsize = batchsize; + this.waitUntilFinished = waitUntilFinished; + this.ascending = ascending; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.executeMicroflowInBatches(xpath, microflow, batchsize.intValue(), waitUntilFinished.booleanValue(), ascending); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeMicroflowInBatches"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser.java b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser.java new file mode 100644 index 0000000..723a421 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Executes the given microflow as if the $currentuser is the provided user (delegation). Use sudoContext to determine if 'apply entity access' should be used + * + * - microflowName: the fully qualified microflow name, 'CommunityCommons.CreateUserIfNotExists' + * - username: The user that should be used to execute the microflow + * - sudoContext: whether entity access should be applied. + */ +public class executeUnverifiedMicroflowAsUser extends CustomJavaAction +{ + private java.lang.String microflowName; + private java.lang.String username; + private java.lang.Boolean sudoContext; + + public executeUnverifiedMicroflowAsUser(IContext context, java.lang.String microflowName, java.lang.String username, java.lang.Boolean sudoContext) + { + super(context); + this.microflowName = microflowName; + this.username = username; + this.sudoContext = sudoContext; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflowName, username, sudoContext); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeUnverifiedMicroflowAsUser"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_1.java b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_1.java new file mode 100644 index 0000000..ee436d1 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_1.java @@ -0,0 +1,59 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Identical to executeMicroflowAsUser, but takes 1 argument + */ +public class executeUnverifiedMicroflowAsUser_1 extends CustomJavaAction +{ + private java.lang.String microflowName; + private java.lang.String username; + private java.lang.Boolean sudoContext; + private java.lang.String arg1name; + private IMendixObject arg1value; + + public executeUnverifiedMicroflowAsUser_1(IContext context, java.lang.String microflowName, java.lang.String username, java.lang.Boolean sudoContext, java.lang.String arg1name, IMendixObject arg1value) + { + super(context); + this.microflowName = microflowName; + this.username = username; + this.sudoContext = sudoContext; + this.arg1name = arg1name; + this.arg1value = arg1value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflowName, username, sudoContext, arg1name, arg1value); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeUnverifiedMicroflowAsUser_1"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_2.java b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_2.java new file mode 100644 index 0000000..f920894 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowAsUser_2.java @@ -0,0 +1,63 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Identical to executeMicroflowAsUser, but takes 2 arguments + */ +public class executeUnverifiedMicroflowAsUser_2 extends CustomJavaAction +{ + private java.lang.String microflowName; + private java.lang.String username; + private java.lang.Boolean sudoContext; + private java.lang.String arg1name; + private IMendixObject arg1value; + private java.lang.String arg2name; + private IMendixObject arg2value; + + public executeUnverifiedMicroflowAsUser_2(IContext context, java.lang.String microflowName, java.lang.String username, java.lang.Boolean sudoContext, java.lang.String arg1name, IMendixObject arg1value, java.lang.String arg2name, IMendixObject arg2value) + { + super(context); + this.microflowName = microflowName; + this.username = username; + this.sudoContext = sudoContext; + this.arg1name = arg1name; + this.arg1value = arg1value; + this.arg2name = arg2name; + this.arg2value = arg2value; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + Object res = Misc.executeMicroflowAsUser(getContext(), microflowName, username, sudoContext, arg1name, arg1value, arg2name, arg2value); + return res == null ? null : res.toString(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeUnverifiedMicroflowAsUser_2"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBackground.java b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBackground.java new file mode 100644 index 0000000..eea19d8 --- /dev/null +++ b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBackground.java @@ -0,0 +1,64 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * This action allows an microflow to be executed independently from this microflow. + * This function is identical to "RunMicroflowAsyncInQueue", except that it takes one argument which will be passed to the microflow being called. + * + * This might be useful to model for example your own batching system, or to run a microflow in its own (system) transaction. The microflow is delayed for at least 200ms and then run with low priority in a system context. Since the microflow run in its own transaction, it is not affected with rollbacks (due to exceptions) or commits in this microflow. + * + * Invocations to this method are guaranteed to be run in FIFO order, only one microflow is run at a time. + * + * Note that since the microflow is run as system transaction, $currentUser is not available and no security restrictions are applied. + * + * - The microflowname specifies the fully qualified name of the microflow (case sensitive) e.g.: 'MyFirstModule.MyFirstMicroflow'. + * - The context object specifies an argument that should be passed to the microflow if applicable. Currently only zero or one argument are supported. Note that editing this object in both microflows might lead to unexpected behavior. + * + * Returns true if scheduled successfully. + */ +public class executeUnverifiedMicroflowInBackground extends CustomJavaAction +{ + private java.lang.String microflowName; + private IMendixObject contextObject; + + public executeUnverifiedMicroflowInBackground(IContext context, java.lang.String microflowName, IMendixObject contextObject) + { + super(context); + this.microflowName = microflowName; + this.contextObject = contextObject; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.runMicroflowInBackground(getContext(), microflowName, contextObject); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeUnverifiedMicroflowInBackground"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBatches.java b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBatches.java new file mode 100644 index 0000000..3c5006d --- /dev/null +++ b/test/javasource/communitycommons/actions/executeUnverifiedMicroflowInBatches.java @@ -0,0 +1,72 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import communitycommons.Misc; + +/** + * Invokes a microflow in batches. The microflow is invoked for each individual item returned by the xpath query. + * + * The objects will be processed in small batches (based on the batchsize), which makes this function very useful to process large amounts of objects without using much memory. All defaut behavior such as commit events are applied as defined in your microflow. + * + * Parameters: + * - xpath: Fully qualified xpath query that indicates the set of objects the microflow should be invoked on. For example: + * '//System.User[Active = true()]' + * - microflow: The microflow that should be invoked. Should accept one argument of the same type as the xpath. For example: + * 'MyFirstModule.UpdateBirthday' + * - batchsize: The amount of objects that should be processed in a single transaction. When in doubt, 1 is fine, but larger batches (for example; 100) will be faster due to less overhead. + * - waitUntilFinished: Whether this call should block (wait) until all objects are + * processed. + * + * Returns true if the batch has successfully started, or, if waitUntilFinished is true, returns true if the batch succeeded completely. + * + * Note, if new objects are added to the dataset while the batch is still running, those objects will be processed as well. + */ +public class executeUnverifiedMicroflowInBatches extends CustomJavaAction +{ + private java.lang.String xpath; + private java.lang.String microflowName; + private java.lang.Long batchsize; + private java.lang.Boolean waitUntilFinished; + private java.lang.Boolean ascending; + + public executeUnverifiedMicroflowInBatches(IContext context, java.lang.String xpath, java.lang.String microflowName, java.lang.Long batchsize, java.lang.Boolean waitUntilFinished, java.lang.Boolean ascending) + { + super(context); + this.xpath = xpath; + this.microflowName = microflowName; + this.batchsize = batchsize; + this.waitUntilFinished = waitUntilFinished; + this.ascending = ascending; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.executeMicroflowInBatches(xpath, microflowName, batchsize.intValue(), waitUntilFinished.booleanValue(), ascending); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "executeUnverifiedMicroflowInBatches"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getCreatedByUser.java b/test/javasource/communitycommons/actions/getCreatedByUser.java new file mode 100644 index 0000000..2bf96b7 --- /dev/null +++ b/test/javasource/communitycommons/actions/getCreatedByUser.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the user that created an object + * + * (or empty if not applicable). + */ +public class getCreatedByUser extends CustomJavaAction +{ + private IMendixObject thing; + + public getCreatedByUser(IContext context, IMendixObject thing) + { + super(context); + this.thing = thing; + } + + @java.lang.Override + public IMendixObject executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.getCreatedByUser(getContext(), thing); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getCreatedByUser"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getFileSize.java b/test/javasource/communitycommons/actions/getFileSize.java new file mode 100644 index 0000000..7cfcdee --- /dev/null +++ b/test/javasource/communitycommons/actions/getFileSize.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the filesize of a file document in bytes. + * + * From version 2.3 on, this function can be used in cloud environments as well. + * + * NOTE: + * before 2.1, this functioned returned the size in kilobytes, although this documentation mentioned bytes + */ +public class getFileSize extends CustomJavaAction +{ + private IMendixObject __document; + private system.proxies.FileDocument document; + + public getFileSize(IContext context, IMendixObject document) + { + super(context); + this.__document = document; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + this.document = this.__document == null ? null : system.proxies.FileDocument.initialize(getContext(), __document); + + // BEGIN USER CODE + return Misc.getFileSize(this.getContext(), document.getMendixObject()); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getFileSize"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getGUID.java b/test/javasource/communitycommons/actions/getGUID.java new file mode 100644 index 0000000..172d505 --- /dev/null +++ b/test/javasource/communitycommons/actions/getGUID.java @@ -0,0 +1,50 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * returns the Global Unique Identifier (GUID, or id) of an object. + */ +public class getGUID extends CustomJavaAction +{ + private IMendixObject item; + + public getGUID(IContext context, IMendixObject item) + { + super(context); + this.item = item; + } + + @java.lang.Override + public java.lang.Long executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.getGUID(item); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getGUID"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getLastChangedByUser.java b/test/javasource/communitycommons/actions/getLastChangedByUser.java new file mode 100644 index 0000000..d35ca98 --- /dev/null +++ b/test/javasource/communitycommons/actions/getLastChangedByUser.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the user that last changed this object as System.User + * + * (or empty if not applicable). + */ +public class getLastChangedByUser extends CustomJavaAction +{ + private IMendixObject thing; + + public getLastChangedByUser(IContext context, IMendixObject thing) + { + super(context); + this.thing = thing; + } + + @java.lang.Override + public IMendixObject executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.getLastChangedByUser(getContext(), thing); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getLastChangedByUser"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getOriginalValueAsString.java b/test/javasource/communitycommons/actions/getOriginalValueAsString.java new file mode 100644 index 0000000..827445e --- /dev/null +++ b/test/javasource/communitycommons/actions/getOriginalValueAsString.java @@ -0,0 +1,58 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the original value of an object member, that is, the last committed value. + * + * This is useful if you want to compare the actual value with the last stored value. + * - item : the object of which you want to inspect a member + * - member: the member to retrieve the previous value from. Note that for references, the module name needs to be included. + * + * The function is applicable for non-String members as well, but always returns a String representation of the previous value. + */ +public class getOriginalValueAsString extends CustomJavaAction +{ + private IMendixObject item; + private java.lang.String member; + + public getOriginalValueAsString(IContext context, IMendixObject item, java.lang.String member) + { + super(context); + this.item = item; + this.member = member; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.getOriginalValueAsString(this.getContext(), item, member); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getOriginalValueAsString"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/getTypeAsString.java b/test/javasource/communitycommons/actions/getTypeAsString.java new file mode 100644 index 0000000..4eb171a --- /dev/null +++ b/test/javasource/communitycommons/actions/getTypeAsString.java @@ -0,0 +1,51 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns the actual type of an Entity. Useful as alternative way to split upon inheritance, or as input of other functions in this module. + */ +public class getTypeAsString extends CustomJavaAction +{ + private IMendixObject instance; + + public getTypeAsString(IContext context, IMendixObject instance) + { + super(context); + this.instance = instance; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + if (instance == null) + return ""; + return instance.getType(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "getTypeAsString"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/memberHasChanged.java b/test/javasource/communitycommons/actions/memberHasChanged.java new file mode 100644 index 0000000..1bf6914 --- /dev/null +++ b/test/javasource/communitycommons/actions/memberHasChanged.java @@ -0,0 +1,57 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Checks whether a member has changed since the last commit. Useful in combination with getOriginalValueAsString. + * + * - item : the object to inspect + * - member: the name of the member to inspect. Note that for references, the module name needs to be included. + * + * Returns true if changed. + */ +public class memberHasChanged extends CustomJavaAction +{ + private IMendixObject item; + private java.lang.String member; + + public memberHasChanged(IContext context, IMendixObject item, java.lang.String member) + { + super(context); + this.item = item; + this.member = member; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.memberHasChanged(this.getContext(), item, member); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "memberHasChanged"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/objectHasChanged.java b/test/javasource/communitycommons/actions/objectHasChanged.java new file mode 100644 index 0000000..0d41f6a --- /dev/null +++ b/test/javasource/communitycommons/actions/objectHasChanged.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.ORM; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Returns true if at least one member (including owned associations) of this object has changed. + * + * For Mendix < 9.5 this action keeps track of changes to the object except when 'changing to the same value'. For Mendix >= 9.5 this action keeps track of all changes. This is a result of a change of the underlying Mendix runtime-server behaviour. + */ +public class objectHasChanged extends CustomJavaAction +{ + private IMendixObject item; + + public objectHasChanged(IContext context, IMendixObject item) + { + super(context); + this.item = item; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return ORM.objectHasChanged(item); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "objectHasChanged"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/objectIsNew.java b/test/javasource/communitycommons/actions/objectIsNew.java new file mode 100644 index 0000000..1b8673e --- /dev/null +++ b/test/javasource/communitycommons/actions/objectIsNew.java @@ -0,0 +1,49 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.systemwideinterfaces.core.IMendixObject; + +/** + * Returns true if this object is new (not committed in the database). + */ +public class objectIsNew extends CustomJavaAction +{ + private IMendixObject mxObject; + + public objectIsNew(IContext context, IMendixObject mxObject) + { + super(context); + this.mxObject = mxObject; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return this.mxObject.isNew(); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "objectIsNew"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/recommitInBatches.java b/test/javasource/communitycommons/actions/recommitInBatches.java new file mode 100644 index 0000000..5127851 --- /dev/null +++ b/test/javasource/communitycommons/actions/recommitInBatches.java @@ -0,0 +1,52 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +public class recommitInBatches extends CustomJavaAction +{ + private java.lang.String xpath; + private java.lang.Long batchsize; + private java.lang.Boolean waitUntilFinished; + private java.lang.Boolean ascending; + + public recommitInBatches(IContext context, java.lang.String xpath, java.lang.Long batchsize, java.lang.Boolean waitUntilFinished, java.lang.Boolean ascending) + { + super(context); + this.xpath = xpath; + this.batchsize = batchsize; + this.waitUntilFinished = waitUntilFinished; + this.ascending = ascending; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.recommitInBatches(xpath, batchsize.intValue(), waitUntilFinished.booleanValue(), ascending); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "recommitInBatches"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/refreshClass.java b/test/javasource/communitycommons/actions/refreshClass.java new file mode 100644 index 0000000..6c85cb9 --- /dev/null +++ b/test/javasource/communitycommons/actions/refreshClass.java @@ -0,0 +1,53 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; +import com.mendix.webui.FeedbackHelper; + +/** + * Refreshes a certain domain object type in the client. Useful to enforce a datagrid to refresh for example. + * + * -objectType : Type of the domain objects to refresh, such as System.User or MyModule.MyFirstEntity. + * (you can use getTypeAsString to determine this dynamically, so that the invoke of this action is not be sensitive to domain model changes). + */ +public class refreshClass extends CustomJavaAction +{ + private java.lang.String objectType; + + public refreshClass(IContext context, java.lang.String objectType) + { + super(context); + this.objectType = objectType; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + FeedbackHelper.addRefreshClass(this.getContext(), objectType); + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "refreshClass"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/refreshClassByObject.java b/test/javasource/communitycommons/actions/refreshClassByObject.java new file mode 100644 index 0000000..a9a39f5 --- /dev/null +++ b/test/javasource/communitycommons/actions/refreshClassByObject.java @@ -0,0 +1,55 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.systemwideinterfaces.core.IMendixObject; +import com.mendix.webui.CustomJavaAction; +import com.mendix.webui.FeedbackHelper; + +/** + * Refreshes a certain domain object type in the client. Useful to enforce a datagrid to refresh for example. + * + * - instance : This object is used to identify the type of objects that need to be refreshed. For example passing $currentUser will refresh all System.Account's. + */ +public class refreshClassByObject extends CustomJavaAction +{ + private IMendixObject instance; + + public refreshClassByObject(IContext context, IMendixObject instance) + { + super(context); + this.instance = instance; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + // BEGIN USER CODE + if (instance != null) { + FeedbackHelper.addRefreshClass(this.getContext(), instance.getType()); + } + return true; + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "refreshClassByObject"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/retrieveURL.java b/test/javasource/communitycommons/actions/retrieveURL.java new file mode 100644 index 0000000..88dd235 --- /dev/null +++ b/test/javasource/communitycommons/actions/retrieveURL.java @@ -0,0 +1,61 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Retrieves data (such as an HTML page) from an URL using the HTTP protocol, and returns it as string. + * + * - url : The URL to retrieve. + * - post : Data to be sent in the request body. If set, a POST request will be send, otherwise a GET request is used. + * + * Example urls: + * 'https://mxforum.mendix.com/search/' + * 'http://www.google.nl/#hl=nl&q=download+mendix' + * + * Example post data: + * 'ipSearchTag=url&x=0&y=0' + */ +public class retrieveURL extends CustomJavaAction +{ + private java.lang.String url; + private java.lang.String postdata; + + public retrieveURL(IContext context, java.lang.String url, java.lang.String postdata) + { + super(context); + this.url = url; + this.postdata = postdata; + } + + @java.lang.Override + public java.lang.String executeAction() throws Exception + { + // BEGIN USER CODE + return Misc.retrieveURL(url, postdata); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "retrieveURL"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/actions/storeURLToFileDocument.java b/test/javasource/communitycommons/actions/storeURLToFileDocument.java new file mode 100644 index 0000000..8c0f80d --- /dev/null +++ b/test/javasource/communitycommons/actions/storeURLToFileDocument.java @@ -0,0 +1,64 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Only the following code will be retained when actions are regenerated: +// - the import list +// - the code between BEGIN USER CODE and END USER CODE +// - the code between BEGIN EXTRA CODE and END EXTRA CODE +// Other code you write will be lost the next time you deploy the project. +// Special characters, e.g., é, ö, à, etc. are supported in comments. + +package communitycommons.actions; + +import com.mendix.systemwideinterfaces.core.IMendixObject; +import communitycommons.Misc; +import com.mendix.systemwideinterfaces.core.IContext; +import com.mendix.webui.CustomJavaAction; + +/** + * Retrieve a document from an URL using a HTTP GET request. + * - url : the URL to retrieve + * - document: the document to store the data into + * - filename: the filename to store it under. Only for internal use, so it can be an arbitrary filename. + * + * Example URL: 'http://www.mendix.com/wordpress/wp-content/themes/mendix_new/images/mendix.png' + * + * NOTE: For images, no thumbnail will be generated. + */ +public class storeURLToFileDocument extends CustomJavaAction +{ + private java.lang.String url; + private IMendixObject __document; + private system.proxies.FileDocument document; + private java.lang.String filename; + + public storeURLToFileDocument(IContext context, java.lang.String url, IMendixObject document, java.lang.String filename) + { + super(context); + this.url = url; + this.__document = document; + this.filename = filename; + } + + @java.lang.Override + public java.lang.Boolean executeAction() throws Exception + { + this.document = this.__document == null ? null : system.proxies.FileDocument.initialize(getContext(), __document); + + // BEGIN USER CODE + return Misc.storeURLToFileDocument(this.getContext(), url, document.getMendixObject(), filename); + // END USER CODE + } + + /** + * Returns a string representation of this action + * @return a string representation of this action + */ + @java.lang.Override + public java.lang.String toString() + { + return "storeURLToFileDocument"; + } + + // BEGIN EXTRA CODE + // END EXTRA CODE +} diff --git a/test/javasource/communitycommons/proxies/DatePartSelector.java b/test/javasource/communitycommons/proxies/DatePartSelector.java new file mode 100644 index 0000000..986a9f7 --- /dev/null +++ b/test/javasource/communitycommons/proxies/DatePartSelector.java @@ -0,0 +1,32 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public enum DatePartSelector +{ + year(new java.lang.String[][] { new java.lang.String[] { "en_US", "year" }, new java.lang.String[] { "nl_NL", "jaar" } }), + month(new java.lang.String[][] { new java.lang.String[] { "en_US", "month" }, new java.lang.String[] { "nl_NL", "maand" } }), + day(new java.lang.String[][] { new java.lang.String[] { "en_US", "day" }, new java.lang.String[] { "nl_NL", "dag" } }); + + private final java.util.Map captions; + + private DatePartSelector(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/communitycommons/proxies/ImageDimensions.java b/test/javasource/communitycommons/proxies/ImageDimensions.java new file mode 100644 index 0000000..aeb13fb --- /dev/null +++ b/test/javasource/communitycommons/proxies/ImageDimensions.java @@ -0,0 +1,243 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public class ImageDimensions +{ + private final com.mendix.systemwideinterfaces.core.IMendixObject imageDimensionsMendixObject; + + private final com.mendix.systemwideinterfaces.core.IContext context; + + /** + * Internal name of this entity + */ + public static final java.lang.String entityName = "CommunityCommons.ImageDimensions"; + + /** + * Enum describing members of this entity + */ + public enum MemberNames + { + Height("Height"), + Width("Width"); + + private final java.lang.String metaName; + + MemberNames(java.lang.String s) + { + metaName = s; + } + + @java.lang.Override + public java.lang.String toString() + { + return metaName; + } + } + + public ImageDimensions(com.mendix.systemwideinterfaces.core.IContext context) + { + this(context, com.mendix.core.Core.instantiate(context, entityName)); + } + + protected ImageDimensions(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixObject imageDimensionsMendixObject) + { + if (imageDimensionsMendixObject == null) { + throw new java.lang.IllegalArgumentException("The given object cannot be null."); + } + if (!com.mendix.core.Core.isSubClassOf(entityName, imageDimensionsMendixObject.getType())) { + throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName)); + } + + this.imageDimensionsMendixObject = imageDimensionsMendixObject; + this.context = context; + } + + /** + * @deprecated Use 'ImageDimensions.load(IContext, IMendixIdentifier)' instead. + */ + @java.lang.Deprecated + public static communitycommons.proxies.ImageDimensions initialize(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixIdentifier mendixIdentifier) throws com.mendix.core.CoreException + { + return communitycommons.proxies.ImageDimensions.load(context, mendixIdentifier); + } + + /** + * Initialize a proxy using context (recommended). This context will be used for security checking when the get- and set-methods without context parameters are called. + * The get- and set-methods with context parameter should be used when for instance sudo access is necessary (IContext.createSudoClone() can be used to obtain sudo access). + * @param context The context to be used + * @param mendixObject The Mendix object for the new instance + * @return a new instance of this proxy class + */ + public static communitycommons.proxies.ImageDimensions initialize(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixObject mendixObject) + { + return new communitycommons.proxies.ImageDimensions(context, mendixObject); + } + + public static communitycommons.proxies.ImageDimensions load(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixIdentifier mendixIdentifier) throws com.mendix.core.CoreException + { + com.mendix.systemwideinterfaces.core.IMendixObject mendixObject = com.mendix.core.Core.retrieveId(context, mendixIdentifier); + return communitycommons.proxies.ImageDimensions.initialize(context, mendixObject); + } + + /** + * Commit the changes made on this proxy object. + * @throws com.mendix.core.CoreException + */ + public final void commit() throws com.mendix.core.CoreException + { + com.mendix.core.Core.commit(context, getMendixObject()); + } + + /** + * Commit the changes made on this proxy object using the specified context. + * @throws com.mendix.core.CoreException + */ + public final void commit(com.mendix.systemwideinterfaces.core.IContext context) throws com.mendix.core.CoreException + { + com.mendix.core.Core.commit(context, getMendixObject()); + } + + /** + * Delete the object. + */ + public final void delete() + { + com.mendix.core.Core.delete(context, getMendixObject()); + } + + /** + * Delete the object using the specified context. + */ + public final void delete(com.mendix.systemwideinterfaces.core.IContext context) + { + com.mendix.core.Core.delete(context, getMendixObject()); + } + /** + * @return value of Height + */ + public final java.lang.Integer getHeight() + { + return getHeight(getContext()); + } + + /** + * @param context + * @return value of Height + */ + public final java.lang.Integer getHeight(com.mendix.systemwideinterfaces.core.IContext context) + { + return (java.lang.Integer) getMendixObject().getValue(context, MemberNames.Height.toString()); + } + + /** + * Set value of Height + * @param height + */ + public final void setHeight(java.lang.Integer height) + { + setHeight(getContext(), height); + } + + /** + * Set value of Height + * @param context + * @param height + */ + public final void setHeight(com.mendix.systemwideinterfaces.core.IContext context, java.lang.Integer height) + { + getMendixObject().setValue(context, MemberNames.Height.toString(), height); + } + + /** + * @return value of Width + */ + public final java.lang.Integer getWidth() + { + return getWidth(getContext()); + } + + /** + * @param context + * @return value of Width + */ + public final java.lang.Integer getWidth(com.mendix.systemwideinterfaces.core.IContext context) + { + return (java.lang.Integer) getMendixObject().getValue(context, MemberNames.Width.toString()); + } + + /** + * Set value of Width + * @param width + */ + public final void setWidth(java.lang.Integer width) + { + setWidth(getContext(), width); + } + + /** + * Set value of Width + * @param context + * @param width + */ + public final void setWidth(com.mendix.systemwideinterfaces.core.IContext context, java.lang.Integer width) + { + getMendixObject().setValue(context, MemberNames.Width.toString(), width); + } + + /** + * @return the IMendixObject instance of this proxy for use in the Core interface. + */ + public final com.mendix.systemwideinterfaces.core.IMendixObject getMendixObject() + { + return imageDimensionsMendixObject; + } + + /** + * @return the IContext instance of this proxy, or null if no IContext instance was specified at initialization. + */ + public final com.mendix.systemwideinterfaces.core.IContext getContext() + { + return context; + } + + @java.lang.Override + public boolean equals(Object obj) + { + if (obj == this) { + return true; + } + if (obj != null && getClass().equals(obj.getClass())) + { + final communitycommons.proxies.ImageDimensions that = (communitycommons.proxies.ImageDimensions) obj; + return getMendixObject().equals(that.getMendixObject()); + } + return false; + } + + @java.lang.Override + public int hashCode() + { + return getMendixObject().hashCode(); + } + + /** + * @return String name of this class + */ + public static java.lang.String getType() + { + return entityName; + } + + /** + * @return String GUID from this object, format: ID_0000000000 + * @deprecated Use getMendixObject().getId().toLong() to get a unique identifier for this object. + */ + @java.lang.Deprecated + public java.lang.String getGUID() + { + return "ID_" + getMendixObject().getId().toLong(); + } +} diff --git a/test/javasource/communitycommons/proxies/LogLevel.java b/test/javasource/communitycommons/proxies/LogLevel.java new file mode 100644 index 0000000..682095d --- /dev/null +++ b/test/javasource/communitycommons/proxies/LogLevel.java @@ -0,0 +1,35 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public enum LogLevel +{ + Trace(new java.lang.String[][] { new java.lang.String[] { "en_US", "Trace" }, new java.lang.String[] { "nl_NL", "Trace" } }), + Debug(new java.lang.String[][] { new java.lang.String[] { "en_US", "Debug" }, new java.lang.String[] { "nl_NL", "Debug" } }), + Info(new java.lang.String[][] { new java.lang.String[] { "en_US", "Info" }, new java.lang.String[] { "nl_NL", "Info" } }), + Warning(new java.lang.String[][] { new java.lang.String[] { "en_US", "Warning" }, new java.lang.String[] { "nl_NL", "Warning" } }), + Error(new java.lang.String[][] { new java.lang.String[] { "en_US", "Error" }, new java.lang.String[] { "nl_NL", "Error" } }), + Critical(new java.lang.String[][] { new java.lang.String[] { "en_US", "Critical" }, new java.lang.String[] { "nl_NL", "Critical" } }); + + private final java.util.Map captions; + + private LogLevel(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/communitycommons/proxies/LogNodes.java b/test/javasource/communitycommons/proxies/LogNodes.java new file mode 100644 index 0000000..09e44e8 --- /dev/null +++ b/test/javasource/communitycommons/proxies/LogNodes.java @@ -0,0 +1,30 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public enum LogNodes +{ + CommunityCommons(new java.lang.String[][] { new java.lang.String[] { "en_US", "CommunityCommons" }, new java.lang.String[] { "nl_NL", "CommunityCommons" } }); + + private final java.util.Map captions; + + private LogNodes(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/communitycommons/proxies/SanitizerPolicy.java b/test/javasource/communitycommons/proxies/SanitizerPolicy.java new file mode 100644 index 0000000..91aeb3e --- /dev/null +++ b/test/javasource/communitycommons/proxies/SanitizerPolicy.java @@ -0,0 +1,35 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public enum SanitizerPolicy +{ + BLOCKS(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows common block elements including

,

, etc." } }), + FORMATTING(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows common formatting elements including , etc." } }), + IMAGES(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows elements from HTTP, HTTPS and relative sources" } }), + LINKS(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows HTTP, HTTPS, MAILTO and relative links" } }), + STYLES(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows certain safe CSS properties in style=\"...\" attributes" } }), + TABLES(new java.lang.String[][] { new java.lang.String[] { "en_US", "Allows common table elements" } }); + + private final java.util.Map captions; + + private SanitizerPolicy(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/communitycommons/proxies/SplitItem.java b/test/javasource/communitycommons/proxies/SplitItem.java new file mode 100644 index 0000000..5cec193 --- /dev/null +++ b/test/javasource/communitycommons/proxies/SplitItem.java @@ -0,0 +1,243 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public class SplitItem +{ + private final com.mendix.systemwideinterfaces.core.IMendixObject splitItemMendixObject; + + private final com.mendix.systemwideinterfaces.core.IContext context; + + /** + * Internal name of this entity + */ + public static final java.lang.String entityName = "CommunityCommons.SplitItem"; + + /** + * Enum describing members of this entity + */ + public enum MemberNames + { + Index("Index"), + Value("Value"); + + private final java.lang.String metaName; + + MemberNames(java.lang.String s) + { + metaName = s; + } + + @java.lang.Override + public java.lang.String toString() + { + return metaName; + } + } + + public SplitItem(com.mendix.systemwideinterfaces.core.IContext context) + { + this(context, com.mendix.core.Core.instantiate(context, entityName)); + } + + protected SplitItem(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixObject splitItemMendixObject) + { + if (splitItemMendixObject == null) { + throw new java.lang.IllegalArgumentException("The given object cannot be null."); + } + if (!com.mendix.core.Core.isSubClassOf(entityName, splitItemMendixObject.getType())) { + throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName)); + } + + this.splitItemMendixObject = splitItemMendixObject; + this.context = context; + } + + /** + * @deprecated Use 'SplitItem.load(IContext, IMendixIdentifier)' instead. + */ + @java.lang.Deprecated + public static communitycommons.proxies.SplitItem initialize(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixIdentifier mendixIdentifier) throws com.mendix.core.CoreException + { + return communitycommons.proxies.SplitItem.load(context, mendixIdentifier); + } + + /** + * Initialize a proxy using context (recommended). This context will be used for security checking when the get- and set-methods without context parameters are called. + * The get- and set-methods with context parameter should be used when for instance sudo access is necessary (IContext.createSudoClone() can be used to obtain sudo access). + * @param context The context to be used + * @param mendixObject The Mendix object for the new instance + * @return a new instance of this proxy class + */ + public static communitycommons.proxies.SplitItem initialize(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixObject mendixObject) + { + return new communitycommons.proxies.SplitItem(context, mendixObject); + } + + public static communitycommons.proxies.SplitItem load(com.mendix.systemwideinterfaces.core.IContext context, com.mendix.systemwideinterfaces.core.IMendixIdentifier mendixIdentifier) throws com.mendix.core.CoreException + { + com.mendix.systemwideinterfaces.core.IMendixObject mendixObject = com.mendix.core.Core.retrieveId(context, mendixIdentifier); + return communitycommons.proxies.SplitItem.initialize(context, mendixObject); + } + + /** + * Commit the changes made on this proxy object. + * @throws com.mendix.core.CoreException + */ + public final void commit() throws com.mendix.core.CoreException + { + com.mendix.core.Core.commit(context, getMendixObject()); + } + + /** + * Commit the changes made on this proxy object using the specified context. + * @throws com.mendix.core.CoreException + */ + public final void commit(com.mendix.systemwideinterfaces.core.IContext context) throws com.mendix.core.CoreException + { + com.mendix.core.Core.commit(context, getMendixObject()); + } + + /** + * Delete the object. + */ + public final void delete() + { + com.mendix.core.Core.delete(context, getMendixObject()); + } + + /** + * Delete the object using the specified context. + */ + public final void delete(com.mendix.systemwideinterfaces.core.IContext context) + { + com.mendix.core.Core.delete(context, getMendixObject()); + } + /** + * @return value of Index + */ + public final java.lang.Integer getIndex() + { + return getIndex(getContext()); + } + + /** + * @param context + * @return value of Index + */ + public final java.lang.Integer getIndex(com.mendix.systemwideinterfaces.core.IContext context) + { + return (java.lang.Integer) getMendixObject().getValue(context, MemberNames.Index.toString()); + } + + /** + * Set value of Index + * @param index + */ + public final void setIndex(java.lang.Integer index) + { + setIndex(getContext(), index); + } + + /** + * Set value of Index + * @param context + * @param index + */ + public final void setIndex(com.mendix.systemwideinterfaces.core.IContext context, java.lang.Integer index) + { + getMendixObject().setValue(context, MemberNames.Index.toString(), index); + } + + /** + * @return value of Value + */ + public final java.lang.String getValue() + { + return getValue(getContext()); + } + + /** + * @param context + * @return value of Value + */ + public final java.lang.String getValue(com.mendix.systemwideinterfaces.core.IContext context) + { + return (java.lang.String) getMendixObject().getValue(context, MemberNames.Value.toString()); + } + + /** + * Set value of Value + * @param value + */ + public final void setValue(java.lang.String value) + { + setValue(getContext(), value); + } + + /** + * Set value of Value + * @param context + * @param value + */ + public final void setValue(com.mendix.systemwideinterfaces.core.IContext context, java.lang.String value) + { + getMendixObject().setValue(context, MemberNames.Value.toString(), value); + } + + /** + * @return the IMendixObject instance of this proxy for use in the Core interface. + */ + public final com.mendix.systemwideinterfaces.core.IMendixObject getMendixObject() + { + return splitItemMendixObject; + } + + /** + * @return the IContext instance of this proxy, or null if no IContext instance was specified at initialization. + */ + public final com.mendix.systemwideinterfaces.core.IContext getContext() + { + return context; + } + + @java.lang.Override + public boolean equals(Object obj) + { + if (obj == this) { + return true; + } + if (obj != null && getClass().equals(obj.getClass())) + { + final communitycommons.proxies.SplitItem that = (communitycommons.proxies.SplitItem) obj; + return getMendixObject().equals(that.getMendixObject()); + } + return false; + } + + @java.lang.Override + public int hashCode() + { + return getMendixObject().hashCode(); + } + + /** + * @return String name of this class + */ + public static java.lang.String getType() + { + return entityName; + } + + /** + * @return String GUID from this object, format: ID_0000000000 + * @deprecated Use getMendixObject().getId().toLong() to get a unique identifier for this object. + */ + @java.lang.Deprecated + public java.lang.String getGUID() + { + return "ID_" + getMendixObject().getId().toLong(); + } +} diff --git a/test/javasource/communitycommons/proxies/StandardEncodings.java b/test/javasource/communitycommons/proxies/StandardEncodings.java new file mode 100644 index 0000000..e65851d --- /dev/null +++ b/test/javasource/communitycommons/proxies/StandardEncodings.java @@ -0,0 +1,35 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies; + +public enum StandardEncodings +{ + US_ASCII(new java.lang.String[][] { new java.lang.String[] { "en_US", "US-ASCII" } }), + ISO_8859_1(new java.lang.String[][] { new java.lang.String[] { "en_US", "ISO-8859-1" } }), + UTF_8(new java.lang.String[][] { new java.lang.String[] { "en_US", "UTF-8" } }), + UTF_16BE(new java.lang.String[][] { new java.lang.String[] { "en_US", "UTF-16BE" } }), + UTF_16LE(new java.lang.String[][] { new java.lang.String[] { "en_US", "UTF-16LE" } }), + UTF_16(new java.lang.String[][] { new java.lang.String[] { "en_US", "UTF-16" } }); + + private final java.util.Map captions; + + private StandardEncodings(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/communitycommons/proxies/constants/Constants.java b/test/javasource/communitycommons/proxies/constants/Constants.java new file mode 100644 index 0000000..86a3679 --- /dev/null +++ b/test/javasource/communitycommons/proxies/constants/Constants.java @@ -0,0 +1,30 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies.constants; + +import com.mendix.core.Core; + +public class Constants +{ + /** + * @deprecated + * The default constructor of the Constants class should not be used. + * Use the static get methods instead. + */ + @java.lang.Deprecated(since = "9.12", forRemoval = true) + public Constants() {} + + // These are the constants for the CommunityCommons module + + /** + * Restricted to 10 files at once for Mendix Cloud v4 compatibility. If you need to merge more than 10 files increase the number here. Setting the value to <=0 means unlimited. + * + * Note: We very strongly recommend to not increase the number for applications running in Mendix Cloud v4. + */ + public static java.lang.Long getMergeMultiplePdfs_MaxAtOnce() + { + return (java.lang.Long)Core.getConfiguration().getConstantValue("CommunityCommons.MergeMultiplePdfs_MaxAtOnce"); + } +} \ No newline at end of file diff --git a/test/javasource/communitycommons/proxies/microflows/Microflows.java b/test/javasource/communitycommons/proxies/microflows/Microflows.java new file mode 100644 index 0000000..24ba170 --- /dev/null +++ b/test/javasource/communitycommons/proxies/microflows/Microflows.java @@ -0,0 +1,55 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package communitycommons.proxies.microflows; + +import java.util.HashMap; +import java.util.Map; +import com.mendix.core.Core; +import com.mendix.systemwideinterfaces.core.IContext; + +public class Microflows +{ + /** + * @deprecated + * The default constructor of the Microflows class should not be used. + * Use the static microflow invocation methods instead. + */ + @java.lang.Deprecated(since = "9.12", forRemoval = true) + public Microflows() {} + + // These are the microflows for the CommunityCommons module + public static void assertTrue(IContext context, boolean _valueToAssert) + { + Map params = new HashMap<>(); + params.put("valueToAssert", _valueToAssert); + Core.microflowCall("CommunityCommons.AssertTrue").withParams(params).execute(context); + } + public static void assertTrue_2(IContext context, boolean _valueToAssert, java.lang.String _message) + { + Map params = new HashMap<>(); + params.put("valueToAssert", _valueToAssert); + params.put("message", _message); + Core.microflowCall("CommunityCommons.AssertTrue_2").withParams(params).execute(context); + } + public static void createUserIfNotExists(IContext context, java.lang.String _username, java.lang.String _role, java.lang.String _password, boolean _webserviceUser) + { + Map params = new HashMap<>(); + params.put("Username", _username); + params.put("Role", _role); + params.put("Password", _password); + params.put("WebserviceUser", _webserviceUser); + Core.microflowCall("CommunityCommons.CreateUserIfNotExists").withParams(params).execute(context); + } + public static void updateUserHelper(IContext context, java.lang.String _username, java.lang.String _role, java.lang.String _password, boolean _webserviceUser, system.proxies.User _user) + { + Map params = new HashMap<>(); + params.put("Username", _username); + params.put("Role", _role); + params.put("Password", _password); + params.put("WebserviceUser", _webserviceUser); + params.put("User", _user == null ? null : _user.getMendixObject()); + Core.microflowCall("CommunityCommons.UpdateUserHelper").withParams(params).execute(context); + } +} diff --git a/test/javasource/system/UserActionsRegistrar.java b/test/javasource/system/UserActionsRegistrar.java index b154e9e..5ace1c1 100644 --- a/test/javasource/system/UserActionsRegistrar.java +++ b/test/javasource/system/UserActionsRegistrar.java @@ -7,6 +7,98 @@ public class UserActionsRegistrar public void registerActions(IActionRegistrator registrator) { registrator.bundleComponentLoaded(); + registrator.registerUserAction(communitycommons.actions.Base64Decode.class); + registrator.registerUserAction(communitycommons.actions.Base64DecodeToFile.class); + registrator.registerUserAction(communitycommons.actions.Base64Encode.class); + registrator.registerUserAction(communitycommons.actions.Base64EncodeFile.class); + registrator.registerUserAction(communitycommons.actions.Clone.class); + registrator.registerUserAction(communitycommons.actions.commitInSeparateDatabaseTransaction.class); + registrator.registerUserAction(communitycommons.actions.commitWithoutEvents.class); + registrator.registerUserAction(communitycommons.actions.copyAttributes.class); + registrator.registerUserAction(communitycommons.actions.CreateLogNode.class); + registrator.registerUserAction(communitycommons.actions.DateTimeToLong.class); + registrator.registerUserAction(communitycommons.actions.DeepClone.class); + registrator.registerUserAction(communitycommons.actions.Delay.class); + registrator.registerUserAction(communitycommons.actions.deleteAll.class); + registrator.registerUserAction(communitycommons.actions.DuplicateFileDocument.class); + registrator.registerUserAction(communitycommons.actions.DuplicateImageDocument.class); + registrator.registerUserAction(communitycommons.actions.EndTransaction.class); + registrator.registerUserAction(communitycommons.actions.EnumerationFromString.class); + registrator.registerUserAction(communitycommons.actions.EscapeHTML.class); + registrator.registerUserAction(communitycommons.actions.executeMicroflowAsUser.class); + registrator.registerUserAction(communitycommons.actions.executeMicroflowAsUser_1.class); + registrator.registerUserAction(communitycommons.actions.executeMicroflowAsUser_2.class); + registrator.registerUserAction(communitycommons.actions.executeMicroflowInBackground.class); + registrator.registerUserAction(communitycommons.actions.executeMicroflowInBatches.class); + registrator.registerUserAction(communitycommons.actions.executeUnverifiedMicroflowAsUser.class); + registrator.registerUserAction(communitycommons.actions.executeUnverifiedMicroflowAsUser_1.class); + registrator.registerUserAction(communitycommons.actions.executeUnverifiedMicroflowAsUser_2.class); + registrator.registerUserAction(communitycommons.actions.executeUnverifiedMicroflowInBackground.class); + registrator.registerUserAction(communitycommons.actions.executeUnverifiedMicroflowInBatches.class); + registrator.registerUserAction(communitycommons.actions.FileDocumentFromFile.class); + registrator.registerUserAction(communitycommons.actions.FileFromFileDocument.class); + registrator.registerUserAction(communitycommons.actions.GenerateHMAC_SHA256.class); + registrator.registerUserAction(communitycommons.actions.GenerateHMAC_SHA256_hash.class); + registrator.registerUserAction(communitycommons.actions.GetApplicationUrl.class); + registrator.registerUserAction(communitycommons.actions.GetCFInstanceIndex.class); + registrator.registerUserAction(communitycommons.actions.getCreatedByUser.class); + registrator.registerUserAction(communitycommons.actions.GetDefaultLanguage.class); + registrator.registerUserAction(communitycommons.actions.GetFileContentsFromResource.class); + registrator.registerUserAction(communitycommons.actions.getFileSize.class); + registrator.registerUserAction(communitycommons.actions.getGUID.class); + registrator.registerUserAction(communitycommons.actions.GetImageDimensions.class); + registrator.registerUserAction(communitycommons.actions.GetIntFromDateTime.class); + registrator.registerUserAction(communitycommons.actions.getLastChangedByUser.class); + registrator.registerUserAction(communitycommons.actions.GetModelVersion.class); + registrator.registerUserAction(communitycommons.actions.getOriginalValueAsString.class); + registrator.registerUserAction(communitycommons.actions.GetRuntimeVersion.class); + registrator.registerUserAction(communitycommons.actions.getTypeAsString.class); + registrator.registerUserAction(communitycommons.actions.Hash.class); + registrator.registerUserAction(communitycommons.actions.HTMLEncode.class); + registrator.registerUserAction(communitycommons.actions.HTMLToPlainText.class); + registrator.registerUserAction(communitycommons.actions.IsInDevelopment.class); + registrator.registerUserAction(communitycommons.actions.IsStringSimplified.class); + registrator.registerUserAction(communitycommons.actions.ListTop.class); + registrator.registerUserAction(communitycommons.actions.LongToDateTime.class); + registrator.registerUserAction(communitycommons.actions.memberHasChanged.class); + registrator.registerUserAction(communitycommons.actions.MergeMultiplePdfs.class); + registrator.registerUserAction(communitycommons.actions.MonthsBetween.class); + registrator.registerUserAction(communitycommons.actions.objectHasChanged.class); + registrator.registerUserAction(communitycommons.actions.objectIsNew.class); + registrator.registerUserAction(communitycommons.actions.OverlayPdfDocument.class); + registrator.registerUserAction(communitycommons.actions.ParseDateTimeWithTimezone.class); + registrator.registerUserAction(communitycommons.actions.RandomHash.class); + registrator.registerUserAction(communitycommons.actions.RandomString.class); + registrator.registerUserAction(communitycommons.actions.RandomStrongPassword.class); + registrator.registerUserAction(communitycommons.actions.recommitInBatches.class); + registrator.registerUserAction(communitycommons.actions.refreshClass.class); + registrator.registerUserAction(communitycommons.actions.refreshClassByObject.class); + registrator.registerUserAction(communitycommons.actions.RegexQuote.class); + registrator.registerUserAction(communitycommons.actions.RegexReplaceAll.class); + registrator.registerUserAction(communitycommons.actions.RemoveEnd.class); + registrator.registerUserAction(communitycommons.actions.retrieveURL.class); + registrator.registerUserAction(communitycommons.actions.RunMicroflowAsyncInQueue.class); + registrator.registerUserAction(communitycommons.actions.StartTransaction.class); + registrator.registerUserAction(communitycommons.actions.storeURLToFileDocument.class); + registrator.registerUserAction(communitycommons.actions.StringFromFile.class); + registrator.registerUserAction(communitycommons.actions.StringLeftPad.class); + registrator.registerUserAction(communitycommons.actions.StringRightPad.class); + registrator.registerUserAction(communitycommons.actions.StringSimplify.class); + registrator.registerUserAction(communitycommons.actions.StringSplit.class); + registrator.registerUserAction(communitycommons.actions.StringToFile.class); + registrator.registerUserAction(communitycommons.actions.StringTrim.class); + registrator.registerUserAction(communitycommons.actions.SubstituteTemplate.class); + registrator.registerUserAction(communitycommons.actions.SubstituteTemplate2.class); + registrator.registerUserAction(communitycommons.actions.SubstringAfter.class); + registrator.registerUserAction(communitycommons.actions.SubstringAfterLast.class); + registrator.registerUserAction(communitycommons.actions.SubstringBefore.class); + registrator.registerUserAction(communitycommons.actions.SubstringBeforeLast.class); + registrator.registerUserAction(communitycommons.actions.ThrowException.class); + registrator.registerUserAction(communitycommons.actions.ThrowWebserviceException.class); + registrator.registerUserAction(communitycommons.actions.TimeMeasureEnd.class); + registrator.registerUserAction(communitycommons.actions.TimeMeasureStart.class); + registrator.registerUserAction(communitycommons.actions.XSSSanitize.class); + registrator.registerUserAction(communitycommons.actions.YearsBetween.class); registrator.registerUserAction(documentgeneration.actions.JA_DocumentGeneration_Initialize.class); registrator.registerUserAction(documentgeneration.actions.JA_GenerateDocument.class); registrator.registerUserAction(documentgeneration.actions.JA_GetApplicationUrl.class); diff --git a/test/javasource/testmodule/proxies/HeaderFooter.java b/test/javasource/testmodule/proxies/HeaderFooter.java new file mode 100644 index 0000000..55cfe01 --- /dev/null +++ b/test/javasource/testmodule/proxies/HeaderFooter.java @@ -0,0 +1,32 @@ +// This file was generated by Mendix Studio Pro. +// +// WARNING: Code you write here will be lost the next time you deploy the project. + +package testmodule.proxies; + +public enum HeaderFooter +{ + Both(new java.lang.String[][] { new java.lang.String[] { "en_US", "Both" } }), + Header(new java.lang.String[][] { new java.lang.String[] { "en_US", "Header" } }), + Footer(new java.lang.String[][] { new java.lang.String[] { "en_US", "Footer" } }); + + private final java.util.Map captions; + + private HeaderFooter(java.lang.String[][] captionStrings) + { + this.captions = new java.util.HashMap<>(); + for (java.lang.String[] captionString : captionStrings) { + captions.put(captionString[0], captionString[1]); + } + } + + public java.lang.String getCaption(java.lang.String languageCode) + { + return captions.getOrDefault(languageCode, "en_US"); + } + + public java.lang.String getCaption() + { + return captions.get("en_US"); + } +} diff --git a/test/javasource/testmodule/proxies/TestContext.java b/test/javasource/testmodule/proxies/TestContext.java index 98a29c2..93c140a 100644 --- a/test/javasource/testmodule/proxies/TestContext.java +++ b/test/javasource/testmodule/proxies/TestContext.java @@ -20,7 +20,8 @@ public class TestContext */ public enum MemberNames { - Name("Name"); + Name("Name"), + HeaderFooter("HeaderFooter"); private final java.lang.String metaName; @@ -159,6 +160,51 @@ public final void setName(com.mendix.systemwideinterfaces.core.IContext context, getMendixObject().setValue(context, MemberNames.Name.toString(), name); } + /** + * Set value of HeaderFooter + * @param headerfooter + */ + public final testmodule.proxies.HeaderFooter getHeaderFooter() + { + return getHeaderFooter(getContext()); + } + + /** + * @param context + * @return value of HeaderFooter + */ + public final testmodule.proxies.HeaderFooter getHeaderFooter(com.mendix.systemwideinterfaces.core.IContext context) + { + Object obj = getMendixObject().getValue(context, MemberNames.HeaderFooter.toString()); + if (obj == null) { + return null; + } + return testmodule.proxies.HeaderFooter.valueOf((java.lang.String) obj); + } + + /** + * Set value of HeaderFooter + * @param headerfooter + */ + public final void setHeaderFooter(testmodule.proxies.HeaderFooter headerfooter) + { + setHeaderFooter(getContext(), headerfooter); + } + + /** + * Set value of HeaderFooter + * @param context + * @param headerfooter + */ + public final void setHeaderFooter(com.mendix.systemwideinterfaces.core.IContext context, testmodule.proxies.HeaderFooter headerfooter) + { + if (headerfooter != null) { + getMendixObject().setValue(context, MemberNames.HeaderFooter.toString(), headerfooter.toString()); + } else { + getMendixObject().setValue(context, MemberNames.HeaderFooter.toString(), null); + } + } + /** * @return the IMendixObject instance of this proxy for use in the Core interface. */ diff --git a/test/javasource/testmodule/proxies/microflows/Microflows.java b/test/javasource/testmodule/proxies/microflows/Microflows.java index cac7afa..2186818 100644 --- a/test/javasource/testmodule/proxies/microflows/Microflows.java +++ b/test/javasource/testmodule/proxies/microflows/Microflows.java @@ -37,10 +37,10 @@ public static boolean aSu_System(IContext context) Map params = new HashMap<>(); return (java.lang.Boolean) Core.microflowCall("TestModule.ASu_System").withParams(params).execute(context); } - public static void dOC_GenerateDocument(IContext context, testmodule.proxies.TestContext _testContext) + public static void dOC_OpenDocumentGenerationPage(IContext context, testmodule.proxies.TestContext _testContext) { Map params = new HashMap<>(); params.put("TestContext", _testContext == null ? null : _testContext.getMendixObject()); - Core.microflowCall("TestModule.DOC_GenerateDocument").withParams(params).execute(context); + Core.microflowCall("TestModule.DOC_OpenDocumentGenerationPage").withParams(params).execute(context); } } diff --git a/test/themesource/communitycommons/native/design-properties.json b/test/themesource/communitycommons/native/design-properties.json new file mode 100644 index 0000000..49d1a20 --- /dev/null +++ b/test/themesource/communitycommons/native/design-properties.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/test/themesource/communitycommons/native/main.js b/test/themesource/communitycommons/native/main.js new file mode 100644 index 0000000..b611ae1 --- /dev/null +++ b/test/themesource/communitycommons/native/main.js @@ -0,0 +1,2 @@ +import * as variables from "../../../theme/native/custom-variables"; + diff --git a/test/themesource/communitycommons/settings.json b/test/themesource/communitycommons/settings.json new file mode 100644 index 0000000..49d1a20 --- /dev/null +++ b/test/themesource/communitycommons/settings.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/test/themesource/communitycommons/web/design-properties.json b/test/themesource/communitycommons/web/design-properties.json new file mode 100644 index 0000000..49d1a20 --- /dev/null +++ b/test/themesource/communitycommons/web/design-properties.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/test/themesource/communitycommons/web/main.scss b/test/themesource/communitycommons/web/main.scss new file mode 100644 index 0000000..122370f --- /dev/null +++ b/test/themesource/communitycommons/web/main.scss @@ -0,0 +1,2 @@ +@import '../../../theme/web/custom-variables'; + diff --git a/test/userlib/checker-qual-3.8.0.jar b/test/userlib/checker-qual-3.8.0.jar new file mode 100644 index 0000000..d30059e Binary files /dev/null and b/test/userlib/checker-qual-3.8.0.jar differ diff --git a/test/userlib/checker-qual-3.8.0.jar.CommunityCommons.RequiredLib b/test/userlib/checker-qual-3.8.0.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/commons-io-2.11.0.jar.CommunityCommons.RequiredLib b/test/userlib/commons-io-2.11.0.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/commons-lang3-3.12.0.jar.CommunityCommons.RequiredLib b/test/userlib/commons-lang3-3.12.0.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/commons-logging-1.2.jar b/test/userlib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/test/userlib/commons-logging-1.2.jar differ diff --git a/test/userlib/commons-logging-1.2.jar.CommunityCommons.RequiredLib b/test/userlib/commons-logging-1.2.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/commons-text-1.10.0.jar b/test/userlib/commons-text-1.10.0.jar new file mode 100644 index 0000000..beada02 Binary files /dev/null and b/test/userlib/commons-text-1.10.0.jar differ diff --git a/test/userlib/commons-text-1.10.0.jar.CommunityCommons.RequiredLib b/test/userlib/commons-text-1.10.0.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/error_prone_annotations-2.5.1.jar b/test/userlib/error_prone_annotations-2.5.1.jar new file mode 100644 index 0000000..fbc220c Binary files /dev/null and b/test/userlib/error_prone_annotations-2.5.1.jar differ diff --git a/test/userlib/error_prone_annotations-2.5.1.jar.CommunityCommons.RequiredLib b/test/userlib/error_prone_annotations-2.5.1.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/failureaccess-1.0.1.jar b/test/userlib/failureaccess-1.0.1.jar new file mode 100644 index 0000000..9b56dc7 Binary files /dev/null and b/test/userlib/failureaccess-1.0.1.jar differ diff --git a/test/userlib/failureaccess-1.0.1.jar.CommunityCommons.RequiredLib b/test/userlib/failureaccess-1.0.1.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/fontbox-2.0.24.jar b/test/userlib/fontbox-2.0.24.jar new file mode 100644 index 0000000..e93794c Binary files /dev/null and b/test/userlib/fontbox-2.0.24.jar differ diff --git a/test/userlib/fontbox-2.0.24.jar.CommunityCommons.RequiredLib b/test/userlib/fontbox-2.0.24.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/guava-30.1.1-jre.jar b/test/userlib/guava-30.1.1-jre.jar new file mode 100644 index 0000000..93ebf3b Binary files /dev/null and b/test/userlib/guava-30.1.1-jre.jar differ diff --git a/test/userlib/guava-30.1.1-jre.jar.CommunityCommons.RequiredLib b/test/userlib/guava-30.1.1-jre.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/j2objc-annotations-1.3.jar b/test/userlib/j2objc-annotations-1.3.jar new file mode 100644 index 0000000..a429c72 Binary files /dev/null and b/test/userlib/j2objc-annotations-1.3.jar differ diff --git a/test/userlib/j2objc-annotations-1.3.jar.CommunityCommons.RequiredLib b/test/userlib/j2objc-annotations-1.3.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/jsr305-3.0.2.jar b/test/userlib/jsr305-3.0.2.jar new file mode 100644 index 0000000..59222d9 Binary files /dev/null and b/test/userlib/jsr305-3.0.2.jar differ diff --git a/test/userlib/jsr305-3.0.2.jar.CommunityCommons.RequiredLib b/test/userlib/jsr305-3.0.2.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar b/test/userlib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar new file mode 100644 index 0000000..45832c0 Binary files /dev/null and b/test/userlib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar differ diff --git a/test/userlib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar.CommunityCommons.RequiredLib b/test/userlib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/owasp-java-html-sanitizer-20211018.2.jar b/test/userlib/owasp-java-html-sanitizer-20211018.2.jar new file mode 100644 index 0000000..55fcd54 Binary files /dev/null and b/test/userlib/owasp-java-html-sanitizer-20211018.2.jar differ diff --git a/test/userlib/owasp-java-html-sanitizer-20211018.2.jar.CommunityCommons.RequiredLib b/test/userlib/owasp-java-html-sanitizer-20211018.2.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/userlib/pdfbox-2.0.24.jar b/test/userlib/pdfbox-2.0.24.jar new file mode 100644 index 0000000..c6515b8 Binary files /dev/null and b/test/userlib/pdfbox-2.0.24.jar differ diff --git a/test/userlib/pdfbox-2.0.24.jar.CommunityCommons.RequiredLib b/test/userlib/pdfbox-2.0.24.jar.CommunityCommons.RequiredLib new file mode 100644 index 0000000..e69de29 diff --git a/test/widgets/aiden.DocumentLayoutWidget.mpk b/test/widgets/aiden.DocumentLayoutWidget.mpk index 04b40b8..a2f8b86 100644 Binary files a/test/widgets/aiden.DocumentLayoutWidget.mpk and b/test/widgets/aiden.DocumentLayoutWidget.mpk differ