package cronapi.odata.server;

import cronapi.util.Operations;
import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;

import javax.persistence.EntityManagerFactory;

public class JPAODataServiceFactory extends ODataJPAServiceFactory {

  private final EntityManagerFactory entityManagerFactory;
  private final String namespace;

  public JPAODataServiceFactory(EntityManagerFactory entityManagerFactory, String namespace) {
    this.entityManagerFactory = entityManagerFactory;
    this.namespace = namespace;
  }

  @Override
  public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
    ODataJPAContext context = getODataJPAContext();
    context.setEntityManagerFactory(entityManagerFactory);
    context.setPersistenceUnitName(namespace);

    context.setJPAEdmExtension(new DatasourceExtension(context));
    context.setoDataJPAQueryExtensionEntityListener(new QueryExtensionEntityListener());

    return context;
  }

  @Override
  public ODataService createODataSingleProcessorService(EdmProvider provider, ODataSingleProcessor processor) {
    return super.createODataSingleProcessorService(provider, processor);
  }
}

@@ -24,16 +24,73 @@
 erver;%0A%0A
+import cronapi.ErrorResponse;%0Aimport cronapi.RestClient;%0A
 import c
@@ -1558,11 +1558,283 @@
 or);%0A  %7D
+%0A%0A  @Override%0A  public Exception handleException(Throwable throwable) %7B%0A    String msg = ErrorResponse.getExceptionMessage(throwable, RestClient.getRestClient() != null ? RestClient.getRestClient().getMethod() : %22GET%22);%0A    return new RuntimeException(msg, throwable);%0A  %7D
 %0A%7D%0A

Handle Exception