I'm using Spring to build a simple Web app. At the front end I have a REST api, which has a PUT method like this: /api/v1/apple/{id}
When the call comes in to this endpoint, the body is deserialised to an Apple.
In the spec for PUT it says: "The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI."
So if apple 21 exists in the DB (and is therefore reachable at /api/v1/apple/21), it should be replaced with the one in the request.
But if it doesn't, a new one should be created, as per the apple in the request, with primary key 21 and URI /api/v1/apple/21.
The problem is that the ReactiveCrudRepository seems not to support this.
According to the release notes, since spring-data r2dbc 1.0.0, if you call save() and the row doesn't exist in the database, it throws a TransientDataAccessException. I see the following:
Failed to updated table [apples]. Row with Id [21] does not exist.
org.springframework.dao.TransientDataAccessResourceException: Failed to updated table [apples]. Row with Id [21] does not exist.
at app//org.springframework.data.r2dbc.core.R2dbcEntityTemplate.lambda$doUpdate$14(R2dbcEntityTemplate.java:707)
.....
So if I supply an ID for my new Apple, I can't create it - at least not using ReactiveCrudRepository. If I remove the ID from the POJO first, it will create it, but with an assigned ID - in other words calling PUT /api/v1/apple/21 will result in creation of an apple, but with some other id (not 21).
What am I missing here? There appear to be no alternatives to the save() method which behave the way I need.
Related
I'm new to ODATA. The examples given in https://olingo.apache.org builds the entityset first and then out of it, it fetches one entity based on the ID passed in the URL. What i need is how to read the entity id from the URL and then build the entity.
Ex: In the request /car.srv/Cars(5), read 5 in the Servlet and then build the entity.
Can someone help me how to do it in Java?
I am using Talend for an integration with salesforce. After some stuffs I want to insert records inside salesforce:
My job is this:
my job works like this:
tSaleforceConnection set the connection:
tSalesforceInput retrieve one row of a given table
tMap is mapping values to create a new record to simulate an insert inside the table
tSalesforceOutput make the insert query,in particular in this component i'm getting this error:
Exception in component tSalesforceOutput_1 (SalesForceConnection)
java.io.IOException: Reason for inactivity is mandatory
What is wrong?
UPDATE
My tSalesforceOutput component:
Is "Inactivity" the target object?
In this case, it seems the field "Reason" is mandatory for this object (or a validation rule checking the field is not null).
Else, can you give a little more information?
TRF
I have a custom object obj__c with external id extId__c in SFDC. Based on the article in https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm I do a /services/data/v40.0/sobjects/obj__c/extId__c/45754?_HttpMethod=PATCH call on Workbench. It updates the the record, if an obj__c with extId 45754 already exists. But if the obj__c doesn't exist then the following error is thrown (Basically Insertion).
message: The extId__c field should not be specified in the sobject data.
errorCode: INVALID_FIELD
there are some changes post API version 37.0, which suggest using POST for insert instead of PATCH. You may try changing version to v36.0(or anything less than 37) , example: /services/data/v36.0/sobjects/obj__c/extId__c/45754?_HttpMethod=PATCH
I finally figured out the issue. I was passing extId__c field in the payload body also, which is forbidden.
In Neo4J, I want to use the bolt protocol.
I installed the 3.1 version of Neo4J.
I my Java project, that already works well with normal HTTP Rest API of Neo4J, I integrate with Maven the needed drivers and achieve to perform request with BOLT.
The problem is everywhere you make a search about bolt they give example like this one :
MATCH (a:Product) return a.name
But I don't want the name, I want all the data of all product, what ever i know or not before what are these columns, like here:
MATCH (a:Product) return * --> here I retrieve only the ids of nodes
I found there https://github.com/neo4j-contrib/neo4j-jdbc/tree/master/neo4j-jdbc-bolt we can "flatten" the result but it seems to not work or I didn't understand how it works:
GraphDatabase.driver( "bolt://localhost:7687/?flatten=-1", AuthTokens.basic( "neo4j", "......." ) );
I put the ?flatten=-1 at the end of my connection address... but that changed nothing.
Anyone can help? Or confirm it's not possible or not working ?
Thanks
Ok I understood my error, I didn’t dig enough in the object returned. So used to have a JSON formatted response, I didn’t see that I have to search in the StatementResult object to find the wanted object with its properties. In fact Eclipse in the “expressions” shows “in fly” only the ids, but inside the object data are there.
Record oneRecord = rs.next();
String src = oneRecord.get("m").get("source");
That way I can reconstruct my object
I have written a program that reads a webservice, retrieving user data, and then is supposed to push that data to ActiveDirectory, thus updating the user's title, address, phone numbers, etc.
The problem is that when I perform the search using the Unboundid Connection class the requested attributes are not returned. Below is the search code:
SearchResult result = connection.search( properties.getProperty("ldap.search.baseDN"),
SearchScope.SUB, "(cn=" + userId + ")",
"personalTitle", "department", "company", "manager", "telephoneNumber",
"streetAddress", "I", "st", "postalCode", "c", "pager", "mobile",
"fax", "cn");
The above code locates the desired user and the cn attribute is returned as expected, but the other attributes all fail to return. If I connect to AD using JXplorer using the same connection credentials, I'm able to see all the desired attributes exist, but are simply not being returned.
I have tried substituting SearchRequest.ALL_OPERATIONAL_ATTRIBUTES, SearchRequest.ALL_USER_ATTRIBUTES and SearchRequest.REQUEST_ATTRS_DEFAULT rather than listing the fields explicitly, but with no success.
I have also looked at the 'Schema' object returned from 'connection.getSchema()' and can see that personalTitle should exist:
connection.getSchema().getAttributeType("personalTitle")
The above code returns:
1.2.840.113556.1.2.615 NAME 'personalTitle' SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' SINGLE-VALUE
So maybe this is a user permission issue? Has anyone experienced this and know how to resolve it?
Thanks,
Mike
LDAP search result entries only include attributes that actually have values, so the behavior you are seeing from the UnboundID LDAP SDK is appropriate and correct. Even if you explicitly request a particular attribute, that attribute will only be included in the entry if it has one or more values.
I think that you're confused by JXplorer because it's reading the schema to determine what attributes could possibly be included in the entry based on its object classes and is showing them to you so that you can set values for those attributes in the editor. But that doesn't mean that the entry returned by the server actually includes any information about those attributes.
To verify this, you can use the ldap-debugger tool provided with the LDAP SDK to see the actual LDAP communication that occurs. Just run a command like:
tools/ldap-debugger --hostname {directory-server-address} \
--port {directory-server-port} --listenPort {listen-port}
This will create a very simple LDAP proxy server that decodes all requests and responses that pass through it. To use it, simply point JXplorer at the specified listen-port. You will see that when JXplorer retrieves the entry, the entry returned by the server will only contain attributes that actually have values.
If you want to figure out what all the possible attributes are that you can include in a given entry, then use the LDAPConnection.getSchema method to retrieve the server schema, then Schema.getObjectClass for each of the object classes in the target entry, and finally use the ObjectClassDefinition.getRequiredAttributes and ObjectClassDefinition.getOptionalAttributes methods to see what attribute types must and may be used in entries with that object class.