Skip to content

Commit

Permalink
Started integrating BusinessCard names in ServiceGroups; #56
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 25, 2019
1 parent ea2fe44 commit edd5070
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.annotation.MustImplementEqualsAndHashcode;
import com.helger.commons.annotation.Nonempty;
Expand Down Expand Up @@ -61,6 +62,16 @@ default String getServiceGroupID ()
@ReturnsMutableCopy
ICommonsList <SMPBusinessCardEntity> getAllEntities ();

/**
* Get the business card entity at the specified index.
*
* @param nIndex
* The index to query. Should be &ge; 0.
* @return <code>null</code> if no such entity exists.
*/
@Nullable
SMPBusinessCardEntity getEntityAtIndex (@Nonnegative int nIndex);

/**
* @return The number of contained entities. Always &ge; 0.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
Expand Down Expand Up @@ -79,17 +80,19 @@ public ICommonsList <SMPBusinessCardEntity> entities ()
return m_aEntities;
}

/**
* @return A mutable list with all {@link SMPBusinessCardEntity} objects.
* Never <code>null</code>.
*/
@Nonnull
@ReturnsMutableCopy
public ICommonsList <SMPBusinessCardEntity> getAllEntities ()
{
return m_aEntities.getClone ();
}

@Nullable
public SMPBusinessCardEntity getEntityAtIndex (@Nonnegative final int nIndex)
{
return m_aEntities.getAtIndex (nIndex);
}

@Nonnegative
public int getEntityCount ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public final class CSMP
/** A regular expression pattern to validate the SMP ID. */
public static final String PATTERN_SMP_ID = "[a-zA-Z0-9\\-\\.]+";

public static final boolean ENABLE_ISSUE_56 = false;

private CSMP ()
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,76 @@ protected ISMPBusinessCard getSelectedObject (@Nonnull final WebPageExecutionCon
return aBusinessCardMgr.getSMPBusinessCardOfID (sID);
}

@Nonnull
public static IHCNode showBusinessCardEntity (@Nonnull final SMPBusinessCardEntity aEntity,
final int nIndex,
@Nonnull final Locale aDisplayLocale)
{
final BootstrapCard aPanel = new BootstrapCard ();
aPanel.createAndAddHeader ().addChild ("Business Entity " + nIndex);

final BootstrapViewForm aForm2 = aPanel.createAndAddBody ().addAndReturnChild (new BootstrapViewForm ());

aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Name").setCtrl (aEntity.names ().getFirst ().getName ()));

{
final Locale aCountry = CountryCache.getInstance ().getCountry (aEntity.getCountryCode ());
final HCNodeList aCtrl = new HCNodeList ();
final EFamFamFlagIcon eIcon = EFamFamFlagIcon.getFromIDOrNull (aCountry.getCountry ());
if (eIcon != null)
{
aCtrl.addChild (eIcon.getAsNode ());
aCtrl.addChild (" ");
}
aCtrl.addChild (aCountry.getDisplayCountry (aDisplayLocale) + " [" + aEntity.getCountryCode () + "]");
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Country code").setCtrl (aCtrl));
}
if (aEntity.hasGeographicalInformation ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Geographical information")
.setCtrl (HCExtHelper.nl2divList (aEntity.getGeographicalInformation ())));
}
if (aEntity.identifiers ().isNotEmpty ())
{
final BootstrapTable aTable = new BootstrapTable (HCCol.star (), HCCol.star ());
aTable.addHeaderRow ().addCells ("Scheme", "Value");
for (final SMPBusinessCardIdentifier aIdentifier : aEntity.identifiers ())
aTable.addBodyRow ().addCells (aIdentifier.getScheme (), aIdentifier.getValue ());
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Identifiers").setCtrl (aTable));
}
if (aEntity.websiteURIs ().isNotEmpty ())
{
final HCNodeList aNL = new HCNodeList ();
for (final String sWebsiteURI : aEntity.websiteURIs ())
aNL.addChild (new HCDiv ().addChild (HCA.createLinkedWebsite (sWebsiteURI)));
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Website URIs").setCtrl (aNL));
}
if (aEntity.contacts ().isNotEmpty ())
{
final BootstrapTable aTable = new BootstrapTable (HCCol.star (), HCCol.star (), HCCol.star (), HCCol.star ());
aTable.addHeaderRow ().addCells ("Type", "Name", "Phone number", "Email address");
for (final SMPBusinessCardContact aContact : aEntity.contacts ())
{
final HCRow aBodyRow = aTable.addBodyRow ();
aBodyRow.addCells (aContact.getType (), aContact.getName (), aContact.getPhoneNumber ());
aBodyRow.addCell (HCA_MailTo.createLinkedEmail (aContact.getEmail ()));
}
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Contacts").setCtrl (aTable));
}
if (aEntity.hasAdditionalInformation ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Additional information")
.setCtrl (HCExtHelper.nl2divList (aEntity.getAdditionalInformation ())));
}
if (aEntity.hasRegistrationDate ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Registration date")
.setCtrl (PDTToString.getAsString (aEntity.getRegistrationDate (),
aDisplayLocale)));
}
return aPanel;
}

