001/* 002 * Copyright 2013 Box, Inc. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.box.api.marshalling.dao; 017 018import com.fasterxml.jackson.annotation.JsonIgnore; 019import com.fasterxml.jackson.annotation.JsonProperty; 020 021import java.util.Map; 022 023/** 024 * Class for errors sent from server. 025 */ 026public class BoxServerError extends BoxTypedObject { 027 028 public static final String FIELD_STATUS = "status"; 029 030 public static final String FIELD_CODE = "code"; 031 032 public static final String FIELD_HELP_URL = "help_url"; 033 034 public static final String FIELD_MESSAGE = "message"; 035 036 public static final String FIELD_REQUEST_ID = "request_id"; 037 038 public BoxServerError() { 039 setType(BoxResourceType.ERROR.toString()); 040 } 041 042 /** 043 * Copy constructor, this does deep copy for all the fields. 044 * 045 * @param obj 046 */ 047 public BoxServerError(BoxServerError obj) { 048 super(obj); 049 } 050 051 /** 052 * Instantiate the object from a map. Each entry in the map reflects to a field. 053 * 054 * @param map 055 */ 056 public BoxServerError(Map<String, Object> map) { 057 super(map); 058 } 059 060 /** 061 * @return the status 062 */ 063 @JsonProperty(FIELD_STATUS) 064 public Integer getStatus() { 065 return (Integer) getValue(FIELD_STATUS); 066 } 067 068 /** 069 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 070 * 071 * @param status the status to set 072 */ 073 @JsonProperty(FIELD_STATUS) 074 public void setStatus(Integer status) { 075 put(FIELD_STATUS, status); 076 } 077 078 /** 079 * @return the code 080 */ 081 @JsonProperty(FIELD_CODE) 082 public String getCode() { 083 return (String) getValue(FIELD_CODE); 084 } 085 086 /** 087 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 088 * 089 * @param code the code to set 090 */ 091 @JsonProperty(FIELD_CODE) 092 protected void setCode(String code) { 093 put(FIELD_CODE, code); 094 } 095 096 /** 097 * @return the help_url 098 */ 099 @JsonProperty(FIELD_HELP_URL) 100 public String getHelpUrl() { 101 return (String) getValue(FIELD_HELP_URL); 102 } 103 104 /** 105 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 106 * 107 * @param helpUrl the help_url to set 108 */ 109 @JsonProperty(FIELD_HELP_URL) 110 protected void setHelpUrl(String helpUrl) { 111 put(FIELD_HELP_URL, helpUrl); 112 } 113 114 /** 115 * @return the message 116 */ 117 @JsonProperty(FIELD_MESSAGE) 118 public String getMessage() { 119 return (String) getValue(FIELD_MESSAGE); 120 } 121 122 /** 123 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 124 * 125 * @param message the message to set 126 */ 127 @JsonProperty(FIELD_MESSAGE) 128 protected void setMessage(String message) { 129 put(FIELD_MESSAGE, message); 130 } 131 132 /** 133 * @return the request_id 134 */ 135 @JsonProperty(FIELD_REQUEST_ID) 136 public String getRequestId() { 137 return (String) getValue(FIELD_REQUEST_ID); 138 } 139 140 /** 141 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 142 * 143 * @param requestId the request_id to set 144 */ 145 @JsonProperty(FIELD_REQUEST_ID) 146 protected void setRequestId(String requestId) { 147 put(FIELD_REQUEST_ID, requestId); 148 } 149 150 /** 151 * Deprecated, use getStatus() instead 152 * 153 * @return status code 154 */ 155 @JsonIgnore 156 @Deprecated 157 public Integer getHttpStatusCode() { 158 return getStatus(); 159 } 160}