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.chunk; 021 022import ca.uhn.fhir.jpa.api.pid.TypedResourcePid; 023import ca.uhn.fhir.model.api.IModelJson; 024import com.fasterxml.jackson.annotation.JsonProperty; 025import org.apache.commons.lang3.builder.EqualsBuilder; 026import org.apache.commons.lang3.builder.HashCodeBuilder; 027 028public class TypedPidJson implements IModelJson { 029 030 @JsonProperty("type") 031 private String myResourceType; 032 033 @JsonProperty("id") 034 private String myPid; 035 036 public TypedPidJson() {} 037 038 public TypedPidJson(String theResourceType, String theId) { 039 myResourceType = theResourceType; 040 myPid = theId; 041 } 042 043 public TypedPidJson(TypedResourcePid theTypedResourcePid) { 044 myResourceType = theTypedResourcePid.resourceType; 045 myPid = theTypedResourcePid.id.toString(); 046 } 047 048 @Override 049 public String toString() { 050 // We put a space in here and not a "/" since this is a PID, not 051 // a resource ID 052 return "[" + myResourceType + " " + myPid + "]"; 053 } 054 055 public String getResourceType() { 056 return myResourceType; 057 } 058 059 public TypedPidJson setResourceType(String theResourceType) { 060 myResourceType = theResourceType; 061 return this; 062 } 063 064 public String getPid() { 065 return myPid; 066 } 067 068 public TypedPidJson setPid(String thePid) { 069 myPid = thePid; 070 return this; 071 } 072 073 @Override 074 public boolean equals(Object theO) { 075 if (this == theO) return true; 076 077 if (theO == null || getClass() != theO.getClass()) return false; 078 079 TypedPidJson id = (TypedPidJson) theO; 080 081 return new EqualsBuilder() 082 .append(myResourceType, id.myResourceType) 083 .append(myPid, id.myPid) 084 .isEquals(); 085 } 086 087 @Override 088 public int hashCode() { 089 return new HashCodeBuilder(17, 37).append(myResourceType).append(myPid).toHashCode(); 090 } 091}