use of com.helger.json.IJsonObject in project peppol-commons by phax.
the class SMPJsonResponse method convertEndpoint.
@Nonnull
public static IJsonObject convertEndpoint(@Nonnull final com.helger.xsds.peppol.smp1.EndpointType aEndpoint) {
final String sEndpointRef = aEndpoint.getEndpointReference() == null ? null : W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference());
final IJsonObject aJsonEP = new JsonObject().add(JSON_TRANSPORT_PROFILE, aEndpoint.getTransportProfile()).add(JSON_ENDPOINT_REFERENCE, sEndpointRef).add(JSON_REQUIRE_BUSINESS_LEVEL_SIGNATURE, aEndpoint.isRequireBusinessLevelSignature()).add(JSON_MINIMUM_AUTHENTICATION_LEVEL, aEndpoint.getMinimumAuthenticationLevel());
aJsonEP.addIfNotNull(JSON_SERVICE_ACTIVATION_DATE, getLDT(aEndpoint.getServiceActivationDate()));
aJsonEP.addIfNotNull(JSON_SERVICE_EXPIRATION_DATE, getLDT(aEndpoint.getServiceExpirationDate()));
convertCertificate(aJsonEP, aEndpoint.getCertificate());
aJsonEP.add(JSON_SERVICE_DESCRIPTION, aEndpoint.getServiceDescription()).add(JSON_TECHNICAL_CONTACT_URL, aEndpoint.getTechnicalContactUrl()).add(JSON_TECHNICAL_INFORMATION_URL, aEndpoint.getTechnicalInformationUrl()).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aEndpoint.getExtension()));
return aJsonEP;
}
use of com.helger.json.IJsonObject in project peppol-commons by phax.
the class SMPJsonResponse method getJsonPrincipal.
@Nonnull
public static IJsonObject getJsonPrincipal(@Nonnull final X500Principal aPrincipal) {
ValueEnforcer.notNull(aPrincipal, "Principal");
final IJsonObject ret = new JsonObject();
ret.add("name", aPrincipal.getName());
try {
for (final Rdn aRdn : new LdapName(aPrincipal.getName()).getRdns()) ret.add(aRdn.getType(), aRdn.getValue());
} catch (final InvalidNameException ex) {
// shit happens
}
return ret;
}
use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveJsonHelper method applyGlobalError.
/**
* Add one global error to the response. Afterwards no validation results
* should be added. The layout of the response object is very similar to the
* one created by
* {@link #applyValidationResultList(IJsonObject, IValidationExecutorSet, List, Locale, long, MutableInt, MutableInt)}.
* <br>
*
* <pre>
* {
* "success" : boolean,
* "interrupted" : boolean,
* "mostSevereErrorLevel" : string,
* "results" : array {
* "success" : string, // as defined by {@link #getJsonTriState(ETriState)}
* "artifactType" : string,
* "artifactPath" : string,
* "items" : array {
* error structure as in {@link #getJsonError(IError, Locale)}
* }
* },
* "durationMS" : number
* }
* </pre>
*
* @param aResponse
* The response JSON object to add to. May not be <code>null</code>.
* @param sErrorMsg
* The error message to use. May not be <code>null</code>.
* @param nDurationMilliseconds
* The duration of the validation in milliseconds. Must be ≥ 0.
*/
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();
{
aResultArray.add(new JsonObject().add(JSON_SUCCESS, getJsonTriState(false)).add(JSON_ARTIFACT_TYPE, ARTIFACT_TYPE_INPUT_PARAMETER).add(JSON_ARTIFACT_PATH, ARTIFACT_PATH_NONE).addJson(JSON_ITEMS, new JsonArray(jsonErrorBuilder().errorLevel(EErrorLevel.ERROR).errorText(sErrorMsg).build())));
}
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);
}
use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveJsonHelper method getAsVES.
@Nullable
public static <T extends IValidationSource> IValidationExecutorSet<T> getAsVES(@Nonnull final ValidationExecutorSetRegistry<T> aRegistry, @Nullable final IJsonObject aJson) {
ValueEnforcer.notNull(aRegistry, "Registry");
if (aJson != null) {
IJsonObject aObj = aJson.getAsObject(JSON_VES);
if (aObj == null)
aObj = aJson;
final String sVESID = aObj.getAsString(JSON_VESID);
if (StringHelper.hasText(sVESID)) {
final VESID aVESID = VESID.parseIDOrNull(sVESID);
if (aVESID != null)
return aRegistry.getOfID(aVESID);
}
}
return null;
}
use of com.helger.json.IJsonObject in project phive by phax.
the class PhiveJsonHelperTest method testGlobalError.
@Test
public void testGlobalError() {
final IJsonObject aObj = new JsonObject();
PhiveJsonHelper.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);
}
Aggregations