|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package org.apache.cloudstack.api.command.user.gui.theme; |
| 18 | + |
| 19 | +import org.apache.cloudstack.acl.RoleType; |
| 20 | +import org.apache.cloudstack.api.APICommand; |
| 21 | +import org.apache.cloudstack.api.ApiConstants; |
| 22 | +import org.apache.cloudstack.api.ApiErrorCode; |
| 23 | +import org.apache.cloudstack.api.BaseCmd; |
| 24 | +import org.apache.cloudstack.api.Parameter; |
| 25 | +import org.apache.cloudstack.api.ServerApiException; |
| 26 | +import org.apache.cloudstack.api.response.GuiThemeResponse; |
| 27 | +import org.apache.cloudstack.context.CallContext; |
| 28 | +import org.apache.cloudstack.gui.theme.GuiTheme; |
| 29 | +import org.apache.cloudstack.gui.theme.GuiThemeJoin; |
| 30 | +import org.apache.cloudstack.gui.theme.GuiThemeService; |
| 31 | + |
| 32 | +import javax.inject.Inject; |
| 33 | + |
| 34 | +@APICommand(name = "createGuiTheme", description = "Creates a customized GUI theme for a set of Common Names (fixed or wildcard), a set of domain UUIDs, and/or a set of " + |
| 35 | + "account UUIDs.", responseObject = GuiThemeResponse.class, entityType = {GuiTheme.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, |
| 36 | + since = "4.21.0.0", authorized = {RoleType.Admin}) |
| 37 | +public class CreateGuiThemeCmd extends BaseCmd { |
| 38 | + |
| 39 | + @Inject |
| 40 | + GuiThemeService guiThemeService; |
| 41 | + |
| 42 | + @Parameter(name = ApiConstants.NAME, required = true, type = CommandType.STRING, length = 2048, description = "A name to identify the theme.") |
| 43 | + private String name; |
| 44 | + |
| 45 | + @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, length = 4096, description = "A description for the theme.") |
| 46 | + private String description; |
| 47 | + |
| 48 | + @Parameter(name = ApiConstants.CSS, type = CommandType.STRING, length = 65535, description = "The CSS to be retrieved and imported into the GUI " + |
| 49 | + "when matching the theme access configurations.") |
| 50 | + private String css; |
| 51 | + |
| 52 | + @Parameter(name = ApiConstants.JSON_CONFIGURATION, type = CommandType.STRING, length = 65535, description = "The JSON with the configurations to be " + |
| 53 | + "retrieved and imported into the GUI when matching the theme access configurations.") |
| 54 | + private String jsonConfiguration; |
| 55 | + |
| 56 | + @Parameter(name = ApiConstants.COMMON_NAMES, type = CommandType.STRING, length = 65535, description = "A set of Common Names (CN) (fixed or " + |
| 57 | + "wildcard) separated by comma that can retrieve the theme; e.g.: *acme.com,acme2.com") |
| 58 | + private String commonNames; |
| 59 | + |
| 60 | + @Parameter(name = ApiConstants.DOMAIN_IDS, type = CommandType.STRING, length = 65535, description = "A set of domain UUIDs (also known as ID for " + |
| 61 | + "the end-user) separated by comma that can retrieve the theme.") |
| 62 | + private String domainIds; |
| 63 | + |
| 64 | + @Parameter(name = ApiConstants.ACCOUNT_IDS, type = CommandType.STRING, length = 65535, description = "A set of account UUIDs (also known as ID for" + |
| 65 | + " the end-user) separated by comma that can retrieve the theme.") |
| 66 | + private String accountIds; |
| 67 | + |
| 68 | + @Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "Defines whether a theme can be retrieved by anyone when only " + |
| 69 | + "the `commonNames` is informed. If the `domainIds` or `accountIds` is informed, it is considered as `false`.") |
| 70 | + private Boolean isPublic = true; |
| 71 | + |
| 72 | + @Parameter(name = ApiConstants.RECURSIVE_DOMAINS, type = CommandType.BOOLEAN, description = "Defines whether the subdomains of the informed domains are considered. Default " + |
| 73 | + "value is false.") |
| 74 | + private Boolean recursiveDomains = false; |
| 75 | + |
| 76 | + public String getName() { |
| 77 | + return name; |
| 78 | + } |
| 79 | + |
| 80 | + public String getDescription() { |
| 81 | + return description; |
| 82 | + } |
| 83 | + |
| 84 | + public String getCss() { |
| 85 | + return css; |
| 86 | + } |
| 87 | + |
| 88 | + public String getJsonConfiguration() { |
| 89 | + return jsonConfiguration; |
| 90 | + } |
| 91 | + |
| 92 | + public String getCommonNames() { |
| 93 | + return commonNames; |
| 94 | + } |
| 95 | + |
| 96 | + public String getDomainIds() { |
| 97 | + return domainIds; |
| 98 | + } |
| 99 | + |
| 100 | + public String getAccountIds() { |
| 101 | + return accountIds; |
| 102 | + } |
| 103 | + |
| 104 | + public Boolean getPublic() { |
| 105 | + return isPublic; |
| 106 | + } |
| 107 | + |
| 108 | + public Boolean getRecursiveDomains() { |
| 109 | + return recursiveDomains; |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public void execute() { |
| 114 | + GuiThemeJoin guiThemeJoin = guiThemeService.createGuiTheme(this); |
| 115 | + |
| 116 | + if (guiThemeJoin == null) { |
| 117 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create the GUI theme."); |
| 118 | + } |
| 119 | + |
| 120 | + GuiThemeResponse response = _responseGenerator.createGuiThemeResponse(guiThemeJoin); |
| 121 | + response.setResponseName(getCommandName()); |
| 122 | + this.setResponseObject(response); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public long getEntityOwnerId() { |
| 127 | + return CallContext.current().getCallingAccountId(); |
| 128 | + } |
| 129 | +} |
0 commit comments