001package ca.uhn.fhir.jpa.binary.api;
002
003/*-
004 * #%L
005 * HAPI FHIR Storage api
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.jpa.util.JsonDateDeserializer;
024import ca.uhn.fhir.jpa.util.JsonDateSerializer;
025import ca.uhn.fhir.model.api.IModelJson;
026import com.fasterxml.jackson.annotation.JsonProperty;
027import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
028import com.fasterxml.jackson.databind.annotation.JsonSerialize;
029import com.google.common.hash.HashingInputStream;
030import org.apache.commons.lang3.builder.ToStringBuilder;
031
032import javax.annotation.Nonnull;
033import java.util.Date;
034
035public class StoredDetails implements IModelJson {
036
037        @JsonProperty("blobId")
038        private String myBlobId;
039        @JsonProperty("bytes")
040        private long myBytes;
041        @JsonProperty("contentType")
042        private String myContentType;
043        @JsonProperty("hash")
044        private String myHash;
045        @JsonProperty("published")
046        @JsonSerialize(using = JsonDateSerializer.class)
047        @JsonDeserialize(using = JsonDateDeserializer.class)
048        private Date myPublished;
049
050        /**
051         * Constructor
052         */
053        @SuppressWarnings("unused")
054        public StoredDetails() {
055                super();
056        }
057
058        /**
059         * Constructor
060         */
061        public StoredDetails(@Nonnull String theBlobId, long theBytes, @Nonnull String theContentType, HashingInputStream theIs, Date thePublished) {
062                myBlobId = theBlobId;
063                myBytes = theBytes;
064                myContentType = theContentType;
065                myHash = theIs.hash().toString();
066                myPublished = thePublished;
067        }
068
069        @Override
070        public String toString() {
071                return new ToStringBuilder(this)
072                        .append("blobId", myBlobId)
073                        .append("bytes", myBytes)
074                        .append("contentType", myContentType)
075                        .append("hash", myHash)
076                        .append("published", myPublished)
077                        .toString();
078        }
079
080        public String getHash() {
081                return myHash;
082        }
083
084        public StoredDetails setHash(String theHash) {
085                myHash = theHash;
086                return this;
087        }
088
089        public Date getPublished() {
090                return myPublished;
091        }
092
093        public StoredDetails setPublished(Date thePublished) {
094                myPublished = thePublished;
095                return this;
096        }
097
098        @Nonnull
099        public String getContentType() {
100                return myContentType;
101        }
102
103        public StoredDetails setContentType(String theContentType) {
104                myContentType = theContentType;
105                return this;
106        }
107
108        @Nonnull
109        public String getBlobId() {
110                return myBlobId;
111        }
112
113        public StoredDetails setBlobId(String theBlobId) {
114                myBlobId = theBlobId;
115                return this;
116        }
117
118        public long getBytes() {
119                return myBytes;
120        }
121
122        public StoredDetails setBytes(long theBytes) {
123                myBytes = theBytes;
124                return this;
125        }
126
127}