001/*- 002 * #%L 003 * HAPI FHIR JPA Server 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.jpa.entity; 021 022import ca.uhn.fhir.batch2.model.WorkChunkMetadata; 023import ca.uhn.fhir.batch2.model.WorkChunkStatusEnum; 024import jakarta.persistence.Column; 025import jakarta.persistence.Entity; 026import jakarta.persistence.EnumType; 027import jakarta.persistence.Enumerated; 028import jakarta.persistence.Id; 029import org.hibernate.annotations.Immutable; 030import org.hibernate.annotations.Subselect; 031 032import java.io.Serializable; 033 034import static ca.uhn.fhir.batch2.model.JobDefinition.ID_MAX_LENGTH; 035 036/** 037 * A view for a Work Chunk that contains only the most necessary information 038 * to satisfy the no-data path. 039 */ 040@Entity 041@Immutable 042@Subselect("SELECT e.id as id, " 043 + " e.seq as seq," 044 + " e.stat as state, " 045 + " e.instance_id as instance_id, " 046 + " e.definition_id as job_definition_id, " 047 + " e.definition_ver as job_definition_version, " 048 + " e.tgt_step_id as target_step_id " 049 + "FROM BT2_WORK_CHUNK e") 050public class Batch2WorkChunkMetadataView implements Serializable { 051 052 @Id 053 @Column(name = "ID", length = ID_MAX_LENGTH) 054 private String myId; 055 056 @Column(name = "SEQ", nullable = false) 057 private int mySequence; 058 059 @Column(name = "STATE", length = ID_MAX_LENGTH, nullable = false) 060 @Enumerated(EnumType.STRING) 061 private WorkChunkStatusEnum myStatus; 062 063 @Column(name = "INSTANCE_ID", length = ID_MAX_LENGTH, nullable = false) 064 private String myInstanceId; 065 066 @Column(name = "JOB_DEFINITION_ID", length = ID_MAX_LENGTH, nullable = false) 067 private String myJobDefinitionId; 068 069 @Column(name = "JOB_DEFINITION_VERSION", nullable = false) 070 private int myJobDefinitionVersion; 071 072 @Column(name = "TARGET_STEP_ID", length = ID_MAX_LENGTH, nullable = false) 073 private String myTargetStepId; 074 075 public String getId() { 076 return myId; 077 } 078 079 public void setId(String theId) { 080 myId = theId; 081 } 082 083 public int getSequence() { 084 return mySequence; 085 } 086 087 public void setSequence(int theSequence) { 088 mySequence = theSequence; 089 } 090 091 public WorkChunkStatusEnum getStatus() { 092 return myStatus; 093 } 094 095 public void setStatus(WorkChunkStatusEnum theStatus) { 096 myStatus = theStatus; 097 } 098 099 public String getInstanceId() { 100 return myInstanceId; 101 } 102 103 public void setInstanceId(String theInstanceId) { 104 myInstanceId = theInstanceId; 105 } 106 107 public String getJobDefinitionId() { 108 return myJobDefinitionId; 109 } 110 111 public void setJobDefinitionId(String theJobDefinitionId) { 112 myJobDefinitionId = theJobDefinitionId; 113 } 114 115 public int getJobDefinitionVersion() { 116 return myJobDefinitionVersion; 117 } 118 119 public void setJobDefinitionVersion(int theJobDefinitionVersion) { 120 myJobDefinitionVersion = theJobDefinitionVersion; 121 } 122 123 public String getTargetStepId() { 124 return myTargetStepId; 125 } 126 127 public void setTargetStepId(String theTargetStepId) { 128 myTargetStepId = theTargetStepId; 129 } 130 131 public WorkChunkMetadata toChunkMetadata() { 132 WorkChunkMetadata metadata = new WorkChunkMetadata(); 133 metadata.setId(getId()); 134 metadata.setInstanceId(getInstanceId()); 135 metadata.setSequence(getSequence()); 136 metadata.setStatus(getStatus()); 137 metadata.setJobDefinitionId(getJobDefinitionId()); 138 metadata.setJobDefinitionVersion(getJobDefinitionVersion()); 139 metadata.setTargetStepId(getTargetStepId()); 140 return metadata; 141 } 142}