public static void isNotBlankOrThrowUnprocessableEntity(String theString, String theMessage) { if (isBlank(theString)) { throw new UnprocessableEntityException(theMessage); } }
public void setLanguage(String theLanguage) { if (defaultString(theLanguage).length() > MAX_LANGUAGE_LENGTH) { throw new UnprocessableEntityException("Language exceeds maximum length of " + MAX_LANGUAGE_LENGTH + " chars: " + theLanguage); } myLanguage = theLanguage; }
public void setProfile(String theProfile) { if (defaultString(theProfile).length() > MAX_PROFILE_LENGTH) { throw new UnprocessableEntityException("Profile name exceeds maximum length of " + MAX_PROFILE_LENGTH + " chars: " + theProfile); } myProfile = theProfile; }
private void verifyMandatoryFilesExist(List<String> theExpectedFilenameFragments) { List<String> notFound = notFound(theExpectedFilenameFragments); if (!notFound.isEmpty()) { throw new UnprocessableEntityException("Could not find the following mandatory files in input: " + notFound); } }
protected void validateChannelEndpoint(Subscription theResource) { if (isBlank(theResource.getChannel().getEndpoint())) { throw new UnprocessableEntityException("Rest-hook subscriptions must have Subscription.channel.endpoint defined"); } }
protected void validateChannelEndpoint(Subscription theResource) { if (isBlank(theResource.getChannel().getEndpoint())) { throw new UnprocessableEntityException("Rest-hook subscriptions must have Subscription.channel.endpoint defined"); } }
public void validateCriteriaAndAddStrategy(final IBaseResource theResource) { String criteria = mySubscriptionCanonicalizer.getCriteria(theResource); try { SubscriptionMatchingStrategy strategy = mySubscriptionStrategyEvaluator.determineStrategy(criteria); mySubscriptionCanonicalizer.setMatchingStrategyTag(myFhirContext, theResource, strategy); } catch (InvalidRequestException | DataFormatException e) { throw new UnprocessableEntityException("Invalid subscription criteria submitted: " + criteria + " " + e.getMessage()); } }
private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue(); if (channelType == null) { throw new UnprocessableEntityException("Subscription.channel.type must be populated"); } if (channelType == SubscriptionChannelType.WEBSOCKET) { return; } if (theExistingStatus != null) { throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } if (theSubscription.getStatus() == null) { throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated on this server"); } throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription"); }
private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue(); if (channelType == null) { throw new UnprocessableEntityException("Subscription.channel.type must be populated"); } if (channelType == SubscriptionChannelType.WEBSOCKET) { return; } if (theExistingStatus != null) { throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } if (theSubscription.getStatus() == null) { throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated on this server"); } throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription"); }
private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatusEnum newStatus, SubscriptionStatusEnum theExistingStatus) { SubscriptionChannelTypeEnum channelType = theSubscription.getChannel().getTypeElement().getValueAsEnum(); if (channelType == null) { throw new UnprocessableEntityException("Subscription.channel.type must be populated"); } if (channelType == SubscriptionChannelTypeEnum.WEBSOCKET) { return; } if (theExistingStatus != null) { throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } if (theSubscription.getStatus() == null) { throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated on this server"); } throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatusEnum.OFF.getCode() + "' or '" + SubscriptionStatusEnum.REQUESTED.getCode() + "' on a newly created subscription"); }
protected void validateMetaCount(int theMetaCount) { if (myConfig.getResourceMetaCountHardLimit() != null) { if (theMetaCount > myConfig.getResourceMetaCountHardLimit()) { throw new UnprocessableEntityException("Resource contains " + theMetaCount + " meta entries (tag/profile/security label), maximum is " + myConfig.getResourceMetaCountHardLimit()); } } }
private boolean requestAppliesToTransaction(FhirContext theContext, RuleOpEnum theOp, IBaseResource theInputResource) { if (!"Bundle".equals(theContext.getResourceDefinition(theInputResource).getName())) { return false; } IBaseBundle request = (IBaseBundle) theInputResource; String bundleType = defaultString(BundleUtil.getBundleType(theContext, request)); //noinspection EnumSwitchStatementWhichMissesCases if (theOp == RuleOpEnum.TRANSACTION) { if ("transaction".equals(bundleType) || "batch".equals(bundleType)) { return true; } else { String msg = theContext.getLocalizer().getMessage(RuleImplOp.class, "invalidRequestBundleTypeForTransaction", '"' + bundleType + '"'); throw new UnprocessableEntityException(msg); } } return false; }
/** * Fail the request by throwing an {@link UnprocessableEntityException} as a result of a validation failure. * Subclasses may change this behaviour by providing alternate behaviour. */ protected void fail(RequestDetails theRequestDetails, ValidationResult theValidationResult) { throw new UnprocessableEntityException(theRequestDetails.getServer().getFhirContext(), theValidationResult.toOperationOutcome()); }
@Override protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave) { super.validateResourceForStorage(theResource, theEntityToSave); RuntimeResourceDefinition resDef = validateCriteriaAndReturnResourceDefinition(theResource); if (resDef == null) { return; } IFhirResourceDao<? extends IBaseResource> dao = getDao(resDef.getImplementingClass()); if (dao == null) { throw new UnprocessableEntityException("Subscription.criteria contains invalid/unsupported resource type: " + resDef); } if (theResource.getChannel().getType() == null) { throw new UnprocessableEntityException("Subscription.channel.type must be populated on this server"); } SubscriptionStatus status = theResource.getStatus(); if (status == null) { throw new UnprocessableEntityException("Subscription.status must be populated on this server"); } }
@Override protected void validateResourceForStorage(Subscription theResource, ResourceTable theEntityToSave) { super.validateResourceForStorage(theResource, theEntityToSave); RuntimeResourceDefinition resDef = validateCriteriaAndReturnResourceDefinition(theResource); IFhirResourceDao<? extends IBaseResource> dao = getDao(resDef.getImplementingClass()); if (dao == null) { throw new UnprocessableEntityException("Subscription.criteria contains invalid/unsupported resource type: " + resDef); } if (theResource.getChannel().getType() == null) { throw new UnprocessableEntityException("Subscription.channel.type must be populated on this server"); } SubscriptionStatusEnum status = theResource.getStatusElement().getValueAsEnum(); if (status == null) { throw new UnprocessableEntityException("Subscription.status must be populated on this server"); } }
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (!allowedBundleTypes.contains(defaultString(theResource.getType()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType() : "(missing)"); throw new UnprocessableEntityException(message); } for (Entry next : theResource.getEntry()) { next.setFullUrl((String)null); } }
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (theResource.getType() == null || !allowedBundleTypes.contains(defaultString(theResource.getType().toCode()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType().toCode() : "(missing)"); throw new UnprocessableEntityException(message); } }
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (theResource.getType() == null || !allowedBundleTypes.contains(defaultString(theResource.getType().toCode()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType().toCode() : "(missing)"); throw new UnprocessableEntityException(message); } }
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }