View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.requests.query;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage;
19  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
20  
21  import javax.xml.bind.annotation.XmlEnum;
22  import javax.xml.bind.annotation.XmlEnumValue;
23  import javax.xml.bind.annotation.XmlType;
24  
25  /**
26   * All possible query types.
27   * @author Jens Riemschneider
28   * @author Michael Ottati
29   */
30  @XmlType(name = "QueryType")
31  @XmlEnum
32  public enum QueryType {
33      /** Searches for documents. */
34      @XmlEnumValue("FindDocuments") FIND_DOCUMENTS("urn:uuid:14d4debf-8f97-4251-9a74-a90016b0af0d", FindDocumentsQuery.class),
35      /** Searches for documents (Multi Patient Variety). */
36      @XmlEnumValue("FindDocumentsForMultiplePatients") FIND_DOCUMENTS_MPQ("urn:uuid:3d1bdb10-39a2-11de-89c2-2f44d94eaa9f", FindDocumentsForMultiplePatientsQuery.class),
37      /** Searches for submission sets. */
38      @XmlEnumValue("FindSubmissionSets") FIND_SUBMISSION_SETS("urn:uuid:f26abbcb-ac74-4422-8a30-edb644bbc1a9", FindSubmissionSetsQuery.class),
39      /** Searches for folders. */
40      @XmlEnumValue("FindFolders") FIND_FOLDERS("urn:uuid:958f3006-baad-4929-a4de-ff1114824431", FindFoldersQuery.class),
41      /** Searches for documents by reference IDs */
42      @XmlEnumValue("FindDocumentsByReferenceId") FIND_DOCUMENTS_BY_REFERENCE_ID("urn:uuid:12941a89-e02e-4be5-967c-ce4bfc8fe492", FindDocumentsByReferenceIdQuery.class),
43      /** Searches for folders (Multi Patient Variety). */
44      @XmlEnumValue("FindFoldersForMultiplePatients") FIND_FOLDERS_MPQ("urn:uuid:50d3f5ac-39a2-11de-a1ca-b366239e58df", FindFoldersForMultiplePatientsQuery.class),
45      /** Returns everything. */
46      @XmlEnumValue("GetAll") GET_ALL("urn:uuid:10b545ea-725c-446d-9b95-8aeb444eddf3", GetAllQuery.class),
47      /** Returns specific documents. */
48      @XmlEnumValue("GetDocuments") GET_DOCUMENTS("urn:uuid:5c4f972b-d56b-40ac-a5fc-c8ca9b40b9d4", GetDocumentsQuery.class),
49      /** Returns specific folders. */
50      @XmlEnumValue("GetFolders") GET_FOLDERS("urn:uuid:5737b14c-8a1a-4539-b659-e03a34a5e1e4", GetFoldersQuery.class),
51      /** Returns specific associations. */
52      @XmlEnumValue("GetAssociations") GET_ASSOCIATIONS("urn:uuid:a7ae438b-4bc2-4642-93e9-be891f7bb155", GetAssociationsQuery.class),
53      /** Returns specific documents and their associations. */
54      @XmlEnumValue("GetDocumentsAndAssociations") GET_DOCUMENTS_AND_ASSOCIATIONS("urn:uuid:bab9529a-4a10-40b3-a01f-f68a615d247a", GetDocumentsAndAssociationsQuery.class),
55      /** Returns specific submission sets. */
56      @XmlEnumValue("GetSubmissionSets") GET_SUBMISSION_SETS("urn:uuid:51224314-5390-4169-9b91-b1980040715a", GetSubmissionSetsQuery.class),
57      /** Returns specific submission sets and their contents. */
58      @XmlEnumValue("GetSubmissionSetAndContents") GET_SUBMISSION_SET_AND_CONTENTS("urn:uuid:e8e3cb2c-e39c-46b9-99e4-c12f57260b83", GetSubmissionSetAndContentsQuery.class),
59      /** Returns specific folders and their contents. */
60      @XmlEnumValue("GetFolderAndContents") GET_FOLDER_AND_CONTENTS("urn:uuid:b909a503-523d-4517-8acf-8e5834dfc4c7", GetFolderAndContentsQuery.class),
61      /** Returns folders for a specific document. */
62      @XmlEnumValue("GetFoldersForDocument") GET_FOLDERS_FOR_DOCUMENT("urn:uuid:10cae35a-c7f9-4cf5-b61e-fc3278ffb578", GetFoldersForDocumentQuery.class),
63      /** Returns all documents with a given relation to a specified entry. */
64      @XmlEnumValue("GetRelatedDocuments") GET_RELATED_DOCUMENTS("urn:uuid:d90e5407-b356-4d91-a89f-873917b4b0e6", GetRelatedDocumentsQuery.class),
65      /** Cross-Community Fetch query (ITI-63). */
66      @XmlEnumValue("Fetch") FETCH("urn:uuid:f2072993-9478-41df-a603-8f016706efe8", FetchQuery.class);
67  
68      private final String id;
69      private final Class<? extends Query> type; 
70      
71      QueryType(String id, Class<? extends Query> type) {
72          this.id = id;
73          this.type = type;
74      }
75  
76      /**
77       * @return the ID of the query.
78       */
79      public String getId() {
80          return id;
81      }
82      
83      /**
84       * @return the class implementing the query. 
85       */
86      public Class<? extends Query> getType() {
87          return type;
88      }
89  
90      /**
91       * Returns a query type by its id.
92       * @param id
93       *          the id. Can be <code>null</code>.
94       * @return the type. <code>null</code> if the id is <code>null</code>.
95       */
96      public static QueryType valueOfId(String id) {
97          if (id == null) {
98              return null;
99          }
100 
101         for (QueryType type : values()) {
102             if (id.equals(type.getId())) {
103                 return type;
104             }
105         }
106         
107         throw new XDSMetaDataException(ValidationMessage.UNKNOWN_QUERY_TYPE, id);
108     }
109 }