I need to add a custom ComplexType to one of my Olingo 2.0 entities being scaed and managed by an ODataJPAServiceFactory. The entity type name is "StoreFront" and the ComplexType is called "OwnerEmbedded". I have created the POJO for OwnerEmbedded and added the definition to the schema successfully by implementing a JPAEdmExtension as follows in my StoreFrontExtension:
public class StoreFrontExtension implements JPAEdmExtension {
@Override
public void extendJPAEdmSchema(final JPAEdmSchemaView view) {
Schema edmSchema = view.getEdmSchema();
if(edmSchema.getComplexTypes() == null) {
edmSchema.setComplexTypes(new ArrayList<ComplexType>());
}
edmSchema.getComplexTypes().add(getOwnerType());
}
private ComplexType getOwnerType() {
ComplexType complexType = new ComplexType();
List<Property> properties = new ArrayList<Property>();
SimpleProperty property = new SimpleProperty();
property.setName("FirstName");
property.setType(EdmSimpleTypeKind.String);
properties.add(property);
property = new SimpleProperty();
property.setName("LastName");
property.setType(EdmSimpleTypeKind.String);
properties.add(property);
property = new SimpleProperty();
property.setName("MiddleInitial");
property.setType(EdmSimpleTypeKind.String);
properties.add(property);
complexType.setName("OwnerEmbedded");
complexType.setProperties(properties);
retu complexType;
}
@Override
public void extendWithOperation(final JPAEdmSchemaView view) {
view.registerOperations(StoreFrontProcessor.class, null);
}
@Override
public InputStream getJPAEdmMappingModelStream() {
retu null;
}
}
I have also created a StoreFrontProcessor, like the one in the tutorial, as follows:
public class StoreFrontProcessor {
private EntityManager em;
public StoreFrontProcessor() {
em = Persistence.createEntityManagerFactory("store-front-persistence-updated")
.createEntityManager();
}
@EdmFunctionImport(retuType = @RetuType(type = Type.COMPLEX), entitySet = "StoreFronts" )
public OwnerEmbedded ownerEmbedded(
@EdmFunctionImportParameter(name = "Id", facets = @EdmFacets(nullable = false)) final Long id) {
OwnerEmbedded owner = new OwnerEmbedded();
owner.setFirstName("Test");
owner.setLastName("Test");
owner.setMiddleInitial("T");
retu owner;
}
}
I have tried this code with and without setting the entitySet attribute of @EdmFuncitonImport.
When retrieving the $metadata for the service, the complex type is defined successfully, but StoreFront does not contain a property with it. Furthermore, my debugger never even hits the constructor in the StoreFrontProcessor class. I have followed these specific instructions in the tutorial:
- Created a dependency to EDM Aotation Project.
- Registered the extension with my ODataJPAContext
- Ensured the object type being retued by the function import is named the same as the complex type.
Generally speaking I have followed the tutorials for setting up the ODataJPAServiceFactory and creating custom complex types.
