Class MCRObjectID

java.lang.Object
org.mycore.datamodel.metadata.MCRObjectID
All Implemented Interfaces:
Comparable<MCRObjectID>

@JsonClassDescription("MyCoRe ObjectID in form {project}_{type}_{int32}, where project is a namespace and type defines the datamodel") public final class MCRObjectID extends Object implements Comparable<MCRObjectID>
This class holds all informations and methods to handle the MyCoRe Object ID. The MyCoRe Object ID is a special ID to identify each metadata object with three parts, they are the project identifier, the type identifier and a string with a number. The syntax of the ID is "projectID_ typeID_ number" as "String_String_Integer".
Version:
$Revision$ $Date$
Author:
Jens Kupferschmidt, Thomas Scheffler (yagee)
  • Field Details

    • MAX_LENGTH

      public static final int MAX_LENGTH
      public constant value for the MCRObjectID length
      See Also:
  • Method Details

    • getNextFreeId

      public static MCRObjectID getNextFreeId(String baseId)
      Returns a MCRObjectID from a given base ID string. A base ID is project_id_type_id. The number is computed by this method. It is the next free number of an item in the database for the given project ID and type ID, with the following additional restriction: The ID returned can be divided by idFormat.numberDistance without remainder. The ID returned minus the last ID returned is at least idFormat.numberDistance. Example for number distance of 1 (default): last ID = 7, next ID = 8 last ID = 8, next ID = 9 Example for number distance of 2: last ID = 7, next ID = 10 last ID = 8, next ID = 10 last ID = 10, next ID = 20
      Parameters:
      baseId - project_id_type_id
    • getNextFreeId

      public static MCRObjectID getNextFreeId(String projectId, String type)
      Returns a MCRObjectID from a given the components of a base ID string. A base ID is project_id_type_id. The number is computed by this method. It is the next free number of an item in the database for the given project ID and type ID, with the following additional restriction: The ID returned can be divided by idFormat.numberDistance without remainder. The ID returned minus the last ID returned is at least idFormat.numberDistance. Example for number distance of 1 (default): last ID = 7, next ID = 8 last ID = 8, next ID = 9 Example for number distance of 2: last ID = 7, next ID = 10 last ID = 8, next ID = 10 last ID = 10, next ID = 20
      Parameters:
      projectId - The first component of project_id_type_id
      type - The second component of project_id_type_id
    • getNextFreeId

      public static MCRObjectID getNextFreeId(String baseId, int maxInWorkflow)
      Returns a MCRObjectID from a given base ID string. Same as getNextFreeId(String) but the additional parameter acts as a lower limit for integer part of the ID.
      Parameters:
      baseId - project_id_type_id
      maxInWorkflow - returned integer part of id will be at least maxInWorkflow + 1
    • getLastID

      public static MCRObjectID getLastID(String baseId)
      Returns the last ID used or reserved for the given object base type.
      Returns:
      a valid MCRObjectID, or null when there is no ID for the given type
    • getInstance

      public static MCRObjectID getInstance(String id)
      This method instantiate this class with a given identifier in MyCoRe schema.
      Parameters:
      id - the MCRObjectID
      Returns:
      an MCRObjectID class instance
      Throws:
      MCRException - if the given identifier is not valid
    • formatID

      public static String formatID(String projectID, String type, int number)
      Normalizes to a object ID of form project_id_ type_id_ number, where number has leading zeros.
      Returns:
      project_id_type_id_number
    • formatID

      public static String formatID(String baseID, int number)
      Normalizes to a object ID of form project_id_ type_id_ number, where number has leading zeros.
      Parameters:
      baseID - is project_id_type_id
      Returns:
      project_id_type_id_number
    • getIDParts

      public static String[] getIDParts(String id)
      Splits the submitted id in its parts. MyCoRe_document_00000001 would be transformed in { "MyCoRe", "document", "00000001" }
      Parameters:
      id - either baseID or complete ID
    • listTypes

      public static List<String> listTypes()
      Returns a list of available mycore object types.
    • isValidType

      public static boolean isValidType(String type)
      Check whether the type passed is a valid type in the current mycore environment. That being said property MCR.Metadata.Type.<type> must be set to true in mycore.properties.
      Parameters:
      type - the type to check
      Returns:
      true if valid, false otherwise
    • isValid

      public static boolean isValid(String id)
      Checks if the given id is a valid mycore id in the form of {project}_{object_type}_{number}.
      Parameters:
      id - the id to check
      Returns:
      true if the id is valid, false otherwise
    • getProjectId

      public String getProjectId()
      This method get the string with project_id. If the ID is not valid, an empty string was returned.
      Returns:
      the string of the project id
    • getTypeId

      public String getTypeId()
      This method gets the string with type_id. If the ID is not valid, an empty string will be returned.
      Returns:
      the string of the type id
    • getNumberAsString

      public String getNumberAsString()
      This method gets the string with number. If the ID is not valid, an empty string will be returned.
      Returns:
      the string of the number
    • getNumberAsInteger

      public int getNumberAsInteger()
      This method gets the integer with number. If the ID is not valid, -1 will be returned.
      Returns:
      the number as integer
    • getBase

      public String getBase()
      This method gets the basic string with project_id_ type_id. If the Id is not valid, an empty string will be returned.
      Returns:
      the string of the schema name
    • equals

      public boolean equals(MCRObjectID in)
      This method check this data again the input and retuns the result as boolean.
      Parameters:
      in - the MCRObjectID to check
      Returns:
      true if all parts are equal, else return false
    • equals

      public boolean equals(Object in)
      This method check this data again the input and retuns the result as boolean.
      Overrides:
      equals in class Object
      Parameters:
      in - the MCRObjectID to check
      Returns:
      true if all parts are equal, else return false.
      See Also:
    • compareTo

      public int compareTo(MCRObjectID o)
      Specified by:
      compareTo in interface Comparable<MCRObjectID>
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      formatID(String, String, int) with getProjectId(), getTypeId(), getNumberAsInteger()
      See Also:
    • hashCode

      public int hashCode()
      returns toString().hashCode()
      Overrides:
      hashCode in class Object
      See Also: