public static void isTrueOrThrowInvalidRequest(boolean theSuccess, String theMessage) { if (theSuccess == false) { throw new InvalidRequestException(theMessage); } }
private static void throwInvalidSyntaxException(String theParameterName) { throw new InvalidRequestException("Invalid _has parameter syntax: " + theParameterName); }
public static void throwInvalidMode(String paramValues) { throw new InvalidRequestException("Invalid mode value: \"" + paramValues + "\""); }
public static void throwInvalidMode(String paramValues) { throw new InvalidRequestException("Invalid mode value: \"" + paramValues + "\""); }
public static void isNotBlankOrThrowInvalidRequest(String theString, String theMessage) { if (isBlank(theString)) { throw new InvalidRequestException(theMessage); } }
private void throwWrongParamType(Object nextValue) { throw new InvalidRequestException("Request has parameter " + myName + " of type " + nextValue.getClass().getSimpleName() + " but method expects type " + myParameterType.getSimpleName()); }
public static void validateFulltextSearchEnabled(IFulltextSearchSvc theSearchDao) { if (theSearchDao == null || theSearchDao.isDisabled()) { throw new InvalidRequestException("Fulltext searching is disabled on this server"); } }
public IFhirResourceDao getResourceDao(String theResourceName) { init(); IFhirResourceDao retVal = myResourceNameToResourceDao.get(theResourceName); if (retVal == null) { List<String> supportedResourceTypes = myResourceNameToResourceDao .keySet() .stream() .sorted() .collect(Collectors.toList()); throw new InvalidRequestException("Unable to process request, this server does not know how to handle resources of type " + theResourceName + " - Can handle: " + supportedResourceTypes); } return retVal; }
public static PatchTypeEnum getTypeForRequestOrThrowInvalidRequestException(RequestDetails theRequest) { String contentTypeAll = defaultString(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE)); String contentType = contentTypeAll; int semiColonIdx = contentType.indexOf(';'); if (semiColonIdx != -1) { contentType = contentTypeAll.substring(0, semiColonIdx); } contentType = contentType.trim(); if (Constants.CT_JSON_PATCH.equals(contentType)) { return PatchTypeEnum.JSON_PATCH; } else if (Constants.CT_XML_PATCH.equals(contentType)) { return PatchTypeEnum.XML_PATCH; } else { throw new InvalidRequestException("Invalid Content-Type for PATCH operation: " + contentTypeAll); } }
private void verifyNoDuplicates(Collection<TermConcept> theConcepts, Set<String> theCodes) { for (TermConcept next : theConcepts) { if (!theCodes.add(next.getCode())) { throw new InvalidRequestException("Duplicate code " + next.getCode() + " found in codesystem after checking " + theCodes.size() + " codes"); } verifyNoDuplicates(next.getChildren().stream().map(TermConceptParentChildLink::getChild).collect(Collectors.toList()), theCodes); } }
@Override public T parse(FhirContext theContext, String theName, List<QualifiedParamList> theParams) throws InternalErrorException, InvalidRequestException { if (theParams.size() == 0 || theParams.get(0).size() == 0) { return null; } if (theParams.size() > 1 || theParams.get(0).size() > 1) { throw new InvalidRequestException("Multiple values detected for non-repeatable parameter '" + theName + "'. This server is not configured to allow multiple (AND) values for this param."); } T value = doParse(theParams.get(0).get(0)); return value; }
public IFhirResourceDao getDaoOrThrowException(Class<? extends IBaseResource> theClass) { IFhirResourceDao retVal = getResourceDao(theClass); if (retVal == null) { List<String> supportedResourceNames = myResourceNameToResourceDao .keySet() .stream() .map(t -> myContext.getResourceDefinition(t).getName()) .sorted() .collect(Collectors.toList()); throw new InvalidRequestException("Unable to process request, this server does not know how to handle resources of type " + myContext.getResourceDefinition(theClass).getName() + " - Can handle: " + supportedResourceNames); } return retVal; }
private String extractTransactionUrlOrThrowException(BUNDLEENTRY nextEntry, String verb) { String url = myVersionAdapter.getEntryRequestUrl(nextEntry); if (isBlank(url)) { throw new InvalidRequestException(myContext.getLocalizer().getMessage(BaseHapiFhirSystemDao.class, "transactionMissingUrl", verb)); } return url; }
private void addPredicateComposite(String theResourceName, RuntimeSearchParam theParamDef, List<? extends IQueryParameterType> theNextAnd) { // TODO: fail if missing is set for a composite query IQueryParameterType or = theNextAnd.get(0); if (!(or instanceof CompositeParam<?, ?>)) { throw new InvalidRequestException("Invalid type for composite param (must be " + CompositeParam.class.getSimpleName() + ": " + or.getClass()); } CompositeParam<?, ?> cp = (CompositeParam<?, ?>) or; RuntimeSearchParam left = theParamDef.getCompositeOf().get(0); IQueryParameterType leftValue = cp.getLeftValue(); myPredicates.add(createCompositeParamPart(theResourceName, myResourceTableRoot, left, leftValue)); RuntimeSearchParam right = theParamDef.getCompositeOf().get(1); IQueryParameterType rightValue = cp.getRightValue(); myPredicates.add(createCompositeParamPart(theResourceName, myResourceTableRoot, right, rightValue)); }
private boolean addToSet(Set<TermConcept> theSetToPopulate, TermConcept theConcept) { boolean retVal = theSetToPopulate.add(theConcept); if (retVal) { if (theSetToPopulate.size() >= myDaoConfig.getMaximumExpansionSize()) { String msg = myContext.getLocalizer().getMessage(BaseHapiTerminologySvcImpl.class, "expansionTooLarge", myDaoConfig.getMaximumExpansionSize()); throw new InvalidRequestException(msg); } } return retVal; }
@Override public IQueryParameterType parse(FhirContext theContext, String theParamName, List<QualifiedParamList> theParams) throws InternalErrorException, InvalidRequestException { String value = theParams.get(0).get(0); if (StringUtils.isBlank(value)) { return null; } IQueryParameterType dt = super.newInstance(); if (theParams.size() == 0 || theParams.get(0).size() == 0) { return dt; } if (theParams.size() > 1 || theParams.get(0).size() > 1) { throw new InvalidRequestException("Multiple values detected for non-repeatable parameter '" + theParamName + "'. This server is not configured to allow multiple (AND/OR) values for this param."); } dt.setValueAsQueryToken(theContext, theParamName, theParams.get(0).getQualifier(), value); return dt; }
@Override void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) { if (isBlank(theValue)) { myLeftType.setValueAsQueryToken(theContext, theParamName, theQualifier, ""); myRightType.setValueAsQueryToken(theContext, theParamName, theQualifier, ""); } else { List<String> parts = ParameterUtil.splitParameterString(theValue, '$', false); if (parts.size() > 2) { throw new InvalidRequestException("Invalid value for composite parameter (only one '$' is valid for this parameter, others must be escaped). Value was: " + theValue); } myLeftType.setValueAsQueryToken(theContext, theParamName, theQualifier, parts.get(0)); if (parts.size() > 1) { myRightType.setValueAsQueryToken(theContext, theParamName, theQualifier, parts.get(1)); } } }
@Override public final void setValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) { if (Constants.PARAMQUALIFIER_MISSING.equals(theQualifier)) { myMissing = "true".equals(theValue); doSetValueAsQueryToken(theContext, theParamName, null, null); } else { if (isNotBlank(theQualifier) && theQualifier.charAt(0) == '.') { if (!isSupportsChain()) { String msg = theContext.getLocalizer().getMessage(BaseParam.class, "chainNotSupported", theParamName + theQualifier, theQualifier); throw new InvalidRequestException(msg); } } myMissing = null; doSetValueAsQueryToken(theContext, theParamName, theQualifier, theValue); } }
private void validateIncludes(String name, List<ConceptSetComponent> listToValidate) { for (ConceptSetComponent nextExclude : listToValidate) { if (isBlank(nextExclude.getSystem()) && !ElementUtil.isEmpty(nextExclude.getConcept(), nextExclude.getFilter())) { throw new InvalidRequestException("ValueSet contains " + name + " criteria with no system defined"); } } }
@Override public EncodingEnum getResourceAsStringEncoding() { if (myEncoding == null) { myEncoding = EncodingEnum.detectEncodingNoDefault(theResourceBody); if (myEncoding == null) { throw new InvalidRequestException(theContext.getLocalizer().getMessage(ValidationContext.class, "unableToDetermineEncoding")); } } return myEncoding; }