use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationInbound method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final String sMigrationKey = aWPEC.params().getAsStringTrimmed(FIELD_MIGRATION_KEY);
final String sParticipantIDScheme = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_SCHEME);
final String sParticipantIDValue = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_VALUE);
IParticipantIdentifier aParticipantID = null;
final String sOwningUserID = aWPEC.params().getAsStringTrimmed(FIELD_OWNING_USER_ID);
final IUser aOwningUser = PhotonSecurityManager.getUserMgr().getUserOfID(sOwningUserID);
final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
// validations
if (StringHelper.hasNoText(sMigrationKey))
aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key must not be empty!");
else if (!SMPParticipantMigration.isValidMigrationKey(sMigrationKey))
aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key is not valid. Please verify the received code is correct.");
if (aIdentifierFactory.isParticipantIdentifierSchemeMandatory() && StringHelper.hasNoText(sParticipantIDScheme))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_SCHEME, "Participant ID scheme must not be empty!");
else if (StringHelper.hasNoText(sParticipantIDValue))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Participant ID value must not be empty!");
else {
aParticipantID = aIdentifierFactory.createParticipantIdentifier(sParticipantIDScheme, sParticipantIDValue);
if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "The provided participant ID has an invalid syntax!");
else if (aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID) != null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Another service group for the same participant ID is already present (may be case insensitive)!");
}
if (StringHelper.hasNoText(sOwningUserID))
aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Owning User must not be empty!");
else if (aOwningUser == null)
aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Provided owning user does not exist!");
if (StringHelper.hasText(sExtension)) {
final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
if (aDoc == null)
aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
}
final HCNodeList aRedirectNotes = new HCNodeList();
if (aFormErrors.isEmpty()) {
// create the Service Group locally
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// SML call
aCaller.migrate(aParticipantID, sMigrationKey, SMPServerConfiguration.getSMLSMPID());
LOGGER.info("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in the SML to this SMP using migration key '" + sMigrationKey + "'");
aRedirectNotes.addChild(success("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in SML to this SMP using migration key ").addChild(code(sMigrationKey)));
} catch (final Exception ex) {
LOGGER.error("Error invoking migrate on SML", ex);
// Use a global field error here, to avoid that users must enter the
// values over and over in case of error
aFormErrors.add(SingleError.builderError().errorText("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.\n" + BootstrapTechnicalUI.getTechnicalDetailsString(ex, CSMPServer.DEFAULT_LOCALE)).build());
if (false)
aWPEC.postRedirectGetInternal(error("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
}
}
if (aFormErrors.isEmpty()) {
// Now create the service group locally (it was already checked that the
// PID is available on this SMP)
ISMPServiceGroup aSG = null;
Exception aCaughtEx = null;
try {
// Do NOT create in SMK/SML
aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, sExtension, false);
} catch (final Exception ex) {
aCaughtEx = ex;
}
if (aSG != null) {
aRedirectNotes.addChild(success("The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created."));
} else {
aRedirectNotes.addChild(error("Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.").addChild(SMPCommonUI.getTechnicalDetailsUI(aCaughtEx)));
}
// Remember internally
if (aParticipantMigrationMgr.createInboundParticipantMigration(aParticipantID, sMigrationKey) != null) {
aRedirectNotes.addChild(success().addChild(div("The participant migration for '" + aParticipantID.getURIEncoded() + "' with migration key ").addChild(code(sMigrationKey)).addChild(" was successfully performed.")).addChild(div("Please inform the source SMP that the migration was successful.")));
} else {
aRedirectNotes.addChild(error("Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'."));
}
aWPEC.postRedirectGetInternal(aRedirectNotes);
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class PageSecureRedirect method isActionAllowed.
@Override
protected boolean isActionAllowed(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final EWebPageFormAction eFormAction, @Nullable final ISMPRedirect aSelectedObject) {
if (eFormAction == EWebPageFormAction.VIEW || eFormAction == EWebPageFormAction.COPY || eFormAction == EWebPageFormAction.EDIT || eFormAction == EWebPageFormAction.DELETE) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
final ISMPServiceGroup aServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup != null) {
final String sDocTypeID = aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID != null) {
aWPEC.getRequestScope().attrs().putIn(ATTR_SERVICE_GROUP, aServiceGroup);
aWPEC.getRequestScope().attrs().putIn(ATTR_DOCTYPE_ID, aDocTypeID);
return true;
}
}
return false;
}
return super.isActionAllowed(aWPEC, eFormAction, aSelectedObject);
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class PageSecureRedirect method getSelectedObject.
@Override
@Nullable
protected ISMPRedirect getSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final String sID) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
final ISMPServiceGroup aServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup != null) {
final String sDocTypeID = aWPEC.params().getAsString(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID != null) {
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
return aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
}
}
return null;
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bIsFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
// State is filtered below
final ICommonsList<ISMPParticipantMigration> aExistingOutgoingMigrations = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(null);
// Get all participant identifiers for which NO new migration can be
// initiated (because they were already migrated or migration is currently
// in progress)
final ICommonsSet<IParticipantIdentifier> aPIDsThatCannotBeUsed = new CommonsHashSet<>();
aPIDsThatCannotBeUsed.addAllMapped(aExistingOutgoingMigrations, x -> x.getState().preventsNewMigration(), ISMPParticipantMigration::getParticipantIdentifier);
// Filter out all for which it makes no sense
final HCServiceGroupSelect aSGSelect = new HCServiceGroupSelect(new RequestField(FIELD_PARTICIPANT_ID), aDisplayLocale, x -> aPIDsThatCannotBeUsed.containsNone(y -> x.getParticipantIdentifier().hasSameContent(y)));
if (!aSGSelect.containsAnyServiceGroup()) {
aForm.addChild(warn("No Service Group on this SMP can currently be migrated."));
} else {
aForm.addChild(getUIHandler().createActionHeader("Start a Participant Migration from this SMP to another SMP"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(aSGSelect).setHelpText("Select the Service Group to migrate to another SMP. Each Service Group can only be migrated once from this SMP. Only Service Groups registered to the SML can be migrated.").setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ISMPBusinessCardManagerFuncTest method testBusinessCard.
@Test
public void testBusinessCard() throws SMPServerException {
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
// Failed to get DB connection. E.g. MySQL down or misconfigured.
return;
}
final SMPBusinessCardEntity aEntity1 = new SMPBusinessCardEntity();
aEntity1.names().add(new SMPBusinessCardName("Test entity", null));
aEntity1.setCountryCode("AT");
final SMPBusinessCardEntity aEntity2 = new SMPBusinessCardEntity();
aEntity2.names().add(new SMPBusinessCardName("Test entity2", null));
aEntity2.setCountryCode("AT");
aEntity2.setGeographicalInformation("Address here");
aEntity2.identifiers().add(new SMPBusinessCardIdentifier("gln", "1234567890123"));
aEntity2.websiteURIs().add("https://www.peppol-directory.org/fake");
aEntity2.contacts().add(new SMPBusinessCardContact("support", "Unit test support", null, "support@peppol.eu"));
aEntity2.setAdditionalInformation("Bla foo fasel");
aEntity2.setRegistrationDate(PDTFactory.getCurrentLocalDate());
final SMPBusinessCardEntity aEntity3 = new SMPBusinessCardEntity();
aEntity3.names().add(new SMPBusinessCardName("Test entity3", null));
aEntity3.setCountryCode("AT");
aEntity3.setAdditionalInformation("Entity 3");
final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IParticipantIdentifier aPI2 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest2");
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aSG = aSGMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
ISMPBusinessCard aBusinessCard = null;
try {
final long nBCCount = aBusinessCardMgr.getSMPBusinessCardCount();
// Create new one
aBusinessCard = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI1, new CommonsArrayList<>(aEntity1));
assertEquals(aPI1, aBusinessCard.getParticipantIdentifier());
assertEquals(1, aBusinessCard.getEntityCount());
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG));
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfID(aSG.getParticipantIdentifier()));
// Update existing
aBusinessCard = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI1, new CommonsArrayList<>(aEntity1, aEntity2));
assertEquals(aPI1, aBusinessCard.getParticipantIdentifier());
assertEquals(2, aBusinessCard.getEntityCount());
// Must not have changed
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG));
assertEquals(aBusinessCard, aBusinessCardMgr.getSMPBusinessCardOfID(aSG.getParticipantIdentifier()));
// Add second one
final ISMPServiceGroup aSG2 = aSGMgr.createSMPServiceGroup(sUserID, aPI2, null, true);
assertNotNull(aSG2);
ISMPBusinessCard aBusinessCard2 = null;
try {
aBusinessCard2 = aBusinessCardMgr.createOrUpdateSMPBusinessCard(aPI2, new CommonsArrayList<>(aEntity3));
assertEquals(aPI2, aBusinessCard2.getParticipantIdentifier());
assertEquals(1, aBusinessCard2.getEntityCount());
assertEquals(nBCCount + 2, aBusinessCardMgr.getSMPBusinessCardCount());
assertEquals(aBusinessCard2, aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aSG2));
assertEquals(aBusinessCard2, aBusinessCardMgr.getSMPBusinessCardOfID(aSG2.getParticipantIdentifier()));
// Cleanup
assertTrue(aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard2).isChanged());
assertEquals(nBCCount + 1, aBusinessCardMgr.getSMPBusinessCardCount());
assertTrue(aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard).isChanged());
assertEquals(nBCCount + 0, aBusinessCardMgr.getSMPBusinessCardCount());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isChanged());
} finally {
// Real cleanup
aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard2);
aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true);
}
} finally {
// Real cleanup
aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard);
aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
Aggregations