001package org.apache.archiva.redback.rest.api.model; 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. 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, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021import io.swagger.v3.oas.annotations.media.Schema; 022 023import javax.xml.bind.annotation.XmlRootElement; 024import java.io.Serializable; 025 026/** 027 * @author Olivier Lamy 028 * @since 1.4 029 */ 030@XmlRootElement( name = "errorMessage" ) 031@Schema(name="ErrorMessage",description = "Information about the error, that occured while processing the REST request.") 032public class ErrorMessage 033 implements Serializable 034{ 035 private String errorKey = ""; 036 037 private String[] args = EMPTY; 038 039 /** 040 * @since 2.1 for message without any key 041 */ 042 private String message = ""; 043 044 private static final String[] EMPTY = new String[0]; 045 046 public ErrorMessage() 047 { 048 // no op 049 } 050 051 public ErrorMessage( String errorKey ) 052 { 053 this.errorKey = errorKey; 054 this.args = EMPTY; 055 } 056 057 public ErrorMessage( String errorKey, String[] args ) 058 { 059 this.errorKey = errorKey; 060 this.args = args; 061 } 062 063 public static ErrorMessage of(String errorKey, String... args) { 064 return new ErrorMessage( errorKey, args ); 065 } 066 067 @Schema(description = "The key of the error message. If this is empty, the message message must be set.") 068 public String getErrorKey() 069 { 070 return errorKey; 071 } 072 073 public void setErrorKey( String errorKey ) 074 { 075 this.errorKey = errorKey; 076 } 077 078 @Schema(description = "Parameters that can be filled to the translated error message") 079 public String[] getArgs() 080 { 081 return args; 082 } 083 084 public void setArgs( String[] args ) 085 { 086 this.args = args; 087 } 088 089 @Schema(description = "Full error message. Either additional to the key in the default language, or if the message is without key.") 090 public String getMessage() 091 { 092 return message; 093 } 094 095 public void setMessage( String message ) 096 { 097 this.message = message; 098 } 099 100 public ErrorMessage message( String message ) 101 { 102 this.message = message; 103 return this; 104 } 105}