use of com.helger.phoss.smp.domain.redirect.SMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method getSMPRedirectOfServiceGroupAndDocumentType.
@Nullable
public ISMPRedirect getSMPRedirectOfServiceGroupAndDocumentType(@Nullable final ISMPServiceGroup aServiceGroup, @Nullable final IDocumentTypeIdentifier aDocTypeID) {
if (aServiceGroup == null)
return null;
if (aDocTypeID == null)
return null;
final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
newExecutor().querySingle("SELECT redirectionUrl, certificateUID, certificate, extension" + " FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? and documentIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()), aDBResult::set);
if (aDBResult.isNotSet())
return null;
final DBResultRow aRow = aDBResult.get();
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(aRow.getAsString(2));
return new SMPRedirect(aServiceGroup, aDocTypeID, aRow.getAsString(0), aRow.getAsString(1), aCertificate, aRow.getAsString(3));
}
use of com.helger.phoss.smp.domain.redirect.SMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerMongoDBTest method testConversion.
@Test
public void testConversion() throws SMPServerException {
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "doctype4711");
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup("blub", aPI, null, true);
assertNotNull(aSG);
try {
_testConversion(new SMPRedirect(aSG, aDocTypeID, "target href", "what ever", null, null));
_testConversion(new SMPRedirect(aSG, aDocTypeID, "target href", "what ever", null, "<ext/>"));
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
use of com.helger.phoss.smp.domain.redirect.SMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method getAllSMPRedirects.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPRedirect> getAllSMPRedirects() {
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, redirectionUrl, certificateUID, certificate, extension" + " FROM smp_service_metadata_red");
final ICommonsList<ISMPRedirect> ret = new CommonsArrayList<>();
if (aDBResult != null)
for (final DBResultRow aRow : aDBResult) {
final ISMPServiceGroup aServiceGroup = m_aServiceGroupMgr.getSMPServiceGroupOfID(new SimpleParticipantIdentifier(aRow.getAsString(0), aRow.getAsString(1)));
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(aRow.getAsString(6));
ret.add(new SMPRedirect(aServiceGroup, new SimpleDocumentTypeIdentifier(aRow.getAsString(2), aRow.getAsString(3)), aRow.getAsString(4), aRow.getAsString(5), aCertificate, aRow.getAsString(7)));
}
return ret;
}
use of com.helger.phoss.smp.domain.redirect.SMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method getAllSMPRedirectsOfServiceGroup.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPRedirect> getAllSMPRedirectsOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
final ICommonsList<ISMPRedirect> ret = new CommonsArrayList<>();
if (aServiceGroup != null) {
final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT documentIdentifierScheme, documentIdentifier, redirectionUrl, certificateUID, certificate, extension" + " FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue()));
if (aDBResult != null)
for (final DBResultRow aRow : aDBResult) {
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(aRow.getAsString(4));
ret.add(new SMPRedirect(aServiceGroup, new SimpleDocumentTypeIdentifier(aRow.getAsString(0), aRow.getAsString(1)), aRow.getAsString(2), aRow.getAsString(3), aCertificate, aRow.getAsString(5)));
}
}
return ret;
}
use of com.helger.phoss.smp.domain.redirect.SMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method createOrUpdateSMPRedirect.
@Nullable
public ISMPRedirect createOrUpdateSMPRedirect(@Nonnull final ISMPServiceGroup aServiceGroup, @Nonnull final IDocumentTypeIdentifier aDocTypeID, @Nonnull @Nonempty final String sRedirectUrl, @Nonnull @Nonempty final String sSubjectUniqueIdentifier, @Nullable final X509Certificate aCertificate, @Nullable final String sExtension) {
ValueEnforcer.notNull(aServiceGroup, "ServiceGroup");
ValueEnforcer.notNull(aDocTypeID, "DocumentTypeIdentifier");
final MutableBoolean aCreatedNew = new MutableBoolean(true);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
final ISMPRedirect aDBRedirect = getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
final String sCertificate = aCertificate == null ? null : CertificateHelper.getPEMEncodedCertificate(aCertificate);
if (aDBRedirect == null) {
// Create new
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_service_metadata_red (businessIdentifierScheme, businessIdentifier, documentIdentifierScheme, documentIdentifier, redirectionUrl, certificateUID, certificate, extension) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), sRedirectUrl, sSubjectUniqueIdentifier, sCertificate, sExtension));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
aCreatedNew.set(true);
} else {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_service_metadata_red" + " SET redirectionUrl=?, certificateUID=?, certificate=?, extension=?" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(sRedirectUrl, sSubjectUniqueIdentifier, sCertificate, sExtension, aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (nUpdated != 1)
throw new IllegalStateException("Failed to update existing DB entry (" + nUpdated + ")");
aCreatedNew.set(false);
}
});
if (eSuccess.isFailure()) {
return null;
}
final SMPRedirect aSMPRedirect = new SMPRedirect(aServiceGroup, aDocTypeID, sRedirectUrl, sSubjectUniqueIdentifier, aCertificate, sExtension);
if (aCreatedNew.booleanValue()) {
AuditHelper.onAuditCreateSuccess(SMPRedirect.OT, aSMPRedirect.getID(), aSMPRedirect.getServiceGroupID(), aSMPRedirect.getDocumentTypeIdentifier().getURIEncoded(), aSMPRedirect.getTargetHref(), aSMPRedirect.getSubjectUniqueIdentifier(), aSMPRedirect.getCertificate(), aSMPRedirect.getExtensionsAsString());
m_aCallbacks.forEach(x -> x.onSMPRedirectCreated(aSMPRedirect));
} else {
AuditHelper.onAuditModifySuccess(SMPRedirect.OT, "set-all", aSMPRedirect.getID(), aSMPRedirect.getServiceGroupID(), aSMPRedirect.getDocumentTypeIdentifier().getURIEncoded(), aSMPRedirect.getTargetHref(), aSMPRedirect.getSubjectUniqueIdentifier(), aSMPRedirect.getCertificate(), aSMPRedirect.getExtensionsAsString());
m_aCallbacks.forEach(x -> x.onSMPRedirectUpdated(aSMPRedirect));
}
return aSMPRedirect;
}
Aggregations