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);
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ISMPRedirectManagerFuncTest method testRedirect.
@Test
public void testRedirect() throws SMPServerException {
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 IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IParticipantIdentifier aPI2 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest2");
final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("junit::testdoc#ext:1.0");
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aSG = aSGMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
try {
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
// Create new one
ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect />");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target", aRedirect.getTargetHref());
assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect />", aRedirect.getFirstExtensionXML().trim());
final long nCount = aRedirectMgr.getSMPRedirectCount();
// Update existing
aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "target2", "suid2", null, "<extredirect2 />");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target2", aRedirect.getTargetHref());
assertEquals("suid2", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect2 />", aRedirect.getFirstExtensionXML().trim());
assertEquals(nCount, aRedirectMgr.getSMPRedirectCount());
// Add second one
final ISMPServiceGroup aSG2 = aSGMgr.createSMPServiceGroup(sUserID, aPI2, null, true);
assertNotNull(aSG2);
try {
aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG2, aDocTypeID, "target2", "suid2", null, "<extredirect2 />");
assertNotNull(aRedirect);
assertSame(aSG2, aRedirect.getServiceGroup());
assertTrue(aDocTypeID.hasSameContent(aRedirect.getDocumentTypeIdentifier()));
assertEquals("target2", aRedirect.getTargetHref());
assertEquals("suid2", aRedirect.getSubjectUniqueIdentifier());
assertEquals("<extredirect2 />", aRedirect.getFirstExtensionXML().trim());
assertEquals(nCount + 1, aRedirectMgr.getSMPRedirectCount());
// Cleanup
assertTrue(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSG2).isChanged());
assertEquals(nCount, aRedirectMgr.getSMPRedirectCount());
assertTrue(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSG).isChanged());
assertEquals(nCount - 1, aRedirectMgr.getSMPRedirectCount());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isChanged());
} finally {
aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true);
}
} finally {
aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ISMPServiceGroupManagerFuncTest method testBasic.
@Test
public void testBasic() throws SMPServerException {
final IIdentifierFactory aIDFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPI1 = aIDFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:junittest1");
final IParticipantIdentifier aPI2 = aIDFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:junittest2");
final String sSG1 = SMPServiceGroup.createSMPServiceGroupID(aPI1);
final String sSG2 = SMPServiceGroup.createSMPServiceGroupID(aPI2);
final String sOwner1ID = CSecurity.USER_ADMINISTRATOR_ID;
final String sOwner2ID = CSecurity.USER_ADMINISTRATOR_ID + "2";
final String sExtension = "<ext val=\"a\" />";
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
assertNotNull(aSGMgr);
try {
// Check empty state
final long nCount = aSGMgr.getSMPServiceGroupCount();
assertEquals(nCount, aSGMgr.getAllSMPServiceGroups().size());
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI1));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI2));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI1));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI2));
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isUnchanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI1, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI1, sOwner2ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner2ID, sExtension).isUnchanged());
// Register first and check state
ISMPServiceGroup aSG1 = aSGMgr.createSMPServiceGroup(sOwner1ID, aPI1, sExtension, true);
assertNotNull(aSG1);
assertEquals(aPI1, aSG1.getParticipantIdentifier());
assertEquals(sSG1, aSG1.getID());
assertEquals(sOwner1ID, aSG1.getOwnerID());
assertEquals(sExtension, aSG1.getFirstExtensionXML().trim());
// Check manager state
assertEquals(nCount + 1, aSGMgr.getSMPServiceGroupCount());
assertEquals(nCount + 1, aSGMgr.getAllSMPServiceGroups().size());
assertTrue(aSGMgr.getAllSMPServiceGroups().contains(aSG1));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI1));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI2));
assertEquals(aSG1, aSGMgr.getSMPServiceGroupOfID(aPI1));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI2));
assertEquals(1, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertTrue(aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).contains(aSG1));
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
// change owner
assertTrue(aSGMgr.updateSMPServiceGroup(aPI1, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroup(aPI1, sOwner2ID, sExtension).isChanged());
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertEquals(1, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
assertTrue(aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).contains(aSG1));
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner2ID, sExtension).isUnchanged());
aSG1 = aSGMgr.getSMPServiceGroupOfID(aPI1);
assertEquals(sOwner2ID, aSG1.getOwnerID());
final ISMPServiceGroup aSG2 = aSGMgr.createSMPServiceGroup(sOwner2ID, aPI2, sExtension, true);
assertNotNull(aSG2);
assertEquals(aPI2, aSG2.getParticipantIdentifier());
assertEquals(sSG2, aSG2.getID());
assertEquals(sOwner2ID, aSG2.getOwnerID());
assertEquals(sExtension, aSG2.getFirstExtensionXML().trim());
// Check manager state
assertEquals(nCount + 2, aSGMgr.getSMPServiceGroupCount());
assertEquals(nCount + 2, aSGMgr.getAllSMPServiceGroups().size());
assertTrue(aSGMgr.getAllSMPServiceGroups().contains(aSG1));
assertTrue(aSGMgr.getAllSMPServiceGroups().contains(aSG2));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI1));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI2));
assertEquals(aSG1, aSGMgr.getSMPServiceGroupOfID(aPI1));
assertEquals(aSG2, aSGMgr.getSMPServiceGroupOfID(aPI2));
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertEquals(2, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
assertTrue(aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).contains(aSG1));
assertTrue(aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).contains(aSG2));
// delete SG1
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isUnchanged());
// Check manager state
assertEquals(nCount + 1, aSGMgr.getSMPServiceGroupCount());
assertEquals(nCount + 1, aSGMgr.getAllSMPServiceGroups().size());
assertTrue(aSGMgr.getAllSMPServiceGroups().contains(aSG2));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI1));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI2));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI1));
assertEquals(aSG2, aSGMgr.getSMPServiceGroupOfID(aPI2));
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertEquals(1, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
assertTrue(aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).contains(aSG2));
// Finally delete SG2
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isChanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isUnchanged());
// Check empty state
assertEquals(nCount, aSGMgr.getSMPServiceGroupCount());
assertEquals(nCount, aSGMgr.getAllSMPServiceGroups().size());
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI1));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI2));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI1));
assertNull(aSGMgr.getSMPServiceGroupOfID(aPI2));
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner1ID).size());
assertEquals(0, aSGMgr.getAllSMPServiceGroupsOfOwner(sOwner2ID).size());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true).isUnchanged());
assertTrue(aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI1, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner1ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI1, sOwner2ID, sExtension).isUnchanged());
assertTrue(aSGMgr.updateSMPServiceGroupNoEx(aPI2, sOwner2ID, sExtension).isUnchanged());
} finally {
// Don't care about the result
aSGMgr.deleteSMPServiceGroupNoEx(aPI1, true);
aSGMgr.deleteSMPServiceGroupNoEx(aPI2, true);
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.
the class ISMPServiceInformationManagerFuncTest method testAll.
@Test
public void testAll() throws SMPServerException {
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final IParticipantIdentifier aPI1 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:junittest1");
final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("junit::testdoc#ext:1.0");
final IProcessIdentifier aProcessID = PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("junit-proc");
final String sUserID = CSecurity.USER_ADMINISTRATOR_ID;
if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
// Failed to get DB connection. E.g. MySQL down or misconfigured.
return;
}
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(sUserID, aPI1, null, true);
assertNotNull(aSG);
try {
final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc/>");
final SMPServiceInformation aServiceInformation = new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi/>");
assertTrue(aServiceInfoMgr.mergeSMPServiceInformation(aServiceInformation).isSuccess());
} finally {
// Don't care about the result
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI1, true);
}
}
Aggregations