# Muyan Low Code Development Platform API

By default, the API dependency is already configured in build.gradle under server folder, on your project, if you are installing according to this Document

Please refer to Javadoc Reference (opens new window) for detailed API documentation.

# Public Platform API

Our public platform API is designed to be decoupled from the platform version. This decoupling ensures that changes to the internal platform structure do not necessarily impact the public API, providing stability and backwards compatibility for developers using our API.

Key benefits of this decoupling include:

  1. Version Independence: The public API can maintain its own versioning scheme, separate from the platform's internal versioning.
  2. Stability: Changes to the internal platform implementation can be made without affecting the public API interface.
  3. Flexibility: It allows for the gradual evolution of the public API without forcing immediate changes to the platform core.
  4. Backwards Compatibility: Older versions of the API can be supported even as the platform evolves.

This approach allows us to continuously improve and update our platform while maintaining a consistent and reliable interface for our API users.

# Table of Contents

  1. StorageUtils
  2. QueryHelper
  3. SimpleQuery
  4. DomainHelper
  5. BeanContainer
  6. AsyncHelper
  7. MessageSeverity

# StorageUtils

Utility class for handling file storage operations.

# Methods

# createStorageFileDomain

public static StorageFieldValue createStorageFileDomain(String fileName, String mimeType, InputStream inputStream)

Creates a StorageFieldValue object representing a file in the system.

  • Parameters:
    • fileName: Name of the file to be stored
    • mimeType: MIME type of the file
    • inputStream: InputStream containing the file data
  • Returns: StorageFieldValue object representing the stored file

# QueryHelper

Provides methods for executing database queries using Groovy's Sql class.

# Methods

# withSession

public static <T> T withNewSession(Closure<T> closure)

Executes a closure within the context of a new database session.

# withTransaction

public static <T> T withTransaction(Closure<T> closure)

Executes a closure within the context of a transaction using an existing database session.

# SimpleQuery

A simple query class for performing database queries.

SimpleQuery.of("WorkTask")
.ge("scheduledStartTime", start)
.listAll();
1
2
3

This query retrieves all WorkTask entities with a scheduled start time greater than or equal to the specified start time.

You can also chain multiple conditions together:

SimpleQuery.of("WorkTask")
.eq("assignee", user)
.ge("scheduledStartTime", start)
.lt("scheduledEndTime", end)
.eq("status", "ACTIVE")
.listAll();
1
2
3
4
5
6

In the above example:

  • "assignee" is the assignee user of the WorkTask, make sure to use related object instead of object.id as the match condition.
  • "WorkTask" is the shortName of the DomainClass.
  • "scheduledStartTime" is the name of a field in the DomainClass.

This query retrieves all WorkTask entities with a scheduled start time greater than or equal to the specified start time, a scheduled end time less than the specified end time, and a status equal to "ACTIVE".

# Methods

TIP

For fields of object type (DOMAIN_OBJECT), use object instead of object.id as the matching condition.

# eq(String fieldName, Object value)

Adds an equality condition to the query.

# ne(String fieldName, Object value)

Adds a non-equality condition to the query.

# gt(String fieldName, Object value)

Adds a greater than condition to the query.

# ge(String fieldName, Object value)

Adds a greater than or equal to condition to the query.

# lt(String fieldName, Object value)

Adds a less than condition to the query.

# le(String fieldName, Object value)

Adds a less than or equal to condition to the query.

# iLike(String fieldName, String value)

Adds a case-insensitive like condition to the query.

# notILike(String fieldName, String value)

Adds a case-insensitive not like condition to the query.

# in(String fieldName, Collection<?> value)

Adds an "in" condition to the query.

# notIn(String fieldName, Collection<?> value)

Adds a "not in" condition to the query.

# isNull(String fieldName)

Adds an "is null" condition to the query.

# notNull(String fieldName)

Adds a "not null" condition to the query.

# get()

Executes the query and returns a single result.

# list(int offset, int limit)

Executes the query and returns a paginated result.

