Search in sources :

Example 11 with JsonObject

use of com.helger.json.JsonObject in project phoss-smp by phax.

the class AjaxExecutorPublicLogin method mainHandleRequest.

@Override
protected void mainHandleRequest(@Nonnull final LayoutExecutionContext aLEC, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final String sLoginName = aLEC.params().getAsString(CLogin.REQUEST_ATTR_USERID);
    final String sPassword = aLEC.params().getAsString(CLogin.REQUEST_ATTR_PASSWORD);
    // Main login
    final ELoginResult eLoginResult = LoggedInUserManager.getInstance().loginUser(sLoginName, sPassword, CSMP.REQUIRED_ROLE_IDS_WRITABLERESTAPI);
    if (eLoginResult.isSuccess()) {
        aAjaxResponse.json(new JsonObject().add(JSON_LOGGEDIN, true));
        return;
    }
    // Get the rendered content of the menu area
    if (GlobalDebug.isDebugMode())
        if (LOGGER.isWarnEnabled())
            LOGGER.warn("Login of '" + sLoginName + "' failed because " + eLoginResult);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IHCNode aRoot = error(EPhotonCoreText.LOGIN_ERROR_MSG.getDisplayText(aDisplayLocale) + " " + eLoginResult.getDisplayText(aDisplayLocale));
    // Set as result property
    aAjaxResponse.json(new JsonObject().add(JSON_LOGGEDIN, false).add(JSON_HTML, HCRenderer.getAsHTMLStringWithoutNamespaces(aRoot)));
}
Also used : Locale(java.util.Locale) ELoginResult(com.helger.photon.security.login.ELoginResult) JsonObject(com.helger.json.JsonObject) IHCNode(com.helger.html.hc.IHCNode)

Example 12 with JsonObject

use of com.helger.json.JsonObject in project phoss-smp by phax.

the class ImportSummary method appendTo.

public void appendTo(@Nonnull final IJsonObject aJson) {
    ValueEnforcer.notNull(aJson, "JsonObject");
    final IJsonArray aActions = new JsonArray();
    for (final Map.Entry<EImportSummaryAction, ImportSummaryItem> eItem : m_aMap.entrySet()) aActions.add(new JsonObject().add("id", eItem.getKey().getID()).add("success", eItem.getValue().getSuccessCount()).add("error", eItem.getValue().getErrorCount()));
    aJson.addJson("actions", aActions);
}
Also used : IJsonArray(com.helger.json.IJsonArray) JsonArray(com.helger.json.JsonArray) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IJsonArray(com.helger.json.IJsonArray) CommonsEnumMap(com.helger.commons.collection.impl.CommonsEnumMap) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap)

Example 13 with JsonObject

use of com.helger.json.JsonObject in project phase4 by phax.

the class PModeLegSecurityJsonConverter method convertToJson.

/**
 * Convert the provided {@link PModeLegSecurity} object to a JSON object. The
 * conversion from JSON Object back to a domain object happens via
 * {@link #convertToNative(IJsonObject)}.
 *
 * @param aValue
 *        The value to be converted. May not be <code>null</code>.
 * @return The non-<code>null</code> JSON object filled with the necessary
 *         values.
 */
