
Call Mothers Entity Set
Call Mothers(1) Entity
{
"Name": "Liz"
}
Create Mother(1) Entity
Delete Mother(1) Entity
{
"Name": "Sarah",
"FatherDetails":[
{
"Name": "Alex"
}
],
"MotherDetails":[
{
"Name": "Anna"
}
]
}
Deep Insert on Child Entity Set
Result of Deep Insert on Child Entity Set
Get Child(FatherId=1, MotherId=2) Entity
{
"Name": "Lena"
}
Put Child(FatherId=1, MotherId=2)
FathersDetails on Child(FatherId=1, MotherId=2) Entity
package com.github.olingo.example.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Objects;
@Entity
@Table(name = "MOTHER")
public class Mother {
@Id
@GeneratedValue
private Long id;
private String name;
private String surname;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Mother mother = (Mother) o;
return Objects.equals(id, mother.id) &&
Objects.equals(name, mother.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
package com.github.olingo.example.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Objects;
@Entity
@Table(name = "FATHER")
public class Father {
@Id
@GeneratedValue
private Long id;
private String name;
private String surname;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Father father = (Father) o;
return Objects.equals(id, father.id) &&
Objects.equals(name, father.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
package com.github.olingo.example.entity;
import javax.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "CHILD")
public class Child {
@EmbeddedId
private ChildPK childPK = new ChildPK();
@ManyToOne(cascade = CascadeType.PERSIST)
@MapsId("fatherId")
private Father father;
@ManyToOne(cascade = CascadeType.PERSIST)
@MapsId("motherId")
private Mother mother;
private String name;
private String surname;
public Child() {
}
public Child(Father father, Mother mother) {
this.childPK = new ChildPK(father, mother);
}
public ChildPK getChildPK() {
return childPK;
}
public void setChildPK(ChildPK childPK) {
this.childPK = childPK;
}
public Father getFather() {
return father;
}
public void setFather(Father father) {
this.father = father;
}
public Mother getMother() {
return mother;
}
public void setMother(Mother mother) {
this.mother = mother;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Child child = (Child) o;
return Objects.equals(childPK, child.childPK) &&
Objects.equals(father, child.father) &&
Objects.equals(mother, child.mother) &&
Objects.equals(name, child.name);
}
@Override
public int hashCode() {
return Objects.hash(childPK, father, mother, name);
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
private ODataResponse postProcessCreateChild(Object createdEntity, PostUriInfo uriParserResultView, String contentType) throws ODataJPARuntimeException, ODataNotFoundException {
Child child = (Child) createdEntity;
if (child.getSurname() == null || child.getSurname().equalsIgnoreCase("")) {
if (child.getMother().getSurname() != null && !child.getMother().getSurname().equalsIgnoreCase("")) {
child.setSurname(child.getMother().getSurname());
} else if (child.getMother().getSurname() != null && !child.getFather().getSurname().equalsIgnoreCase("")) {
child.setSurname(child.getFather().getSurname());
} else {
child.setSurname("Gashi");
}
}
return responseBuilder.build(uriParserResultView, createdEntity, contentType);
}
@Override
public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataJPAModelException, ODataJPARuntimeException, ODataNotFoundException, EdmException, EntityProviderException {
logger.info("POST: Entity {} called", uriParserResultView.getTargetEntitySet().getName());
ODataResponse response = null;
try {
Object createdEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
if (createdEntity.getClass().equals(Child.class)) {
response = postProcessCreateChild(createdEntity, uriParserResultView, contentType);
} else {
response = responseBuilder.build(uriParserResultView, createdEntity, contentType);
}
} finally {
this.close();
}
return response;
}
{
"Name": "Sarah",
"FatherDetails":[
{
"Name": "Alex",
"Surname": "Miller"
}
],
"MotherDetails":[
{
"Name": "Anna",
"Surname": "Berisha"
}
]
}
Create Child Entity with Custom Logic
Read newly created Child Entity with Custom Logic
Edrilan Berisha
SAP S/4HANA Financials Development
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |