3030import org .apache .cloudstack .api .InternalIdentity ;
3131import org .apache .cloudstack .api .response .ExceptionResponse ;
3232import org .apache .commons .collections .MapUtils ;
33+ import org .apache .commons .lang3 .ObjectUtils ;
3334import org .apache .commons .lang3 .StringUtils ;
3435import org .apache .logging .log4j .LogManager ;
3536import org .apache .logging .log4j .Logger ;
@@ -47,6 +48,7 @@ public final class ErrorMessageResolver {
4748
4849 private static final String ERROR_MESSAGES_FILENAME = "error-messages.json" ;
4950 private static final String ERROR_KEY_ADMIN_SUFFIX = ".admin" ;
51+ private static final boolean INCLUDE_METADATA_ID_IN_MESSAGE = false ;
5052
5153 private static final ObjectMapper MAPPER = new ObjectMapper ();
5254
@@ -127,12 +129,16 @@ private static String getMetadataObjectStringValue(Object obj) {
127129 StringBuilder sb = new StringBuilder ();
128130 sb .append ("'" ).append (name ).append ("'" );
129131
132+ if (!CallContext .current ().isCallingAccountRootAdmin ()) {
133+ return sb .toString ();
134+ }
135+
130136 Long id = null ;
131- if (CallContext . current (). isCallingAccountRootAdmin () && obj instanceof InternalIdentity ) {
137+ if (INCLUDE_METADATA_ID_IN_MESSAGE && obj instanceof InternalIdentity ) {
132138 id = ((InternalIdentity ) obj ).getId ();
133139 }
134140
135- if (id == null && uuid == null ) {
141+ if (ObjectUtils . allNull ( id , uuid ) ) {
136142 return sb .toString ();
137143 }
138144 sb .append (" (" );
@@ -225,7 +231,11 @@ private static synchronized void reloadIfRequired() {
225231 }
226232
227233 private static String expand (String template , Map <String , String > metadata ) {
228- if (metadata == null || metadata .isEmpty ()) {
234+ Map <String , Object > allMetadata = CallContext .current ().getContextStringKeyParameters ();
235+ if (MapUtils .isNotEmpty (allMetadata )) {
236+ allMetadata .putAll (metadata );
237+ }
238+ if (MapUtils .isEmpty (allMetadata )) {
229239 return template ;
230240 }
231241 String result = template ;
0 commit comments