org.apache.olingo.odata2.api.processor.ODataSingleProcessor Java Examples

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataSingleProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAServiceFactory.java    From lemonaid with MIT License 6 votes vote down vote up
/**
 * Creates an OData Service based on the values set in
 * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} and
 * {@link org.apache.olingo.odata2.api.processor.ODataContext}.
 */
@Override
public final ODataService createService(final ODataContext ctx) throws ODataException {

	oDataContext = ctx;

	// Initialize OData JPA Context
	oDataJPAContext = initializeODataJPAContext();

	validatePreConditions();

	ODataJPAFactory factory = ODataJPAFactory.createFactory();
	ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();

	// OData JPA Processor
	if (oDataJPAContext.getODataContext() == null) {
		oDataJPAContext.setODataContext(ctx);
	}

	ODataSingleProcessor odataJPAProcessor = new ODataJPAProcessor(oDataJPAContext);

	// OData Entity Data Model Provider based on JPA
	EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);

	return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
}
 
Example #2
Source File: ContentNegotiationDollarFormatTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  // service document
  final String contentType = HttpContentType.APPLICATION_ATOM_SVC_UTF8;
  final ODataResponse responseAtomXml =
      ODataResponse.status(HttpStatusCodes.OK).contentHeader(contentType).entity("Test passed.").build();
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          eq(contentType))).thenReturn(responseAtomXml);

  // csv
  final ODataResponse value =
      ODataResponse.status(HttpStatusCodes.OK).contentHeader(CUSTOM_CONTENT_TYPE).entity("any content").build();
  when(((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class), eq("csv")))
      .thenReturn(value);
  when(((CustomContentType) processor).getCustomContentTypes(ServiceDocumentProcessor.class)).thenReturn(
      Arrays.asList("csv"));

  return processor;
}
 
Example #3
Source File: ServiceFactory.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public ODataService createService(ODataContext ctx) throws ODataException
{
   ODataService res = null;

   // Gets the last `root` segment of the URL
   // Stores this value in the `serviceName` variable
   // if the URL is http://dhus.gael.fr/odata/v1/Products/...
   //               \__________________________/\_________...
   //                          ROOT                ODATA
   // serviceName:="v1"
   // The length of the `root` part of the URL can be extended with the servlet's split parameter.
   // see http://http://olingo.apache.org/doc/odata2/index.html
   List<PathSegment> pathSegs = ctx.getPathInfo().getPrecedingSegments();
   String serviceName = pathSegs.get(pathSegs.size() - 1).getPath();

   if (serviceName.equals(SERVICE_NAME))
   {
      EdmProvider edmProvider = new Model();
      ODataSingleProcessor oDataProcessor = new Processor();

      res = createODataSingleProcessorService(edmProvider, oDataProcessor);
   }

   return res;
}
 
Example #4
Source File: LanguageNegotiationTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), anyString()))
      .thenThrow(new MyException(null));
  return processor;
}
 
Example #5
Source File: ErrorResponseTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);

  when(((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
      any(String.class))).thenThrow(new ODataRuntimeException("unit testing"));
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class),
      any(String.class))).thenThrow(
      new ODataRuntimeApplicationException("unit testing", Locale.ROOT, HttpStatusCodes.FORBIDDEN));

  return processor;
}
 
Example #6
Source File: ContextTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
      ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          any(String.class))).thenReturn(ODataResponse.entity("service document").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #7
Source File: UrlRewriteTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
      ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          any(String.class))).thenReturn(ODataResponse.entity("service document").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #8
Source File: FitLoadTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
      ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          any(String.class))).thenReturn(ODataResponse.entity("service document").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #9
Source File: DebugDisabledTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          any(String.class)))
      .thenReturn(
          ODataResponse.entity("<?xml version=\"1.0\" encoding=\"UTF-8\"?><servicedocument/>").status(
              HttpStatusCodes.OK).build());
  return processor;
}
 
Example #10
Source File: AcceptHeaderTypeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  String contentType = "application/atom+xml";
  ODataResponse response =
      ODataResponse.status(HttpStatusCodes.OK).contentHeader(contentType).entity("Test passed.").build();
  when(processor.readEntity(any(GetEntityUriInfo.class), any(String.class))).thenReturn(response);
  when(processor.readEntitySet(any(GetEntitySetUriInfo.class), any(String.class))).thenReturn(response);

  return processor;
}
 
Example #11
Source File: BasicBatchTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataService createService() throws ODataException {
  final EdmProvider provider = createEdmProvider();

  final ODataSingleProcessor processor = createProcessor();

  return new ODataSingleProcessorService(provider, processor) {
    Edm edm = MockFacade.getMockEdm();

    @Override
    public Edm getEntityDataModel() throws ODataException {
      return edm;
    }
  };
}
 
Example #12
Source File: MetadataTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
      ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #13
