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.packages; 021 022import ca.uhn.fhir.rest.server.util.JsonDateDeserializer; 023import ca.uhn.fhir.rest.server.util.JsonDateSerializer; 024import com.fasterxml.jackson.annotation.JsonAutoDetect; 025import com.fasterxml.jackson.annotation.JsonInclude; 026import com.fasterxml.jackson.annotation.JsonProperty; 027import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 028import com.fasterxml.jackson.databind.annotation.JsonSerialize; 029import io.swagger.v3.oas.annotations.media.Schema; 030import jakarta.annotation.Nonnull; 031 032import java.util.Date; 033import java.util.LinkedHashMap; 034import java.util.Map; 035 036@Schema(description = "Represents an NPM package metadata response") 037@JsonInclude(JsonInclude.Include.NON_NULL) 038@JsonAutoDetect( 039 creatorVisibility = JsonAutoDetect.Visibility.NONE, 040 fieldVisibility = JsonAutoDetect.Visibility.NONE, 041 getterVisibility = JsonAutoDetect.Visibility.NONE, 042 isGetterVisibility = JsonAutoDetect.Visibility.NONE, 043 setterVisibility = JsonAutoDetect.Visibility.NONE) 044public class NpmPackageMetadataJson { 045 046 @JsonProperty("dist-tags") 047 private DistTags myDistTags; 048 049 @JsonProperty("modified") 050 @JsonSerialize(using = JsonDateSerializer.class) 051 @JsonDeserialize(using = JsonDateDeserializer.class) 052 private Date myModified; 053 054 @JsonProperty("name") 055 private String myName; 056 057 @JsonProperty("versions") 058 private Map<String, Version> myVersionIdToVersion; 059 060 public void addVersion(Version theVersion) { 061 getVersions().put(theVersion.getVersion(), theVersion); 062 } 063 064 @Nonnull 065 public Map<String, Version> getVersions() { 066 if (myVersionIdToVersion == null) { 067 myVersionIdToVersion = new LinkedHashMap<>(); 068 } 069 return myVersionIdToVersion; 070 } 071 072 public DistTags getDistTags() { 073 return myDistTags; 074 } 075 076 public void setDistTags(DistTags theDistTags) { 077 myDistTags = theDistTags; 078 } 079 080 public void setModified(Date theModified) { 081 myModified = theModified; 082 } 083 084 public void setName(String theName) { 085 myName = theName; 086 } 087 088 public static class DistTags { 089 090 @JsonProperty("latest") 091 private String myLatest; 092 093 public String getLatest() { 094 return myLatest; 095 } 096 097 public DistTags setLatest(String theLatest) { 098 myLatest = theLatest; 099 return this; 100 } 101 } 102 103 @JsonInclude(JsonInclude.Include.NON_NULL) 104 @JsonAutoDetect( 105 creatorVisibility = JsonAutoDetect.Visibility.NONE, 106 fieldVisibility = JsonAutoDetect.Visibility.NONE, 107 getterVisibility = JsonAutoDetect.Visibility.NONE, 108 isGetterVisibility = JsonAutoDetect.Visibility.NONE, 109 setterVisibility = JsonAutoDetect.Visibility.NONE) 110 public static class Version { 111 112 @JsonProperty("name") 113 private String myName; 114 115 @JsonProperty("version") 116 private String myVersion; 117 118 @JsonProperty("description") 119 private String myDescription; 120 121 @JsonProperty("fhirVersion") 122 private String myFhirVersion; 123 124 @Schema(description = "The size of this package in bytes", example = "1000") 125 @JsonProperty("_bytes") 126 private long myBytes; 127 128 public String getName() { 129 return myName; 130 } 131 132 public void setName(String theName) { 133 myName = theName; 134 } 135 136 public String getDescription() { 137 return myDescription; 138 } 139 140 public void setDescription(String theDescription) { 141 myDescription = theDescription; 142 } 143 144 public String getFhirVersion() { 145 return myFhirVersion; 146 } 147 148 public void setFhirVersion(String theFhirVersion) { 149 myFhirVersion = theFhirVersion; 150 } 151 152 public String getVersion() { 153 return myVersion; 154 } 155 156 public void setVersion(String theVersion) { 157 myVersion = theVersion; 158 } 159 160 public long getBytes() { 161 return myBytes; 162 } 163 164 public void setBytes(long theBytes) { 165 myBytes = theBytes; 166 } 167 } 168}