Class ResearchObject
- java.lang.Object
-
- uk.org.esciencelab.researchobjectservice.researchobject.ResearchObject
-
@Entity public class ResearchObject extends java.lang.ObjectA 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 voidappendToField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value)Append the given value to the given list field.voidclearField(java.lang.String field)Reset the given field to its initial value (from the template).java.lang.StringcomputeContentSha256()Compute a SHA-256 checksum of the RO's JSON content.booleancontentHasChanged()com.fasterxml.jackson.databind.node.ObjectNodegetContent()java.lang.StringgetContentSha256()java.util.DategetCreatedAt()java.util.DategetDepositedAt()java.net.URIgetDepositionUrl()com.fasterxml.jackson.databind.JsonNodegetField(java.lang.String name)Get a specific field from the JSON content.java.lang.StringgetFriendlyId()longgetId()java.util.DategetModifiedAt()ResearchObjectProfilegetProfile()java.lang.StringgetProfileName()booleanisMutable()protected voidonCreate()protected voidonUpdate()voidpatchContent(com.fasterxml.jackson.databind.JsonNode jsonPatch)Apply a JSON patch to the content.voidsetAndValidateContent(com.fasterxml.jackson.databind.node.ObjectNode content)Set content, but perform validation beforehand.voidsetContent(com.fasterxml.jackson.databind.node.ObjectNode content)Replace RO content without validating first.voidsetDepositionUrl(java.net.URI depositionUrl)voidsetField(java.lang.String field, com.fasterxml.jackson.databind.JsonNode value)Set a given field to the given value.voidsetProfile(ResearchObjectProfile profile)Set the profile of the RO.booleansupportsAppend(java.lang.String field)Can this field be appended to? (Is it a list?)voidupdateContentSha256()Compute and update the SHA-256 checksum of the content.voidvalidate()Validate the RO against its profile.voidvalidateAndUpdateState()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 ProfileValidationExceptionSet 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.JsonProcessingExceptionCompute a SHA-256 checksum of the RO's JSON content.- Returns:
- The SHA-256 digest as a hex string.
- Throws:
java.security.NoSuchAlgorithmExceptioncom.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 ProfileValidationExceptionSet 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 ProfileValidationExceptionAppend 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.JsonPatchExceptionApply a JSON patch to the content.- Parameters:
jsonPatch-- Throws:
java.io.IOExceptioncom.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 ProfileValidationExceptionValidate the RO against its profile.- Throws:
ProfileValidationException
-
validateAndUpdateState
public void validateAndUpdateState() throws ProfileValidationExceptionValidate 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()
-
-