Class StructureUtil

Object
StructureUtil

@Internal public class StructureUtil extends Object

Contains miscellaneous utility methods.

  • Field Details

    • MAX_PROPERTY_LENGTH

      public static final int MAX_PROPERTY_LENGTH
      See Also:
    • STRING_LONG

      public static final La<String,Long> STRING_LONG
    • INT_ITERATOR_TO_INT

      public static final La<IntIterator,Integer> INT_ITERATOR_TO_INT
    • LONG_ITERATOR_TO_LONG

      public static final La<LongIterator,Long> LONG_ITERATOR_TO_LONG
  • Constructor Details

    • StructureUtil

      public StructureUtil()
  • Method Details

    • applyPermissions

      public static PermissionLevel applyPermissions(List<PermissionRule> permissions, ApplicationUser user, List<Object> stack, La<Long,List<PermissionRule>> resolver, PermissionLevel pass)
    • createJAXBContext

      public static JAXBContext createJAXBContext(Class contextClass)
    • getSingleParameterLong

      @Nullable public static Long getSingleParameterLong(@Nullable Map map, @Nullable String name)
    • getSingleParameterInteger

      @Nullable public static Integer getSingleParameterInteger(@Nullable Map map, @Nullable String name)
    • getSingleParameterBoolean

      public static boolean getSingleParameterBoolean(@Nullable Map map, @Nullable String name)
    • getSingleParameter

      @Nullable public static String getSingleParameter(@Nullable Map map, @Nullable String name)
    • getSingleString

      @Nullable public static String getSingleString(Object r)
    • getSingleLong

      @Nullable public static Long getSingleLong(Object r)
    • getStringList

      @NotNull public static List<String> getStringList(Object r)
    • getMultiParameter

      @NotNull public static List<String> getMultiParameter(@Nullable Map map, @Nullable String name)
    • getMultiParameterLong

      @NotNull public static List<Long> getMultiParameterLong(@Nullable Map map, @Nullable String name)
    • getCommaSeparatedParameter

      @NotNull public static <T> List<T> getCommaSeparatedParameter(@Nullable Map map, @Nullable String name, @NotNull Function<String,T> converter)
    • setLongProperty

      public static void setLongProperty(ApplicationProperties properties, String name, String value)
      Sets a possibly long value (template) as an application property. Because properties may be limited to 255 characters, this method breaks up long property into several properties each no longer than allowed.
      Parameters:
      properties - properties interface
      name - the name of the property
      value - the value
    • getLongProperty

      @NotNull public static String getLongProperty(ApplicationProperties properties, String name)
      Reads a value previously stored in properties using setLongValue
      Parameters:
      properties - application propeties
      name - the name of the property to read
      Returns:
      property value or an empty string
    • getBooleanSystemProperty

      public static boolean getBooleanSystemProperty(String key, boolean defaultValue)
      Similar to Boolean.getBoolean(String), but with ability to specify default value if no value is specified.
    • lastOrZero

      public static long lastOrZero(LongList list)
      Returns the last element of the given list if it's not empty, 0 otherwise.
      Parameters:
      list - the list of longs
      Returns:
      last value of list or 0 if it's empty.
    • listsEqual

      public static boolean listsEqual(LongList list1, LongList list2)
      Tests whether the given lists are equal (contain the same numbers in the same order). An empty list is considered equal to a null list.
      Parameters:
      list1 - the first list
      list2 - the second list
      Returns:
      true if the lists are equal, false otherwise.
    • copyPermissionsOrNull

      @Nullable public static List<PermissionRule> copyPermissionsOrNull(@Nullable Collection<? extends PermissionRule> permissions)
    • copyPermissions

      @NotNull public static List<PermissionRule> copyPermissions(@Nullable Collection<? extends PermissionRule> permissions)
    • getDebugIssueString

      @NotNull public static String getDebugIssueString(@Nullable Long issue)
      Returns a string representation of the issue that is used to write log messages. Writes issue ID and, if possible, issue key.
      Parameters:
      issue - the ID of the issue
      Returns:
      string that can be used in output
    • appendDebugIssueString

      public static StringBuilder appendDebugIssueString(@Nullable Long issue, StringBuilder sb)
    • getDebugIssueKey

      @Nullable public static String getDebugIssueKey(long issueId)
      Returns issue key if possible. Use for debug output.
    • getDebugIssueString

      @NotNull public static String getDebugIssueString(@Nullable Issue issue)
      Returns a string representation of the issue that is used to write log messages. Writes issue ID and, if possible, issue key.
      Parameters:
      issue - the issue
      Returns:
      string that can be used in output
    • issueKeyOrId

      public static String issueKeyOrId(@Nullable Issue issue, @Nullable Long issueId)
      Returns:
      issue key if the issue object is not 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.
    • appendDebugIssueString

      @NotNull public static StringBuilder appendDebugIssueString(@Nullable Long issueId, @Nullable String issueKey, StringBuilder r)
    • appendDebugStructureString

      @NotNull public static StringBuilder appendDebugStructureString(long structureId, StructureManager manager, StringBuilder sb)
    • getDebugStructureString

      public static String getDebugStructureString(long structureId, StructureManager structureManager)
    • username

      @NotNull public static String username(@Nullable ApplicationUser user)
    • debugConstant

      public static String debugConstant(IssueConstant constant)
    • debugAction

      public static String debugAction(ActionDescriptor action)
    • getTextInCurrentUserLocale

      @NotNull public static String getTextInCurrentUserLocale(String key, Object... parameters)
    • getTextInCurrentUserLocale

      @NotNull public static String getTextInCurrentUserLocale(@NotNull I18nText i18nText)
    • getText

      @NotNull public static String getText(@Nullable Locale locale, @Nullable 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:
      1. If locale is not null, it is used.
      2. Otherwise, if user is not null, the user locale (set up in the user preferences) is used.
      3. If both locale and user are null, JIRA default locale is used. In a highly unlikely event when JIRA application parameters are inaccessible, root (neutral) locale is used.
      Parameters:
      messageParameters - can be the same as I18nHelper.getText(String, Object)
    • getJiraDefaultLocale

      @NotNull public static Locale getJiraDefaultLocale()
    • getUserKey

      @Nullable public static String getUserKey(@Nullable ApplicationUser user)
    • getUserName

      @Nullable public static String getUserName(@Nullable ApplicationUser user)
    • getUserByKey

      @Nullable public static ApplicationUser getUserByKey(@Nullable String userKey)
    • getApplicationUserByName

      @Nullable public static ApplicationUser getApplicationUserByName(@Nullable String userName)
    • getUserNameByKey

      @Nullable public static String getUserNameByKey(@Nullable String userKey)
    • migrateUserNameToUserKey

      @Nullable public static String migrateUserNameToUserKey(@Nullable String userName)
    • createRuntimeSignature

      public static int createRuntimeSignature()
      Returns:
      a fairly random number that is used to identify the scope of some other data for external components with longer lifecycle (such as browsers or other addons). The signature is retrieved once per component lifecycle and all other data it provides is valid only within the same signature.
    • getDebugRowString

      public static String getDebugRowString(long row)
    • getDebugRowString

      public static String getDebugRowString(StructureRow row)
    • toJson

      @NotNull public static String toJson(@Nullable Object object)
    • fromJson

      @Nullable public static <T> T fromJson(String specJson, Class<T> expectedClass)
    • fromJson

      @Nullable public static Map<String,Object> fromJson(String json)
    • toMap

      @Nullable public static Map<String,Object> toMap(Object object)
    • setType

      public static <T> Class<Set<T>> setType()
    • mapType

      public static <T, V> Class<Map<T,V>> mapType()
    • listType

      public static <T> Class<List<T>> listType()
    • onlyOneIsTrue

      public static boolean onlyOneIsTrue(boolean... booleans)
    • swap

      public static <T> void swap(List<T> list, int a, int b)
    • warnExceptionIfDebug

      public static void warnExceptionIfDebug(Logger log, String message, Throwable t)
    • getMessageWithCauseChain

      public static String getMessageWithCauseChain(Throwable t)
    • getItemDescription

      @Nullable public static String getItemDescription(ItemIdentity itemId)
    • getItemDisplayable

      @NotNull public static ItemDisplayable getItemDisplayable(@NotNull ItemIdentity itemId, StructureAttributeService attributeService)
    • getItemDisplayable

      @NotNull public static ItemDisplayable getItemDisplayable(@NotNull StructureRow row, StructureAttributeService attributeService)
    • getItemDisplayable

      @NotNull public static Map<ItemIdentity,ItemDisplayable> getItemDisplayable(@NotNull Collection<ItemIdentity> itemIds, StructureAttributeService attributeService)
    • getGroupName

      @Nullable public static String getGroupName(Group group)
    • isMutuallyExclusive

      public static boolean isMutuallyExclusive(LongList list1, LongList list2)
    • isMutuallyExclusive

      public static boolean isMutuallyExclusive(LongSet set1, LongSet set2)
    • toDebugJson

      @NotNull public static String toDebugJson(@Nullable Object object)
    • nn

      public static long nn(@Nullable Long value, long defaultValue)
    • nn

      public static int nn(@Nullable Integer value, int defaultValue)
    • nnv

      @NotNull public static <T> T nnv(@Nullable T value, @NotNull T defaultValue)
    • lv

      public static long lv(String v, long defaultValue)
    • iv

      public static int iv(String v, int defaultValue)
    • lvn

      public static Long lvn(String v)
    • ivn

      public static Integer ivn(String v)
    • nn

      public static String nn(String value)
    • nnl

      public static long nnl(Long value)
    • nni

      public static int nni(Integer value)
    • getBaseUrl

      @NotNull public static String getBaseUrl()
    • decodeURL

      public static String decodeURL(String url)
    • encodeURL

      public static String encodeURL(String url)
    • encodeURIComponent

      public static String encodeURIComponent(String cmp)
    • isSubMap

      public static boolean isSubMap(Map<String,Object> map, Map<String,Object> subMap)
    • isDevMode

      @Internal public static boolean isDevMode()
    • nonBlank

      @NotNull public static String nonBlank(@Nullable String value) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • memoize

      public static <T> Supplier<T> memoize(Supplier<T> supplier)
      Not thread safe