@Override
protected void showSelectedObject (@Nonnull final WebPageExecutionContext aWPEC,
@Nonnull final ISMPBusinessCard aSelectedObject)
Expand All @@ -310,69 +380,7 @@ protected void showSelectedObject (@Nonnull final WebPageExecutionContext aWPEC,
for (final SMPBusinessCardEntity aEntity : aSelectedObject.getAllEntities ())
{
++nIndex;
final BootstrapCard aPanel = aForm.addAndReturnChild (new BootstrapCard ());
aPanel.createAndAddHeader ().addChild ("Business Entity " + nIndex);

final BootstrapViewForm aForm2 = aPanel.createAndAddBody ().addAndReturnChild (new BootstrapViewForm ());

aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Name")
.setCtrl (aEntity.names ().getFirst ().getName ()));

{
final Locale aCountry = CountryCache.getInstance ().getCountry (aEntity.getCountryCode ());
final HCNodeList aCtrl = new HCNodeList ();
final EFamFamFlagIcon eIcon = EFamFamFlagIcon.getFromIDOrNull (aCountry.getCountry ());
if (eIcon != null)
{
aCtrl.addChild (eIcon.getAsNode ());
aCtrl.addChild (" ");
}
aCtrl.addChild (aCountry.getDisplayCountry (aDisplayLocale) + " [" + aEntity.getCountryCode () + "]");
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Country code").setCtrl (aCtrl));
}
if (aEntity.hasGeographicalInformation ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Geographical information")
.setCtrl (HCExtHelper.nl2divList (aEntity.getGeographicalInformation ())));
}
if (aEntity.identifiers ().isNotEmpty ())
{
final BootstrapTable aTable = new BootstrapTable (HCCol.star (), HCCol.star ());
aTable.addHeaderRow ().addCells ("Scheme", "Value");
for (final SMPBusinessCardIdentifier aIdentifier : aEntity.identifiers ())
aTable.addBodyRow ().addCells (aIdentifier.getScheme (), aIdentifier.getValue ());
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Identifiers").setCtrl (aTable));
}
if (aEntity.websiteURIs ().isNotEmpty ())
{
final HCNodeList aNL = new HCNodeList ();
for (final String sWebsiteURI : aEntity.websiteURIs ())
aNL.addChild (new HCDiv ().addChild (HCA.createLinkedWebsite (sWebsiteURI)));
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Website URIs").setCtrl (aNL));
}
if (aEntity.contacts ().isNotEmpty ())
{
final BootstrapTable aTable = new BootstrapTable (HCCol.star (), HCCol.star (), HCCol.star (), HCCol.star ());
aTable.addHeaderRow ().addCells ("Type", "Name", "Phone number", "Email address");
for (final SMPBusinessCardContact aContact : aEntity.contacts ())
{
final HCRow aBodyRow = aTable.addBodyRow ();
aBodyRow.addCells (aContact.getType (), aContact.getName (), aContact.getPhoneNumber ());
aBodyRow.addCell (HCA_MailTo.createLinkedEmail (aContact.getEmail ()));
}
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Contacts").setCtrl (aTable));
}
if (aEntity.hasAdditionalInformation ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Additional information")
.setCtrl (HCExtHelper.nl2divList (aEntity.getAdditionalInformation ())));
}
if (aEntity.hasRegistrationDate ())
{
aForm2.addFormGroup (new BootstrapFormGroup ().setLabel ("Registration date")
.setCtrl (PDTToString.getAsString (aEntity.getRegistrationDate (),
aDisplayLocale)));
}
aForm.addChild (showBusinessCardEntity (aEntity, nIndex, aDisplayLocale));
}