@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModeLegSecurity aValue) {
    final IJsonObject ret = new JsonObject();
    if (aValue.hasWSSVersion())
        ret.add(ATTR_WSS_VERSION, aValue.getWSSVersionAsString());
    if (aValue.x509SignElements().isNotEmpty())
        ret.addJson(ELEMENT_X509_SIGN_ELEMENT, new JsonArray().addAll(aValue.x509SignElements()));
    if (aValue.x509SignAttachments().isNotEmpty())
        ret.addJson(ELEMENT_X509_SIGN_ATTACHMENT, new JsonArray().addAll(aValue.x509SignAttachments()));
    if (aValue.hasX509SignatureCertificate())
        ret.add(ELEMENT_X509_SIGNATURE_CERTIFICATE, aValue.getX509SignatureCertificate());
    if (aValue.hasX509SignatureHashFunction())
        ret.add(ATTR_X509_SIGNATURE_HASH_FUNCTION, aValue.getX509SignatureHashFunctionID());
    if (aValue.hasX509SignatureAlgorithm())
        ret.add(ATTR_X509_SIGNATURE_ALGORITHM, aValue.getX509SignatureAlgorithmID());
    if (aValue.x509EncryptionEncryptElements().isNotEmpty())
        ret.addJson(ELEMENT_X509_ENCRYPTION_ENCRYPT_ELEMENT, new JsonArray().addAll(aValue.x509EncryptionEncryptElements()));
    if (aValue.x509EncryptionEncryptAttachments().isNotEmpty())
        ret.addJson(ELEMENT_X509_ENCRYPTION_ENCRYPT_ATTACHMENT, new JsonArray().addAll(aValue.x509EncryptionEncryptAttachments()));
    if (aValue.hasX509EncryptionCertificate())
        ret.add(ELEMENT_X509_ENCRYPTION_CERTIFICATE, aValue.getX509EncryptionCertificate());
    ret.add(ATTR_X509_ENCRYPTION_ALGORITHM, aValue.getX509EncryptionAlgorithmID());
    if (aValue.hasX509EncryptionMinimumStrength())
        ret.add(ATTR_X509_ENCRYPTION_MINIMUM_STRENGTH, aValue.getX509EncryptionMinimumStrength().intValue());
    if (aValue.hasUsernameTokenUsername())
        ret.add(ATTR_USERNAME_TOKEN_USERNAME, aValue.getUsernameTokenUsername());
    if (aValue.hasUsernameTokenPassword())
        ret.add(ATTR_USERNAME_TOKEN_PASSWORD, aValue.getUsernameTokenPassword());
    if (aValue.isUsernameTokenDigestDefined())
        ret.add(ATTR_USERNAME_TOKEN_DIGEST, aValue.isUsernameTokenDigest());
    if (aValue.isUsernameTokenNonceDefined())
        ret.add(ATTR_USERNAME_TOKEN_NONCE, aValue.isUsernameTokenNonce());
    if (aValue.isUsernameTokenCreatedDefined())
        ret.add(ATTR_USERNAME_TOKEN_CREATED, aValue.isUsernameTokenCreated());
    if (aValue.isPModeAuthorizeDefined())
        ret.add(ATTR_PMODE_AUTHORIZE, aValue.isPModeAuthorize());
    if (aValue.isSendReceiptDefined())
        ret.add(ATTR_SEND_RECEIPT, aValue.isSendReceipt());
    if (aValue.hasSendReceiptReplyPattern())
        ret.add(ATTR_SEND_RECEIPT_REPLY_PATTERN, aValue.getSendReceiptReplyPatternID());
    if (aValue.isSendReceiptNonRepudiationDefined())
        ret.add(ATTR_SEND_RECEIPT_NON_REPUDIATION, aValue.isSendReceiptNonRepudiation());
    return ret;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 14 with JsonObject

use of com.helger.json.JsonObject in project phase4 by phax.

the class PModePayloadProfileJsonConverter method convertToJson.

@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModePayloadProfile aValue) {
    final IJsonObject ret = new JsonObject();
    ret.add(NAME, aValue.getName());
    ret.add(MIME_TYPE, aValue.getMimeType().getAsString());
    if (aValue.hasXSDFilename())
        ret.add(XSD_FILENAME, aValue.getXSDFilename());
    if (aValue.hasMaxSizeKB())
        ret.add(MAX_SIZE_KB, aValue.getMaxSizeKB().intValue());
    ret.add(MANDATORY, aValue.isMandatory());
    return ret;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 15 with JsonObject

use of com.helger.json.JsonObject in project phase4 by phax.

the class PModeLegProtocolJsonConverter method convertToJson.

@Nonnull
public static IJsonObject convertToJson(@Nonnull final PModeLegProtocol aValue) {
    final IJsonObject ret = new JsonObject();
    if (aValue.hasAddress())
        ret.add(ADDRESS, aValue.getAddress());
    ret.add(SOAP_VERSION, aValue.getSoapVersion().getVersion());
    return ret;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Aggregations

JsonObject (com.helger.json.JsonObject)40 IJsonObject (com.helger.json.IJsonObject)38 Nonnull (javax.annotation.Nonnull)27 JsonArray (com.helger.json.JsonArray)16 IJsonArray (com.helger.json.IJsonArray)13 Map (java.util.Map)5 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 StopWatch (com.helger.commons.timing.StopWatch)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 ZonedDateTime (java.time.ZonedDateTime)3 Locale (java.util.Locale)3 Nonempty (com.helger.commons.annotation.Nonempty)2 CommonsTreeMap (com.helger.commons.collection.impl.CommonsTreeMap)2 IError (com.helger.commons.error.IError)2 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)2 IHCNode (com.helger.html.hc.IHCNode)2 JsonWriter (com.helger.json.serialize.JsonWriter)2