Search in sources :

Example 51 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 52 with IJsonObject

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;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName) Nonnull(javax.annotation.Nonnull)

Example 53 with IJsonObject

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 &ge; 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);
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IJsonArray(com.helger.json.IJsonArray)

Example 54 with IJsonObject

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;
}
Also used : VESID(com.helger.phive.api.executorset.VESID) IJsonObject(com.helger.json.IJsonObject) Nullable(javax.annotation.Nullable)

Example 55 with IJsonObject

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);
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Test(org.junit.Test)

Aggregations

IJsonObject (com.helger.json.IJsonObject)79 JsonObject (com.helger.json.JsonObject)44 Nonnull (javax.annotation.Nonnull)41 IJsonArray (com.helger.json.IJsonArray)22 JsonArray (com.helger.json.JsonArray)19 Test (org.junit.Test)15 JsonWriter (com.helger.json.serialize.JsonWriter)12 IJson (com.helger.json.IJson)10 Map (java.util.Map)10 StopWatch (com.helger.commons.timing.StopWatch)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ZonedDateTime (java.time.ZonedDateTime)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)7 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 Nullable (javax.annotation.Nullable)5 Nonempty (com.helger.commons.annotation.Nonempty)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3