org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo Java Examples

The following examples show how to use org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo. 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: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  if (!appliesFilter(data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final ExpandSelectTreeNode expandSelectTreeNode =
      UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
  ODataResponse odr =
      ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
          .build();

  return odr;
}
 
Example #2
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
    final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  ExpandSelectTreeNode expandSelectTree = null;
  try {
    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
    expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
    entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
    entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
        .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}
 
Example #3
Source File: HttpExceptionResponseTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void genericHttpExceptions() throws Exception {
  disableLogging();

  final List<ODataHttpException> toTestExceptions = getHttpExceptionsForTest();

  int firstKey = 1;
  for (final ODataHttpException oDataException : toTestExceptions) {
    final String key = String.valueOf(firstKey++);
    final Matcher<GetEntityUriInfo> match = new EntityKeyMatcher(key);
    when(processor.readEntity(Matchers.argThat(match), any(String.class))).thenThrow(oDataException);

    final HttpResponse response = executeGetRequest("Managers('" + key + "')");

    assertEquals("Expected status code does not match for exception type '"
        + oDataException.getClass().getSimpleName() + "'.",
        oDataException.getHttpStatus().getStatusCode(), response.getStatusLine().getStatusCode());

    final String content = StringHelper.inputStreamToString(response.getEntity().getContent());
    Map<String, String> prefixMap = new HashMap<String, String>();
    prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
    assertXpathExists("/a:error/a:code", content);
  }

}
 
Example #4
Source File: HttpExceptionResponseTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void test404HttpNotFound() throws Exception {
  when(processor.readEntity(any(GetEntityUriInfo.class), any(String.class))).thenThrow(
      new ODataNotFoundException(ODataNotFoundException.ENTITY));

  final HttpResponse response = executeGetRequest("Managers('199')");
  assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode());

  final String content = StringHelper.inputStreamToString(response.getEntity().getContent());
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
  XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
  assertXpathExists("/a:error/a:code", content);
  assertXpathValuesEqual("\"" + MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText()
      + "\"", "/a:error/a:message", content);
}
 
Example #5
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private GetEntityUriInfo mockURIInfoWithTopSkip(EdmMapping mapping) throws EdmException {
  UriInfo uriInfo = EasyMock.createMock(UriInfo.class);
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  List<KeyPredicate> keyPreds = EasyMock.createMock(ArrayList.class);
  EasyMock.expect(uriInfo.getKeyPredicates()).andStubReturn(keyPreds); 
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(null);
  EasyMock.expect(uriInfo.getTop()).andStubReturn(1);
  EasyMock.expect(uriInfo.getSkip()).andStubReturn(2);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
  EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(Arrays.asList(edmProperty));
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(null);
  EasyMock.replay(edmEntityType, edmEntitySet, uriInfo, keyPreds, edmProperty);
  return uriInfo;
}
 
Example #6
Source File: JPAQueryBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public Query build(GetEntityUriInfo uriInfo) throws ODataJPARuntimeException {
  Query query = null;
  try {
    ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo);
    if (listener != null) {
      query = listener.getQuery(uriInfo, em);
      JPQLContext jpqlContext = JPQLContext.getJPQLContext();
      query = getParameterizedQueryForListeners(jpqlContext, query);
    }
    if (query == null) {
      query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntity);
    }
  } catch (Exception e) {
    throw ODataJPARuntimeException.throwException(
        ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
  } finally {
    JPQLContext.removeJPQLContext();
    ODataExpressionParser.removePositionalParametersThreadLocal();
  }
  return query;
}
 
Example #7
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final ExpandSelectTreeNode expandSelectTreeNode =
      UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());

  return ODataResponse.fromResponse(writeEntry(entitySet, expandSelectTreeNode, data, contentType))
      .build();
}
 
