Class ResearchObject
- java.lang.Object
-
- uk.org.esciencelab.researchobjectservice.researchobject.ResearchObject
-
@Entity public class ResearchObject extends java.lang.Object
A representation of a RO produced by the composer. Links to a ResearchObjectProfile using "profile_name" as the foreign key, which links to the profile's "name". Has JSON "content" which is stored in a Postgres "jsonb" field.
-
-
Constructor Summary
Constructors Constructor Description ResearchObject()
ResearchObject(ResearchObjectProfile profile)
Create an RO with the given profile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendToField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value)
Append the given value to the given list field.void
clearField(java.lang.String field)
Reset the given field to its initial value (from the template).java.lang.String
computeContentSha256()
Compute a SHA-256 checksum of the RO's JSON content.boolean
contentHasChanged()
com.fasterxml.jackson.databind.node.ObjectNode
getContent()
java.lang.String
getContentSha256()
java.util.Date
getCreatedAt()
java.util.Date
getDepositedAt()
java.net.URI
getDepositionUrl()
com.fasterxml.jackson.databind.JsonNode
getField(java.lang.String name)
Get a specific field from the JSON content.java.lang.String
getFriendlyId()
long
getId()
java.util.Date
getModifiedAt()
ResearchObjectProfile
getProfile()
java.lang.String
getProfileName()
boolean
isMutable()
protected void
onCreate()
protected void
onUpdate()
void
patchContent(com.fasterxml.jackson.databind.JsonNode jsonPatch)
Apply a JSON patch to the content.void
setAndValidateContent(com.fasterxml.jackson.databind.node.ObjectNode content)
Set content, but perform validation beforehand.void
setContent(com.fasterxml.jackson.databind.node.ObjectNode content)
Replace RO content without validating first.void
setDepositionUrl(java.net.URI depositionUrl)
void
setField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value)
Set a given field to the given value.void
setProfile(ResearchObjectProfile profile)
Set the profile of the RO.boolean
supportsAppend(java.lang.String field)
Can this field be appended to? (Is it a list?)void
updateContentSha256()
Compute and update the SHA-256 checksum of the content.void
validate()
Validate the RO against its profile.void
validateAndUpdateState()
Validate the RO and mark it as validated.
-
-
-
Constructor Detail
-
ResearchObject
public ResearchObject()
-
ResearchObject
public ResearchObject(ResearchObjectProfile profile)
Create an RO with the given profile. Initializes the content to the skeleton template.- Parameters:
profile
-
-
-
Method Detail
-
getId
public long getId()
-
getFriendlyId
public java.lang.String getFriendlyId()
-
getProfileName
public java.lang.String getProfileName()
-
getProfile
public ResearchObjectProfile getProfile()
-
setProfile
public void setProfile(ResearchObjectProfile profile)
Set the profile of the RO. This will reset the RO's content to the profile's template.- Parameters:
profile
-
-
getContent
public com.fasterxml.jackson.databind.node.ObjectNode getContent()
-
setContent
public void setContent(com.fasterxml.jackson.databind.node.ObjectNode content)
Replace RO content without validating first.- Parameters:
content
-
-
setAndValidateContent
public void setAndValidateContent(com.fasterxml.jackson.databind.node.ObjectNode content) throws ProfileValidationException
Set content, but perform validation beforehand.- Parameters:
content
-- Throws:
ProfileValidationException
-
getContentSha256
public java.lang.String getContentSha256()
-
computeContentSha256
public java.lang.String computeContentSha256() throws java.security.NoSuchAlgorithmException, com.fasterxml.jackson.core.JsonProcessingException
Compute a SHA-256 checksum of the RO's JSON content.- Returns:
- The SHA-256 digest as a hex string.
- Throws:
java.security.NoSuchAlgorithmException
com.fasterxml.jackson.core.JsonProcessingException
-
updateContentSha256
public void updateContentSha256()
Compute and update the SHA-256 checksum of the content.
-
contentHasChanged
public boolean contentHasChanged()
-
getField
public com.fasterxml.jackson.databind.JsonNode getField(java.lang.String name)
Get a specific field from the JSON content.- Parameters:
name
- The name of the field to get.- Returns:
-
setField
public void setField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value) throws ProfileValidationException
Set a given field to the given value.- Parameters:
field
-value
-- Throws:
ProfileValidationException
-
appendToField
public void appendToField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value) throws ProfileValidationException
Append the given value to the given list field.- Parameters:
field
-value
-- Throws:
ProfileValidationException
-
clearField
public void clearField(java.lang.String field)
Reset the given field to its initial value (from the template).- Parameters:
field
-
-
patchContent
public void patchContent(com.fasterxml.jackson.databind.JsonNode jsonPatch) throws java.io.IOException, com.github.fge.jsonpatch.JsonPatchException
Apply a JSON patch to the content.- Parameters:
jsonPatch
-- Throws:
java.io.IOException
com.github.fge.jsonpatch.JsonPatchException
-
supportsAppend
public boolean supportsAppend(java.lang.String field)
Can this field be appended to? (Is it a list?)- Parameters:
field
-- Returns:
-
validate
public void validate() throws ProfileValidationException
Validate the RO against its profile.- Throws:
ProfileValidationException
-
validateAndUpdateState
public void validateAndUpdateState() throws ProfileValidationException
Validate the RO and mark it as validated.- Throws:
ProfileValidationException
-
getDepositionUrl
public java.net.URI getDepositionUrl()
-
setDepositionUrl
public void setDepositionUrl(java.net.URI depositionUrl)
-
isMutable
public boolean isMutable()
-
getCreatedAt
public java.util.Date getCreatedAt()
-
getModifiedAt
public java.util.Date getModifiedAt()
-
getDepositedAt
public java.util.Date getDepositedAt()
-
onCreate
protected void onCreate()
-
onUpdate
protected void onUpdate()
-
-