001/*-
002 * #%L
003 * HAPI FHIR JPA Server - Batch2 Task Processor
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.batch2.jobs.parameters;
021
022import ca.uhn.fhir.interceptor.model.RequestPartitionId;
023import ca.uhn.fhir.model.api.IModelJson;
024import com.fasterxml.jackson.annotation.JsonProperty;
025import jakarta.validation.constraints.Pattern;
026import org.apache.commons.lang3.builder.EqualsBuilder;
027import org.apache.commons.lang3.builder.HashCodeBuilder;
028import org.apache.commons.lang3.builder.ToStringBuilder;
029import org.apache.commons.lang3.builder.ToStringStyle;
030
031/**
032 * Represents the pair of partition and (search) url, which can be used to configure batch2 jobs.
033 * It will be used to determine which FHIR resources are selected for the job.
034 * Please note that the url is a partial url, which means it does not include server base and tenantId,
035 * and it starts with the with resource type.
036 * e.g. Patient?, Observation?status=final
037 */
038public class PartitionedUrl implements IModelJson {
039        @JsonProperty("url")
040        @Pattern(
041                        regexp = "^[A-Z][A-Za-z0-9]+\\?.*",
042                        message = "If populated, URL must be a search URL in the form '{resourceType}?[params]'")
043        private String myUrl;
044
045        @JsonProperty("requestPartitionId")
046        private RequestPartitionId myRequestPartitionId;
047
048        public String getUrl() {
049                return myUrl;
050        }
051
052        public PartitionedUrl setUrl(String theUrl) {
053                myUrl = theUrl;
054                return this;
055        }
056
057        public RequestPartitionId getRequestPartitionId() {
058                return myRequestPartitionId;
059        }
060
061        public PartitionedUrl setRequestPartitionId(RequestPartitionId theRequestPartitionId) {
062                myRequestPartitionId = theRequestPartitionId;
063                return this;
064        }
065
066        @Override
067        public String toString() {
068                ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
069                b.append("myUrl", myUrl);
070                b.append("myRequestPartitionId", myRequestPartitionId);
071                return b.toString();
072        }
073
074        @Override
075        public boolean equals(Object obj) {
076                if (this == obj) {
077                        return true;
078                }
079                if (!(obj instanceof PartitionedUrl)) {
080                        return false;
081                }
082                PartitionedUrl other = (PartitionedUrl) obj;
083                EqualsBuilder b = new EqualsBuilder();
084                b.append(myUrl, other.myUrl);
085                b.append(myRequestPartitionId, other.myRequestPartitionId);
086                return b.isEquals();
087        }
088
089        @Override
090        public int hashCode() {
091                HashCodeBuilder b = new HashCodeBuilder();
092                b.append(myRequestPartitionId);
093                b.append(myUrl);
094                return b.hashCode();
095        }
096}