@Test public void testGlobalError () { final IJsonObject aObj = new JsonObject (); BDVEJsonHelper.applyGlobalError (aObj, "My error", 123); final String sJson = aObj.getAsJsonString (); assertEquals ("{\"success\":false," + "\"interrupted\":false," + "\"mostSevereErrorLevel\":\"ERROR\"," + "\"results\":[{\"success\":\"FALSE\",\"artifactType\":\"input-parameter\",\"artifactPath\":\"none\",\"items\":[{\"errorLevel\":\"ERROR\",\"errorText\":\"My error\"}]}]," + "\"durationMS\":123}", sJson); }
public static void applyGlobalError (@Nonnull final IJsonObject aResponse, @Nonnull final String sErrorMsg, @Nonnegative final long nDurationMilliseconds) { ValueEnforcer.notNull (aResponse, "Response"); ValueEnforcer.notNull (sErrorMsg, "ErrorMsg"); ValueEnforcer.isGE0 (nDurationMilliseconds, "DurationMilliseconds"); final IJsonArray aResultArray = new JsonArray (); { final IJsonObject aError = getJsonError (SingleError.builderError ().setErrorText (sErrorMsg).build (), CGlobal.DEFAULT_LOCALE); aResultArray.add (new JsonObject ().add (JSON_SUCCESS, getJsonTriState (false)) .add (JSON_ARTIFACT_TYPE, ARTFACT_TYPE_INPUT_PARAMETER) .add (JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE) .addJson (JSON_ITEMS, new JsonArray (aError))); } aResponse.add (JSON_SUCCESS, false); aResponse.add (JSON_INTERRUPTED, false); aResponse.add (JSON_MOST_SEVERE_ERROR_LEVEL, getJsonErrorLevel (EErrorLevel.ERROR)); aResponse.addJson (JSON_RESULTS, aResultArray); aResponse.add (JSON_DURATION_MS, nDurationMilliseconds); }
BDVEJsonHelper { public static void applyGlobalError (@Nonnull final IJsonObject aResponse, @Nonnull final String sErrorMsg, @Nonnegative final long nDurationMilliseconds) { ValueEnforcer.notNull (aResponse, "Response"); ValueEnforcer.notNull (sErrorMsg, "ErrorMsg"); ValueEnforcer.isGE0 (nDurationMilliseconds, "DurationMilliseconds"); final IJsonArray aResultArray = new JsonArray (); { final IJsonObject aError = getJsonError (SingleError.builderError ().setErrorText (sErrorMsg).build (), CGlobal.DEFAULT_LOCALE); aResultArray.add (new JsonObject ().add (JSON_SUCCESS, getJsonTriState (false)) .add (JSON_ARTIFACT_TYPE, ARTFACT_TYPE_INPUT_PARAMETER) .add (JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE) .addJson (JSON_ITEMS, new JsonArray (aError))); } aResponse.add (JSON_SUCCESS, false); aResponse.add (JSON_INTERRUPTED, false); aResponse.add (JSON_MOST_SEVERE_ERROR_LEVEL, getJsonErrorLevel (EErrorLevel.ERROR)); aResponse.addJson (JSON_RESULTS, aResultArray); aResponse.add (JSON_DURATION_MS, nDurationMilliseconds); } }
BDVEJsonHelper { public static void applyGlobalError (@Nonnull final IJsonObject aResponse, @Nonnull final String sErrorMsg, @Nonnegative final long nDurationMilliseconds) { ValueEnforcer.notNull (aResponse, "Response"); ValueEnforcer.notNull (sErrorMsg, "ErrorMsg"); ValueEnforcer.isGE0 (nDurationMilliseconds, "DurationMilliseconds"); final IJsonArray aResultArray = new JsonArray (); { final IJsonObject aError = getJsonError (SingleError.builderError ().setErrorText (sErrorMsg).build (), CGlobal.DEFAULT_LOCALE); aResultArray.add (new JsonObject ().add (JSON_SUCCESS, getJsonTriState (false)) .add (JSON_ARTIFACT_TYPE, ARTFACT_TYPE_INPUT_PARAMETER) .add (JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE) .addJson (JSON_ITEMS, new JsonArray (aError))); } aResponse.add (JSON_SUCCESS, false); aResponse.add (JSON_INTERRUPTED, false); aResponse.add (JSON_MOST_SEVERE_ERROR_LEVEL, getJsonErrorLevel (EErrorLevel.ERROR)); aResponse.addJson (JSON_RESULTS, aResultArray); aResponse.add (JSON_DURATION_MS, nDurationMilliseconds); } private  BDVEJsonHelper(); }
BDVEJsonHelper { public static void applyGlobalError (@Nonnull final IJsonObject aResponse, @Nonnull final String sErrorMsg, @Nonnegative final long nDurationMilliseconds) { ValueEnforcer.notNull (aResponse, "Response"); ValueEnforcer.notNull (sErrorMsg, "ErrorMsg"); ValueEnforcer.isGE0 (nDurationMilliseconds, "DurationMilliseconds"); final IJsonArray aResultArray = new JsonArray (); { final IJsonObject aError = getJsonError (SingleError.builderError ().setErrorText (sErrorMsg).build (), CGlobal.DEFAULT_LOCALE); aResultArray.add (new JsonObject ().add (JSON_SUCCESS, getJsonTriState (false)) .add (JSON_ARTIFACT_TYPE, ARTFACT_TYPE_INPUT_PARAMETER) .add (JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE) .addJson (JSON_ITEMS, new JsonArray (aError))); } aResponse.add (JSON_SUCCESS, false); aResponse.add (JSON_INTERRUPTED, false); aResponse.add (JSON_MOST_SEVERE_ERROR_LEVEL, getJsonErrorLevel (EErrorLevel.ERROR)); aResponse.addJson (JSON_RESULTS, aResultArray); aResponse.add (JSON_DURATION_MS, nDurationMilliseconds); } private  BDVEJsonHelper(); @Nonnull @Nonempty static String getJsonErrorLevel(@Nonnull final IErrorLevel aErrorLevel); @Nullable static IErrorLevel getAsErrorLevel(@Nullable final String sErrorLevel); @Nonnull @Nonempty static String getJsonTriState(final boolean b); @Nonnull static String getJsonTriState(@Nonnull final ETriState eTriState); @Nullable static ETriState getAsTriState(@Nullable final String sTriState); @Nullable static IJsonObject getJsonStackTrace(@Nullable final Throwable t); @Nullable static IJsonObject getJsonErrorLocation(@Nullable final ILocation aLocation); @Nullable static ILocation getAsErrorLocation(@Nullable final IJsonObject aObj); @Nonnull static IJsonObject getJsonError(@Nonnull final IErrorLevel aErrorLevel,
                                          @Nullable final String sErrorID,
                                          @Nullable final String sErrorFieldName,
                                          @Nullable final ILocation aErrorLocation,
                                          @Nullable final String sTest,
                                          @Nonnull final String sErrorText,
                                          @Nullable final Throwable t); @Nonnull static IJsonObject getJsonError(@Nonnull final IError aError, @Nonnull final Locale aDisplayLocale); @Nonnull static IError getAsIError(@Nonnull final IJsonObject aObj); @Nonnull static IJsonObject getJsonVES(@Nonnull final IValidationExecutorSet <?> aVES); static void applyGlobalError(@Nonnull final IJsonObject aResponse,
                                       @Nonnull final String sErrorMsg,
                                       @Nonnegative final long nDurationMilliseconds); @Nonnull @Nonempty static String getArtifactPathType(@Nonnull final IReadableResource aRes); static void applyValidationResultList(@Nonnull final IJsonObject aResponse,
                                                @Nonnull final IValidationExecutorSet <?> aVES,
                                                @Nonnull final List <? extends ValidationResult> aValidationResultList,
                                                @Nonnull final Locale aDisplayLocale,
                                                @Nonnegative final long nDurationMilliseconds,
                                                @Nullable final MutableInt aWarningCount,
                                                @Nullable final MutableInt aErrorCount); @Nullable static IValidationExecutorSet <T> getAsVES(@Nonnull final ValidationExecutorSetRegistry <T> aRegistry,
                                                                                   @Nullable final IJsonObject aJson); @Nullable static IReadableResource getAsValidationResource(@Nullable final String sArtefactPathType, @Nullable final String sArtefactPath); @Nullable static ValidationResultList getAsValidationResultList(@Nullable final IJsonObject aJson); }
