Package org.mycore.datamodel.metadata
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)
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
public constant value for the MCRObjectID length -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
This method check this data again the input and retuns the result as boolean.boolean
equals
(MCRObjectID in) This method check this data again the input and retuns the result as boolean.static String
Normalizes to a object ID of form project_id_ type_id_ number, where number has leading zeros.static String
Normalizes to a object ID of form project_id_ type_id_ number, where number has leading zeros.getBase()
This method gets the basic string with project_id_ type_id.static String[]
getIDParts
(String id) Splits the submittedid
in its parts.static MCRObjectID
getInstance
(String id) This method instantiate this class with a given identifier in MyCoRe schema.static MCRObjectID
Returns the last ID used or reserved for the given object base type.static MCRObjectID
getNextFreeId
(String baseId) Returns a MCRObjectID from a given base ID string.static MCRObjectID
getNextFreeId
(String baseId, int maxInWorkflow) Returns a MCRObjectID from a given base ID string.static MCRObjectID
getNextFreeId
(String projectId, String type) Returns a MCRObjectID from a given the components of a base ID string.int
This method gets the integer with number.This method gets the string with number.This method get the string with project_id.This method gets the string with type_id.int
hashCode()
returns toString().hashCode()static boolean
Checks if the given id is a valid mycore id in the form of {project}_{object_type}_{number}.static boolean
isValidType
(String type) Check whether the type passed is a valid type in the current mycore environment.Returns a list of available mycore object types.toString()
-
Field Details
-
MAX_LENGTH
public static final int MAX_LENGTHpublic constant value for the MCRObjectID length- See Also:
-
-
Method Details
-
getNextFreeId
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
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_idtype
- The second component of project_id_type_id
-
getNextFreeId
Returns a MCRObjectID from a given base ID string. Same asgetNextFreeId(String)
but the additional parameter acts as a lower limit for integer part of the ID.- Parameters:
baseId
- project_id_type_idmaxInWorkflow
- returned integer part of id will be at leastmaxInWorkflow + 1
-
getLastID
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
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
Normalizes to a object ID of form project_id_ type_id_ number, where number has leading zeros.- Returns:
- project_id_type_id_number
-
formatID
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
Splits the submittedid
in its parts.MyCoRe_document_00000001
would be transformed in { "MyCoRe", "document", "00000001" }- Parameters:
id
- either baseID or complete ID
-
listTypes
Returns a list of available mycore object types. -
isValidType
Check whether the type passed is a valid type in the current mycore environment. That being said propertyMCR.Metadata.Type.<type>
must be set totrue
in mycore.properties.- Parameters:
type
- the type to check- Returns:
- true if valid, false otherwise
-
isValid
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
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
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
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
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
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
This method check this data again the input and retuns the result as boolean. -
compareTo
- Specified by:
compareTo
in interfaceComparable<MCRObjectID>
-
toString
- Overrides:
toString
in classObject
- Returns:
formatID(String, String, int)
withgetProjectId()
,getTypeId()
,getNumberAsInteger()
- See Also:
-
hashCode
public int hashCode()returns toString().hashCode()
-