public class StructureUtil extends Object
Contains miscellaneous utility methods.
Modifier and Type | Field and Description |
---|---|
static La<IntIterator,Integer> |
INT_ITERATOR_TO_INT |
static La<LongIterator,Long> |
LONG_ITERATOR_TO_LONG |
static int |
MAX_PROPERTY_LENGTH |
static La<String,Long> |
STRING_LONG |
Constructor and Description |
---|
StructureUtil() |
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
appendDebugIssueString(Long issue,
StringBuilder sb) |
static StringBuilder |
appendDebugIssueString(Long issueId,
String issueKey,
StringBuilder r) |
static StringBuilder |
appendDebugStructureString(long structureId,
StructureManager manager,
StringBuilder sb) |
static PermissionLevel |
applyPermissions(List<PermissionRule> permissions,
ApplicationUser user,
List<Object> stack,
La<Long,List<PermissionRule>> resolver,
PermissionLevel pass) |
static List<PermissionRule> |
copyPermissions(Collection<? extends PermissionRule> permissions) |
static List<PermissionRule> |
copyPermissionsOrNull(Collection<? extends PermissionRule> permissions) |
static JAXBContext |
createJAXBContext(Class contextClass) |
static int |
createRuntimeSignature() |
static String |
debugAction(ActionDescriptor action) |
static String |
debugConstant(IssueConstant constant) |
static String |
decodeURL(String url) |
static ObjectMapper |
defaultMapper() |
static String |
encodeURIComponent(String cmp) |
static String |
encodeURL(String url) |
static Map<String,Object> |
fromJson(String json) |
static <T> T |
fromJson(String specJson,
Class<T> expectedClass) |
static <T> T |
fromJson(String specJson,
Class<T> expectedClass,
ObjectMapper mapper) |
static Map<String,Object> |
fromJson(String json,
ObjectMapper mapper) |
static <T> T |
fromJson(String json,
TypeReference<T> typeRef) |
static <T> T |
fromJson(String json,
TypeReference<T> typeRef,
ObjectMapper mapper) |
static <T> T |
fromMap(Map json,
Class<T> expectedClass) |
static <T> T |
fromMap(Map json,
Class<T> expectedClass,
ObjectMapper mapper) |
static ApplicationUser |
getApplicationUserByName(String userName) |
static String |
getBaseUrl() |
static boolean |
getBooleanSystemProperty(String key,
boolean defaultValue)
Similar to
Boolean.getBoolean(String) , but with ability to specify default value if no value is specified. |
static <T> List<T> |
getCommaSeparatedParameter(Map map,
String name,
Function<String,T> converter) |
static String |
getDebugIssueKey(long issueId)
Returns issue key if possible.
|
static String |
getDebugIssueString(Issue issue)
Returns a string representation of the issue that is used to write log messages.
|
static String |
getDebugIssueString(Long issue)
Returns a string representation of the issue that is used to write log messages.
|
static String |
getDebugRowString(long row) |
static String |
getDebugRowString(StructureRow row) |
static String |
getDebugStructureString(long structureId,
StructureManager structureManager) |
static String |
getGroupName(Group group) |
static String |
getItemDescription(ItemIdentity itemId) |
static Map<ItemIdentity,ItemDisplayable> |
getItemDisplayable(Collection<ItemIdentity> itemIds,
StructureAttributeService attributeService) |
static ItemDisplayable |
getItemDisplayable(ItemIdentity itemId,
StructureAttributeService attributeService) |
static ItemDisplayable |
getItemDisplayable(StructureRow row,
StructureAttributeService attributeService) |
static Locale |
getJiraDefaultLocale() |
static String |
getLongProperty(ApplicationProperties properties,
String name)
Reads a value previously stored in properties using setLongValue
|
static String |
getMessageWithCauseChain(Throwable t) |
static List<String> |
getMultiParameter(Map map,
String name) |
static List<Long> |
getMultiParameterLong(Map map,
String name) |
static String |
getSingleParameter(Map map,
String name) |
static boolean |
getSingleParameterBoolean(Map map,
String name) |
static Integer |
getSingleParameterInteger(Map map,
String name) |
static Long |
getSingleParameterLong(Map map,
String name) |
static String |
getSingleString(Object r) |
static List<String> |
getStringList(Object r) |
static String |
getText(Locale locale,
ApplicationUser user,
String textKey,
Object... messageParameters)
Formats the text taken from the i18n bundle with the specified parameters in the locale that is selected as follows:
If locale is not null, it is used.
Otherwise, if user is not null, the user locale (set up in the user preferences) is used.
If both locale and user are null, JIRA default locale is used.
|
static String |
getTextInCurrentUserLocale(I18nText i18nText) |
static String |
getTextInCurrentUserLocale(String key,
Object... parameters) |
static ApplicationUser |
getUserByKey(String userKey) |
static String |
getUserKey(ApplicationUser user) |
static String |
getUserName(ApplicationUser user) |
static String |
getUserNameByKey(String userKey) |
static boolean |
isDevMode() |
static boolean |
isMutuallyExclusive(LongList list1,
LongList list2) |
static boolean |
isMutuallyExclusive(LongSet set1,
LongSet set2) |
static boolean |
isSubMap(Map<String,Object> map,
Map<String,Object> subMap) |
static String |
issueKeyOrId(Issue issue,
Long issueId) |
static int |
iv(String v,
int defaultValue) |
static Integer |
ivn(String v) |
static long |
lastOrZero(LongList list)
Returns the last element of the given list if it's not empty, 0 otherwise.
|
static boolean |
listsEqual(LongList list1,
LongList list2)
Tests whether the given lists are equal (contain the same numbers in the same order).
|
static <T> Class<List<T>> |
listType() |
static long |
lv(String v,
long defaultValue) |
static Long |
lvn(String v) |
static <T,V> Class<Map<T,V>> |
mapType() |
static <T> Supplier<T> |
memoize(Supplier<T> supplier)
Not thread safe
|
static String |
migrateUserNameToUserKey(String userName) |
static int |
nn(Integer value,
int defaultValue) |
static long |
nn(Long value,
long defaultValue) |
static String |
nn(String value) |
static int |
nni(Integer value) |
static long |
nnl(Long value) |
static <T> T |
nnv(T value,
T defaultValue) |
static String |
nonBlank(String value) |
static boolean |
onlyOneIsTrue(boolean... booleans) |
static void |
setLongProperty(ApplicationProperties properties,
String name,
String value)
Sets a possibly long value (template) as an application property.
|
static <T> Class<Set<T>> |
setType() |
static <T> void |
swap(List<T> list,
int a,
int b) |
static String |
toDebugJson(Object object) |
static String |
toJson(Object object) |
static String |
toJson(Object object,
ObjectMapper mapper) |
static Map<String,Object> |
toMap(Object object) |
static Map<String,Object> |
toMap(Object object,
ObjectMapper mapper) |
static String |
username(ApplicationUser user) |
static void |
warnExceptionIfDebug(Logger log,
String message,
Throwable t) |
static ObjectMapper |
withUnknownPropertiesMapper() |
public static final int MAX_PROPERTY_LENGTH
public static PermissionLevel applyPermissions(List<PermissionRule> permissions, ApplicationUser user, List<Object> stack, La<Long,List<PermissionRule>> resolver, PermissionLevel pass)
public static JAXBContext createJAXBContext(Class contextClass)
@Nullable public static Long getSingleParameterLong(@Nullable Map map, @Nullable String name)
@Nullable public static Integer getSingleParameterInteger(@Nullable Map map, @Nullable String name)
public static boolean getSingleParameterBoolean(@Nullable Map map, @Nullable String name)
@Nullable public static String getSingleParameter(@Nullable Map map, @Nullable String name)
@NotNull public static List<String> getMultiParameter(@Nullable Map map, @Nullable String name)
@NotNull public static List<Long> getMultiParameterLong(@Nullable Map map, @Nullable String name)
@NotNull public static <T> List<T> getCommaSeparatedParameter(@Nullable Map map, @Nullable String name, @NotNull Function<String,T> converter)
public static void setLongProperty(ApplicationProperties properties, String name, String value)
properties
- properties interfacename
- the name of the propertyvalue
- the value@NotNull public static String getLongProperty(ApplicationProperties properties, String name)
properties
- application propetiesname
- the name of the property to readpublic static boolean getBooleanSystemProperty(String key, boolean defaultValue)
Boolean.getBoolean(String)
, but with ability to specify default value if no value is specified.public static long lastOrZero(LongList list)
list
- the list of longslist
or 0 if it's empty.public static boolean listsEqual(LongList list1, LongList list2)
null
list.list1
- the first listlist2
- the second listtrue
if the lists are equal, false
otherwise.@Nullable public static List<PermissionRule> copyPermissionsOrNull(@Nullable Collection<? extends PermissionRule> permissions)
@NotNull public static List<PermissionRule> copyPermissions(@Nullable Collection<? extends PermissionRule> permissions)
@NotNull public static String getDebugIssueString(@Nullable Long issue)
issue
- the ID of the issuepublic static StringBuilder appendDebugIssueString(@Nullable Long issue, StringBuilder sb)
@Nullable public static String getDebugIssueKey(long issueId)
@NotNull public static String getDebugIssueString(@Nullable Issue issue)
issue
- the issuepublic static String issueKeyOrId(@Nullable Issue issue, @Nullable Long issueId)
null
. Otherwise, if issue ID is not null
, returns issue ID in the form "issue #123". Otherwise,
returns string "(no issue ID)".
Better suited for high-level log messages than getDebugIssueString(java.lang.Long)
in that it is easily recognizable as issue representation to JIRA admin.@NotNull public static StringBuilder appendDebugIssueString(@Nullable Long issueId, @Nullable String issueKey, StringBuilder r)
@NotNull public static StringBuilder appendDebugStructureString(long structureId, StructureManager manager, StringBuilder sb)
public static String getDebugStructureString(long structureId, StructureManager structureManager)
@NotNull public static String username(@Nullable ApplicationUser user)
public static String debugConstant(IssueConstant constant)
public static String debugAction(ActionDescriptor action)
@NotNull public static String getTextInCurrentUserLocale(String key, Object... parameters)
@NotNull public static String getTextInCurrentUserLocale(@NotNull I18nText i18nText)
@NotNull public static String getText(@Nullable Locale locale, @Nullable ApplicationUser user, String textKey, Object... messageParameters)
root
(neutral) locale is used.messageParameters
- can be the same as I18nHelper.getText(String, Object)
@NotNull public static Locale getJiraDefaultLocale()
@Nullable public static String getUserKey(@Nullable ApplicationUser user)
@Nullable public static String getUserName(@Nullable ApplicationUser user)
@Nullable public static ApplicationUser getUserByKey(@Nullable String userKey)
@Nullable public static ApplicationUser getApplicationUserByName(@Nullable String userName)
@Nullable public static String migrateUserNameToUserKey(@Nullable String userName)
public static int createRuntimeSignature()
public static String getDebugRowString(long row)
public static String getDebugRowString(StructureRow row)
@Nullable public static <T> T fromJson(String specJson, Class<T> expectedClass, ObjectMapper mapper)
@Nullable public static <T> T fromJson(String json, TypeReference<T> typeRef)
@Nullable public static <T> T fromJson(String json, TypeReference<T> typeRef, ObjectMapper mapper)
@Nullable public static <T> T fromMap(Map json, Class<T> expectedClass, ObjectMapper mapper)
public static ObjectMapper defaultMapper()
public static ObjectMapper withUnknownPropertiesMapper()
public static boolean onlyOneIsTrue(boolean... booleans)
public static <T> void swap(List<T> list, int a, int b)
public static void warnExceptionIfDebug(Logger log, String message, Throwable t)
@Nullable public static String getItemDescription(ItemIdentity itemId)
@NotNull public static ItemDisplayable getItemDisplayable(@NotNull ItemIdentity itemId, StructureAttributeService attributeService)
@NotNull public static ItemDisplayable getItemDisplayable(@NotNull StructureRow row, StructureAttributeService attributeService)
@NotNull public static Map<ItemIdentity,ItemDisplayable> getItemDisplayable(@NotNull Collection<ItemIdentity> itemIds, StructureAttributeService attributeService)
@Nullable public static String getGroupName(Group group)
public static boolean isMutuallyExclusive(LongList list1, LongList list2)
public static boolean isMutuallyExclusive(LongSet set1, LongSet set2)
public static long nn(@Nullable Long value, long defaultValue)
public static int nn(@Nullable Integer value, int defaultValue)
@NotNull public static <T> T nnv(@Nullable T value, @NotNull T defaultValue)
public static long lv(String v, long defaultValue)
public static int iv(String v, int defaultValue)
public static long nnl(Long value)
public static int nni(Integer value)
@NotNull public static String getBaseUrl()
@Internal public static boolean isDevMode()
@NotNull public static String nonBlank(@Nullable String value) throws IllegalArgumentException
IllegalArgumentException
Copyright © 2024 Tempo Software. All Rights Reserved.