# list(int offset, int limit, List<String> orderBy)

Executes the query and returns a paginated result with ordering.

# list(int offset, int limit, List<String> orderBy, boolean asc)

Executes the query and returns a paginated result with ordering and sort direction.

# listAll()

Executes the query and returns all results.

# static SimpleQuery<?> of(String domainName)

Creates a new query for the specified domain.

# static <T> SimpleQuery<T> of(Class<T> clazz)

Creates a new query for the specified class.

# static <T> SimpleQuery<T> of(Class<T> clazz, boolean and)

Creates a new query for the specified class with the specified logical operator.

# static Object getById(String domainName, Long id)

Retrieves an entity by its ID for the specified domain.

# static <T> T getById(Class<T> clazz, Long id)

Retrieves an entity by its ID for the specified class.

# static List<Object> getByIds(String domainName, List<Long> ids)

Retrieves a list of entities by their IDs for the specified domain.

# static <T> List<T> getByIds(Class<T> clazz, List<Long> ids)

Retrieves a list of entities by their IDs for the specified class.

# static List<Object> getAll(String domainName)

Retrieves all entities for the specified domain.

# static <T> List<T> getAll(Class<T> clazz)

Retrieves all entities for the specified class.

# DomainHelper

Provides utility methods for domain object operations.

# Methods

# buildDomain

public static Object buildDomain(String domainName) public static Object buildDomain(String domainName, Object properties)

Builds a domain object with the given name and optional properties.

# createDomain

public static void createDomain(Object requestData)

Creates a domain object with the given request data.

# updateDomain

public static void updateDomain(Object requestData)

Updates a domain object with the given request data.

# deleteDomain

public static void deleteDomain(Object requestData)

Deletes a domain object with the given request data.

# BeanContainer

Manages and retrieves bean instances.

# Methods

# getBean

public static <T> T getBean(Class<T> beanClass)

Retrieves a bean instance by its class type.

# getBeansOfType

public static <T> Collection<T> getBeansOfType(Class<T> beanClass)

Retrieves a collection of beans by their class type.

# registerBean

static void registerBean(Object bean)

Registers a bean instance in the container.

# AsyncHelper

Provides utility methods for asynchronous task execution.

# Methods

# scheduleAtFixRate

public static Runnable scheduleAtFixRate(long period, Runnable runnable)

Schedules a task to run periodically at a fixed rate.

# task

public static void task(Runnable runnable) public static void task(boolean newThread, Runnable runnable)

Executes a task asynchronously, maintaining the current context (e.g., tenant information).

# MessageSeverity

Enum representing different severity levels for messages.

# Enum Values

  • INFO
  • WARNING
  • ERROR
  • IMPORTANT
  • INTERNAL
  • ACTION_REQUIRED

# Methods

# getLabel

Returns the label associated with the severity level.

# get

static MessageSeverity get(String label)

Performs a reverse lookup to get the MessageSeverity enum value from its label.

# MessageHelper

MessageHelper is a utility class for handling message-related operations in the platform. It provides methods for pushing notifications and managing message-related tasks.

# Dependencies

  • tech.muyan.domain.Notification

# Methods

# pushNotification

public static void pushNotification(Notification notification)

Pushes a notification to the platform.

# Parameters
  • notification: The Notification object to be pushed.
# Throws
  • IllegalStateException: If the method is called without proper platform implementation.
# Notes

This method is intended to be provided by the platform implementation dynamically. The tech.muyan:api library should not be included in runtime.

# Usage Example

Notification notification = new Notification();
notification.setContent("New message received");
notification.setToUserName("john.doe");
notification.setSeverity(MessageSeverity.INFO);
try {
    MessageHelper.pushNotification(notification);
} catch (IllegalStateException e) {
    // Handle the case where the platform implementation is not available
    System.err.println("Platform implementation not available: " + e.getMessage());
}
1
2
3
4
5
6
7
8
9
10
Last Updated: 10/26/2024, 9:20:23 AM