001package ca.uhn.fhir.jpa.packages; 002 003/* 004 * #%L 005 * HAPI FHIR JPA Server 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 com.fasterxml.jackson.annotation.JsonAutoDetect; 024import com.fasterxml.jackson.annotation.JsonInclude; 025import com.fasterxml.jackson.annotation.JsonProperty; 026import io.swagger.annotations.ApiModel; 027import io.swagger.annotations.ApiModelProperty; 028 029import java.util.ArrayList; 030import java.util.List; 031 032@ApiModel("Represents an NPM package search response") 033@JsonInclude(JsonInclude.Include.NON_NULL) 034@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) 035public class NpmPackageSearchResultJson { 036 037 @JsonProperty("objects") 038 private List<ObjectElement> myObjects; 039 @JsonProperty("total") 040 private int myTotal; 041 042 public List<ObjectElement> getObjects() { 043 if (myObjects == null) { 044 myObjects = new ArrayList<>(); 045 } 046 return myObjects; 047 } 048 049 public ObjectElement addObject() { 050 ObjectElement object = new ObjectElement(); 051 getObjects().add(object); 052 return object; 053 } 054 055 public int getTotal() { 056 return myTotal; 057 } 058 059 public void setTotal(int theTotal) { 060 myTotal = theTotal; 061 } 062 063 public boolean hasPackageWithId(String thePackageId) { 064 return getObjects().stream().anyMatch(t -> t.getPackage().getName().equals(thePackageId)); 065 } 066 067 public Package getPackageWithId(String thePackageId) { 068 return getObjects().stream().map(t -> t.getPackage()).filter(t -> t.getName().equals(thePackageId)).findFirst().orElseThrow(() -> new IllegalArgumentException()); 069 } 070 071 @JsonInclude(JsonInclude.Include.NON_NULL) 072 @JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) 073 public static class ObjectElement { 074 075 @JsonProperty("package") 076 private Package myPackage; 077 078 public Package getPackage() { 079 if (myPackage == null) { 080 myPackage = new Package(); 081 } 082 return myPackage; 083 } 084 } 085 086 @JsonInclude(JsonInclude.Include.NON_NULL) 087 @JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) 088 public static class Package { 089 090 @JsonProperty("name") 091 private String myName; 092 @JsonProperty("version") 093 private String myVersion; 094 @JsonProperty("description") 095 private String myDescription; 096 @JsonProperty("fhirVersion") 097 private List<String> myFhirVersion; 098 @ApiModelProperty(value = "The size of this package in bytes", example = "1000") 099 @JsonProperty("_bytes") 100 private long myBytes; 101 102 public long getBytes() { 103 return myBytes; 104 } 105 106 public Package setBytes(long theBytes) { 107 myBytes = theBytes; 108 return this; 109 } 110 111 public String getName() { 112 return myName; 113 } 114 115 public Package setName(String theName) { 116 myName = theName; 117 return this; 118 } 119 120 public String getDescription() { 121 return myDescription; 122 } 123 124 public Package setDescription(String theDescription) { 125 myDescription = theDescription; 126 return this; 127 } 128 129 public List<String> getFhirVersion() { 130 if (myFhirVersion == null) { 131 myFhirVersion = new ArrayList<>(); 132 } 133 return myFhirVersion; 134 } 135 136 public String getVersion() { 137 return myVersion; 138 } 139 140 public Package setVersion(String theVersion) { 141 myVersion = theVersion; 142 return this; 143 } 144 145 public Package addFhirVersion(String theFhirVersionId) { 146 if (!getFhirVersion().contains(theFhirVersionId)) { 147 getFhirVersion().add(theFhirVersionId); 148 getFhirVersion().sort(PackageVersionComparator.INSTANCE); 149 } 150 return this; 151 } 152 } 153}