Source File: BasicHttpTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class)))
      .thenReturn(ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  when(
      ((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
          any(String.class)))
      .thenReturn(ODataResponse.entity("service document").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #14
Source File: CxfCacheUriInfoIssueTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
      ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
  return processor;
}
 
Example #15
Source File: AbstractContentNegotiationTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataService createService() throws ODataException {
  DataContainer dataContainer = new DataContainer();
  dataContainer.init();
  final ODataSingleProcessor processor = new ListsProcessor(new ScenarioDataSource(dataContainer));
  final EdmProvider provider = new ScenarioEdmProvider();
  return new ODataSingleProcessorService(provider, processor) {};
}
 
Example #16
Source File: AbstractRefTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessorService createService() {
  DataContainer dataContainer = new DataContainer();
  dataContainer.reset();
  ODataSingleProcessor processor = new ListsProcessor(new ScenarioDataSource(dataContainer));
  EdmProvider provider = new ScenarioEdmProvider();

  return new ODataSingleProcessorService(provider, processor) {};
}
 
Example #17
Source File: InvalidDataInScenarioTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessorService createService() {
  ODataSingleProcessor processor = new LocalProcessor();
  EdmProvider provider = new ScenarioEdmProvider();

  return new ODataSingleProcessorService(provider, processor) {};
}
 
Example #18
Source File: ODataJPAServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an OData Service based on the values set in
 * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} and
 * {@link org.apache.olingo.odata2.api.processor.ODataContext}.
 */
@Override
public final ODataService createService(final ODataContext ctx) throws ODataException {

  oDataContext = ctx;

  // Initialize OData JPA Context
  oDataJPAContext = initializeODataJPAContext();

  validatePreConditions();

  ODataJPAFactory factory = ODataJPAFactory.createFactory();
  ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();

  // OData JPA Processor
  if (oDataJPAContext.getODataContext() == null) {
    oDataJPAContext.setODataContext(ctx);
  }

  ODataSingleProcessor odataJPAProcessor = createCustomODataProcessor(oDataJPAContext);
  if(odataJPAProcessor == null) {
    odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
  }
  // OData Entity Data Model Provider based on JPA
  EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);

  return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
}
 
Example #19
Source File: AbstractEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public ODataResponse getEntityMedia(GetMediaResourceUriInfo uri_info,
      ODataSingleProcessor processor) throws ODataException
{
   KeyPredicate startKP = uri_info.getKeyPredicates().get(0);
   T t = Navigator.<T>navigate(uri_info.getStartEntitySet(), startKP,
         uri_info.getNavigationSegments(), null);
   ODataResponse resp = t.getEntityMedia(processor);
   if (resp == null)
   {
      throw new ExpectedException("No stream for entity " + getEntityName());
   }
   return resp;
}
 
Example #20
Source File: ODataSingleProcessorServiceTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Before
public void before() throws Exception {
  provider = mock(EdmProvider.class);
  processor = mock(ODataSingleProcessor.class, withSettings().extraInterfaces(CustomContentType.class));
  service = new ODataSingleProcessorService(provider, processor);
}
 
Example #21
Source File: RuntimeDelegateImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
protected ODataService createODataSingleProcessorService(final EdmProvider provider,
    final ODataSingleProcessor processor) {
  return new ODataSingleProcessorService(provider, processor);
}
 
Example #22
Source File: BasicBatchTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  return new TestSingleProc();
}
 
Example #23
Source File: RuntimeDelegate.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected abstract ODataService createODataSingleProcessorService(EdmProvider provider,
ODataSingleProcessor processor);
 
Example #24
Source File: JPAReferenceServiceFactory.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext context) {
  return new CustomODataJPAProcessor(context);
}
 
Example #25
Source File: RequestContentTypeTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  return mock(ODataSingleProcessor.class);
}
 
Example #26
Source File: ODataJPAServiceFactory.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext oDataJPAContext) {
  return null;
}
 
Example #27
Source File: ODataJPAFactoryImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public ODataSingleProcessor createODataProcessor(final ODataJPAContext oDataJPAContext) {
  return new ODataJPADefaultProcessor(oDataJPAContext) { };
}
 
Example #28
Source File: ExceptionsTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  return mock(ODataSingleProcessor.class);
}
 
Example #29
Source File: Node.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ODataResponse getEntityMedia (ODataSingleProcessor processor)
      throws ODataException
{
   initNode ();
   if (hasStream ())
   {
      try
      {
         User u = Security.getCurrentUser();
         String user_name = (u == null ? null : u.getUsername ());
         
         InputStream is = new BufferedInputStream (getStream());
         
         RegulatedInputStream.Builder builder = 
            new RegulatedInputStream.Builder (is, TrafficDirection.OUTBOUND);
         builder.userName (user_name);

         CopyStreamAdapter adapter = new CopyStreamAdapter ();
         CopyStreamListener recorder = new DownloadActionRecordListener (
               this.getId (), this.getName (), u);
         CopyStreamListener closer = new DownloadStreamCloserListener (is);
         adapter.addCopyStreamListener (recorder);
         adapter.addCopyStreamListener (closer);
         builder.copyStreamListener (adapter);
         if (getContentLength ()>0) builder.streamSize(getContentLength());
         is = builder.build();

         String etag = getName () + "-" + getContentLength ();

         // A priori Node never change, so the lastModified should be as
         // far as possible than today.
         long last_modified =  System.currentTimeMillis () - ONE_YEAR_MS;

         // If node is not a data file, it cannot be downloaded and set to -1
         // As a stream exists, this control is probably obsolete.
         long content_length = getContentLength ()==0?-1:getContentLength ();

         return MediaResponseBuilder.prepareMediaResponse(etag, getName(),
            getContentType (), last_modified, content_length,
            processor.getContext (), is);
      }
      catch (Exception e)
      {
         throw new ODataException (
            "An exception occured while creating the stream for node " + 
            getName(), e);
      }
   }
   else
   {
      throw new ODataException ("No stream for node " + getName ());
   }
}
 
Example #30
Source File: HttpExceptionResponseTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  processor = mock(ODataSingleProcessor.class);

  return processor;
}