BDVEJsonHelper { public static void applyGlobalError (@Nonnull final IJsonObject aResponse, @Nonnull final String sErrorMsg, @Nonnegative final long nDurationMilliseconds) { ValueEnforcer.notNull (aResponse, "Response"); ValueEnforcer.notNull (sErrorMsg, "ErrorMsg"); ValueEnforcer.isGE0 (nDurationMilliseconds, "DurationMilliseconds"); final IJsonArray aResultArray = new JsonArray (); { final IJsonObject aError = getJsonError (SingleError.builderError ().setErrorText (sErrorMsg).build (), CGlobal.DEFAULT_LOCALE); aResultArray.add (new JsonObject ().add (JSON_SUCCESS, getJsonTriState (false)) .add (JSON_ARTIFACT_TYPE, ARTFACT_TYPE_INPUT_PARAMETER) .add (JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE) .addJson (JSON_ITEMS, new JsonArray (aError))); } aResponse.add (JSON_SUCCESS, false); aResponse.add (JSON_INTERRUPTED, false); aResponse.add (JSON_MOST_SEVERE_ERROR_LEVEL, getJsonErrorLevel (EErrorLevel.ERROR)); aResponse.addJson (JSON_RESULTS, aResultArray); aResponse.add (JSON_DURATION_MS, nDurationMilliseconds); } private  BDVEJsonHelper(); @Nonnull @Nonempty static String getJsonErrorLevel(@Nonnull final IErrorLevel aErrorLevel); @Nullable static IErrorLevel getAsErrorLevel(@Nullable final String sErrorLevel); @Nonnull @Nonempty static String getJsonTriState(final boolean b); @Nonnull static String getJsonTriState(@Nonnull final ETriState eTriState); @Nullable static ETriState getAsTriState(@Nullable final String sTriState); @Nullable static IJsonObject getJsonStackTrace(@Nullable final Throwable t); @Nullable static IJsonObject getJsonErrorLocation(@Nullable final ILocation aLocation); @Nullable static ILocation getAsErrorLocation(@Nullable final IJsonObject aObj); @Nonnull static IJsonObject getJsonError(@Nonnull final IErrorLevel aErrorLevel,
                                          @Nullable final String sErrorID,
                                          @Nullable final String sErrorFieldName,
                                          @Nullable final ILocation aErrorLocation,
                                          @Nullable final String sTest,
                                          @Nonnull final String sErrorText,
                                          @Nullable final Throwable t); @Nonnull static IJsonObject getJsonError(@Nonnull final IError aError, @Nonnull final Locale aDisplayLocale); @Nonnull static IError getAsIError(@Nonnull final IJsonObject aObj); @Nonnull static IJsonObject getJsonVES(@Nonnull final IValidationExecutorSet <?> aVES); static void applyGlobalError(@Nonnull final IJsonObject aResponse,
                                       @Nonnull final String sErrorMsg,
                                       @Nonnegative final long nDurationMilliseconds); @Nonnull @Nonempty static String getArtifactPathType(@Nonnull final IReadableResource aRes); static void applyValidationResultList(@Nonnull final IJsonObject aResponse,
                                                @Nonnull final IValidationExecutorSet <?> aVES,
                                                @Nonnull final List <? extends ValidationResult> aValidationResultList,
                                                @Nonnull final Locale aDisplayLocale,
                                                @Nonnegative final long nDurationMilliseconds,
                                                @Nullable final MutableInt aWarningCount,
                                                @Nullable final MutableInt aErrorCount); @Nullable static IValidationExecutorSet <T> getAsVES(@Nonnull final ValidationExecutorSetRegistry <T> aRegistry,
                                                                                   @Nullable final IJsonObject aJson); @Nullable static IReadableResource getAsValidationResource(@Nullable final String sArtefactPathType, @Nullable final String sArtefactPath); @Nullable static ValidationResultList getAsValidationResultList(@Nullable final IJsonObject aJson); static final String JSON_ERRORLEVEL_SUCCESS; static final String JSON_ERRORLEVEL_WARN; static final String JSON_ERRORLEVEL_ERROR; static final String JSON_TRISTATE_TRUE; static final String JSON_TRISTATE_FALSE; static final String JSON_TRISTATE_UNDEFINED; static final String JSON_CLASS; static final String JSON_MESSAGE; static final String JSON_STACK_TRACE; static final String JSON_RESOURCE_ID; static final String JSON_LINE_NUM; static final String JSON_COLUMN_NUM; static final String JSON_ERROR_LEVEL; static final String JSON_ERROR_ID; static final String JSON_ERROR_FIELD_NAME; static final String JSON_ERROR_LOCATION_OBJ; static final String JSON_ERROR_LOCATION_STR; static final String JSON_ERROR_TEXT; static final String JSON_EXCEPTION; static final String JSON_TEST; static final String JSON_VESID; static final String JSON_NAME; static final String JSON_DEPRECATED; static final String JSON_SUCCESS; static final String JSON_ARTIFACT_TYPE; static final String JSON_ARTIFACT_PATH_TYPE; static final String JSON_ARTIFACT_PATH; static final String JSON_ITEMS; static final String JSON_INTERRUPTED; static final String JSON_MOST_SEVERE_ERROR_LEVEL; static final String JSON_RESULTS; static final String JSON_DURATION_MS; static final String JSON_VES; static final String ARTFACT_TYPE_INPUT_PARAMETER; static final String ARTIFACT_PATH_NONE; }