Class Util


  • public class Util
    extends Object
    Utility class containing misc methods to perform common tasks
    Author:
    Charles Edward Bedon Cortazar <charles.bedon@kuwaiba.org>
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • getRealValue

        public static Object getRealValue​(String value,
                                          String type)
                                   throws InvalidArgumentException
        Converts a String value to an object value based on a give mapping. This method does not convert binary or relationship-like attributes
        Parameters:
        value - Value as String
        type - The alleged type of the provided value
        Returns:
        the converted value
        Throws:
        InvalidArgumentException - If the type can't be converted
      • getListTypeItemNodes

        public static List<org.neo4j.graphdb.Node> getListTypeItemNodes​(org.neo4j.graphdb.Node listTypeClassNode,
                                                                        List<String> listTypeIds)
        Gets the list type items nodes instances of the provided class and ids
        Parameters:
        listTypeIds - The ids of the list type items nodes to find
        listTypeClassNode - Node the list items are supposed to be instance of
        Returns:
        The corresponding list type item nodes. The ones not found will be ignored
      • releaseRelationships

        public static void releaseRelationships​(org.neo4j.graphdb.Node instance,
                                                RelTypes relationshipType,
                                                org.neo4j.graphdb.Direction relationshipDirection,
                                                String propertyName,
                                                String propertyValue)
        Releases all relationships related to an object given its direction and a relationship's property value
        Parameters:
        instance - Object from/to the relationships are connected
        relationshipType - Relationship type
        relationshipDirection - Relationship Direction
        propertyName - Relationship's property to be used as filter
        propertyValue - Relationship's property value to be used as filter
      • deleteTemplateObject

        public static void deleteTemplateObject​(org.neo4j.graphdb.Node instance)
      • saveFile

        public static void saveFile​(String directory,
                                    String fileName,
                                    byte[] content)
                             throws FileNotFoundException,
                                    IOException
        Saves a file, receiving the file name and the contents as parameters. If the directory structure doesn't exist, it's created
        Parameters:
        directory - path to the directory
        fileName - the file name
        content - the file content
        Throws:
        FileNotFoundException
        IOException
      • createClassMetadataLightFromNode

        public static ClassMetadataLight createClassMetadataLightFromNode​(org.neo4j.graphdb.Node classNode)
        Converts a class metadata node into a ClassMetadataLight object
        Parameters:
        classNode - the class Node
        Returns:
        a class metadata light object
      • createClassMetadataFromNode

        public static ClassMetadata createClassMetadataFromNode​(org.neo4j.graphdb.Node classNode)
        Converts a class metadata node into a ClassMetadata object
        Parameters:
        classNode - a class metadata node
        Returns:
        a class metadata object
      • createAttributeMetadataFromNode

        public static AttributeMetadata createAttributeMetadataFromNode​(org.neo4j.graphdb.Node attributeNode)
        Converts a attribute metadata node into a AttrributeMetadata object
        Parameters:
        attributeNode -
        Returns:
        the attribute as an instance of AttributeMetada class
      • createRemoteObjectLightFromPoolNode

        public static BusinessObjectLight createRemoteObjectLightFromPoolNode​(org.neo4j.graphdb.Node instance)
      • createTaskFromNode

        public static Task createTaskFromNode​(org.neo4j.graphdb.Node taskNode)
      • createProcessInstanceFromNode

        public static ProcessInstance createProcessInstanceFromNode​(org.neo4j.graphdb.Node processInstanceNode)
      • createUserProfileLightFromNode

        public static UserProfileLight createUserProfileLightFromNode​(org.neo4j.graphdb.Node userNode)
        Creates a UserProfileLight object (a user object without privileges) from a node
        Parameters:
        userNode - The source user node
        Returns:
        The UserProfileLight object built with the information of the source node
      • createUserProfileWithoutGroupPrivilegesFromNode

        public static UserProfile createUserProfileWithoutGroupPrivilegesFromNode​(org.neo4j.graphdb.Node userNode)
        Converts a node representing a user into a UserProfile object. The privileges inherited from the group will not be taken into account. See also createUserProfileFromNode.
        Parameters:
        userNode - The source user node
        Returns:
        UserProfile The UserProfile object built with the information of the source node
      • createUserProfileWithGroupPrivilegesFromNode

        public static UserProfile createUserProfileWithGroupPrivilegesFromNode​(org.neo4j.graphdb.Node userNode)
        Converts a node representing a user into a UserProfile object. The privileges inherited from the group will be computed. Note that the user privileges override the group privileges with the same feature token. See also createUserProfileWithoutGroupPrivilegesFromNode.
        Parameters:
        userNode - The source user node
        Returns:
        UserProfile The UserProfile object built with the information of the source node
      • deleteUserNode

        public static void deleteUserNode​(org.neo4j.graphdb.Node userNode)
                                   throws InvalidArgumentException
        Releases all the relationships associated to a user, and deletes the node corresponding to such user. The user "admin" can not be deleted. Historical entry associated to the user to be deleted are NOT deleted, so they can be edited later if necessary.
        Parameters:
        userNode - The user node.
        Throws:
        InvalidArgumentException - If you try to delete the default administrator
      • createGroupProfileFromNode

        public static GroupProfile createGroupProfileFromNode​(org.neo4j.graphdb.Node groupNode)
        Converts a node representing a group into a GroupProfile object
        Parameters:
        groupNode - The source node
        Returns:
        A GroupProfile object built from the source node information
      • createGroupProfileLightFromNode

        public static GroupProfileLight createGroupProfileLightFromNode​(org.neo4j.graphdb.Node groupNode)
        Converts a node representing a group into a GroupProfileLight object
        Parameters:
        groupNode - The source node
        Returns:
        A GroupProfileLight object built from the source node information
      • createPrivilegeFromNode

        public static Privilege createPrivilegeFromNode​(org.neo4j.graphdb.Node privilegeNode)
      • createGenericObjectListFromNode

        public static GenericObjectList createGenericObjectListFromNode​(org.neo4j.graphdb.Node listTypeNode)
                                                                 throws InvalidArgumentException
        Creates a generic object list (a list type) from a node
        Parameters:
        listTypeNode - the list type node
        Returns:
        a list type The specified list type node is malformed and lacks uuid property.
        Throws:
        InvalidArgumentException
      • isSubclassOf

        public static boolean isSubclassOf​(String allegedParentClass,
                                           org.neo4j.graphdb.Node currentNode)
        Traverses the graph up into the class hierarchy trying to find out if a given class is the subclass of another
        Parameters:
        allegedParentClass - The alleged parent class name
        currentNode -
        Returns:
      • isPossibleChild

        public static boolean isPossibleChild​(String allegedParentClass,
                                              org.neo4j.graphdb.Node currentNode)
        Traverses the graph up into the class hierarchy trying to find out if a given class is the possible child of another
        Parameters:
        allegedParentClass - The alleged parent class name
        currentNode -
        Returns:
      • getAllSubclasses

        public static Iterable<org.neo4j.graphdb.Node> getAllSubclasses​(org.neo4j.graphdb.Node classMetadata)
        Retrieves the subclasses of a given class metadata node within the class hierarchy
        Parameters:
        classMetadata - The parent class metadata
        Returns:
        The root node of the list of class metadata nodes
      • getAttributeFromNode

        public static String getAttributeFromNode​(org.neo4j.graphdb.Node objectNode,
                                                  String attribute)
        Retrieves a String with the property value of the attribute if exists as attribute of the node, if the property is a date it is formating into yyyy-MM-DD, if does not exists it return an empty string.
        Parameters:
        objectNode - The object node
        attribute - The name of the attribute. This works only for primitive types
        Returns:
        The string representation of the value of the given attribute
      • getTypeOfAttribute

        public static String getTypeOfAttribute​(org.neo4j.graphdb.Node classNode,
                                                String attributeName)
        Gets the type(String, Integer, Float, Boolean, etc) of an attribute
        Parameters:
        classNode -
        attributeName -
        Returns:
        A string with the type of the attribute
      • getClassName

        public static String getClassName​(org.neo4j.graphdb.Node instance)
        Gets the class name of a given object given its respective node
        Parameters:
        instance - the node to be tested
        Returns:
        The object class name. Null if none
      • changeAttributeTypeIfPrimitive

        public static void changeAttributeTypeIfPrimitive​(org.neo4j.graphdb.Node classNode,
                                                          String attributeName,
                                                          String newAttributeType)
                                                   throws InvalidArgumentException
        Transactions are not handled here
        Parameters:
        classNode -
        attributeName -
        newAttributeType -
        Throws:
        InvalidArgumentException
      • changeAttributeProperty

        public static void changeAttributeProperty​(org.neo4j.graphdb.Node classNode,
                                                   String attributeName,
                                                   String propertyName,
                                                   Object propertyValue)
      • changeAttributeName

        public static void changeAttributeName​(org.neo4j.graphdb.Node classNode,
                                               String oldAttributeName,
                                               String newAttributeName)
        Parameters:
        classNode -
        oldAttributeName -
        newAttributeName -
      • deleteAttributeIfPrimitive

        public static void deleteAttributeIfPrimitive​(org.neo4j.graphdb.Node classNode,
                                                      String attributeName)
      • deleteAttributeIfListType

        public static void deleteAttributeIfListType​(org.neo4j.graphdb.Node classNode,
                                                     String attributeName)
      • createActivityLogEntry

        public static org.neo4j.graphdb.Node createActivityLogEntry​(org.neo4j.graphdb.Node objectNode,
                                                                    String userName,
                                                                    int type,
                                                                    long timestamp,
                                                                    String affectedProperty,
                                                                    String oldValue,
                                                                    String newValue,
                                                                    String notes,
                                                                    org.neo4j.graphdb.GraphDatabaseService graphDb)
                                                             throws ApplicationObjectNotFoundException
        Creates a new log entry upon an action performed by an user.Transactions are not managed here
        Parameters:
        objectNode - The node corresponding to the object that was affected by the action. Null if it's a general activity log entry (that is, it's not related to any specific object)
        userName - User that performed the action
        type -
        timestamp -
        notes -
        oldValue -
        newValue -
        affectedProperty -
        graphDb - A reference to the connection handler.
        Returns:
        Throws:
        ApplicationObjectNotFoundException - If the user or the root of all log entries can't be found
      • convertIfPossible

        public static Object convertIfPossible​(Object oldValue,
                                               String convertTo)
                                        throws InvalidArgumentException
        Tries to convert an attribute value to a new attribute type. It only works with primitive types String, Integer, Float, Boolean, Long, Date and Timestamp
        Parameters:
        oldValue - The old value
        convertTo - The type we want to convert the old value to
        Returns:
        The converted value
        Throws:
        InvalidArgumentException - If it's not possible to perform the conversion
      • formatObjectList

        public static String formatObjectList​(List<BusinessObjectLight> objectList,
                                              boolean startFromTheLast,
                                              int howManyToShow)
        Outputs as a string a list of inventory objects (usually a list of parents in the containment hierarchy)
        Parameters:
        objectList - The list of objects
        startFromTheLast - The output string should start from the first or the last object?
        howManyToShow - How many elements should be displayed? used -1 to show all
        Returns:
        A string with the names of the objects concatenated with a "/" as separator
      • findNodeByLabelAndId

        public static org.neo4j.graphdb.Node findNodeByLabelAndId​(org.neo4j.graphdb.GraphDatabaseService graphDb,
                                                                  org.neo4j.graphdb.Label label,
                                                                  long id)
        Finds a node tagged with a label and with a particular id
        Parameters:
        graphDb - The graphdb handler.
        label - The label used to tag the node
        id - The id of the node to find
        Returns:
        The node or null if no node with with that label and id could be found