View Javadoc
1   package ca.uhn.fhir.validation;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
24  
25  /**
26   * Encapsulates the results of validation
27   *
28   * @see ca.uhn.fhir.validation.FhirValidator
29   * @since 0.7
30   */
31  public class ValidationResult {
32      private OperationOutcome myOperationOutcome;
33  
34      private ValidationResult(OperationOutcome myOperationOutcome) {
35          this.myOperationOutcome = myOperationOutcome;
36      }
37  
38      public static ValidationResult valueOf(OperationOutcome myOperationOutcome) {
39          return new ValidationResult(myOperationOutcome);
40      }
41  
42      public OperationOutcome getOperationOutcome() {
43          return myOperationOutcome;
44      }
45  
46      @Override
47      public String toString() {
48          return "ValidationResult{" +
49                  "myOperationOutcome=" + myOperationOutcome +
50                  ", description='" + toDescription() + '\'' +
51                  '}';
52      }
53  
54      private String toDescription() {
55          StringBuilder b = new StringBuilder(100);
56          if (myOperationOutcome != null) {
57              OperationOutcome.Issue issueFirstRep = myOperationOutcome.getIssueFirstRep();
58              b.append(issueFirstRep.getDetails().getValue());
59              b.append(" - ");
60              b.append(issueFirstRep.getLocationFirstRep().getValue());
61          }
62          return b.toString();
63      }
64  
65      /**
66       * Was the validation successful
67       * @return true if the validation was successful
68       */
69      public boolean isSuccessful() {
70          return myOperationOutcome == null || myOperationOutcome.getIssue().isEmpty();
71      }
72  }