use of com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager in project phoss-smp by phax.
the class BusinessCardServerAPI method deleteBusinessCard.
/**
* Delete an existing business card.
*
* @param sServiceGroupID
* The service group (participant) ID.
* @param aCredentials
* The credentials to be used. May not be <code>null</code>.
* @throws SMPServerException
* In case of error
* @since 5.0.2
*/
public void deleteBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "DELETE /businesscard/" + sServiceGroupID;
final String sAction = "deleteBusinessCard";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aServiceGroupID, aSMPUser);
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr == null) {
throw new SMPBadRequestException("This SMP server does not support the Business Card API", m_aAPIProvider.getCurrentURI());
}
final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroupID);
if (aBusinessCard == null) {
// No such business card
throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager in project phoss-smp by phax.
the class BusinessCardServerAPI method getBusinessCard.
@Nonnull
public PD3BusinessCardType getBusinessCard(final String sServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /businesscard/" + sServiceGroupID;
final String sAction = "getBusinessCard";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr == null) {
throw new SMPBadRequestException("This SMP server does not support the Business Card API", m_aAPIProvider.getCurrentURI());
}
final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aServiceGroup);
if (aBusinessCard == null) {
// No such business card
throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aBusinessCard.getAsJAXBObject();
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager in project phoss-smp by phax.
the class BusinessCardInterfaceTest method testGetCreateV2GetDeleteGet.
@Test
public void testGetCreateV2GetDeleteGet() {
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
assertNotNull(aSGMgr);
final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
assertNotNull(aBCMgr);
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
final String sPI = aPI.getURIEncoded();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
Response aResponseMsg;
try {
// Create SG
aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get SG - must work
assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
// Get BC - not existing
aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
_testResponseJerseyClient(aResponseMsg, 404);
// Create BC with some entities
final PD2BusinessCardType aBC = new PD2BusinessCardType();
aBC.setParticipantIdentifier(PD2APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
PD2BusinessEntityType aBE = new PD2BusinessEntityType();
aBE.setName("BusinessEntity1");
aBE.setCountryCode("AT");
aBE.setGeographicalInformation("Vienna");
aBC.addBusinessEntity(aBE);
aBE = new PD2BusinessEntityType();
aBE.setName("BusinessEntity2");
aBE.setCountryCode("DE");
aBE.setGeographicalInformation("Berlin");
aBC.addBusinessEntity(aBE);
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC2ObjFactory.createBusinessCard(aBC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get BC - must work (always V3)
PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
assertNotNull(aReadBC);
assertEquals(2, aReadBC.getBusinessEntityCount());
ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
assertNotNull(aGetBC);
// Update BC - add entity
aBE = new PD2BusinessEntityType();
aBE.setName("BusinessEntity3");
aBE.setCountryCode("SE");
aBE.setGeographicalInformation("Stockholm");
aBC.addBusinessEntity(aBE);
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC2ObjFactory.createBusinessCard(aBC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get BC - must work (always V3)
aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
assertNotNull(aReadBC);
assertEquals(3, aReadBC.getBusinessEntityCount());
aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
assertNotNull(aGetBC);
} finally {
// Delete Business Card
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
// must be deleted
_testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
// Delete service Group
aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
// must be deleted
_testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
}
}
use of com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager in project phoss-smp by phax.
the class PageSecureBusinessCard method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPBusinessCard aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit Business Card" : "Create new Business Card"));
if (bEdit) {
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(aSelectedObject.getID()).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
} else {
// Show only service groups that don't have a BC already
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getID() : null), aDisplayLocale, x -> aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(x) == null)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
}
final HCDiv aEntityContainer = aForm.addAndReturnChild(new HCDiv().setID("entitycontainer"));
final IRequestParamMap aEntities = aWPEC.getRequestParamMap().getMap(PREFIX_ENTITY);
if (bFormSubmitted) {
// Re-show of form
if (aEntities != null)
for (final String sEntityRowID : aEntities.keySet()) aEntityContainer.addChild(_createEntityInputForm(aWPEC, null, sEntityRowID, aFormErrors, bFormSubmitted));
} else {
if (aSelectedObject != null) {
// add all existing stored entities
for (final SMPBusinessCardEntity aEntity : aSelectedObject.getAllEntities()) aEntityContainer.addChild(_createEntityInputForm(aWPEC, aEntity, (String) null, aFormErrors, bFormSubmitted));
}
}
{
final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
final JSVar aJSAppendData = aJSAppend.param("data");
aJSAppend.body().add(JQuery.idRef(aEntityContainer).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
final JSPackage aOnAdd = new JSPackage();
aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_ENTITY.getInvocationURL(aRequestScope)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
aForm.addChild(new BootstrapButton().addChild("Add Entity").setIcon(EDefaultIcon.PLUS).setOnClick(aOnAdd));
}
}
use of com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager in project phoss-smp by phax.
the class PageSecureBusinessCard method showListOfExistingObjects.
@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
final ICommonsList<ISMPBusinessCard> aAllBusinessCards = aBusinessCardMgr.getAllSMPBusinessCards();
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Create new Business Card", createCreateURL(aWPEC), EDefaultIcon.NEW);
aToolbar.addChild(new BootstrapButton().setOnClick(aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_PUBLISH_ALL_TO_INDEXER)).setIcon(EFamFamIcon.ARROW_REDO).addChild("Update all Business Cards in " + SMPWebAppConfiguration.getDirectoryName()).setDisabled(aAllBusinessCards.isEmpty()));
aNodeList.addChild(aToolbar);
final HCTable aTable = new HCTable(new DTCol("Service Group").setDataSort(0, 1).setInitialSorting(ESortOrder.ASCENDING), new DTCol("Name"), new DTCol("Country"), new DTCol("GeoInfo"), new DTCol("Identifiers"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
for (final ISMPBusinessCard aCurObject : aAllBusinessCards) {
final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
final String sDisplayName = aCurObject.getID();
if (aCurObject.getEntityCount() == 0) {
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(new HCA(aViewLink).addChild(sDisplayName));
for (int i = 1; i < aTable.getColumnCount() - 1; ++i) aRow.addCell();
aRow.addCell(_createActionCell(aWPEC, aCurObject));
} else {
for (final SMPBusinessCardEntity aEntity : aCurObject.getAllEntities()) {
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(new HCA(aViewLink).addChild(sDisplayName));
aRow.addCell(aEntity.names().getFirst().getName());
final Locale aCountry = CountryCache.getInstance().getCountry(aEntity.getCountryCode());
final IHCCell<?> aCountryCell = aRow.addCell();
final EFamFamFlagIcon eIcon = EFamFamFlagIcon.getFromIDOrNull(aCountry.getCountry());
if (eIcon != null)
aCountryCell.addChild(eIcon.getAsNode()).addChild(" ");
aCountryCell.addChild(aCountry.getDisplayCountry(aDisplayLocale));
aRow.addCell(HCExtHelper.nl2divList(aEntity.getGeographicalInformation()));
{
final HCNodeList aIdentifiers = new HCNodeList();
for (final SMPBusinessCardIdentifier aIdentifier : aEntity.identifiers()) aIdentifiers.addChild(div(aIdentifier.getScheme()).addChild(" - ").addChild(aIdentifier.getValue()));
aRow.addCell(aIdentifiers);
}
aRow.addCell(_createActionCell(aWPEC, aCurObject));
}
}
}
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
aNodeList.addChild(aTable).addChild(aDataTables);
}
Aggregations