@Override protected DataAccessException convertHibernateAccessException(HibernateException theException) { if (theException instanceof ConstraintViolationException) { String constraintName = ((ConstraintViolationException) theException).getConstraintName(); switch (defaultString(constraintName)) { case ResourceHistoryTable.IDX_RESVER_ID_VER: throw new ResourceVersionConflictException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceVersionConstraintFailure")); case ResourceIndexedCompositeStringUnique.IDX_IDXCMPSTRUNIQ_STRING: throw new ResourceVersionConflictException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceIndexedCompositeStringUniqueConstraintFailure")); } } return super.convertHibernateAccessException(theException); }
ourLog.info("Failed to reindex because of a version conflict. Leaving in unindexed state: {}", e.getMessage()); reindexFailure = null;
ourLog.info("Failed to reindex because of a version conflict. Leaving in unindexed state: {}", e.getMessage()); reindexFailure = null;
@Delete() public void deletePatient(@IdParam IdType theId) { // .. Delete the patient .. if (couldntFindThisId) { throw new ResourceNotFoundException("Unknown version"); } if (conflictHappened) { throw new ResourceVersionConflictException("Couldn't delete because [foo]"); } // otherwise, delete was successful return; // can also return MethodOutcome } //END SNIPPET: delete
public void validateDeleteConflictsEmptyOrThrowException(List<DeleteConflict> theDeleteConflicts) { if (theDeleteConflicts.isEmpty()) { return; } IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext()); String firstMsg = null; for (DeleteConflict next : theDeleteConflicts) { StringBuilder b = new StringBuilder(); b.append("Unable to delete "); b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); b.append(" because at least one resource has a reference to this resource. First reference found was resource "); b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); b.append(" in path "); b.append(next.getSourcePath()); String msg = b.toString(); if (firstMsg == null) { firstMsg = msg; } OperationOutcomeUtil.addIssue(getContext(), oo, OO_SEVERITY_ERROR, msg, null, "processing"); } throw new ResourceVersionConflictException(firstMsg, oo); }
@Update public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient) { String resourceId = theId.getIdPart(); String versionId = theId.getVersionIdPart(); // this will contain the ETag String currentVersion = "1"; // populate this with the current version if (!versionId.equals(currentVersion)) { throw new ResourceVersionConflictException("Expected version " + currentVersion); } // ... perform the update ... return new MethodOutcome(); } //END SNIPPET: updateEtag
break; case Constants.STATUS_HTTP_409_CONFLICT: ex = new ResourceVersionConflictException("Server responded with HTTP 409"); break; case Constants.STATUS_HTTP_412_PRECONDITION_FAILED:
break; case Constants.STATUS_HTTP_409_CONFLICT: ex = new ResourceVersionConflictException("Server responded with HTTP 409"); break; case Constants.STATUS_HTTP_412_PRECONDITION_FAILED:
throw new ResourceVersionConflictException("Trying to update " + resourceId + " but this is not the current version");
@Override public DaoMethodOutcome patch(IIdType theId, PatchTypeEnum thePatchType, String thePatchBody, RequestDetails theRequestDetails) { ResourceTable entityToUpdate = readEntityLatestVersion(theId); if (theId.hasVersionIdPart()) { if (theId.getVersionIdPartAsLong() != entityToUpdate.getVersion()) { throw new ResourceVersionConflictException("Version " + theId.getVersionIdPart() + " is not the most recent version of this resource, unable to apply patch"); } } validateResourceType(entityToUpdate); IBaseResource resourceToUpdate = toResource(entityToUpdate, false); IBaseResource destination; if (thePatchType == PatchTypeEnum.JSON_PATCH) { destination = JsonPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } else { destination = XmlPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } @SuppressWarnings("unchecked") T destinationCasted = (T) destination; return update(destinationCasted, null, true, theRequestDetails); }
@Override protected DataAccessException convertHibernateAccessException(HibernateException theException) { if (theException instanceof ConstraintViolationException) { String constraintName = ((ConstraintViolationException) theException).getConstraintName(); switch (defaultString(constraintName)) { case ResourceHistoryTable.IDX_RESVER_ID_VER: throw new ResourceVersionConflictException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceVersionConstraintFailure")); case ResourceIndexedCompositeStringUnique.IDX_IDXCMPSTRUNIQ_STRING: throw new ResourceVersionConflictException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceIndexedCompositeStringUniqueConstraintFailure")); } } return super.convertHibernateAccessException(theException); }
public void validateDeleteConflictsEmptyOrThrowException(List<DeleteConflict> theDeleteConflicts) { if (theDeleteConflicts.isEmpty()) { return; } IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext()); String firstMsg = null; for (DeleteConflict next : theDeleteConflicts) { StringBuilder b = new StringBuilder(); b.append("Unable to delete "); b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); b.append(" because at least one resource has a reference to this resource. First reference found was resource "); b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); b.append(" in path "); b.append(next.getSourcePath()); String msg = b.toString(); if (firstMsg == null) { firstMsg = msg; } OperationOutcomeUtil.addIssue(getContext(), oo, OO_SEVERITY_ERROR, msg, null, "processing"); } throw new ResourceVersionConflictException(firstMsg, oo); }
throw new ResourceVersionConflictException("Trying to delete " + theId + " but this is not the current version");
break; case Constants.STATUS_HTTP_409_CONFLICT: ex = new ResourceVersionConflictException("Server responded with HTTP 409"); break; case Constants.STATUS_HTTP_412_PRECONDITION_FAILED:
break; case Constants.STATUS_HTTP_409_CONFLICT: ex = new ResourceVersionConflictException("Server responded with HTTP 409"); break; case Constants.STATUS_HTTP_412_PRECONDITION_FAILED:
throw new ResourceVersionConflictException("Trying to update " + resourceId + " but this is not the current version");
@Override public DaoMethodOutcome patch(IIdType theId, PatchTypeEnum thePatchType, String thePatchBody, RequestDetails theRequestDetails) { ResourceTable entityToUpdate = readEntityLatestVersion(theId); if (theId.hasVersionIdPart()) { if (theId.getVersionIdPartAsLong() != entityToUpdate.getVersion()) { throw new ResourceVersionConflictException("Version " + theId.getVersionIdPart() + " is not the most recent version of this resource, unable to apply patch"); } } validateResourceType(entityToUpdate); IBaseResource resourceToUpdate = toResource(entityToUpdate, false); IBaseResource destination; if (thePatchType == PatchTypeEnum.JSON_PATCH) { destination = JsonPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } else { destination = XmlPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } @SuppressWarnings("unchecked") T destinationCasted = (T) destination; return update(destinationCasted, null, true, theRequestDetails); }
throw new ResourceVersionConflictException("Trying to delete " + theId + " but this is not the current version");