if (nIndex == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@
import com.helger.peppolid.factory.IIdentifierFactory;
import com.helger.phoss.smp.ESMPRESTType;
import com.helger.phoss.smp.SMPServerConfiguration;
import com.helger.phoss.smp.app.CSMP;
import com.helger.phoss.smp.app.SMPWebAppConfiguration;
import com.helger.phoss.smp.domain.SMPMetaManager;
import com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard;
import com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager;
import com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup;
import com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager;
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation;
Expand Down Expand Up @@ -404,6 +408,7 @@ protected void showSelectedObject (@Nonnull final WebPageExecutionContext aWPEC,
@Nonnull final ISMPServiceGroup aSelectedObject)
{
final HCNodeList aNodeList = aWPEC.getNodeList ();
final Locale aDisplayLocale = aWPEC.getDisplayLocale ();

aNodeList.addChild (getUIHandler ().createActionHeader ("Show details of service group '" +
aSelectedObject.getID () +
Expand All @@ -419,6 +424,23 @@ protected void showSelectedObject (@Nonnull final WebPageExecutionContext aWPEC,
aForm.addFormGroup (new BootstrapFormGroup ().setLabel ("Extension")
.setCtrl (SMPCommonUI.getExtensionDisplay (aSelectedObject)));

if (CSMP.ENABLE_ISSUE_56)
{
aForm.addChild (getUIHandler ().createDataGroupHeader ("Business Card Information"));

final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr ();
final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup (aSelectedObject);
if (aBC != null)
{
int nIndex = 0;
for (final SMPBusinessCardEntity aEntity : aBC.getAllEntities ())
{
++nIndex;
aForm.addChild (PageSecureBusinessCard.showBusinessCardEntity (aEntity, nIndex, aDisplayLocale));
}
}
}

aNodeList.addChild (aForm);
}

Expand Down Expand Up @@ -588,6 +610,7 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
final HCNodeList aNodeList = aWPEC.getNodeList ();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr ();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr ();
final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr ();
final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType ();
final boolean bShowExtensionDetails = SMPWebAppConfiguration.isServiceGroupsExtensionsShow ();

Expand All @@ -611,6 +634,7 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext

final HCTable aTable = new HCTable (new DTCol ("Participant ID").setInitialSorting (ESortOrder.ASCENDING),
new DTCol ("Owner"),
CSMP.ENABLE_ISSUE_56 ? new DTCol ("Business Card Name") : null,
new DTCol (new HCSpan ().addChild (bShowExtensionDetails ? "Ext" : "Ext?")
.setTitle ("Is an Extension present?")),
new DTCol (new HCSpan ().addChild ("Docs")
Expand Down Expand Up @@ -640,6 +664,20 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
final HCRow aRow = aTable.addBodyRow ();
aRow.addCell (new HCA (aViewLink).addChild (sDisplayName));
aRow.addCell (SMPCommonUI.getOwnerName (aCurObject.getOwnerID ()));
if (CSMP.ENABLE_ISSUE_56)
{
String sName = null;
final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup (aCurObject);
if (aBC != null)
{
final SMPBusinessCardEntity aEntity = aBC.getEntityAtIndex (0);
if (aEntity != null)
sName = aEntity.names ().getFirst ().getName ();
}
aRow.addCell (sName);
}
else
aRow.addCell ();
if (bShowExtensionDetails)
{
if (aCurObject.extensions ().isNotEmpty ())
Expand Down

0 comments on commit edd5070

Please sign in to comment.