ClassName

public final class ClassName

The ClassName util provides several methods which should help for example with getting class name or package from string representation of class. There is also methods related with creating names for repository, service interface and implementation of this service interface.

Methods

getEntityClassName

public static String getEntityClassName(String simpleName)

Retrieves fully qualified entity class name, for the End User Defined Entity.

Parameters:
  • simpleName – the simple class name (without the package)
Returns:

fully qualified class name

getEntityTypeSuffix

public static String getEntityTypeSuffix(String name)

Retrieves entity type suffix from the class name. If the class is neither a history type class, nor a trash type class, it returns empty String.

Parameters:
  • name – class name
Returns:

suffix of an entity type or empty String, if not applicable

getEnumPackage

public static String getEnumPackage(String className)

Returns the package name that contain enum added as a field to a class with a given name.

Parameters:
  • className – name of a class that contain enum field
Returns:

package name of the enum generated for the class

getHistoryClassName

public static String getHistoryClassName(String className)

Retrieves fully qualified history class name, for the given class.

Parameters:
  • className – class name
Returns:

fully qualified history class name

getInterfaceName

public static String getInterfaceName(String className)

Retrieves interface name for the End User Defined Entity or for Developer Defined Entity that do not define their own interface.

Parameters:
  • className – entity class name
Returns:

fully qualified interface name

getPackage

public static String getPackage(String className)

Returns package name from the fully qualified class name. If package cannot be resolved, an empty String will be returned.

Parameters:
  • className – fully qualified class name
Returns:

package name

getRepositoryName

public static String getRepositoryName(String className)

Retrieves repository class name for the given entity class name.

Parameters:
  • className – entity class name
Returns:

fully qualified repository class name

getServiceName

public static String getServiceName(String className)

Retrieves fully qualified class name of the org.motechproject.mds.service.MotechDataService service implementation.

Parameters:
  • className – entity class name
Returns:

fully qualified MDS service implementation name

getSimpleName

public static String getSimpleName(String className)

Returns simple name of the class (without the package prefix), from the given String. If the name is already simple, it will return that name.

Parameters:
  • className – class name
Returns:

simple class name

getTrashClassName

public static String getTrashClassName(String className)

Retrieves fully qualified trash class name, for the given class.

Parameters:
  • className – class name
Returns:

fully qualified trash class name

isHistoryClassName

public static boolean isHistoryClassName(String className)

Verifies whether the given class name matches history class naming pattern.

Parameters:
  • className – class name to verify
Returns:

true, if given class matches history class naming pattern; false otherwise

isTrashClassName

public static boolean isTrashClassName(String className)

Verifies whether the given class name matches trash class naming pattern.

Parameters:
  • className – class name to verify
Returns:

true, if given class matches trash class naming pattern; false otherwise

restId

public static String restId(String entityName, String module, String namespace)

Builds REST id, based on the entity name, module name and namespace.

Parameters:
  • entityName – name of the entity
  • module – name of the module
  • namespace – namespace
Returns:

REST id

restLookupUrl

public static String restLookupUrl(String entityName, String entityModule, String entityNamespace, String lookupMethodName)

Builds URL endpoint, to access lookups via REST, based on the entity name, module, namespace and lookup method name.

Parameters:
  • entityName – name of the entity
  • entityModule – name of the module
  • entityNamespace – namespace
  • lookupMethodName – name of the lookup method
Returns:

URL endpoint for REST lookup

restUrl

public static String restUrl(String entityName, String entityModule, String entityNamespace)

Builds URL endpoint to access REST operations, based on the entity name, module name and namespace.

Parameters:
  • entityName – name of the entity
  • entityModule – name of the module
  • entityNamespace – namespace
Returns:

URL endpoint for REST

simplifiedModuleName

public static String simplifiedModuleName(String moduleName)

Returns simplified name of the module. It will drop the “motech” and “motechplatform” prefix from the module names. Also any blank spaces will be removed.

Parameters:
  • moduleName – module name to simplify
Returns:

simplified module name

trimTrashHistorySuffix

public static String trimTrashHistorySuffix(String name)

Removes entity type suffix from the class name. If the name does not contain entity type suffix, the passed name will be returned.

Parameters:
  • name – class name
Returns:

class name, trimmed from type suffix