NEO4J Rest API: Create or update - neo4j

I'm using neo4j 1.8.2. My nodes have a property that I used as an identifier. Is possible update the other properties if a node with that identifier exists or create it otherwise using only one request?

You should index that property and use the index to search for the node and create if not present or update otherwise. See the doc here
It would require two requests though, I'm not sure you can do it only with one using the REST API. You'd probably need to write your extension or plugin (doc here) and perhaps use the
pessimistic locking if you really need a single request.

Related

What is the JSONAPI equivalent of Ruby on Rails Nested Attributes create/update?

We are considering changing our rails app (which relies heavily on Nested Attributes-style data creation) to use JSONAPI instead. However, it seems that JSONAPI may not support this style of document creation/updating?
I've read around and this is sometimes referred to as "compound documents" or "sideposting". My research has been inconclusive, so posting here in hopes that someone out there knows the deal.
For example if in our app we had a Person that has many PhoneNumber, I would like to be able to send a PATCH to /person/1 that had information relating to phone numbers. RoR Nested Attributes allows for sending new phone numbers (ones without an id), modifying existing ones, and deleting existing ones. Is there an equivalent for this in JSONAPI?
If not, how would a client go about submitting this data to the server? A separate request for every object? On some of our pages that could result in 100 plus requests... and each one would need to be managed for errors indivdually?
JSON:API specification v1.0 does not support to create, update or delete more than one resource with one request. So if your server only supports that version of the specification without any custom modification the client would need to submit separate requests for each resource that should be created, updated or deleted. That means the client needs to handle errors for each one individually. This may include rolling back partial changes if one requests fails in a series of related updates.
The missing support for atomic operations is known to be a problematic limitation for some use cases. It should be resolved with the upcoming v1.1. This version is planned to add extensions to the specification. An extension can extend the specification. An extension Atomic Opersions is proposed, which would add support for creating, updating and deleting multiple resources with one request. A client would be able to provide a list of mutations that must be processed in a linear and atomic manner by matter by a server implementing that extension. This means that the modifications are processed in order and will either completely succeed or fail together.

In neo4j 2.x REST API, how to create/get unique nodes using constraints?

This article is a follow-up to the question I posted earlier. The issue is that in neo4j 2.x docs, there is a note to the effect that constraints are recommended for creating or getting unique nodes:
As of Neo4j 2.0, unique constraints have been added. These make Neo4j
enforce the uniqueness, guaranteeing that uniqueness is maintained.
See the section called “Constraints” for details about this. For most
cases, the unique constraints should be used rather than the features
described below.
But in the Constraints sections of the neo4j docs, there is no explanation of how to invoke the REST API to create-or-get a unique node (unique on some label/property combination).
QUESTION: in neo4j 2.0, should I use uniqueness=get_or_create? If not, then what REST API endpoints are recommended for doing this?
Actually the unique constraints and schema indexes are created and maintained with Cypher.
(CREATE/DROP) INDEX ON :Label(property)
The application of the index/constraints happens automatically under the hood when running cypher queries.
MERGE is the get-or-create equivalent.
If you create or update a node with a duplicate property, that update will not happen and you receive an error.

How to setup custom id-field in DB4O

I've read the documentation and samples multiple times and can't find out how to do this.,
I'm trying to wire up DB4O to use my own custom Id field. based on the documentation you can define your own IDs but as far as I can tell they won't replace Db4o's internal IDs, As in it won't actually use those Ids to identify the objects.
Basically all the examples do are tell Db4o to generate some sort of unique id and index it, I don't see anywhere on how to tell it that this is the ID that you should use.
Is it possible to have our own IDs on our model replace the internal IDs used to keep track of the relationships?
we need to have our own Ids since our system relies heavily on REST.
There no direct support for this. You need to create your own mechanism.
Simplest way: Use Guid on .NET. Or use a UUID in Java. In Java: Add UUID-Support: configuration.common().add(new UuidSupport());
Use callback to create new id's. Doesn't not work in TCP client/server.
See also this page.
Side note: You build a REST app. How many request does it need to handle? db4o is internally inherently single threaded. It can only handle a very limited load.

How to handle multiple database accesses?

In my program I have multiple databases. One is fixed and cannot be changed, but there are also some others, the so called user databases.
I thought now I have to start for every database one connection and to connect to each data dictionary. How is it possible to connect to more than one database with one connection by handing over the data dictionary filename? Btw. I am using a local server.
thank you very much,
André
P.S.: Okay I might find the answer to my problem.
The Key word is CreateDDLink. The procedure is connecting to another data dictionary, but before a master dictionary has to be set.
Links may be what you are looking for as you indicated in the question. You can use the API or SQL to create a permanent link alias, or you can dynamically create links on the fly.
I would recomend reviewing this specific help file page: Using Tables from Multiple Data Dictionaries
for a permanent alias (using SQL) look at sp_createlink. You can either create the link to authenticate the current user or set up the link to authenticate as a specific user. Then use the link name in your SQL statements.
select * from linkname.tablename
Or dynamically you can use the following which will authenticate the current user:
select * from "..\dir\otherdd.add".table1
However, links are only available to SQL. If you want to use the table directly (i.e. via a TAdsTable component) you will need to create views. See KB 080519-2034. The KB mentions you can't post updates if the SQL statement for the view results in a static cursor, but you can get around that by creating triggers on the view.

Grails Shiro plugin : confirming my understanding

I'm bit vague about how to start using the shiro plugin, after reading few documents. I decided against Nimble, as it comes with few tables and UI plugins.
I setup shiro plugin with wildcard realm, with my own tables. I may use permission based (rather tan role based) access control as it scales well. Now, the steps for it.
assign the permission string to the subject, and save it in the db
check the permission through isPermitted, hasPermission (or relevant tags in GSP).
Now,
1. when to use the accesscontrol through filter?
2. is there a closure injected into the controller where I can define the permission for the actions in it? I read somewhere about accessControl static closure on each controller, but not seems to be documented.
3. How do I create a typical access control scenario like only the creator of (something, a post etc) can delete it? One possibility is creating and persisting a permission string based on userid. to check the permission retrieve the object (post), get the userid and compare with subject.. seems bit complicated.. any easy implementation?
thanks a lot..
Babu.
1 when to use the access control security filter?
A. Use accessControl{true} when you want to limit access to controller actions to authenticated users.
B. Use accessControl() when you want to limit access to controller actions, regardless of parameter content, based on permissions "${controllerName}:${actionName}".
C. When you want to limit actions based on parameter content, e.g. only delete a domain object for which you have the delete permission "${name}:${id}:delete", you need to check isPermitted explicitly in the controller.
3 How do I create a typical access control scenario like only the
creator?
I would add a the necessary permission(s) to the user when the post is created, e.g. "post:${postId}:*" This way the permissions belong to users and/or roles, and not to arbitrary domain objects, as intended in the Shiro way of working. As opposed to file system permissions, which belong to files and directories instead of users.

Resources