Example #8
Source File: AcceptHeaderTypeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private HttpResponse testGetRequest(final String uriExtension, final String acceptHeader,
    final HttpStatusCodes expectedStatus, final String expectedContentType)
    throws ClientProtocolException, IOException, ODataException {
  // prepare
  ODataResponse expectedResponse = ODataResponse.contentHeader(expectedContentType).entity("Test passed.").build();
  when(processor.readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(expectedResponse);
  when(processor.readEntity(any(GetEntityUriInfo.class), any(String.class))).thenReturn(expectedResponse);
  when(processor.readEntitySet(any(GetEntitySetUriInfo.class), any(String.class))).thenReturn(expectedResponse);

  HttpGet getRequest = new HttpGet(URI.create(getEndpoint().toString() + uriExtension));
  getRequest.setHeader(HttpHeaders.ACCEPT, acceptHeader);

  // execute
  HttpResponse response = getHttpClient().execute(getRequest);

  // validate
  assertEquals(expectedStatus.getStatusCode(), response.getStatusLine().getStatusCode());
  Header[] contentTypeHeaders = response.getHeaders("Content-Type");
  assertEquals("Found more then one content type header in response.", 1, contentTypeHeaders.length);
  assertEquals("Received content type does not match expected.", expectedContentType, contentTypeHeaders[0]
      .getValue());
  assertEquals("Received status code does not match expected.", expectedStatus.getStatusCode(), response
      .getStatusLine().getStatusCode());
  //
  return response;
}
 
Example #9
Source File: JPQLBuilderFactoryTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private GetEntityUriInfo getEntityUriInfo() throws EdmException {
  GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(edmEntityType.getName()).andStubReturn("");
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
  EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
  EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
  EasyMock.expect(getEntityView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
  EasyMock.replay(startEdmEntityType, startEdmEntitySet);
  EasyMock.replay(edmEntityType, edmEntitySet);
  EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
  List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(getEntityView.getNavigationSegments()).andStubReturn(navigationSegments);
  EasyMock.replay(getEntityView);
  return getEntityView;
}
 
Example #10
Source File: InvalidDataInScenarioTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
  HashMap<String, Object> data = new HashMap<String, Object>();

  if ("Employees".equals(uriInfo.getTargetEntitySet().getName())) {
    if ("2".equals(uriInfo.getKeyPredicates().get(0).getLiteral())) {
      data.put("EmployeeId", "1");
      data.put("TeamId", "420");
    }

    ODataContext context = getContext();
    EntityProviderWriteProperties writeProperties =
        EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).build();

    return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), data, writeProperties);
  } else {
    throw new ODataApplicationException("Wrong testcall", Locale.getDefault(), HttpStatusCodes.NOT_IMPLEMENTED);
  }
}
 
Example #11
Source File: MapProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build();

  // query
  final String mappedKeyName =
      (String) uriInfo.getTargetEntitySet().getEntityType().getKeyProperties().get(0).getMapping().getObject();
  final String keyValue = uriInfo.getKeyPredicates().get(0).getLiteral();
  final int index = indexOf(mappedKeyName, keyValue);
  if ((index < 0) || (index > records.size())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY.addContent(keyValue));
  }
  final HashMap<String, String> record = records.get(index);

  final HashMap<String, Object> data = new HashMap<String, Object>();
  for (final String pName : uriInfo.getTargetEntitySet().getEntityType().getPropertyNames()) {
    final EdmProperty property = (EdmProperty) uriInfo.getTargetEntitySet().getEntityType().getProperty(pName);
    final String mappedPropertyName = (String) property.getMapping().getObject();
    data.put(pName, record.get(mappedPropertyName));
  }

  final ODataResponse response =
      EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), data, properties);
  return response;
}
 
