use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method getAllSMPServiceInformationOfServiceGroup.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceInformation> getAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
final ICommonsList<ISMPServiceInformation> ret = new CommonsArrayList<>();
if (aServiceGroup != null) {
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sm.documentIdentifierScheme, sm.documentIdentifier, sm.extension," + " sp.processIdentifierType, sp.processIdentifier, sp.extension," + " se.transportProfile, se.endpointReference, se.requireBusinessLevelSignature, se.minimumAuthenticationLevel," + " se.serviceActivationDate, se.serviceExpirationDate, se.certificate, se.serviceDescription," + " se.technicalContactUrl, se.technicalInformationUrl, se.extension" + " FROM smp_service_metadata AS sm" + " INNER JOIN smp_process AS sp" + " ON sm.businessIdentifierScheme=sp.businessIdentifierScheme AND sm.businessIdentifier=sp.businessIdentifier" + " AND sm.documentIdentifierScheme=sp.documentIdentifierScheme AND sm.documentIdentifier=sp.documentIdentifier" + " INNER JOIN smp_endpoint AS se" + " ON sp.businessIdentifierScheme=se.businessIdentifierScheme AND sp.businessIdentifier=se.businessIdentifier" + " AND sp.documentIdentifierScheme=se.documentIdentifierScheme AND sp.documentIdentifier=se.documentIdentifier" + " AND sp.processIdentifierType=se.processIdentifierType AND sp.processIdentifier=se.processIdentifier" + " WHERE sm.businessIdentifierScheme=? AND sm.businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
if (aDBResult != null) {
final ICommonsMap<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aGrouping = new CommonsHashMap<>();
for (final DBResultRow aDBRow : aDBResult) {
// Document type ID and extension
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(aDBRow.getAsString(0), aDBRow.getAsString(1));
final String sServiceInformationExtension = aDBRow.getAsString(2);
// Process without endpoints
final SMPProcess aProcess = new SMPProcess(new SimpleProcessIdentifier(aDBRow.getAsString(3), aDBRow.getAsString(4)), null, aDBRow.getAsString(5));
// Don't add endpoint to process, because that impacts
// SMPProcess.equals/hashcode
final SMPEndpoint aEndpoint = new SMPEndpoint(aDBRow.getAsString(6), aDBRow.getAsString(7), aDBRow.getAsBoolean(8, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE), aDBRow.getAsString(9), aDBRow.getAsXMLOffsetDateTime(10), aDBRow.getAsXMLOffsetDateTime(11), aDBRow.getAsString(12), aDBRow.getAsString(13), aDBRow.getAsString(14), aDBRow.getAsString(15), aDBRow.getAsString(16));
aGrouping.computeIfAbsent(new DocTypeAndExtension(aDocTypeID, sServiceInformationExtension), k -> new CommonsHashMap<>()).computeIfAbsent(aProcess, k -> new CommonsArrayList<>()).add(aEndpoint);
}
for (final Map.Entry<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aEntry : aGrouping.entrySet()) {
// Flatten list
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final Map.Entry<SMPProcess, ICommonsList<SMPEndpoint>> aEntry2 : aEntry.getValue().entrySet()) {
final SMPProcess aProcess = aEntry2.getKey();
aProcess.addEndpoints(aEntry2.getValue());
aProcesses.add(aProcess);
}
final DocTypeAndExtension aDE = aEntry.getKey();
ret.add(new SMPServiceInformation(aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
}
}
}
return ret;
}
use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteAllSMPServiceInformationOfServiceGroup.
@Nonnull
public EChange deleteAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
if (aServiceGroup == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final Wrapper<ICommonsList<ISMPServiceInformation>> aAllDeleted = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// get the old ones first
aAllDeleted.set(getAllSMPServiceInformationOfServiceGroup(aServiceGroup));
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
});
if (eSuccess.isFailure() || ret.get().longValue() <= 0) {
AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, "no-such-id", aServiceGroup.getID());
return EChange.UNCHANGED;
}
// Callback outside of transaction
if (aAllDeleted.isSet())
for (final ISMPServiceInformation aSMPServiceInformation : aAllDeleted.get()) {
AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID());
m_aCBs.forEach(x -> x.onSMPServiceInformationDeleted(aSMPServiceInformation));
}
return EChange.CHANGED;
}
use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.
the class SMPServiceInformationManagerMongoDB method mergeSMPServiceInformation.
@Nonnull
public ESuccess mergeSMPServiceInformation(@Nonnull final ISMPServiceInformation aSMPServiceInformationObj) {
final SMPServiceInformation aSMPServiceInformation = (SMPServiceInformation) aSMPServiceInformationObj;
ValueEnforcer.notNull(aSMPServiceInformation, "ServiceInformation");
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation (" + aSMPServiceInformationObj + ")");
// Check for an update
boolean bChangedExisting = false;
final ISMPServiceInformation aOldInformation = getSMPServiceInformationOfServiceGroupAndDocumentType(aSMPServiceInformation.getServiceGroup(), aSMPServiceInformation.getDocumentTypeIdentifier());
if (aOldInformation != null) {
// This is not true for the REST API
if (EqualsHelper.identityEqual(aOldInformation, aSMPServiceInformation))
bChangedExisting = true;
}
if (bChangedExisting) {
// Edit existing
getCollection().replaceOne(new Document(BSON_ID, aOldInformation.getID()), toBson(aSMPServiceInformation));
AuditHelper.onAuditModifySuccess(SMPServiceInformation.OT, "set-all", aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded(), aOldInformation.getAllProcesses(), aOldInformation.getExtensionsAsString());
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation - success - updated");
m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
} else {
// (Optionally delete the old one and) create the new one
boolean bRemovedOld = false;
if (aOldInformation != null) {
// Delete only if present
final DeleteResult aDR = getCollection().deleteOne(new Document(BSON_ID, aOldInformation.getID()));
bRemovedOld = aDR.wasAcknowledged() && aDR.getDeletedCount() > 0;
}
if (!getCollection().insertOne(toBson(aSMPServiceInformation)).wasAcknowledged())
throw new IllegalStateException("Failed to insert into MongoDB Collection");
if (bRemovedOld) {
AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
} else if (aOldInformation != null) {
AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
}
AuditHelper.onAuditCreateSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
if (LOGGER.isDebugEnabled())
LOGGER.debug("mergeSMPServiceInformation - success - created");
if (bChangedExisting)
m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
else
m_aCBs.forEach(x -> x.onSMPServiceInformationCreated(aSMPServiceInformation));
}
return ESuccess.SUCCESS;
}
use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_PROCESS);
final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_ENDPOINT);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID() : aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_GROUP_ID);
ISMPServiceGroup aServiceGroup = null;
final String sDocTypeIDScheme = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_SCHEME);
final String sDocTypeIDValue = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_VALUE);
IDocumentTypeIdentifier aDocTypeID = null;
final String sProcessIDScheme = bEdit ? aSelectedProcess.getProcessIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_SCHEME);
final String sProcessIDValue = bEdit ? aSelectedProcess.getProcessIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_VALUE);
IProcessIdentifier aProcessID = null;
final String sTransportProfileID = bEdit ? aSelectedEndpoint.getTransportProfile() : aWPEC.params().getAsStringTrimmed(FIELD_TRANSPORT_PROFILE);
final ISMPTransportProfile aTransportProfile = aTransportProfileMgr.getSMPTransportProfileOfID(sTransportProfileID);
final String sEndpointReference = aWPEC.params().getAsStringTrimmed(FIELD_ENDPOINT_REFERENCE);
final boolean bRequireBusinessLevelSignature = aWPEC.params().getAsBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
final String sMinimumAuthenticationLevel = aWPEC.params().getAsStringTrimmed(FIELD_MINIMUM_AUTHENTICATION_LEVEL);
final String sNotBefore = aWPEC.params().getAsStringTrimmed(FIELD_NOT_BEFORE);
final LocalDate aNotBeforeDate = PDTFromString.getLocalDateFromString(sNotBefore, aDisplayLocale);
final String sNotAfter = aWPEC.params().getAsStringTrimmed(FIELD_NOT_AFTER);
final LocalDate aNotAfterDate = PDTFromString.getLocalDateFromString(sNotAfter, aDisplayLocale);
final String sCertificate = aWPEC.params().getAsStringTrimmed(FIELD_CERTIFICATE);
final String sServiceDescription = aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_DESCRIPTION);
final String sTechnicalContact = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_CONTACT);
final String sTechnicalInformation = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_INFORMATION);
final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
// validations
if (StringHelper.hasNoText(sServiceGroupID))
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A service group must be selected!");
else {
aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided service group does not exist!");
}
if (aIdentifierFactory.isDocumentTypeIdentifierSchemeMandatory() && StringHelper.hasNoText(sDocTypeIDScheme))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_SCHEME, "Document type ID scheme must not be empty!");
else if (StringHelper.hasNoText(sDocTypeIDValue))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "Document type ID value must not be empty!");
else {
aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(sDocTypeIDScheme, sDocTypeIDValue);
if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "The provided document type ID has an invalid syntax!");
else {
if (aServiceGroup != null)
if (aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "At least one redirect is registered for this document type. Delete the redirect before you can create an endpoint.");
}
}
if (aIdentifierFactory.isProcessIdentifierSchemeMandatory() && StringHelper.hasNoText(sProcessIDScheme))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID scheme must not be empty!");
else if (StringHelper.hasNoText(sProcessIDValue))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID value must not be empty!");
else {
aProcessID = aIdentifierFactory.createProcessIdentifier(sProcessIDScheme, sProcessIDValue);
if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, "The provided process ID has an invalid syntax!");
}
if (StringHelper.hasNoText(sTransportProfileID))
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile must not be empty!");
else if (aTransportProfile == null)
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile of type '" + sTransportProfileID + "' does not exist!");
if (!bEdit && aServiceGroup != null && aDocTypeID != null && aProcessID != null && aTransportProfile != null && aServiceInfoMgr.findServiceInformation(aServiceGroup, aDocTypeID, aProcessID, aTransportProfile) != null) {
final String sMsg = "Another endpoint for the provided service group, document type, process and transport profile is already present. Some of the identifiers may be treated case insensitive!";
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, sMsg);
}
if (StringHelper.hasNoText(sEndpointReference)) {
if (false)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "Endpoint Reference must not be empty!");
} else if (URLHelper.getAsURL(sEndpointReference) == null)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "The Endpoint Reference is not a valid URL!");
if (aNotBeforeDate != null && aNotAfterDate != null)
if (aNotBeforeDate.isAfter(aNotAfterDate))
aFormErrors.addFieldError(FIELD_NOT_BEFORE, "Not Before Date must not be after Not After Date!");
if (StringHelper.hasNoText(sCertificate))
aFormErrors.addFieldError(FIELD_CERTIFICATE, "Certificate must not be empty!");
else {
X509Certificate aCert = null;
try {
aCert = CertificateHelper.convertStringToCertficate(sCertificate);
} catch (final CertificateException ex) {
// Fall through
}
if (aCert == null)
aFormErrors.addFieldError(FIELD_CERTIFICATE, "The provided certificate string is not a valid X509 certificate!");
}
if (StringHelper.hasNoText(sServiceDescription))
aFormErrors.addFieldError(FIELD_SERVICE_DESCRIPTION, "Service Description must not be empty!");
if (StringHelper.hasNoText(sTechnicalContact))
aFormErrors.addFieldError(FIELD_TECHNICAL_CONTACT, "Technical Contact must not be empty!");
if (StringHelper.hasText(sExtension)) {
final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
if (aDoc == null)
aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
}
if (aFormErrors.isEmpty()) {
ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo == null)
aServiceInfo = new SMPServiceInformation(aServiceGroup, aDocTypeID, null, null);
ISMPProcess aProcess = aServiceInfo.getProcessOfID(aProcessID);
if (aProcess == null) {
aProcess = new SMPProcess(aProcessID, null, null);
aServiceInfo.addProcess((SMPProcess) aProcess);
}
aProcess.setEndpoint(new SMPEndpoint(sTransportProfileID, sEndpointReference, bRequireBusinessLevelSignature, sMinimumAuthenticationLevel, PDTFactory.createXMLOffsetDateTime(aNotBeforeDate), PDTFactory.createXMLOffsetDateTime(aNotAfterDate), sCertificate, sServiceDescription, sTechnicalContact, sTechnicalInformation, sExtension));
if (aServiceInfoMgr.mergeSMPServiceInformation(aServiceInfo).isSuccess()) {
if (bEdit) {
aWPEC.postRedirectGetInternal(success("Successfully edited the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(success("Successfully created a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
} else {
if (bEdit) {
aWPEC.postRedirectGetInternal(error("Error editing the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(error("Error creating a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
}
}
}
use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.
the class SMPMetaManager method _performMigrations.
private void _performMigrations() {
// Required for SQL version
try (final WebScoped aWS = new WebScoped()) {
// See issue #128
PhotonBasicManager.getSystemMigrationMgr().performMigrationIfNecessary("ensure-transport-profiles-128", () -> {
LOGGER.info("Started running migration to ensure all used transport profiles are automatically created");
for (final ISMPServiceInformation aSI : m_aServiceInformationMgr.getAllSMPServiceInformation()) for (final ISMPProcess aProc : aSI.getAllProcesses()) for (final ISMPEndpoint aEP : aProc.getAllEndpoints()) {
final String sTransportProfile = aEP.getTransportProfile();
if (!m_aTransportProfileMgr.containsSMPTransportProfileWithID(sTransportProfile)) {
m_aTransportProfileMgr.createSMPTransportProfile(sTransportProfile, sTransportProfile + " (automatically created)", false);
LOGGER.info("Created missing transport profile '" + sTransportProfile + "'");
}
}
});
}
}
Aggregations