Class BeansUtils

java.lang.Object
cz.metacentrum.perun.core.api.BeansUtils

public class BeansUtils extends Object
Beans Utilities.
  • Constructor Details

    • BeansUtils

      public BeansUtils()
  • Method Details

    • getDateFormatter

      public static DateFormat getDateFormatter()
      Method create formatter with default settings for perun timestamps and set lenient on false Timestamp format: "yyyy-MM-dd HH:mm:ss.S" - "ex. 2014-01-01 10:10:10.0" Lenient on false means that formatter will be more strict to creating timestamp from string IMPORTANT: SimpleDateFormat is not thread safe !!!
      Returns:
      date formatter
    • getDateFormatterWithoutTime

      public static DateFormat getDateFormatterWithoutTime()
      Method create formatter with default settings for perun timestamps (only date without time) and set lenient on false. Timestamp format: "yyyy-MM-dd" - "ex. 2014-01-01" Lenient on false means that formatter will be more strict to creating timestamp from string IMPORTANT: SimpleDateFormat is not thread safe !!!
      Returns:
      date formatter
    • eraseEscaping

      public static String eraseEscaping(String text)
      This method take text and for every chars in "<>\" erase escaping also change '\0' to 'null' if it is escaped zero symbol. Escaping char is \. Expecting: Before using this method, text must be escaped by using method createEscaping. So in text will never be string like "\\>", "\" or "\\\". For every \ in text it put \\ and for every < it put \< and for every > it put \>
      Parameters:
      text - text from which will be erase escaping
      Returns:
      nonescaped text
    • createEscaping

      public static String createEscaping(String text)
      This method take text and for every chars in "<>\" create escaping Escaping char is \. For every \\ in text it put \ and for every \< it put < and for every \> it put >
      Parameters:
      text - text from which will be erase escaping
      Returns:
      escaped text
    • replacePointyBracketsByApostrophe

      public static String replacePointyBracketsByApostrophe(String text)
      This method get text and all nonescaped characters < and > replace by apostrophe
      Parameters:
      text -
      Returns:
      text where nonescaped characters < and > will be reaplace by apostrophe '
    • replaceEscapedNullByStringNull

      public static String replaceEscapedNullByStringNull(String text)
      This method get text and all escaped \0 replace for text null
      Parameters:
      text -
      Returns:
      text where \0 is replaced for null
    • isEscaped

      public static boolean isEscaped(String text, int position)
      Return true, if char on position in text is escaped by '\' Return false, if not.
      Parameters:
      text - text in which will be searching
      position - position in text <0-text.length>
      Returns:
      true if char is escaped, false if not
    • attributeValueToString

      public static String attributeValueToString(Object attributeValue, String type)
      Converts attribute value to string (serialize object to string). This is a wrapper for passing value and type only for specific use.
      Parameters:
      attributeValue - value of the attribute
      type - type of resulting attribute
      Returns:
      string representation of the value
      Throws:
      InternalErrorException
      See Also:
    • attributeValueToString

      public static String attributeValueToString(Attribute attribute)
      Converts attribute value to string (for storing into DB)
      Parameters:
      attribute - value of the attribute
      Returns:
      string representation of the value
      Throws:
      InternalErrorException
    • deserializeStringToMap

      public static Map<String,String> deserializeStringToMap(String text)
      This method get map created by example : {=, =} Keys and values are escaped for "\", "<" and ">" Example of escaping key="key\\s\>" is "key\s>" Return Map<String, String> attribute to value.
      Parameters:
      text - text from which will be parsed map
      Returns:
      map<string, string> attributes
    • parseEscapedListValue

      public static List<String> parseEscapedListValue(String value)
      From the given list, parses all values separated by the comma ',' char. The value has to end with the comma ',' char. All escaped commas '{backslash},' will not be used to split the value. If there is a backslash character: * it must be either follow by the comma ',' meaning that this comma is not used for split; or * it must be paired with another backslash '{backslash}{backslash}'. In that case, this double backslash in the result value would be replaced by a single back slash. Example: input: 'value1,val{backslash}ue2,val{backslash},ue3,' result: ['value1', 'val{backslash}ue2', val,ue3']
      Parameters:
      value - value to be parsed
      Returns:
      list of parsed values
    • stringToAttributeValue

      public static Object stringToAttributeValue(String stringValue, String type)
      Converts string representation of an attribute value to correct java object
      Parameters:
      stringValue - string representation of the attribute value
      type - type of the value ("Java.lang.String" for example)/
      Returns:
      Throws:
      InternalErrorException
    • stringToMapOfAttributes

      public static LinkedHashMap<String,String> stringToMapOfAttributes(String attributesAsString)
      Converts string representation of an attribute value to the LinkedHashMap
      Parameters:
      attributesAsString - Map attribute in String representation.
      Returns:
      LinkedHashMap with key values pairs extracted from the input or an empty map when the input parameter is an empty string or null.
    • convertRichBeanNameToBeanName

      public static String convertRichBeanNameToBeanName(String beanName)
      Take perunBean name and if it is RichObject, convert it to simple name. RichObject mean: starts with "Rich" and continue with Upper Letter [A-Z] Ex.: RichGroup -> Group, RichUser -> User Ex.: RichardObject -> RichardObject Ex.: Null -> Null
      Parameters:
      beanName - bean Name of PerunBean (simple name of object)
      Returns:
      converted beanName (without Rich part)
    • prepareInSQLClause

      public static String prepareInSQLClause(String identifier, List<? extends PerunBean> beans)
      Create a string with set of IN clause. Every in clause has maximum 1000 ids. Identifier means for what IN clause is calling (Like 'table.id') Reason for using is compatibility with oracle and other dbs. Example: " ( in (10,15,...) or in (...) or ... ) "
      Parameters:
      beans - list of perun beans
      Returns:
      string with some sql IN clause
    • prepareInSQLClause

      public static String prepareInSQLClause(List<Integer> beansIds, String identifier)
      Create a string with set of IN clause. Every in clause has maximum 1000 ids. Identifier means for what IN clause is calling (Like 'table.id') Reason for using is compatibility with oracle and other dbs. Example: " ( in (10,15,...) or in (...) or ... ) "
      Parameters:
      beansIds - list of perun bean ids
      Returns:
      string with some sql IN clause
    • getPropertyFromCustomConfiguration

      public static String getPropertyFromCustomConfiguration(String propertyFile, String propertyName)
      Gets particular property from custom property file.
      Parameters:
      propertyFile - name of properties file
      propertyName - name of the property
      Returns:
      value of the property
    • getAllPropertiesFromCustomConfiguration

      public static Map<String,String> getAllPropertiesFromCustomConfiguration(String propertyFile)
      Gets all properties from custom property file.
      Parameters:
      propertyFile - name of properties file
      Returns:
      all properties with values
    • isPerunReadOnly

      public static boolean isPerunReadOnly()
      True if this instance of perun is read only. False if not.
      Returns:
      true or false (readOnly or not)
    • initializatorEnabled

      public static boolean initializatorEnabled()
      True if DB initializator is enabled, false if not Default is false
      Returns:
      true if enabled, false if disabled
    • notNull

      public static void notNull(Object e, String name)
      Checks whether the object is null or not.
      Parameters:
      e -
      name -
      Throws:
      InternalErrorException - which wraps NullPointerException
    • setConfig

      public static void setConfig(CoreConfig coreConfig)
      Set configuration that can be later queried by getCoreConfig().
    • getCoreConfig

      public static CoreConfig getCoreConfig()
    • getSinglePair

      public static Pair<Integer,Integer> getSinglePair(Set<Pair<Integer,Integer>> pairs)
    • getSingleId

      public static Integer getSingleId(Set<Pair<Integer,Integer>> pairs)
    • getAttributeDefinitionAbbreviation

      public static String getAttributeDefinitionAbbreviation(AttributeDefinition ad)
      Returns abbreviation in format [Entity]:[V/D/C]:[friendlyName] [Entity] is something like 'U' for user, 'G-R' for group-resource etc.
      Parameters:
      ad - attribute definition
      Returns:
      abbreviation in format [Entity]:[V/D/C]:[friendlyName]
    • parseEntityAbbreviation

      public static String parseEntityAbbreviation(AttributeDefinition ad)
    • getDefaultMailSender

      public static JavaMailSender getDefaultMailSender()
      Return instance of JavaMailSender with shared Perun configuration used to send mail notifications by.
      Returns:
      single instance of JavaMailSender
    • convertRichMemberToCandidate

      public static Candidate convertRichMemberToCandidate(RichMember richMember, UserExtSource primaryUserExtSource)
      Convert object richMember to object candidate. PrimaryUserExtSource is used as the main userExtSource for candidate object
      Parameters:
      richMember -
      primaryUserExtSource - main userExtSource for candidate object
      Returns:
      converted object candidate from richMember
    • additionalIdentifiersIntersection

      public static List<String> additionalIdentifiersIntersection(String firstAdditionalIdentifiers, String secondAdditionalIdentifiers)
      creates an intersection of two additionalIdentifiers arrays given as string.
      Parameters:
      firstAdditionalIdentifiers - first parameter which contains additional identifiers
      secondAdditionalIdentifiers - second parameter which contains additional identifiers
      Returns:
      Intersection of the given String parameters