com.almworks.jira.structure.util
Class StructureUtil

java.lang.Object
  extended by com.almworks.jira.structure.util.StructureUtil

public class StructureUtil
extends Object

Contains miscellaneous utility methods.


Field Summary
static long GLOBAL_STRUCTURE_ID
           
static La<com.almworks.integers.IntIterator,Integer> INT_ITERATOR_TO_INT
           
static La<com.almworks.integers.LongIterator,Long> LONG_ITERATOR_TO_LONG
           
static int MAX_PROPERTY_LENGTH
           
static La<String,Long> STRING_LONG
           
 
Constructor Summary
StructureUtil()
           
 
Method Summary
static StringBuilder appendDebugStructureString(StringBuilder sb, long structureId, StructureManager manager)
           
static PermissionLevel applyPermissions(List<PermissionRule> permissions, com.atlassian.crowd.embedded.api.User 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 String debugAction(com.opensymphony.workflow.loader.ActionDescriptor action)
           
static String debugConstant(com.atlassian.jira.issue.IssueConstant constant)
           
static String getDebugIssueKey(long issueId)
          Returns issue key if possible.
static String getDebugIssueString(com.atlassian.jira.issue.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 getDebugStructureString(long structureId, StructureManager manager)
           
static Locale getJiraDefaultLocale()
           
static String getLongProperty(com.atlassian.jira.config.properties.ApplicationProperties properties, String name)
          Reads a value previously stored in properties using setLongValue
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 getText(Locale locale, com.atlassian.crowd.embedded.api.User 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.
static String getTextInCurrentUserLocale(String key, Object... parameters)
           
static com.atlassian.crowd.embedded.api.User getUserByKey(String userKey)
           
static com.atlassian.crowd.embedded.api.User getUserByName(String userName)
           
static String getUserKey(com.atlassian.crowd.embedded.api.User user)
           
static String getUserNameByKey(String userKey)
           
static String issueKeyOrId(com.atlassian.jira.issue.Issue issue, Long issueId)
           
static long lastOrZero(com.almworks.integers.LongList list)
          Returns the last element of the given list if it's not empty, 0 otherwise.
static boolean listsEqual(com.almworks.integers.LongList list1, com.almworks.integers.LongList list2)
          Tests whether the given lists are equal (contain the same numbers in the same order).
static String migrateUserNameToUserKey(String userName)
           
static void setLongProperty(com.atlassian.jira.config.properties.ApplicationProperties properties, String name, String value)
          Sets a possibly long value (template) as an application property.
static String username(com.atlassian.crowd.embedded.api.User user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBAL_STRUCTURE_ID

public static final long GLOBAL_STRUCTURE_ID
See Also:
Constant Field Values

MAX_PROPERTY_LENGTH

public static final int MAX_PROPERTY_LENGTH
See Also:
Constant Field Values

STRING_LONG

public static final La<String,Long> STRING_LONG

INT_ITERATOR_TO_INT

public static final La<com.almworks.integers.IntIterator,Integer> INT_ITERATOR_TO_INT

LONG_ITERATOR_TO_LONG

public static final La<com.almworks.integers.LongIterator,Long> LONG_ITERATOR_TO_LONG
Constructor Detail

StructureUtil

public StructureUtil()
Method Detail

applyPermissions

public static PermissionLevel applyPermissions(List<PermissionRule> permissions,
                                               com.atlassian.crowd.embedded.api.User user,
                                               List<Object> stack,
                                               La<Long,List<PermissionRule>> resolver,
                                               PermissionLevel pass)

createJAXBContext

public static JAXBContext createJAXBContext(Class contextClass)

getSingleParameterLong

public static Long getSingleParameterLong(Map map,
                                          String name)

getSingleParameterInteger

public static Integer getSingleParameterInteger(Map map,
                                                String name)

getSingleParameterBoolean

public static boolean getSingleParameterBoolean(Map map,
                                                String name)

getSingleParameter

public static String getSingleParameter(Map map,
                                        String name)

getMultiParameter

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

getMultiParameterLong

public static List<Long> getMultiParameterLong(Map map,
                                               String name)

setLongProperty

public static void setLongProperty(com.atlassian.jira.config.properties.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

public static String getLongProperty(com.atlassian.jira.config.properties.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

lastOrZero

public static long lastOrZero(com.almworks.integers.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(com.almworks.integers.LongList list1,
                                 com.almworks.integers.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

getDebugIssueKey

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


getDebugIssueString

@NotNull
public static String getDebugIssueString(@Nullable
                                                 com.atlassian.jira.issue.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
                                  com.atlassian.jira.issue.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.

appendDebugStructureString

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

getDebugStructureString

@NotNull
public static String getDebugStructureString(long structureId,
                                                     StructureManager manager)

username

@NotNull
public static String username(@Nullable
                                      com.atlassian.crowd.embedded.api.User user)

debugConstant

public static String debugConstant(com.atlassian.jira.issue.IssueConstant constant)

debugAction

public static String debugAction(com.opensymphony.workflow.loader.ActionDescriptor action)

getTextInCurrentUserLocale

public static String getTextInCurrentUserLocale(String key,
                                                Object... parameters)

getText

public static String getText(@Nullable
                             Locale locale,
                             @Nullable
                             com.atlassian.crowd.embedded.api.User 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

public static Locale getJiraDefaultLocale()

getUserKey

@Nullable
public static String getUserKey(@Nullable
                                         com.atlassian.crowd.embedded.api.User user)

getUserByKey

@Nullable
public static com.atlassian.crowd.embedded.api.User getUserByKey(@Nullable
                                                                          String userKey)

getUserByName

@Nullable
public static com.atlassian.crowd.embedded.api.User getUserByName(@Nullable
                                                                           String userName)

getUserNameByKey

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

migrateUserNameToUserKey

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


Copyright © 2013 ALMWorks. All Rights Reserved.