Example #12
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void buildQueryWithMultipleKeys() {
  EdmMapping mapping = (EdmMapping) mockMapping();
  try {
    assertNotNull(builder.build((GetEntityUriInfo) mockURIInfoWithMultipleKeyPredicates(mapping)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #13
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void buildQueryGetEntityTest() {
  EdmMapping mapping = (EdmMapping) mockMapping();
  try {
    assertNotNull(builder.build((GetEntityUriInfo) mockURIInfo(mapping)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #14
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void buildQueryValueNormalizeTest() {
  EdmMapping mapping = (EdmMapping) mockNormalizedValueMapping();
  try {
    assertNotNull(builder.build((GetEntityUriInfo) mockURIInfo(mapping)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #15
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void buildQueryNormalizeTest() {
  EdmMapping mapping = (EdmMapping) mockNormalizedMapping();
  try {
    assertNotNull(builder.build((GetEntityUriInfo) mockURIInfo(mapping)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #16
Source File: ODataJPAResponseBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private GetEntityUriInfo getLocalGetURIInfo() {
  GetEntityUriInfo objGetEntityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
  EasyMock.expect(objGetEntityUriInfo.getSelect()).andStubReturn(getSelectItemList());
  EasyMock.expect(objGetEntityUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
  EasyMock.expect(objGetEntityUriInfo.getExpand()).andStubReturn(getExpandList());
  EasyMock.replay(objGetEntityUriInfo);
  return objGetEntityUriInfo;
}
 
Example #17
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private GetEntityUriInfo mockURIInfoWithTopSkipInline(EdmMapping mapping) throws EdmException {
  UriInfoImpl uriInfo = EasyMock.createMock(UriInfoImpl.class);
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  List<KeyPredicate> keyPreds = EasyMock.createMock(ArrayList.class);
  EasyMock.expect(uriInfo.getKeyPredicates()).andStubReturn(keyPreds); 
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(null);
  EasyMock.expect(uriInfo.getTop()).andStubReturn(1);
  EasyMock.expect(uriInfo.getSkip()).andStubReturn(2);
  EasyMock.expect(uriInfo.isCount()).andStubReturn(false);
  EasyMock.expect(uriInfo.getInlineCount()).andStubReturn(InlineCount.ALLPAGES);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
  EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(Arrays.asList(edmProperty));
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(null);
  uriInfo.setCount(true);
  EasyMock.expectLastCall().times(1);
  uriInfo.setCount(false);
  EasyMock.expectLastCall().times(1);
  Map<String, String> data = new HashMap<String, String>();
  data.put("count", "5");
  uriInfo.setCustomQueryOptions(data );
  EasyMock.expectLastCall().times(1);
  EasyMock.expect(uriInfo.getCustomQueryOptions()).andStubReturn(data);
  EasyMock.replay(edmEntityType, edmEntitySet, uriInfo, keyPreds, edmProperty);
  return uriInfo;
}
 
Example #18
Source File: ODataJPAResponseBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private GetEntityUriInfo mockEntityUriInfoForExpand() {

    List<SelectItem> selectItemList = new ArrayList<SelectItem>();
    List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
    ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
    // Mocking the navigation property
    EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
    try {
      EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderItemDetails");
    } catch (EdmException e) {
      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
    }
    EasyMock.replay(navigationProperty);
    // Mocking the navigation property segments and adding to expand list
    NavigationPropertySegment navigationPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
    EasyMock.expect(navigationPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
    EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
    EasyMock.replay(navigationPropertySegment);
    navigationPropertyList.add(navigationPropertySegment);
    expandList.add(navigationPropertyList);
    // Mocking EntityUriInfo
    GetEntityUriInfo entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
    EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(selectItemList);
    EasyMock.expect(entityUriInfo.getExpand()).andStubReturn(expandList);
    EasyMock.replay(entityUriInfo);
    return entityUriInfo;
  }
 
Example #19
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void buildGetEntityTest() {
  try {
    assertNotNull(builder.build((GetEntityUriInfo) mockURIInfoWithListener(false)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #20
Source File: ODataJPADefaultProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
    throws ODataException {
  ODataResponse oDataResponse = null;
  try {
    oDataJPAContext.setODataContext(getContext());
    Object jpaEntity = jpaProcessor.process(uriParserResultView);
    oDataResponse =
        responseBuilder.build(uriParserResultView, jpaEntity, contentType);
  } finally {
    close();
  }
  return oDataResponse;
}
 
Example #21
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 #22
Source File: ODataJPADefaultProcessorTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private GetEntityUriInfo getEntityUriInfo() {
  GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  try {
    EasyMock.expect(getEntityView.getExpand()).andStubReturn(null);
    EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
    EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
    EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);

    EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
    EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
    EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
    EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SO_ID));

    EasyMock.expect(edmEntityType.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(SALES_ORDER));

    EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
    EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
    EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
    EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
    EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
    EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());

    EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());

    EasyMock.replay(edmEntityType, edmEntitySet);
    EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
    List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
    EasyMock.expect(getEntityView.getNavigationSegments()).andReturn(navigationSegments);
    EasyMock.expect(getEntityView.getStartEntitySet()).andReturn(edmEntitySet);

    EasyMock.replay(getEntityView);
  } catch (EdmException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  return getEntityView;
}
 
Example #23
Source File: JPALink.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public void create(final EdmEntitySet entitySet, final ODataEntry oDataEntry,
    final List<String> navigationPropertyNames)
    throws ODataJPARuntimeException,
    ODataJPAModelException {

  List<Object> targetJPAEntities = new ArrayList<Object>();
  try {
    for (String navPropertyName : navigationPropertyNames) {
      List<String> links = oDataEntry.getMetadata().getAssociationUris(navPropertyName);
      if (links == null || links.isEmpty() == true) {
        links = extractLinkURI(oDataEntry, navPropertyName);
      }
      if (links != null && links.isEmpty() == false) {

        EdmNavigationProperty navProperty = (EdmNavigationProperty) entitySet.getEntityType()
            .getProperty(
                navPropertyName);

        for (String link : links) {
          UriInfo bindingUriInfo = parser.parseBindingLink(link, new HashMap<String, String>());
          targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) bindingUriInfo);
          if (targetJPAEntity != null) {
            targetJPAEntities.add(targetJPAEntity);
          }
        }
        if (targetJPAEntity == null){
          throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND
              .addContent(navPropertyName), null);
        }
        if (!targetJPAEntities.isEmpty()) {
          linkJPAEntities(targetJPAEntities, sourceJPAEntity, navProperty);
        }
        targetJPAEntities.clear();
      }
    }
  } catch (EdmException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
  }

}
 
Example #24
Source File: JPQLSelectSingleContext.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void setResultsView(final Object resultsView) {
  if (resultsView instanceof GetEntityUriInfo) {
    entityView = (GetEntityUriInfo) resultsView;
  }

}
 
Example #25
Source File: ODataJPAProcessor.java    From lemonaid with MIT License 4 votes vote down vote up
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
		throws ODataException {
	authorization.check(READ, uriParserResultView);
	ODataResponse oDataResponse = null;
	try {
		oDataJPAContext.setODataContext(getContext());
		Object jpaEntity = jpaProcessor.process(uriParserResultView);
		jpaEntity = enrichEntity(uriParserResultView, jpaEntity);
		if (jpaEntity instanceof Mentor) {
			if (!authorization.isMentor() && !authorization.isProjectMember()) {
				if (!((Mentor) jpaEntity).isPublicProfile()) {
					throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
                   }
                   //Set non public values to null!
                   if ((!((Mentor) jpaEntity).getCompanyPublic())) {
					((Mentor) jpaEntity).setCompany(null);
                   }
                   if (!((Mentor) jpaEntity).getJobTitlePublic()) {
					((Mentor) jpaEntity).setJobTitle(null);
                   }
                   if (!((Mentor) jpaEntity).getAddress1Public()) {
					((Mentor) jpaEntity).setAddress1(null);
                   }
                   if (!((Mentor) jpaEntity).getAddress2Public()) {
					((Mentor) jpaEntity).setAddress2(null);
                   }
                   if (!((Mentor) jpaEntity).getCityPublic()) {
					((Mentor) jpaEntity).setCity(null);
                   }
                   if (!((Mentor) jpaEntity).getZipPublic()) {
					((Mentor) jpaEntity).setZip(null);
                   }
                   if (!((Mentor) jpaEntity).getStatePublic()) {
					((Mentor) jpaEntity).setState(null);
                   }
                    if (!((Mentor) jpaEntity).getCountryPublic()) {
                      ((Mentor) jpaEntity).setCountryId(null);
                   }
                   if (!((Mentor) jpaEntity).getPhonePublic()) {
					((Mentor) jpaEntity).setPhone(null);
                   }
                   if (!((Mentor) jpaEntity).getEmail1Public()) {
					((Mentor) jpaEntity).setEmail1(null);
                   }
                   if (!((Mentor) jpaEntity).getEmail2Public()) {
					((Mentor) jpaEntity).setEmail2(null);
                   }
                   if (!((Mentor) jpaEntity).getSoftSkillsPublic()) {
                       ((Mentor) jpaEntity).setSoftSkill1Id(null);
                       ((Mentor) jpaEntity).setSoftSkill2Id(null);
                       ((Mentor) jpaEntity).setSoftSkill3Id(null);
                       ((Mentor) jpaEntity).setSoftSkill4Id(null);
                       ((Mentor) jpaEntity).setSoftSkill5Id(null);
                       ((Mentor) jpaEntity).setSoftSkill6Id(null);
                   }
                   if(!((Mentor) jpaEntity).getAttachmentsPublic()) {
					((Mentor) jpaEntity).setAttachments(null);
                   }
			}else{
                       ((Mentor) jpaEntity).setPublicLongitude(((Mentor) jpaEntity).getLongitude());
                       ((Mentor) jpaEntity).setPublicLatitude(((Mentor) jpaEntity).getLatitude());
               }
		}
		oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity, contentType);
	} finally {
		close();
	}
	return oDataResponse;
}
 
Example #26
Source File: ODataSingleProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
/**
 * @see EntityProcessor
 */
@Override
public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
  throw new ODataNotImplementedException();
}
 
Example #27
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Query getQuery(GetEntityUriInfo uriInfo, EntityManager em) {
  return query;
}
 
Example #28
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Query getQuery(GetEntityUriInfo uriInfo, EntityManager em) {
  return query;
}
 
Example #29
Source File: JPQLSelectSingleStatementBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private JPQLSelectSingleContext createSelectContext(EdmSimpleType edmType) throws ODataJPARuntimeException,
EdmException {
  // Object Instantiation

  JPQLSelectSingleContext JPQLSelectSingleContextImpl = null;// new JPQLSelectSingleContextImpl();
  GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);

  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  List<SelectItem> selectItemList = null;

  // Setting up the expected value
  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
 
  JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
  EasyMock.expect(edmMapping.getJPAType())
  .andStubReturn(null);
  EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
  setSpecificProperties(keyPredicate, kpProperty, edmType);
  try {
    EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
    EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);

  } catch (EdmException e2) {
    fail("this should not happen");
  }
  EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
  EasyMock.replay(edmMapping, kpProperty, keyPredicate);
  EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EasyMock.expect(getEntityView.getSelect()).andStubReturn(selectItemList);

  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.replay(edmEntitySet);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
  EasyMock.replay(edmEntityType);
  ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
  arrayList.add(keyPredicate);
  EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(arrayList);
  EasyMock.replay(getEntityView);

  JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView);
  try {
    JPQLSelectSingleContextImpl = (JPQLSelectSingleContext) contextBuilder1.build();
  } catch (ODataJPAModelException e) {
    fail("Model Exception thrown");
  }

  return JPQLSelectSingleContextImpl;
}
 
Example #30
Source File: JPQLJoinSelectSingleContextTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public void setUp(final boolean toThrowException) throws Exception {
  entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
  final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
  final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
  final List<KeyPredicate> keyPredicates = createKeyPredicates(toThrowException);
  NavigationSegment navigationSegment = new NavigationSegment() {

    @Override
    public EdmNavigationProperty getNavigationProperty() {
      return navigationProperty;
    }

    @Override
    public List<KeyPredicate> getKeyPredicates() {
      return keyPredicates;
    }

    @Override
    public EdmEntitySet getEntitySet() {
      // TODO Auto-generated method stub
      return null;
    }
  };
  NavigationSegment navigationSegment1 = new NavigationSegment() {

    @Override
    public EdmNavigationProperty getNavigationProperty() {
      return navigationProperty1;
    }

    @Override
    public List<KeyPredicate> getKeyPredicates() {
      return keyPredicates;
    }

    @Override
    public EdmEntitySet getEntitySet() {
      // TODO Auto-generated method stub
      return null;
    }
  };
  navigationSegments.add(navigationSegment);
  navigationSegments.add(navigationSegment1);
  EasyMock.expect(entityUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
  EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(null);
  EasyMock.expect(entityUriInfo.getFilter()).andStubReturn(null);
  EasyMock.expect(entityUriInfo.getKeyPredicates()).andStubReturn(createKeyPredicates(toThrowException));
  EasyMock.expect(entityUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
  EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
  EasyMock.expect(entityUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
  EasyMock.replay(startEdmEntityType, startEdmEntitySet);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
  EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
  EasyMock.replay(edmEntityType, edmEntitySet, entityUriInfo);

}