on 02-15-2019 5:41 AM
Hi everyone,
Currently we are working on CRUD operation on onpremise by using white listed API(API_PRODUCT_SRV).
@Override protected Integer run() throws Exception
{
final ODataUpdateResult oDataUpdateResult=service.updateProduct(toUpdate).execute();
return oDataUpdateResult.getHttpStatusCode());
}
Thanks and Regards,
Meenakshi A N
Are you sure that you searched in the whole project and not only in one of the POM files?
Apart from that, kindly increase the version of this dependency to the latest one:
<parent>
<groupId>com.sap.cloud.servicesdk.prov</groupId>
<artifactId>projects-parent-odatav2</artifactId>
<version>1.17.1</version>
</parent>
Check it out on Maven Central:
https://mvnrepository.com/artifact/com.sap.cloud.servicesdk.prov/projects-parent-odatav2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Referring to your statement that you do not have the S/4HANA Cloud SDK dependency in your project:
Kindly search for the string
<groupId>com.sap.cloud.s4hana</groupId>
in your source code. Can you find it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
package my.company;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.productmaster.*;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultProductMasterService;
import com.sap.cloud.sdk.service.prov.api.operations.Read;
import com.sap.cloud.sdk.service.prov.api.operations.Create;
//import com.sap.cloud.sdk.service.prov.api.operations.Delete;
import com.sap.cloud.sdk.service.prov.api.operations.Query;
import com.sap.cloud.sdk.service.prov.api.operations.Update;
import com.sap.cloud.sdk.service.prov.api.response.QueryResponse;
import com.sap.cloud.sdk.service.prov.api.response.ReadResponse;
import com.sap.cloud.sdk.service.prov.api.response.CreateResponse;
//import com.sap.cloud.sdk.service.prov.api.response.DeleteResponse;
import com.sap.cloud.sdk.service.prov.api.response.UpdateResponse;
//import com.sap.cloud.sdk.service.prov.api.response.DeleteResponse;
import com.sap.cloud.sdk.service.prov.api.request.*;
import com.sap.cloud.sdk.odatav2.connectivity.ODataException;
import java.util.*;
import org.modelmapper.ModelMapper;
public class Service {
@Query(serviceName = "ProductService", entity = "Products")
public QueryResponse queryPersons(QueryRequest req) throws ODataException {
System.out.println("Inside @query");
List<Product> result = new GetAllProductsCommand(new DefaultProductMasterService()).execute();
// System.out.println(result);
return QueryResponse.setSuccess().setData(result).response();
}
@Read(serviceName = "ProductService", entity = "Products")
public ReadResponse readPerson(ReadRequest req) throws ODataException {
String key = String.valueOf(req.getKeys().get("Product"));
Product result = new GetProductByKeyCommand(new DefaultProductMasterService(), key).execute();
return ReadResponse.setSuccess().setData(result).response();
}
@Update(serviceName = "ProductService", entity = "Products")
public UpdateResponse updatePerson(UpdateRequest req) throws ODataException {
Product toUpdate = new ModelMapper().map(req.getMapData(), Product.class);
System.out.println(req.getMapData());
System.out.println(toUpdate);
String key = String.valueOf(req.getKeys().get("Product"));
toUpdate.setProduct(key);
System.out.println(toUpdate);
int s=new UpdateProductCommand(new DefaultProductMasterService(), toUpdate).execute();
System.out.println(s);
return UpdateResponse.setSuccess().response();
}
}
Hi Dennis/Marco,
I am using 1.17.1 version of s/4 hana cloud sdk.Please guide me with further actions to make crud operation work currently in onpremise.
Thanks and Regards,
Meenakshi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dennis/Marco,
Correction in the version which I am using for s/4 hana cloud sdk.I have not included any dependency for s/4 hana cloud sdk.Here is my pom.xml file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">;
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sap.cloud.servicesdk.prov</groupId>
<artifactId>projects-parent-odatav2</artifactId>
<version>1.17.1</version>
</parent>
<artifactId>SideBySide_ProductMaster-srv</artifactId>
<groupId>sap</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>SideBySide_ProductMaster-srv</name>
<properties>
<packageName>my.company</packageName>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>npm</executable>
<workingDirectory>${project.basedir}/../</workingDirectory>
</configuration>
<executions>
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<activation>
<property>
<name>devmode</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources combine.children="append">
<resource>
<directory>${project.build.sourceDirectory}</directory>
<targetPath>sources</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
As indicated by Dennis already, pls tell us which version of the S/4HANA Cloud SDK you're using. I suspect that you're not using the latest one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
which version of the SAP S/4HANA Cloud SDK are you using?
Best regards,
Dennis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dahms,
Yes.I have considered Virtual Data Model for OData only. HereBy attaching the entire log file for your perusal.
"msg":"Exception in update Entity","stacktrace":["com.sap.cloud.sdk.service.prov.api.exception.ServiceSDKException: while trying to invoke the method java.lang.Integer.intValue() of a null object returned from my.company.UpdateProductCommand.execute()","\tat com.sap.cloud.sdk.service.prov.api.util.ProcessorHelper.invokeOperation(ProcessorHelper.java:122)","\tat com.sap.cloud.sdk.service.prov.v2.data.provider.CXSDataProvider.updateEntity(CXSDataProvider.java:481)","\tat com.sap.cloud.sdk.service.prov.v2.rt.data.provider.HybridDataProvider.updateEntity(HybridDataProvider.java:284)"
Thanks and regards,
Meenakshi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On a side note: Have you considered using the Virtual Data Model for OData? Is there any particular reason for not using it in your case?
Apart from that:
- Do you see any log entries in the SAP Cloud Connector?
- Do you see any entries in transaction /n/iwfnd/error_log?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.