@Override public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters) { if (theParameters.isEmpty()) { return; } if (theParameters.size() > 1) { throw new IllegalArgumentException( "Type " + theParam.getClass().getCanonicalName() + " does not support multiple values"); } theParam.setValueAsQueryToken(theContext, theParamName, theParameters.getQualifier(), theParameters.get(0)); } };
private void parseParams(RequestDetails theRequest, List<QualifiedParamList> paramList, String theQualifiedParamName, String theQualifier) { QualifierDetails qualifiers = QualifierDetails.extractQualifiersFromParameterName(theQualifier); if (!qualifiers.passes(getQualifierWhitelist(), getQualifierBlacklist())) { return; } String[] value = theRequest.getParameters().get(theQualifiedParamName); if (value != null) { for (String nextParam : value) { if (nextParam.contains(",") == false) { paramList.add(QualifiedParamList.singleton(theQualifier, nextParam)); } else { paramList.add(QualifiedParamList.splitQueryStringByCommasIgnoreEscape(theQualifier, nextParam)); } } } }
public static QualifiedParamList splitQueryStringByCommasIgnoreEscape(String theQualifier, String theParams) { QualifiedParamList retVal = new QualifiedParamList(); retVal.setQualifier(theQualifier); if (countTrailingSlashes(prev) % 2 == 1) { int idx = retVal.size() - 1; String existing = retVal.get(idx); prev = existing.substring(0, existing.length() - 1) + ','; retVal.set(idx, prev); } else { prev = null; int idx = retVal.size() - 1; String existing = retVal.get(idx); prev = existing + str; retVal.set(idx, prev); } else { retVal.add(str); prev = str;
public static QualifiedParamList singleton(String theQualifier, String theParamValue) { QualifiedParamList retVal = new QualifiedParamList(1); retVal.setQualifier(theQualifier); retVal.add(theParamValue); return retVal; }
@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; }
@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; }
QualifiedParamList paramList = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(qualifier, next.getValue()); nameToParamLists.put(paramName, paramList); if (paramList.size() > 0 && paramList.get(0).size() > 0) { String intString = paramList.get(0).get(0); try { paramMap.setCount(Integer.parseInt(intString)); if (isNotBlank(paramList.get(0).getQualifier()) && paramList.get(0).getQualifier().startsWith(".")) { throw new InvalidRequestException("Invalid parameter chain: " + nextParamName + paramList.get(0).getQualifier());
@Override public Object incomingServer(Object theObject) { IPrimitiveType<?> obj = (IPrimitiveType<?>) theObject; List<QualifiedParamList> paramList = Collections.singletonList(QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null, obj.getValueAsString())); return mySearchParameterBinding.parse(myContext, paramList); }
public static QualifiedParamList singleton(String theParamValue) { return singleton(null, theParamValue); }
@Override public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters) { myList.clear(); for (String next : theParameters) { PT nextParam = newInstance(); nextParam.setValueAsQueryToken(theContext, theParamName, theParameters.getQualifier(), next); myList.add(nextParam); } }
@Override public List<QualifiedParamList> encode(FhirContext theContext, Object theObject) throws InternalErrorException { ArrayList<QualifiedParamList> retVal = new ArrayList<QualifiedParamList>(); // TODO: declaring method should probably have a generic type.. @SuppressWarnings("rawtypes") IParamBinder paramBinder = myParamBinder; @SuppressWarnings("unchecked") List<IQueryParameterOr<?>> val = paramBinder.encode(theContext, theObject); for (IQueryParameterOr<?> nextOr : val) { retVal.add(new QualifiedParamList(nextOr, theContext)); } return retVal; }
@Override public IQueryParameterOr<?> parse(FhirContext theContext, String theParamName, List<QualifiedParamList> theString) throws InternalErrorException, InvalidRequestException { IQueryParameterOr<?> dt; try { dt = newInstance(); if (theString.size() == 0 || theString.get(0).size() == 0) { return dt; } if (theString.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.setValuesAsQueryTokens(theContext, theParamName, theString.get(0)); } catch (SecurityException e) { throw new InternalErrorException(e); } return dt; } }
@Override public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, List<QualifiedParamList> theParameters) throws InvalidRequestException { boolean haveHadUnqualifiedParameter = false; for (QualifiedParamList paramList : theParameters) { if (paramList.size() == 0) { continue; } if (paramList.size() > 1) { throw new InvalidRequestException("DateRange parameter does not suppport OR queries"); } String param = paramList.get(0); /* * Since ' ' is escaped as '+' we'll be nice to anyone might have accidentally not * escaped theirs */ param = param.replace(' ', '+'); DateParam parsed = new DateParam(); parsed.setValueAsQueryToken(theContext, theParamName, paramList.getQualifier(), param); addParam(parsed); if (parsed.getPrefix() == null) { if (haveHadUnqualifiedParameter) { throw new InvalidRequestException("Multiple date parameters with the same name and no qualifier (>, <, etc.) is not supported"); } haveHadUnqualifiedParameter = true; } } }
@Override public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters) { setMissing(null); setPrefix(null); setValueAsString(null); if (theParameters.size() == 1) { setValueAsString(theParameters.get(0)); } else if (theParameters.size() > 1) { throw new InvalidRequestException("This server does not support multi-valued dates for this parameter: " + theParameters); } }
@Override public Object incomingServer(Object theObject) { IPrimitiveType<?> obj = (IPrimitiveType<?>) theObject; List<QualifiedParamList> paramList = Collections.singletonList(QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null, obj.getValueAsString())); return mySearchParameterBinding.parse(myContext, paramList); }
private void convertAndAddIncludeToList(ArrayList<QualifiedParamList> retVal, Include include) { String qualifier = include.isRecurse() ? Constants.PARAM_INCLUDE_QUALIFIER_RECURSE : null; retVal.add(QualifiedParamList.singleton(qualifier, include.getValue())); }
@Override public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { if (theSourceClientArgument == null) { if (isRequired()) { throw new NullPointerException("SearchParameter '" + getName() + "' is required and may not be null"); } } else { List<QualifiedParamList> value = encode(theContext, theSourceClientArgument); for (QualifiedParamList nextParamEntry : value) { StringBuilder b = new StringBuilder(); for (String str : nextParamEntry) { if (b.length() > 0) { b.append(","); } b.append(str); } String qualifier = nextParamEntry.getQualifier(); String paramName = isNotBlank(qualifier) ? getName() + qualifier : getName(); List<String> paramValues = theTargetQueryArguments.get(paramName); if (paramValues == null) { paramValues = new ArrayList<>(value.size()); theTargetQueryArguments.put(paramName, paramValues); } paramValues.add(b.toString()); } } }
public static QualifiedParamList singleton(String theQualifier, String theParamValue) { QualifiedParamList retVal = new QualifiedParamList(1); retVal.setQualifier(theQualifier); retVal.add(theParamValue); return retVal; }
@Override public List<QualifiedParamList> encode(FhirContext theContext, Object theObject) throws InternalErrorException { ArrayList<QualifiedParamList> retVal = new ArrayList<>(); // TODO: declaring method should probably have a generic type.. @SuppressWarnings("rawtypes") IParamBinder paramBinder = myParamBinder; @SuppressWarnings("unchecked") List<IQueryParameterOr<?>> val = paramBinder.encode(theContext, theObject); for (IQueryParameterOr<?> nextOr : val) { retVal.add(new QualifiedParamList(nextOr, theContext)); } return retVal; }
@Override public IQueryParameterOr<?> parse(FhirContext theContext, String theParamName, List<QualifiedParamList> theString) throws InternalErrorException, InvalidRequestException { IQueryParameterOr<?> dt; try { dt = newInstance(); if (theString.size() == 0 || theString.get(0).size() == 0) { return dt; } if (theString.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.setValuesAsQueryTokens(theContext, theParamName, theString.get(0)); } catch (SecurityException e) { throw new InternalErrorException(e); } return dt; } }