pub struct Resource { /* private fields */ }Expand description
A Resource is a set of Atoms that shares a single Subject. A Resource only contains valid Values, but it might lack required properties. All changes to the Resource are applied after committing them (e.g. by using).
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn check_required_props(&self, store: &impl Storelike) -> AtomicResult<()>
pub fn check_required_props(&self, store: &impl Storelike) -> AtomicResult<()>
Fetches all ‘required’ properties. Returns an error if any are missing in this Resource.
Sourcepub fn destroy(
&mut self,
store: &impl Storelike,
) -> AtomicResult<CommitResponse>
pub fn destroy( &mut self, store: &impl Storelike, ) -> AtomicResult<CommitResponse>
Removes / deletes the resource from the store by performing a Commit. Recursively deletes the resource’s children.
Sourcepub fn get_children(
&self,
store: &impl Storelike,
) -> AtomicResult<Vec<Resource>>
pub fn get_children( &self, store: &impl Storelike, ) -> AtomicResult<Vec<Resource>>
Gets the children of this resource.
pub fn from_propvals(propvals: PropVals, subject: String) -> Resource
Sourcepub fn get(&self, property_url: &str) -> AtomicResult<&Value>
pub fn get(&self, property_url: &str) -> AtomicResult<&Value>
Get a value by property URL
pub fn get_commit_builder(&self) -> &CommitBuilder
Sourcepub fn get_classes(&self, store: &impl Storelike) -> AtomicResult<Vec<Class>>
pub fn get_classes(&self, store: &impl Storelike) -> AtomicResult<Vec<Class>>
Checks if the classes are there, if not, fetches them. Returns an empty vector if there are no classes found.
Sourcepub fn get_main_class(&self) -> AtomicResult<String>
pub fn get_main_class(&self) -> AtomicResult<String>
Returns the first item of the is_ array
Sourcepub fn get_parent(&self, store: &impl Storelike) -> AtomicResult<Resource>
pub fn get_parent(&self, store: &impl Storelike) -> AtomicResult<Resource>
Returns the Parent of this Resource.
Throws in case of recursion
Sourcepub fn get_parent_tree(
&self,
store: &impl Storelike,
) -> AtomicResult<Vec<Resource>>
pub fn get_parent_tree( &self, store: &impl Storelike, ) -> AtomicResult<Vec<Resource>>
Walks the parent tree upwards until there is no parent, then returns them as a vector.
Sourcepub fn get_propvals(&self) -> &PropVals
pub fn get_propvals(&self) -> &PropVals
Returns all PropVals. Useful if you want to iterate over all Atoms / Properties.
Sourcepub fn get_shortname(
&self,
shortname: &str,
store: &impl Storelike,
) -> AtomicResult<&Value>
pub fn get_shortname( &self, shortname: &str, store: &impl Storelike, ) -> AtomicResult<&Value>
Gets a value by its property shortname or property URL.
pub fn get_subject(&self) -> &String
Sourcepub fn has_parent(&self, store: &impl Storelike, parent: &str) -> bool
pub fn has_parent(&self, store: &impl Storelike, parent: &str) -> bool
checks if a resouce has a specific parent. iterates over all parents.
Sourcepub fn into_propvals(self) -> PropVals
pub fn into_propvals(self) -> PropVals
Returns all PropVals.
pub fn random_subject(store: &impl Storelike) -> String
Sourcepub fn new_generate_subject(store: &impl Storelike) -> Resource
pub fn new_generate_subject(store: &impl Storelike) -> Resource
Create a new resource with a generated Subject
Sourcepub fn new_instance(
class_url: &str,
store: &impl Storelike,
) -> AtomicResult<Resource>
pub fn new_instance( class_url: &str, store: &impl Storelike, ) -> AtomicResult<Resource>
Create a new instance of some Class. The subject is generated, but can be changed. Does not save the resource to the store.
Sourcepub fn push(
&mut self,
property: &str,
value: SubResource,
skip_existing: bool,
) -> AtomicResult<&mut Self>
pub fn push( &mut self, property: &str, value: SubResource, skip_existing: bool, ) -> AtomicResult<&mut Self>
Appends a Resource to a specific property through the commitbuilder. Useful if you want to have compact Commits that add things to existing ResourceArrays.
Sourcepub fn remove_propval(&mut self, property_url: &str)
pub fn remove_propval(&mut self, property_url: &str)
Remove a propval from a resource by property URL.
Sourcepub fn remove_propval_shortname(
&mut self,
property_shortname: &str,
store: &impl Storelike,
) -> AtomicResult<()>
pub fn remove_propval_shortname( &mut self, property_shortname: &str, store: &impl Storelike, ) -> AtomicResult<()>
Remove a propval from a resource by property URL or shortname. Returns error if propval does not exist in this resource or its class.
Sourcepub fn resolve_shortname_to_property(
&self,
shortname: &str,
store: &impl Storelike,
) -> AtomicResult<Property>
pub fn resolve_shortname_to_property( &self, shortname: &str, store: &impl Storelike, ) -> AtomicResult<Property>
Tries to resolve the shortname of a Property to a Property. Currently only tries the shortnames for linked classes - not for other properties.
pub fn reset_commit_builder(&mut self)
Sourcepub fn save(&mut self, store: &impl Storelike) -> AtomicResult<CommitResponse>
pub fn save(&mut self, store: &impl Storelike) -> AtomicResult<CommitResponse>
Saves the resource (with all the changes) to the store by creating a Commit. Uses default Agent to sign the Commit. Stores changes on the Subject’s Server by sending a Commit. Returns the generated Commit, the new Resource and the old Resource.
Sourcepub fn save_locally(
&mut self,
store: &impl Storelike,
) -> AtomicResult<CommitResponse>
pub fn save_locally( &mut self, store: &impl Storelike, ) -> AtomicResult<CommitResponse>
Saves the resource (with all the changes) to the store by creating a Commit. Uses default Agent to sign the Commit. Returns the generated Commit and the new Resource. Does not validate rights / hierarchy. Does not store these changes on the server of the Subject - the Commit will be lost, unless you handle it manually.
Sourcepub fn set_string(
&mut self,
property_url: String,
value: &str,
store: &impl Storelike,
) -> AtomicResult<&mut Self>
pub fn set_string( &mut self, property_url: String, value: &str, store: &impl Storelike, ) -> AtomicResult<&mut Self>
Insert a Property/Value combination. Overwrites existing Property/Value. Validates the datatype.
Sourcepub fn set(
&mut self,
property: String,
value: Value,
store: &impl Storelike,
) -> AtomicResult<&mut Self>
pub fn set( &mut self, property: String, value: Value, store: &impl Storelike, ) -> AtomicResult<&mut Self>
Inserts a Property/Value combination.
Checks datatype.
Overwrites existing.
Adds the change to the commit builder’s set map.
Sourcepub fn set_unsafe(&mut self, property: String, value: Value) -> &mut Self
pub fn set_unsafe(&mut self, property: String, value: Value) -> &mut Self
Does not validate property / datatype combination. Inserts a Property/Value combination. Overwrites existing. Adds it to the CommitBuilder.
Sourcepub fn set_shortname(
&mut self,
property: &str,
value: &str,
store: &impl Storelike,
) -> AtomicResult<&mut Self>
pub fn set_shortname( &mut self, property: &str, value: &str, store: &impl Storelike, ) -> AtomicResult<&mut Self>
Sets a property / value combination. Property can be a shortname (e.g. ‘description’ instead of the full URL). Returns error if propval does not exist in this resource or its class.
Sourcepub fn set_propvals_unsafe(&mut self, propvals: PropVals)
pub fn set_propvals_unsafe(&mut self, propvals: PropVals)
Overwrites all current PropVals. Does not perform validation.
Sourcepub fn set_subject(&mut self, url: String) -> &mut Self
pub fn set_subject(&mut self, url: String) -> &mut Self
Changes the subject of the Resource. Does not ‘move’ the Resource See https://github.com/atomicdata-dev/atomic-server/issues/44
Sourcepub fn to_json_ad(&self) -> AtomicResult<String>
pub fn to_json_ad(&self) -> AtomicResult<String>
Converts Resource to JSON-AD string.
Sourcepub fn to_json(&self, store: &impl Storelike) -> AtomicResult<String>
pub fn to_json(&self, store: &impl Storelike) -> AtomicResult<String>
Converts Resource to plain JSON string.
Sourcepub fn to_json_ld(&self, store: &impl Storelike) -> AtomicResult<String>
pub fn to_json_ld(&self, store: &impl Storelike) -> AtomicResult<String>
Converts Resource to JSON-LD string, with @context object and RDF compatibility.