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 com.fasterxml.jackson.annotation.JsonAutoDetect;
023import com.fasterxml.jackson.annotation.JsonInclude;
024import com.fasterxml.jackson.annotation.JsonProperty;
025import io.swagger.v3.oas.annotations.media.Schema;
026import org.apache.commons.lang3.builder.ToStringBuilder;
027import org.apache.commons.lang3.builder.ToStringStyle;
028
029import java.util.ArrayList;
030import java.util.HashMap;
031import java.util.List;
032import java.util.Map;
033
034@Schema(description = "Represents an NPM package installation response")
035@JsonInclude(JsonInclude.Include.NON_NULL)
036@JsonAutoDetect(
037                creatorVisibility = JsonAutoDetect.Visibility.NONE,
038                fieldVisibility = JsonAutoDetect.Visibility.NONE,
039                getterVisibility = JsonAutoDetect.Visibility.NONE,
040                isGetterVisibility = JsonAutoDetect.Visibility.NONE,
041                setterVisibility = JsonAutoDetect.Visibility.NONE)
042public class PackageInstallOutcomeJson {
043
044        @JsonProperty("messages")
045        private List<String> myMessage;
046
047        @JsonProperty("resourcesInstalled")
048        private Map<String, Integer> myResourcesInstalled;
049
050        public List<String> getMessage() {
051                if (myMessage == null) {
052                        myMessage = new ArrayList<>();
053                }
054                return myMessage;
055        }
056
057        public Map<String, Integer> getResourcesInstalled() {
058                if (myResourcesInstalled == null) {
059                        myResourcesInstalled = new HashMap<>();
060                }
061                return myResourcesInstalled;
062        }
063
064        public void incrementResourcesInstalled(String theResourceType) {
065                Integer existing = getResourcesInstalled().get(theResourceType);
066                if (existing == null) {
067                        getResourcesInstalled().put(theResourceType, 1);
068                } else {
069                        getResourcesInstalled().put(theResourceType, existing + 1);
070                }
071        }
072
073        @Override
074        public String toString() {
075                return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
076                                .append("message", myMessage)
077                                .append("resourcesInstalled", myResourcesInstalled)
078                                .toString();
079        }
080}