@Test public void testDeleteLink() { testCase = 1; try { ODataJPAContext context = mockODataJPAContext(false); JPALink link = new JPALink(context); Field processor = JPALink.class. getDeclaredField("jpaProcessor"); processor.setAccessible(true); processor.set(link, new JPAProcessorMock()); link.delete(mockDeleteURIInfo(false)); assertNull(header.getNotesDetails()); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchFieldException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchMethodException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public void delete(final DeleteUriInfo uriInfo) throws ODataJPARuntimeException { try { int index = context.getODataContext().getPathInfo().getODataSegments().size() - 2; List<String> linkSegments = new ArrayList<String>(); String customLinkSegment = context.getODataContext().getPathInfo().getODataSegments().get(0).getPath(); linkSegments.add(customLinkSegment); customLinkSegment = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getName(); linkSegments.add(customLinkSegment); HashMap<String, String> options = new HashMap<String, String>(); List<KeyPredicate> keyPredicates = uriInfo.getNavigationSegments().get(0).getKeyPredicates(); StringBuffer condition = new StringBuffer(); String literal = null; KeyPredicate keyPredicate = null; int size = keyPredicates.size(); for (int i = 0; i < size; i++) { keyPredicate = keyPredicates.get(i); literal = ((EdmSimpleType) keyPredicate.getProperty().getType()).toUriLiteral(keyPredicate.getLiteral()); condition.append(keyPredicate.getProperty().getName()).append(SPACE); condition.append(ODATA_OPERATOR_NE).append(SPACE); condition.append(literal).append(SPACE); if (i != size - 1) { condition.append(ODATA_OPERATOR_OR).append(SPACE); } } if (condition.length() > 0) { options.put(ODATA_COMMAND_FILTER, condition.toString()); } UriInfo parsedUriInfo = parser.parseLinkSegments(linkSegments, options); List<Object> relatedEntities = jpaProcessor.process((GetEntitySetUriInfo) parsedUriInfo); parsedUriInfo = parser.parseURISegment(0, index); if (parsedUriInfo != null) { targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) parsedUriInfo); if (targetJPAEntity == null) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND .addContent(parsedUriInfo.getTargetEntitySet().getName()), null); } NavigationSegment navigationSegment = uriInfo.getNavigationSegments().get(0); EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); delinkJPAEntities(targetJPAEntity, relatedEntities, navigationProperty); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } }
JPALink { public void delete(final DeleteUriInfo uriInfo) throws ODataJPARuntimeException { try { int index = context.getODataContext().getPathInfo().getODataSegments().size() - 2; List<String> linkSegments = new ArrayList<String>(); String customLinkSegment = context.getODataContext().getPathInfo().getODataSegments().get(0).getPath(); linkSegments.add(customLinkSegment); customLinkSegment = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getName(); linkSegments.add(customLinkSegment); HashMap<String, String> options = new HashMap<String, String>(); List<KeyPredicate> keyPredicates = uriInfo.getNavigationSegments().get(0).getKeyPredicates(); StringBuffer condition = new StringBuffer(); String literal = null; KeyPredicate keyPredicate = null; int size = keyPredicates.size(); for (int i = 0; i < size; i++) { keyPredicate = keyPredicates.get(i); literal = ((EdmSimpleType) keyPredicate.getProperty().getType()).toUriLiteral(keyPredicate.getLiteral()); condition.append(keyPredicate.getProperty().getName()).append(SPACE); condition.append(ODATA_OPERATOR_NE).append(SPACE); condition.append(literal).append(SPACE); if (i != size - 1) { condition.append(ODATA_OPERATOR_OR).append(SPACE); } } if (condition.length() > 0) { options.put(ODATA_COMMAND_FILTER, condition.toString()); } UriInfo parsedUriInfo = parser.parseLinkSegments(linkSegments, options); List<Object> relatedEntities = jpaProcessor.process((GetEntitySetUriInfo) parsedUriInfo); parsedUriInfo = parser.parseURISegment(0, index); if (parsedUriInfo != null) { targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) parsedUriInfo); if (targetJPAEntity == null) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND .addContent(parsedUriInfo.getTargetEntitySet().getName()), null); } NavigationSegment navigationSegment = uriInfo.getNavigationSegments().get(0); EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); delinkJPAEntities(targetJPAEntity, relatedEntities, navigationProperty); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } }
JPALink { public void delete(final DeleteUriInfo uriInfo) throws ODataJPARuntimeException { try { int index = context.getODataContext().getPathInfo().getODataSegments().size() - 2; List<String> linkSegments = new ArrayList<String>(); String customLinkSegment = context.getODataContext().getPathInfo().getODataSegments().get(0).getPath(); linkSegments.add(customLinkSegment); customLinkSegment = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getName(); linkSegments.add(customLinkSegment); HashMap<String, String> options = new HashMap<String, String>(); List<KeyPredicate> keyPredicates = uriInfo.getNavigationSegments().get(0).getKeyPredicates(); StringBuffer condition = new StringBuffer(); String literal = null; KeyPredicate keyPredicate = null; int size = keyPredicates.size(); for (int i = 0; i < size; i++) { keyPredicate = keyPredicates.get(i); literal = ((EdmSimpleType) keyPredicate.getProperty().getType()).toUriLiteral(keyPredicate.getLiteral()); condition.append(keyPredicate.getProperty().getName()).append(SPACE); condition.append(ODATA_OPERATOR_NE).append(SPACE); condition.append(literal).append(SPACE); if (i != size - 1) { condition.append(ODATA_OPERATOR_OR).append(SPACE); } } if (condition.length() > 0) { options.put(ODATA_COMMAND_FILTER, condition.toString()); } UriInfo parsedUriInfo = parser.parseLinkSegments(linkSegments, options); List<Object> relatedEntities = jpaProcessor.process((GetEntitySetUriInfo) parsedUriInfo); parsedUriInfo = parser.parseURISegment(0, index); if (parsedUriInfo != null) { targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) parsedUriInfo); if (targetJPAEntity == null) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND .addContent(parsedUriInfo.getTargetEntitySet().getName()), null); } NavigationSegment navigationSegment = uriInfo.getNavigationSegments().get(0); EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); delinkJPAEntities(targetJPAEntity, relatedEntities, navigationProperty); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } JPALink(final ODataJPAContext context); }
JPALink { public void delete(final DeleteUriInfo uriInfo) throws ODataJPARuntimeException { try { int index = context.getODataContext().getPathInfo().getODataSegments().size() - 2; List<String> linkSegments = new ArrayList<String>(); String customLinkSegment = context.getODataContext().getPathInfo().getODataSegments().get(0).getPath(); linkSegments.add(customLinkSegment); customLinkSegment = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getName(); linkSegments.add(customLinkSegment); HashMap<String, String> options = new HashMap<String, String>(); List<KeyPredicate> keyPredicates = uriInfo.getNavigationSegments().get(0).getKeyPredicates(); StringBuffer condition = new StringBuffer(); String literal = null; KeyPredicate keyPredicate = null; int size = keyPredicates.size(); for (int i = 0; i < size; i++) { keyPredicate = keyPredicates.get(i); literal = ((EdmSimpleType) keyPredicate.getProperty().getType()).toUriLiteral(keyPredicate.getLiteral()); condition.append(keyPredicate.getProperty().getName()).append(SPACE); condition.append(ODATA_OPERATOR_NE).append(SPACE); condition.append(literal).append(SPACE); if (i != size - 1) { condition.append(ODATA_OPERATOR_OR).append(SPACE); } } if (condition.length() > 0) { options.put(ODATA_COMMAND_FILTER, condition.toString()); } UriInfo parsedUriInfo = parser.parseLinkSegments(linkSegments, options); List<Object> relatedEntities = jpaProcessor.process((GetEntitySetUriInfo) parsedUriInfo); parsedUriInfo = parser.parseURISegment(0, index); if (parsedUriInfo != null) { targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) parsedUriInfo); if (targetJPAEntity == null) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND .addContent(parsedUriInfo.getTargetEntitySet().getName()), null); } NavigationSegment navigationSegment = uriInfo.getNavigationSegments().get(0); EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); delinkJPAEntities(targetJPAEntity, relatedEntities, navigationProperty); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } JPALink(final ODataJPAContext context); void setSourceJPAEntity(final Object jpaEntity); void setTargetJPAEntity(final Object jpaEntity); Object getTargetJPAEntity(); Object getSourceJPAEntity(); void create(final PostUriInfo uriInfo, final InputStream content, final String requestContentType,
      final String contentType); void update(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType,
      final String contentType); void delete(final DeleteUriInfo uriInfo); void save(); void create(final EdmEntitySet entitySet, final ODataEntry oDataEntry,
      final List<String> navigationPropertyNames); @SuppressWarnings("unchecked") static void linkJPAEntities(final Collection<Object> targetJPAEntities, final Object sourceJPAEntity,
      final EdmNavigationProperty navigationProperty); }
