use of com.helger.json.IJsonObject 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.IJsonObject in project phoss-directory by phax.
the class PDBusinessCardTest method testJson.
@Test
public void testJson() {
PDBusinessCard aBC = new PDBusinessCard(new PDIdentifier("a", "b"), new CommonsArrayList<>(_createBE(), _createBE().setAdditionalInfo("Gni gna gnu")));
IJsonObject aJson = aBC.getAsJson();
assertNotNull(aJson);
PDBusinessCard aBC2 = PDBusinessCard.of(aJson);
assertNotNull(aBC2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBC2, aBC);
// None set
aBC = new PDBusinessCard(new PDIdentifier("a", "b"), null);
aJson = aBC.getAsJson();
assertNotNull(aJson);
aBC2 = PDBusinessCard.of(aJson);
assertNotNull(aBC2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aBC2, aBC);
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDContactTest method testJson.
@Test
public void testJson() {
PDContact aContact = new PDContact("t", "n", "p", "e");
IJsonObject aJson = aContact.getAsJson();
assertNotNull(aJson);
PDContact aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
// No type
aContact = new PDContact(null, "n", "p", "e");
aJson = aContact.getAsJson();
assertNotNull(aJson);
aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
// No name
aContact = new PDContact("t", null, "p", "e");
aJson = aContact.getAsJson();
assertNotNull(aJson);
aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
// No phone number
aContact = new PDContact("t", "n", null, "e");
aJson = aContact.getAsJson();
assertNotNull(aJson);
aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
// No email
aContact = new PDContact("t", "n", "p", null);
aJson = aContact.getAsJson();
assertNotNull(aJson);
aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
// None set
aContact = new PDContact(null, null, null, null);
aJson = aContact.getAsJson();
assertNotNull(aJson);
aContact2 = PDContact.of(aJson);
assertNotNull(aContact2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aContact2, aContact);
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDStoredBusinessEntity method getAsSearchResultJsonObject.
@Nonnull
public static IJsonObject getAsSearchResultJsonObject(@Nonnull @Nonempty final ICommonsList<PDStoredBusinessEntity> aDocs) {
ValueEnforcer.notEmptyNoNullValue(aDocs, "Docs");
final PDStoredBusinessEntity aFirst = aDocs.getFirst();
final IJsonObject ret = new JsonObject();
ret.addJson("participantID", _getIDAsJson(aFirst.m_aParticipantID.getScheme(), aFirst.m_aParticipantID.getValue()));
// Add the items retrieved from SMP as well
final IJsonArray aDocTypes = new JsonArray();
for (final IDocumentTypeIdentifier aDocTypeID : aFirst.m_aDocumentTypeIDs) aDocTypes.add(_getIDAsJson(aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (aDocTypes.isNotEmpty())
ret.addJson("docTypes", aDocTypes);
final IJsonArray aEntities = new JsonArray();
for (final PDStoredBusinessEntity aDoc : aDocs) {
final IJsonObject aEntity = new JsonObject();
// Multilingual names
final IJsonArray aMLNames = new JsonArray();
for (final PDStoredMLName aName : aDoc.m_aNames) aMLNames.add(_getMLNameAsJson(aName.getName(), aName.getLanguageCode()));
if (aMLNames.isNotEmpty())
aEntity.addJson("name", aMLNames);
aEntity.add("countryCode", aDoc.m_sCountryCode);
if (StringHelper.hasText(aDoc.m_sGeoInfo))
aEntity.add("geoInfo", aDoc.m_sGeoInfo);
final IJsonArray aIDs = new JsonArray();
for (final PDStoredIdentifier aID : aDoc.m_aIdentifiers) aIDs.add(_getIDAsJson(aID.getScheme(), aID.getValue()));
if (aIDs.isNotEmpty())
aEntity.addJson("identifiers", aIDs);
final IJsonArray aWebsites = new JsonArray();
for (final String sWebsite : aDoc.m_aWebsiteURIs) aWebsites.add(sWebsite);
if (aWebsites.isNotEmpty())
aEntity.addJson("websites", aWebsites);
final IJsonArray aContacts = new JsonArray();
for (final PDStoredContact aContact : aDoc.m_aContacts) aContacts.add(new JsonObject().addIfNotNull("type", aContact.getType()).addIfNotNull("name", aContact.getName()).addIfNotNull("phone", aContact.getPhone()).addIfNotNull("email", aContact.getEmail()));
if (aContacts.isNotEmpty())
aEntity.addJson("contacts", aContacts);
if (StringHelper.hasText(aDoc.m_sAdditionalInformation))
aEntity.add("additionalInfo", aDoc.m_sAdditionalInformation);
if (aDoc.m_aRegistrationDate != null)
aEntity.add("regDate", PDTWebDateHelper.getAsStringXSD(aDoc.m_aRegistrationDate));
aEntities.add(aEntity);
}
ret.addJson("entities", aEntities);
return ret;
}
use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class PDNameTest method testJson.
@Test
public void testJson() {
PDName aName = new PDName("ACME", "en");
IJsonObject aJson = aName.getAsJson();
assertNotNull(aJson);
PDName aName2 = PDName.of(aJson);
assertNotNull(aName2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aName2, aName);
// No language
aName = new PDName("ACME");
aJson = aName.getAsJson();
assertNotNull(aJson);
aName2 = PDName.of(aJson);
assertNotNull(aName2);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aName2, aName);
}
Aggregations