use of com.helger.json.JsonObject in project phoss-directory by phax.
the class PDBusinessEntity method getAsJson.
@Nonnull
public IJsonObject getAsJson() {
final IJsonObject ret = new JsonObject();
ret.addJson("name", new JsonArray().addAllMapped(m_aNames, PDName::getAsJson));
ret.add("countrycode", m_sCountryCode);
if (hasGeoInfo())
ret.add("geoinfo", m_sGeoInfo);
if (m_aIDs.isNotEmpty())
ret.addJson("id", new JsonArray().addAllMapped(m_aIDs, PDIdentifier::getAsJson));
if (m_aWebsiteURIs.isNotEmpty())
ret.addJson("website", new JsonArray().addAll(m_aWebsiteURIs));
if (m_aContacts.isNotEmpty())
ret.addJson("contact", new JsonArray().addAllMapped(m_aContacts, PDContact::getAsJson));
if (hasAdditionalInfo())
ret.add("additionalinfo", m_sAdditionalInfo);
if (hasRegistrationDate())
ret.add("regdate", PDTWebDateHelper.getAsStringXSD(m_aRegistrationDate));
return ret;
}
use of com.helger.json.JsonObject in project phoss-directory by phax.
the class PDIdentifier method getAsJson.
@Nonnull
public static IJsonObject getAsJson(@Nullable final String sScheme, @Nullable final String sValue) {
final IJsonObject ret = new JsonObject();
ret.add("scheme", sScheme);
ret.add("value", sValue);
return ret;
}
use of com.helger.json.JsonObject in project phoss-directory by phax.
the class ExportAllManager method queryAllContainedParticipantsAsJSON.
@Nonnull
public static IJsonObject queryAllContainedParticipantsAsJSON(@Nonnull final EQueryMode eQueryMode) throws IOException {
final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
// Query all and group by participant ID
final ICommonsSortedSet<IParticipantIdentifier> aSet = new CommonsTreeSet<>(Comparator.comparing(IParticipantIdentifier::getURIEncoded));
PDMetaManager.getStorageMgr().searchAll(aQuery, -1, PDField.PARTICIPANT_ID::getDocValue, aSet::add);
// XML root
final IJsonObject aObj = new JsonObject();
aObj.add("version", 1);
aObj.add("creationdt", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentZonedDateTimeUTC()));
aObj.add("count", aSet.size());
// For all participants
final IJsonArray aArray = new JsonArray();
for (final IParticipantIdentifier aParticipantID : aSet) aArray.add(aParticipantID.getURIEncoded());
aObj.addJson("participants", aArray);
return aObj;
}
use of com.helger.json.JsonObject 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.JsonObject 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