001package ca.uhn.fhir.jpa.model.entity;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Model
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.context.FhirVersionEnum;
024import ca.uhn.fhir.util.StringUtil;
025import org.apache.commons.lang3.builder.ToStringBuilder;
026import org.apache.commons.lang3.builder.ToStringStyle;
027
028import javax.persistence.Column;
029import javax.persistence.Entity;
030import javax.persistence.EnumType;
031import javax.persistence.Enumerated;
032import javax.persistence.ForeignKey;
033import javax.persistence.GeneratedValue;
034import javax.persistence.GenerationType;
035import javax.persistence.Id;
036import javax.persistence.Index;
037import javax.persistence.JoinColumn;
038import javax.persistence.ManyToOne;
039import javax.persistence.OneToMany;
040import javax.persistence.OneToOne;
041import javax.persistence.SequenceGenerator;
042import javax.persistence.Table;
043import javax.persistence.Temporal;
044import javax.persistence.TemporalType;
045import javax.persistence.Version;
046import java.util.Date;
047import java.util.List;
048
049@Entity()
050@Table(name = "NPM_PACKAGE_VER", uniqueConstraints = {
051}, indexes = {
052        @Index(name = "IDX_PACKVER", columnList = "PACKAGE_ID,VERSION_ID", unique = true)
053})
054public class NpmPackageVersionEntity {
055
056        public static final int VERSION_ID_LENGTH = 200;
057        public static final int PACKAGE_DESC_LENGTH = 200;
058        public static final int FHIR_VERSION_LENGTH = 10;
059
060        @SequenceGenerator(name = "SEQ_NPM_PACKVER", sequenceName = "SEQ_NPM_PACKVER")
061        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_NPM_PACKVER")
062        @Id
063        @Column(name = "PID")
064        private Long myId;
065        @Column(name = "PACKAGE_ID", length = NpmPackageEntity.PACKAGE_ID_LENGTH, nullable = false)
066        private String myPackageId;
067        @Column(name = "VERSION_ID", length = NpmPackageVersionEntity.VERSION_ID_LENGTH, nullable = false)
068        private String myVersionId;
069        @ManyToOne
070        @JoinColumn(name = "PACKAGE_PID", nullable = false, foreignKey = @ForeignKey(name = "FK_NPM_PKV_PKG"))
071        private NpmPackageEntity myPackage;
072        @OneToOne
073        @JoinColumn(name = "BINARY_RES_ID", referencedColumnName = "RES_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_NPM_PKV_RESID"))
074        private ResourceTable myPackageBinary;
075        @Temporal(TemporalType.TIMESTAMP)
076        @Column(name = "SAVED_TIME", nullable = false)
077        private Date mySavedTime;
078        @Column(name = "PKG_DESC", nullable = true, length = PACKAGE_DESC_LENGTH)
079        private String myDescription;
080        @Column(name = "DESC_UPPER", nullable = true, length = PACKAGE_DESC_LENGTH)
081        private String myDescriptionUpper;
082        @Column(name = "CURRENT_VERSION", nullable = false)
083        private boolean myCurrentVersion;
084        @Column(name = "FHIR_VERSION_ID", length = NpmPackageVersionEntity.FHIR_VERSION_LENGTH, nullable = false)
085        private String myFhirVersionId;
086        @Enumerated(EnumType.STRING)
087        @Column(name = "FHIR_VERSION", length = NpmPackageVersionEntity.FHIR_VERSION_LENGTH, nullable = false)
088        private FhirVersionEnum myFhirVersion;
089        @Column(name = "PACKAGE_SIZE_BYTES", nullable = false)
090        private long myPackageSizeBytes;
091        @Temporal(TemporalType.TIMESTAMP)
092        @Version
093        @Column(name = "UPDATED_TIME", nullable = false)
094        private Date myUpdatedTime;
095        @OneToMany(mappedBy = "myPackageVersion")
096        private List<NpmPackageVersionResourceEntity> myResources;
097
098        public Date getUpdatedTime() {
099                return myUpdatedTime;
100        }
101
102        public long getPackageSizeBytes() {
103                return myPackageSizeBytes;
104        }
105
106        public void setPackageSizeBytes(long thePackageSizeBytes) {
107                myPackageSizeBytes = thePackageSizeBytes;
108        }
109
110        public boolean isCurrentVersion() {
111                return myCurrentVersion;
112        }
113
114        public void setCurrentVersion(boolean theCurrentVersion) {
115                myCurrentVersion = theCurrentVersion;
116        }
117
118        public String getPackageId() {
119                return myPackageId;
120        }
121
122        public void setPackageId(String thePackageId) {
123                myPackageId = thePackageId;
124        }
125
126        public String getVersionId() {
127                return myVersionId;
128        }
129
130        public void setVersionId(String theVersionId) {
131                myVersionId = theVersionId;
132        }
133
134        public String getFhirVersionId() {
135                return myFhirVersionId;
136        }
137
138        public void setFhirVersionId(String theFhirVersionId) {
139                myFhirVersionId = theFhirVersionId;
140        }
141
142        public FhirVersionEnum getFhirVersion() {
143                return myFhirVersion;
144        }
145
146        public void setFhirVersion(FhirVersionEnum theFhirVersion) {
147                myFhirVersion = theFhirVersion;
148        }
149
150        public NpmPackageEntity getPackage() {
151                return myPackage;
152        }
153
154        public void setPackage(NpmPackageEntity thePackage) {
155                myPackage = thePackage;
156        }
157
158        public ResourceTable getPackageBinary() {
159                return myPackageBinary;
160        }
161
162        public void setPackageBinary(ResourceTable thePackageBinary) {
163                myPackageBinary = thePackageBinary;
164        }
165
166        public void setSavedTime(Date theSavedTime) {
167                mySavedTime = theSavedTime;
168        }
169
170        public String getDescription() {
171                return myDescription;
172        }
173
174        public void setDescription(String theDescription) {
175                myDescription = theDescription;
176                myDescriptionUpper = StringUtil.normalizeStringForSearchIndexing(theDescription);
177        }
178
179        @Override
180        public String toString() {
181                return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
182                        .append("myId", myId)
183                        .append("myPackageId", myPackageId)
184                        .append("myVersionId", myVersionId)
185                        .append("myDescriptionUpper", myDescriptionUpper)
186                        .append("myFhirVersionId", myFhirVersionId)
187                        .toString();
188        }
189
190        public List<NpmPackageVersionResourceEntity> getResources() {
191                return myResources;
192        }
193}