
001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2023 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.jpa.bulk.imprt.model.BulkImportJobFileJson; 023 024import java.io.Serializable; 025import java.nio.charset.StandardCharsets; 026import javax.persistence.Column; 027import javax.persistence.Entity; 028import javax.persistence.ForeignKey; 029import javax.persistence.GeneratedValue; 030import javax.persistence.GenerationType; 031import javax.persistence.Id; 032import javax.persistence.Index; 033import javax.persistence.JoinColumn; 034import javax.persistence.Lob; 035import javax.persistence.ManyToOne; 036import javax.persistence.SequenceGenerator; 037import javax.persistence.Table; 038 039import static org.apache.commons.lang3.StringUtils.left; 040 041@Entity 042@Table( 043 name = "HFJ_BLK_IMPORT_JOBFILE", 044 indexes = {@Index(name = "IDX_BLKIM_JOBFILE_JOBID", columnList = "JOB_PID")}) 045public class BulkImportJobFileEntity implements Serializable { 046 047 public static final int MAX_DESCRIPTION_LENGTH = 500; 048 049 @Id 050 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_BLKIMJOBFILE_PID") 051 @SequenceGenerator(name = "SEQ_BLKIMJOBFILE_PID", sequenceName = "SEQ_BLKIMJOBFILE_PID") 052 @Column(name = "PID") 053 private Long myId; 054 055 @ManyToOne 056 @JoinColumn( 057 name = "JOB_PID", 058 referencedColumnName = "PID", 059 nullable = false, 060 foreignKey = @ForeignKey(name = "FK_BLKIMJOBFILE_JOB")) 061 private BulkImportJobEntity myJob; 062 063 @Column(name = "FILE_SEQ", nullable = false) 064 private int myFileSequence; 065 066 @Column(name = "FILE_DESCRIPTION", nullable = true, length = MAX_DESCRIPTION_LENGTH) 067 private String myFileDescription; 068 069 @Lob 070 @Column(name = "JOB_CONTENTS", nullable = false) 071 private byte[] myContents; 072 073 @Column(name = "TENANT_NAME", nullable = true, length = PartitionEntity.MAX_NAME_LENGTH) 074 private String myTenantName; 075 076 public String getFileDescription() { 077 return myFileDescription; 078 } 079 080 public void setFileDescription(String theFileDescription) { 081 myFileDescription = left(theFileDescription, MAX_DESCRIPTION_LENGTH); 082 } 083 084 public BulkImportJobEntity getJob() { 085 return myJob; 086 } 087 088 public void setJob(BulkImportJobEntity theJob) { 089 myJob = theJob; 090 } 091 092 public int getFileSequence() { 093 return myFileSequence; 094 } 095 096 public void setFileSequence(int theFileSequence) { 097 myFileSequence = theFileSequence; 098 } 099 100 public String getContents() { 101 return new String(myContents, StandardCharsets.UTF_8); 102 } 103 104 public void setContents(String theContents) { 105 myContents = theContents.getBytes(StandardCharsets.UTF_8); 106 } 107 108 public BulkImportJobFileJson toJson() { 109 return new BulkImportJobFileJson().setContents(getContents()).setTenantName(getTenantName()); 110 } 111 112 public String getTenantName() { 113 return myTenantName; 114 } 115 116 public void setTenantName(String theTenantName) { 117 myTenantName = theTenantName; 118 } 119}