Fix a number of problems reported by ErrorProne

This commit is contained in:
James 2017-10-16 10:00:27 -04:00
parent 22cd9d8641
commit a782bd7630
21 changed files with 11648 additions and 11423 deletions

View File

@ -73,6 +73,7 @@ public class IgPackUploader extends BaseCommand {
.and(StructureDefinition.URL.matches().value(nextResourceUrl))
.execute();
}
break;
default:
throw new ParseException("This command does not support FHIR version " + ctx.getVersion().getVersion());
}

View File

@ -1,5 +1,25 @@
package org.hl7.fhir.convertors;
/*-
* #%L
* HAPI FHIR - Converter
* %%
* Copyright (C) 2014 - 2017 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.ArrayList;
import java.util.List;

View File

@ -97,7 +97,7 @@ public class ConnectionWrapper implements Connection {
@Override
public String getClientInfo(String theName) throws SQLException {
return getClientInfo(theName);
return myWrap.getClientInfo(theName);
}
@Override

View File

@ -118,8 +118,13 @@ public abstract class BaseJpaTest {
protected List<String> toUnqualifiedVersionlessIdValues(IBundleProvider theFound) {
List<String> retVal = new ArrayList<String>();
int size = theFound.size();
Integer size = theFound.size();
ourLog.info("Found {} results", size);
if (size == null) {
size = 99999;
}
List<IBaseResource> resources = theFound.getResources(0, size);
for (IBaseResource next : resources) {
retVal.add(next.getIdElement().toUnqualifiedVersionless().getValue());

View File

@ -102,6 +102,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
case XML:
encoded = myFhirCtx.newXmlParser().encodeResourceToString(input);
try {
@ -110,6 +111,7 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
}
throw new IllegalStateException(); // shouldn't get here

View File

@ -133,6 +133,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
case XML:
encoded = myFhirCtx.newXmlParser().encodeResourceToString(input);
try {
@ -141,6 +142,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
}
throw new IllegalStateException(); // shouldn't get here

View File

@ -133,6 +133,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
case XML:
encoded = myFhirCtx.newXmlParser().encodeResourceToString(input);
try {
@ -141,6 +142,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
} catch (PreconditionFailedException e) {
return (OperationOutcome) e.getOperationOutcome();
}
break;
}
throw new IllegalStateException(); // shouldn't get here

View File

@ -1772,8 +1772,9 @@ public class ProfileUtilities extends TranslatingUtilities {
case BUNDLED : return "b";
case CONTAINED : return "c";
case REFERENCED: return "r";
default: return "?";
}
return "?";
}
@ -2232,7 +2233,7 @@ public class ProfileUtilities extends TranslatingUtilities {
if (definition != null && definition.hasShort()) {
if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, gt(definition.getShortElement()), null)));
} else if (fallback != null && fallback != null && fallback.hasShort()) {
} else if (fallback != null && fallback.hasShort()) {
if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, gt(fallback.getShortElement()), null)));
}

View File

@ -1187,6 +1187,7 @@ public class FHIRPathEngine {
return result;
case Concatenate:
result = new TypeDetails(CollectionStatus.SINGLETON, "");
return result;
case Plus:
result = new TypeDetails(CollectionStatus.SINGLETON);
if (left.hasType(worker, "integer") && right.hasType(worker, "integer"))

View File

@ -360,6 +360,9 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
// TODO: anything?\
break;
}
next();
}
@ -401,6 +404,10 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
case Boolean:
// TODO: anything?
break;
}
next();
}

View File

@ -354,11 +354,15 @@ public class StructureMapUtilities {
private static void renderGroup(StringBuilder b, StructureMapGroupComponent g) {
b.append("group ");
switch (g.getTypeMode()) {
case TYPES: b.append("for types");
case TYPEANDTYPES: b.append("for type+types ");
default: // NONE, NULL
}
case TYPES:
b.append("for types");
break;
case TYPEANDTYPES:
b.append("for type+types ");
break;
default: // NONE, NULL
break;
}
b.append(g.getName());
if (g.hasExtends()) {
b.append(" extends ");

View File

@ -364,6 +364,9 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
// TODO: anything?
break;
}
next();
}
@ -405,6 +408,10 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
case Boolean:
// TODO: anything?
break;
}
next();
}

View File

@ -1125,6 +1125,7 @@ public class FHIRPathEngine {
return result;
case Concatenate:
result = new TypeDetails(CollectionStatus.SINGLETON, "");
return result;
case Plus:
result = new TypeDetails(CollectionStatus.SINGLETON);
if (left.hasType(worker, "integer") && right.hasType(worker, "integer"))

View File

@ -1628,7 +1628,7 @@ public class ProfileUtilities {
if (definition != null && definition.hasShort()) {
if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, definition.getShort(), null)));
} else if (fallback != null && fallback != null && fallback.hasShort()) {
} else if (fallback != null && fallback.hasShort()) {
if (!c.getPieces().isEmpty()) c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, fallback.getShort(), null)));
}

View File

@ -35,6 +35,7 @@ public class OperationOutcomeUtilities {
case ERROR : return IssueSeverity.ERROR;
case WARNING : return IssueSeverity.WARNING;
case INFORMATION : return IssueSeverity.INFORMATION;
case NULL : return IssueSeverity.NULL;
}
return IssueSeverity.NULL;
}
@ -70,6 +71,7 @@ public class OperationOutcomeUtilities {
case TIMEOUT: return IssueType.TIMEOUT;
case THROTTLED: return IssueType.THROTTLED;
case INFORMATIONAL: return IssueType.INFORMATIONAL;
case NULL: return IssueType.NULL;
}
return IssueType.NULL;
}

View File

@ -589,20 +589,20 @@ public class QuestionnaireBuilder {
private Type convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
switch (af) {
// simple cases
case BOOLEAN: if (value instanceof BooleanType) return (Type) value;
case DECIMAL: if (value instanceof DecimalType) return (Type) value;
case INTEGER: if (value instanceof IntegerType) return (Type) value;
case DATE: if (value instanceof DateType) return (Type) value;
case DATETIME: if (value instanceof DateTimeType) return (Type) value;
case TIME: if (value instanceof TimeType) return (Type) value;
case BOOLEAN: if (value instanceof BooleanType) return (Type) value; break;
case DECIMAL: if (value instanceof DecimalType) return (Type) value; break;
case INTEGER: if (value instanceof IntegerType) return (Type) value; break;
case DATE: if (value instanceof DateType) return (Type) value; break;
case DATETIME: if (value instanceof DateTimeType) return (Type) value; break;
case TIME: if (value instanceof TimeType) return (Type) value; break;
case STRING:
if (value instanceof StringType)
return (Type) value;
else if (value instanceof UriType)
return new StringType(((UriType) value).asStringValue());
case TEXT: if (value instanceof StringType) return (Type) value;
case QUANTITY: if (value instanceof Quantity) return (Type) value;
break;
case TEXT: if (value instanceof StringType) return (Type) value; break;
case QUANTITY: if (value instanceof Quantity) return (Type) value; break;
// complex cases:
// ? QuestionnaireItemTypeAttachment: ...?
@ -621,6 +621,7 @@ public class QuestionnaireBuilder {
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
}
break;
case REFERENCE:
if (value instanceof Reference)
@ -629,6 +630,9 @@ public class QuestionnaireBuilder {
Reference r = new Reference();
r.setReference(((StringType) value).asStringValue());
}
break;
default:
break;
}
throw new FHIRException("Unable to convert from '"+value.getClass().toString()+"' for Answer Format "+af.toCode()+", path = "+path);

View File

@ -365,11 +365,14 @@ public class StructureMapUtilities {
private static void renderGroup(StringBuilder b, StructureMapGroupComponent g) {
b.append("group ");
switch (g.getTypeMode()) {
case TYPES: b.append("for types");
case TYPEANDTYPES: b.append("for type+types ");
case TYPES:
b.append("for types");
break;
case TYPEANDTYPES:
b.append("for type+types ");
break;
default: // NONE, NULL
}
b.append("for types ");
b.append(g.getName());
if (g.hasExtends()) {
b.append(" extends ");

View File

@ -364,6 +364,9 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
// TODO GG: This isn't handled. Should it be?
break;
}
next();
}
@ -405,6 +408,10 @@ public class JsonTrackingParser {
break;
case Eof :
throw lexer.error("Unexpected End of File");
case End:
case Boolean:
// TODO GG: These aren't handled. SHould they be?
break;
}
next();
}

View File

@ -270,7 +270,7 @@ public class TestingUtilities {
JsonArray a1 = (JsonArray) n1;
JsonArray a2 = (JsonArray) n2;
if (a1.size() != a1.size())
if (a1.size() != a2.size())
return "array properties differ at "+path+": count "+Integer.toString(a1.size())+"/"+Integer.toString(a2.size());
for (int i = 0; i < a1.size(); i++) {
String s = compareNodes(path+"["+Integer.toString(i)+"]", a1.get(i), a2.get(i));

View File

@ -1,24 +1,31 @@
package ca.uhn.fhir.to;
import static org.apache.commons.lang3.StringUtils.defaultString;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Conformance;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpResponse;
import ca.uhn.fhir.rest.client.impl.GenericClient;
import ca.uhn.fhir.to.model.HomeRequest;
import ca.uhn.fhir.util.ExtensionConstants;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicHeader;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.CapabilityStatement;
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent;
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IDomainResource;
@ -26,23 +33,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.thymeleaf.TemplateEngine;
import ca.uhn.fhir.context.*;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Conformance;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.client.api.*;
import ca.uhn.fhir.rest.client.impl.GenericClient;
import ca.uhn.fhir.to.model.HomeRequest;
import ca.uhn.fhir.util.ExtensionConstants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import static org.apache.commons.lang3.StringUtils.defaultString;
public class BaseController {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseController.class);
static final String PARAM_RESOURCE = "resource";
static final String RESOURCE_COUNT_EXT_URL = "http://hl7api.sourceforge.net/hapi-fhir/res/extdefs.html#resourceCount";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseController.class);
@Autowired
protected TesterConfig myConfig;
private Map<FhirVersionEnum, FhirContext> myContexts = new HashMap<FhirVersionEnum, FhirContext>();
@ -298,6 +301,8 @@ public class BaseController {
return loadAndAddConfDstu2(theServletRequest, theRequest, theModel);
case DSTU3:
return loadAndAddConfDstu3(theServletRequest, theRequest, theModel);
case R4:
return loadAndAddConfR4(theServletRequest, theRequest, theModel);
case DSTU2_1:
case DSTU2_HL7ORG:
break;
@ -427,6 +432,67 @@ public class BaseController {
return capabilityStatement;
}
private IBaseResource loadAndAddConfR4(HttpServletRequest theServletRequest, final HomeRequest theRequest, final ModelMap theModel) {
CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor);
org.hl7.fhir.r4.model.CapabilityStatement capabilityStatement = new org.hl7.fhir.r4.model.CapabilityStatement();
try {
capabilityStatement = client.fetchConformance().ofType(org.hl7.fhir.r4.model.CapabilityStatement.class).execute();
} catch (Exception ex) {
ourLog.warn("Failed to load conformance statement, error was: {}", ex.toString());
theModel.put("errorMsg", toDisplayError("Failed to load conformance statement, error was: " + ex.toString(), ex));
}
theModel.put("jsonEncodedConf", getContext(theRequest).newJsonParser().encodeResourceToString(capabilityStatement));
Map<String, Number> resourceCounts = new HashMap<String, Number>();
long total = 0;
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestComponent nextRest : capabilityStatement.getRest()) {
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent nextResource : nextRest.getResource()) {
List<org.hl7.fhir.r4.model.Extension> exts = nextResource.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
if (exts != null && exts.size() > 0) {
Number nextCount = ((org.hl7.fhir.r4.model.DecimalType) (exts.get(0).getValue())).getValueAsNumber();
resourceCounts.put(nextResource.getTypeElement().getValue(), nextCount);
total += nextCount.longValue();
}
}
}
theModel.put("resourceCounts", resourceCounts);
if (total > 0) {
for (org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestComponent nextRest : capabilityStatement.getRest()) {
Collections.sort(nextRest.getResource(), new Comparator<org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent>() {
@Override
public int compare(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent theO1, org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent theO2) {
org.hl7.fhir.r4.model.DecimalType count1 = new org.hl7.fhir.r4.model.DecimalType();
List<org.hl7.fhir.r4.model.Extension> count1exts = theO1.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
if (count1exts != null && count1exts.size() > 0) {
count1 = (org.hl7.fhir.r4.model.DecimalType) count1exts.get(0).getValue();
}
org.hl7.fhir.r4.model.DecimalType count2 = new org.hl7.fhir.r4.model.DecimalType();
List<org.hl7.fhir.r4.model.Extension> count2exts = theO2.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
if (count2exts != null && count2exts.size() > 0) {
count2 = (org.hl7.fhir.r4.model.DecimalType) count2exts.get(0).getValue();
}
int retVal = count2.compareTo(count1);
if (retVal == 0) {
retVal = theO1.getTypeElement().getValue().compareTo(theO2.getTypeElement().getValue());
}
return retVal;
}
});
}
}
theModel.put("requiredParamExtension", ExtensionConstants.PARAM_IS_REQUIRED);
theModel.put("conf", capabilityStatement);
return capabilityStatement;
}
protected String logPrefix(ModelMap theModel) {
return "[server=" + theModel.get("serverId") + "] - ";
}
@ -599,6 +665,22 @@ public class BaseController {
}
/**
* A hook to be overridden by subclasses. The overriding method can modify the error message
* based on its content and/or the related exception.
*
* @param theErrorMsg The original error message to be displayed to the user.
* @param theException The exception that occurred. May be null.
* @return The modified error message to be displayed to the user.
*/
protected String toDisplayError(String theErrorMsg, Exception theException) {
return theErrorMsg;
}
protected enum ResultType {
BUNDLE, NONE, RESOURCE, TAGLIST
}
public static class CaptureInterceptor implements IClientInterceptor {
private IHttpRequest myLastRequest;
@ -667,20 +749,4 @@ public class BaseController {
}
protected enum ResultType {
BUNDLE, NONE, RESOURCE, TAGLIST
}
/**
* A hook to be overridden by subclasses. The overriding method can modify the error message
* based on its content and/or the related exception.
*
* @param theErrorMsg The original error message to be displayed to the user.
* @param theException The exception that occurred. May be null.
* @return The modified error message to be displayed to the user.
*/
protected String toDisplayError(String theErrorMsg, Exception theException) {
return theErrorMsg;
}
}