JPALink { public void delete(final DeleteUriInfo uriInfo) throws ODataJPARuntimeException { try { int index = context.getODataContext().getPathInfo().getODataSegments().size() - 2; List<String> linkSegments = new ArrayList<String>(); String customLinkSegment = context.getODataContext().getPathInfo().getODataSegments().get(0).getPath(); linkSegments.add(customLinkSegment); customLinkSegment = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getName(); linkSegments.add(customLinkSegment); HashMap<String, String> options = new HashMap<String, String>(); List<KeyPredicate> keyPredicates = uriInfo.getNavigationSegments().get(0).getKeyPredicates(); StringBuffer condition = new StringBuffer(); String literal = null; KeyPredicate keyPredicate = null; int size = keyPredicates.size(); for (int i = 0; i < size; i++) { keyPredicate = keyPredicates.get(i); literal = ((EdmSimpleType) keyPredicate.getProperty().getType()).toUriLiteral(keyPredicate.getLiteral()); condition.append(keyPredicate.getProperty().getName()).append(SPACE); condition.append(ODATA_OPERATOR_NE).append(SPACE); condition.append(literal).append(SPACE); if (i != size - 1) { condition.append(ODATA_OPERATOR_OR).append(SPACE); } } if (condition.length() > 0) { options.put(ODATA_COMMAND_FILTER, condition.toString()); } UriInfo parsedUriInfo = parser.parseLinkSegments(linkSegments, options); List<Object> relatedEntities = jpaProcessor.process((GetEntitySetUriInfo) parsedUriInfo); parsedUriInfo = parser.parseURISegment(0, index); if (parsedUriInfo != null) { targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) parsedUriInfo); if (targetJPAEntity == null) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND .addContent(parsedUriInfo.getTargetEntitySet().getName()), null); } NavigationSegment navigationSegment = uriInfo.getNavigationSegments().get(0); EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty(); delinkJPAEntities(targetJPAEntity, relatedEntities, navigationProperty); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } } JPALink(final ODataJPAContext context); void setSourceJPAEntity(final Object jpaEntity); void setTargetJPAEntity(final Object jpaEntity); Object getTargetJPAEntity(); Object getSourceJPAEntity(); void create(final PostUriInfo uriInfo, final InputStream content, final String requestContentType,
      final String contentType); void update(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType,
      final String contentType); void delete(final DeleteUriInfo uriInfo); void save(); void create(final EdmEntitySet entitySet, final ODataEntry oDataEntry,
      final List<String> navigationPropertyNames); @SuppressWarnings("unchecked") static void linkJPAEntities(final Collection<Object> targetJPAEntities, final Object sourceJPAEntity,
      final EdmNavigationProperty navigationProperty);  }