001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2024 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.persistence.megascale;
011
012import ca.cdr.api.model.json.IModelJson;
013import com.fasterxml.jackson.annotation.JsonProperty;
014import io.swagger.v3.oas.annotations.media.Schema;
015import org.apache.commons.lang3.Validate;
016
017import java.util.ArrayList;
018import java.util.List;
019
020/**
021 * Hook method return value for the
022 * {@link ca.cdr.api.fhir.interceptor.CdrPointcut#STORAGE_MEGASCALE_PROVIDE_DB_INFO}
023 * pointcut.
024 *
025 * @since 2023.02.R01
026 */
027@Schema(
028                name = "MegaScaleCredentialResponse",
029                description = "Response object for a MegaScale database credential request")
030public class MegaScaleCredentialResponseJson implements IModelJson {
031
032        @JsonProperty("databaseUrl")
033        @Schema(description = "The JDBC database connection URL")
034        private String myDatabaseUrl;
035
036        @JsonProperty("databaseUsername")
037        @Schema(description = "The JDBC database connection username")
038        private String myDatabaseUsername;
039
040        @JsonProperty("databasePassword")
041        @Schema(description = "The JDBC database connection password")
042        private String myDatabasePassword;
043
044        @JsonProperty("databaseInitializationStatements")
045        @Schema(
046                        description = "Any statements returned here will be issued to the database as raw SQL "
047                                        + "if the database is found to be empty, immediately after the Smile CDR "
048                                        + "database schema is initialized.")
049        private List<String> myDatabaseInitializationStatements;
050
051        /**
052         * Constructor
053         */
054        public MegaScaleCredentialResponseJson() {
055                super();
056        }
057
058        /**
059         * Constructor
060         *
061         * @param theDatabaseUrl      The JDBC URL
062         * @param theDatabaseUsername The JDBC username
063         * @param theDatabasePassword The JDBC password
064         */
065        public MegaScaleCredentialResponseJson(
066                        String theDatabaseUrl, String theDatabaseUsername, String theDatabasePassword) {
067                myDatabaseUrl = theDatabaseUrl;
068                myDatabaseUsername = theDatabaseUsername;
069                myDatabasePassword = theDatabasePassword;
070        }
071
072        /**
073         * Any statements returned here will be issued to the database as raw SQL
074         * if the database is found to be empty, immediately after the Smile CDR
075         * database schema is initialized.
076         *
077         * @param theSql The raw SQL statement to execute.
078         */
079        public void addDatabaseInitializationStatement(String theSql) {
080                Validate.notBlank(theSql, "theSql must not be blank");
081                getDatabaseInitializationStatements().add(theSql);
082        }
083
084        public List<String> getDatabaseInitializationStatements() {
085                if (myDatabaseInitializationStatements == null) {
086                        myDatabaseInitializationStatements = new ArrayList<>();
087                }
088                return myDatabaseInitializationStatements;
089        }
090
091        public void setDatabaseInitializationStatements(List<String> theDatabaseInitializationStatements) {
092                myDatabaseInitializationStatements = theDatabaseInitializationStatements;
093        }
094
095        public String getDatabaseUrl() {
096                return myDatabaseUrl;
097        }
098
099        public void setDatabaseUrl(String theDatabaseUrl) {
100                myDatabaseUrl = theDatabaseUrl;
101        }
102
103        public String getDatabaseUsername() {
104                return myDatabaseUsername;
105        }
106
107        public void setDatabaseUsername(String theDatabaseUsername) {
108                myDatabaseUsername = theDatabaseUsername;
109        }
110
111        public String getDatabasePassword() {
112                return myDatabasePassword;
113        }
114
115        public void setDatabasePassword(String theDatabasePassword) {
116                myDatabasePassword = theDatabasePassword;
117        }
118}