List<BusinessPartner> businessPartners =
new DefaultBusinessPartnerService()
.getAllBusinessPartner()
.select(BusinessPartner.BUSINESS_PARTNER,
BusinessPartner.LAST_NAME,
BusinessPartner.FIRST_NAME,
BusinessPartner.IS_MALE,
BusinessPartner.IS_FEMALE,
BusinessPartner.CREATION_DATE)
.filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.eq(CATEGORY_PERSON))
.orderBy(BusinessPartner.LAST_NAME, Order.ASC)
.execute();
response.setContentType("application/json");
response.getWriter().write(new Gson().toJson(businessPartners));
List<OperationalAcctgDocItemCube> operationalAcctgDocItemCubes =
new DefaultAccountingDocumentService()
.getAllOperationalAcctgDocItemCube()
.select(OperationalAcctgDocItemCube.COMPANY_CODE,
OperationalAcctgDocItemCube.ACCOUNTING_DOCUMENT,
OperationalAcctgDocItemCube.CUSTOMER)
.filter(OperationalAcctgDocItemCube.IS_CLEARED.eq(false))
.execute();
response.setContentType("application/json");
response.getWriter().write(new Gson().toJson(operationalAcctgDocItemCubes));
[
{
"CompanyCode":"1010",
"AccountingDocument":"9400000020",
"Customer":"10100001"
}
]
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
}
<filter>
<filter-name>RestCsrfPreventionFilter</filter-name>
<filter-class>org.apache.catalina.filters.RestCsrfPreventionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestCsrfPreventionFilter</filter-name>
<url-pattern>/restricted/*</url-pattern>
</filter-mapping>
static class RecastData {
@SerializedName("nlp")
@Expose
private Nlp nlp;
public Nlp getNlp() {
return nlp;
}
}
static class Nlp {
@SerializedName("entities")
@Expose
private Entities entities;
public Entities getEntities() {
return entities;
}
public void setEntities(Entities entities) {
this.entities = entities;
}
}
static class Entities {
@SerializedName("customer_id")
@Expose
private List<CustomerId> customerId = null;
public List<CustomerId> getCustomerId() {
return customerId;
}
public void setCustomerId(List<CustomerId> customerId) {
this.customerId = customerId;
}
}
static class CustomerId {
@SerializedName("value")
@Expose
private String value;
@SerializedName("raw")
@Expose
private String raw;
@SerializedName("confidence")
@Expose
private String confidence;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getRaw() {
return raw;
}
public void setRaw(String raw) {
this.raw = raw;
}
public String getConfidence() {
return confidence;
}
public void setConfidence(String confidence) {
this.confidence = confidence;
}
}
static class TextResponse {
String type = "text";
String content;
public String getResponse() {
Gson gson = new Gson();
return gson.toJson(this);
}
public void setContent(String content) {
this.content = content;
}
}
static class ResponseWrapper {
TextResponse[] replies;
Conversation conversation;
public ResponseWrapper(TextResponse replies) {
this.replies = new TextResponse[]{replies};
this.conversation = new Conversation(new Memory());
}
public String getResponse() {
Gson gson = new Gson();
return gson.toJson(this);
}
public Memory getMemory() {
return conversation.getMemory();
}
public void setMemory(Memory memory) {
this.conversation.setMemory(memory);
}
}
static class Memory {
}
static class Conversation {
Memory memory;
public Conversation(Memory memory) {
this.memory = memory;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}
BufferedReader reader = request.getReader();
Gson gson = new Gson();
RecastData myData = gson.fromJson(reader, RecastData.class);
String custeomerid = myData.getNlp().getEntities().getCustomerId().get(0).getValue();
package com.sap.cloud.sdk.tutorial;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.accountingdocument.OperationalAcctgDocItemCube;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.accountingdocument.OperationalAcctgDocItemCubeFluentHelper;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.AccountingDocumentService;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultAccountingDocumentService;
import org.slf4j.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory;
import com.sap.cloud.sdk.odatav2.connectivity.ODataException;
@WebServlet("/AccgDocs")
public class AccgDocItemServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger logger = CloudLoggerFactory.getLogger(OperationalAcctgDocItemCube.class);
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
try {
List<OperationalAcctgDocItemCube> operationalAcctgDocItemCubes =
new DefaultAccountingDocumentService().getAllOperationalAcctgDocItemCube().select(OperationalAcctgDocItemCube.COMPANY_CODE,
OperationalAcctgDocItemCube.ACCOUNTING_DOCUMENT,
OperationalAcctgDocItemCube.CUSTOMER)
.filter(OperationalAcctgDocItemCube.IS_CLEARED.eq(false))
.execute();
response.setContentType("application/json");
response.getWriter().write(new Gson().toJson(operationalAcctgDocItemCubes));
} catch (final ODataException e) {
logger.error(e.getMessage(), e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write(e.getMessage());
}
}
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
BufferedReader reader = request.getReader();
Gson gson = new Gson();
RecastData myData = gson.fromJson(reader, RecastData.class);
try {
Entities entities = myData.getNlp().getEntities();
String customer_id;
TextResponse textResponse = new TextResponse();
if(entities.getCustomerId()==null){
textResponse.setContent("Mhm, I can't identify this customer");
} else {
customer_id = entities.getCustomerId().get(0).getValue();
List<OperationalAcctgDocItemCube> operationalAcctgDocItemCubes =
new DefaultAccountingDocumentService().getAllOperationalAcctgDocItemCube().select(
OperationalAcctgDocItemCube.COMPANY_CODE,
OperationalAcctgDocItemCube.ACCOUNTING_DOCUMENT)
.filter(OperationalAcctgDocItemCube.CUSTOMER.eq(customer_id))
.execute();
if (operationalAcctgDocItemCubes.size() > 0) {
OperationalAcctgDocItemCube oneDoc = operationalAcctgDocItemCubes.get(0);
textResponse.setContent("There are uncleared documents. For example document " + oneDoc.getAccountingDocument() + " with company " + oneDoc.getCompanyCode());
} else {
textResponse.setContent("There are no uncleared documents! That is great");
}
}
ResponseWrapper responseWrapper = new ResponseWrapper(textResponse);
response.setContentType("application/json");
response.getWriter().println(responseWrapper.getResponse());
} catch (final ODataException e) {
logger.error(e.getMessage(), e);
response.setContentType("application/json");
response.getWriter().write(e.getMessage());
}
}
static class RecastData {
@SerializedName("nlp")
@Expose
private Nlp nlp;
public Nlp getNlp() {
return nlp;
}
}
static class Nlp {
@SerializedName("entities")
@Expose
private Entities entities;
public Entities getEntities() {
return entities;
}
public void setEntities(Entities entities) {
this.entities = entities;
}
}
static class Entities {
@SerializedName("customer_id")
@Expose
private List<CustomerId> customerId = null;
public List<CustomerId> getCustomerId() {
return customerId;
}
public void setCustomerId(List<CustomerId> customerId) {
this.customerId = customerId;
}
}
static class CustomerId {
@SerializedName("value")
@Expose
private String value;
@SerializedName("raw")
@Expose
private String raw;
@SerializedName("confidence")
@Expose
private String confidence;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getRaw() {
return raw;
}
public void setRaw(String raw) {
this.raw = raw;
}
public String getConfidence() {
return confidence;
}
public void setConfidence(String confidence) {
this.confidence = confidence;
}
}
static class TextResponse {
String type = "text";
String content;
public String getResponse() {
Gson gson = new Gson();
return gson.toJson(this);
}
public void setContent(String content) {
this.content = content;
}
}
static class ResponseWrapper {
TextResponse[] replies;
Conversation conversation;
public ResponseWrapper(TextResponse replies) {
this.replies = new TextResponse[]{replies};
this.conversation = new Conversation(new Memory());
}
public String getResponse() {
Gson gson = new Gson();
return gson.toJson(this);
}
public Memory getMemory() {
return conversation.getMemory();
}
public void setMemory(Memory memory) {
this.conversation.setMemory(memory);
}
}
static class Memory {
}
static class Conversation {
Memory memory;
public Conversation(Memory memory) {
this.memory = memory;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |