001/*-
002 * #%L
003 * HAPI FHIR JPA Model
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.model.entity;
021
022import ca.uhn.fhir.context.FhirVersionEnum;
023import ca.uhn.fhir.util.StringUtil;
024import jakarta.persistence.Column;
025import jakarta.persistence.Entity;
026import jakarta.persistence.EnumType;
027import jakarta.persistence.Enumerated;
028import jakarta.persistence.ForeignKey;
029import jakarta.persistence.GeneratedValue;
030import jakarta.persistence.GenerationType;
031import jakarta.persistence.Id;
032import jakarta.persistence.Index;
033import jakarta.persistence.JoinColumn;
034import jakarta.persistence.ManyToOne;
035import jakarta.persistence.OneToMany;
036import jakarta.persistence.SequenceGenerator;
037import jakarta.persistence.Table;
038import jakarta.persistence.Temporal;
039import jakarta.persistence.TemporalType;
040import jakarta.persistence.Version;
041import org.apache.commons.lang3.builder.ToStringBuilder;
042import org.apache.commons.lang3.builder.ToStringStyle;
043
044import java.util.Date;
045import java.util.List;
046
047@Entity()
048@Table(
049                name = "NPM_PACKAGE_VER",
050                uniqueConstraints = {},
051                indexes = {
052                        @Index(name = "IDX_PACKVER", columnList = "PACKAGE_ID,VERSION_ID", unique = true),
053                        @Index(name = "FK_NPM_PKV_PKG", columnList = "PACKAGE_PID"),
054                        @Index(name = "FK_NPM_PKV_RESID", columnList = "BINARY_RES_ID")
055                })
056public class NpmPackageVersionEntity {
057
058        public static final int VERSION_ID_LENGTH = 200;
059        public static final int PACKAGE_DESC_LENGTH = 512;
060        public static final int FHIR_VERSION_LENGTH = 10;
061        public static final int FHIR_VERSION_ID_LENGTH = 20;
062
063        @SequenceGenerator(name = "SEQ_NPM_PACKVER", sequenceName = "SEQ_NPM_PACKVER")
064        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_NPM_PACKVER")
065        @Id
066        @Column(name = "PID")
067        private Long myId;
068
069        @Column(name = "PACKAGE_ID", length = NpmPackageEntity.PACKAGE_ID_LENGTH, nullable = false)
070        private String myPackageId;
071
072        @Column(name = "VERSION_ID", length = NpmPackageVersionEntity.VERSION_ID_LENGTH, nullable = false)
073        private String myVersionId;
074
075        @ManyToOne
076        @JoinColumn(name = "PACKAGE_PID", nullable = false, foreignKey = @ForeignKey(name = "FK_NPM_PKV_PKG"))
077        private NpmPackageEntity myPackage;
078
079        @ManyToOne
080        @JoinColumn(
081                        name = "BINARY_RES_ID",
082                        referencedColumnName = "RES_ID",
083                        nullable = false,
084                        foreignKey = @ForeignKey(name = "FK_NPM_PKV_RESID"))
085        private ResourceTable myPackageBinary;
086
087        @Temporal(TemporalType.TIMESTAMP)
088        @Column(name = "SAVED_TIME", nullable = false)
089        private Date mySavedTime;
090
091        @Column(name = "PKG_DESC", nullable = true, length = PACKAGE_DESC_LENGTH)
092        private String myDescription;
093
094        @Column(name = "DESC_UPPER", nullable = true, length = PACKAGE_DESC_LENGTH)
095        private String myDescriptionUpper;
096
097        @Column(name = "PKG_AUTHOR", nullable = true, length = PACKAGE_DESC_LENGTH)
098        private String myAuthor;
099
100        @Column(name = "AUTHOR_UPPER", nullable = true, length = PACKAGE_DESC_LENGTH)
101        private String myAuthorUpper;
102
103        @Column(name = "CURRENT_VERSION", nullable = false)
104        private boolean myCurrentVersion;
105
106        @Column(name = "FHIR_VERSION_ID", length = NpmPackageVersionEntity.FHIR_VERSION_ID_LENGTH, nullable = false)
107        private String myFhirVersionId;
108
109        @Enumerated(EnumType.STRING)
110        @Column(name = "FHIR_VERSION", length = NpmPackageVersionEntity.FHIR_VERSION_LENGTH, nullable = false)
111        private FhirVersionEnum myFhirVersion;
112
113        @Column(name = "PACKAGE_SIZE_BYTES", nullable = false)
114        private long myPackageSizeBytes;
115
116        @Temporal(TemporalType.TIMESTAMP)
117        @Version
118        @Column(name = "UPDATED_TIME", nullable = false)
119        private Date myUpdatedTime;
120
121        @OneToMany(mappedBy = "myPackageVersion")
122        private List<NpmPackageVersionResourceEntity> myResources;
123
124        public Date getUpdatedTime() {
125                return myUpdatedTime;
126        }
127
128        public long getPackageSizeBytes() {
129                return myPackageSizeBytes;
130        }
131
132        public void setPackageSizeBytes(long thePackageSizeBytes) {
133                myPackageSizeBytes = thePackageSizeBytes;
134        }
135
136        public boolean isCurrentVersion() {
137                return myCurrentVersion;
138        }
139
140        public void setCurrentVersion(boolean theCurrentVersion) {
141                myCurrentVersion = theCurrentVersion;
142        }
143
144        public String getPackageId() {
145                return myPackageId;
146        }
147
148        public void setPackageId(String thePackageId) {
149                myPackageId = thePackageId;
150        }
151
152        public String getVersionId() {
153                return myVersionId;
154        }
155
156        public void setVersionId(String theVersionId) {
157                myVersionId = theVersionId;
158        }
159
160        public String getFhirVersionId() {
161                return myFhirVersionId;
162        }
163
164        public void setFhirVersionId(String theFhirVersionId) {
165                myFhirVersionId = theFhirVersionId;
166        }
167
168        public FhirVersionEnum getFhirVersion() {
169                return myFhirVersion;
170        }
171
172        public void setFhirVersion(FhirVersionEnum theFhirVersion) {
173                myFhirVersion = theFhirVersion;
174        }
175
176        public NpmPackageEntity getPackage() {
177                return myPackage;
178        }
179
180        public void setPackage(NpmPackageEntity thePackage) {
181                myPackage = thePackage;
182        }
183
184        public ResourceTable getPackageBinary() {
185                return myPackageBinary;
186        }
187
188        public void setPackageBinary(ResourceTable thePackageBinary) {
189                myPackageBinary = thePackageBinary;
190        }
191
192        public void setSavedTime(Date theSavedTime) {
193                mySavedTime = theSavedTime;
194        }
195
196        public String getDescription() {
197                return myDescription;
198        }
199
200        public void setDescription(String theDescription) {
201                myDescription = theDescription;
202                myDescriptionUpper = StringUtil.normalizeStringForSearchIndexing(theDescription);
203        }
204
205        public String getAuthor() {
206                return myAuthor;
207        }
208
209        public void setAuthor(String theAuthor) {
210                myAuthor = theAuthor;
211                myAuthorUpper = StringUtil.normalizeStringForSearchIndexing(theAuthor);
212        }
213
214        @Override
215        public String toString() {
216                return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
217                                .append("myId", myId)
218                                .append("myPackageId", myPackageId)
219                                .append("myVersionId", myVersionId)
220                                .append("myDescriptionUpper", myDescriptionUpper)
221                                .append("myFhirVersionId", myFhirVersionId)
222                                .toString();
223        }
224
225        public List<NpmPackageVersionResourceEntity> getResources() {
226                return myResources;
227        }
228}