use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.
the class SMPServerAPI method getServiceGroup.
@Nonnull
public ServiceGroupType getServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID;
final String sAction = "getServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
// Retrieve the service group
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
// Then add the service metadata references
final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectPeppol();
final ServiceMetadataReferenceCollectionType aCollectionType = new ServiceMetadataReferenceCollectionType();
for (final IDocumentTypeIdentifier aDocTypeID : aServiceInfoMgr.getAllSMPDocumentTypesOfServiceGroup(aServiceGroup)) {
// Ignore all service information without endpoints
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo != null && aServiceInfo.getTotalEndpointCount() > 0) {
final ServiceMetadataReferenceType aMetadataReference = new ServiceMetadataReferenceType();
aMetadataReference.setHref(m_aAPIDataProvider.getServiceMetadataReferenceHref(aPathServiceGroupID, aDocTypeID));
aCollectionType.addServiceMetadataReference(aMetadataReference);
}
}
aSG.setServiceMetadataReferenceCollection(aCollectionType);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aSG;
} 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.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.
the class BDXR1ServerAPI method getServiceGroup.
@Nonnull
public ServiceGroupType getServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID;
final String sAction = "getServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
// Retrieve the service group
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
// Then add the service metadata references
final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectBDXR1();
final ServiceMetadataReferenceCollectionType aCollectionType = new ServiceMetadataReferenceCollectionType();
for (final IDocumentTypeIdentifier aDocTypeID : aServiceInfoMgr.getAllSMPDocumentTypesOfServiceGroup(aServiceGroup)) {
// Ignore all service information without endpoints
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo != null && aServiceInfo.getTotalEndpointCount() > 0) {
final ServiceMetadataReferenceType aMetadataReference = new ServiceMetadataReferenceType();
aMetadataReference.setHref(m_aAPIDataProvider.getServiceMetadataReferenceHref(aPathServiceGroupID, aDocTypeID));
aCollectionType.addServiceMetadataReference(aMetadataReference);
}
}
aSG.setServiceMetadataReferenceCollection(aCollectionType);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aSG;
} 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.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.
the class BDXR1ServerAPI method deleteServiceRegistration.
public void deleteServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
final String sAction = "deleteServiceRegistration";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
if (aPathDocTypeID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
if (aServiceInfo != null) {
// Handle service information
final EChange eChange = aServiceInfoMgr.deleteSMPServiceInformation(aServiceInfo);
if (eChange.isUnchanged()) {
// Most likely an internal error or an inconsistency
throw new SMPNotFoundException("serviceInformation (" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - ServiceInformation");
STATS_COUNTER_SUCCESS.increment(sAction);
} else {
// No Service Info, so should be a redirect
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
if (aRedirect != null) {
// Handle redirect
final EChange eChange = aRedirectMgr.deleteSMPRedirect(aRedirect);
if (eChange.isUnchanged()) {
// Most likely an internal error or an inconsistency
throw new SMPNotFoundException("redirect(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - Redirect");
STATS_COUNTER_SUCCESS.increment(sAction);
} else {
// Neither redirect nor endpoint found
throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
}
}
} 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.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.
the class BDXR1ServerAPI method getCompleteServiceGroup.
@Nonnull
public CompleteServiceGroupType getCompleteServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /complete/" + sPathServiceGroupID;
final String sAction = "getCompleteServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group ID '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
// Then add the service metadata references
final ServiceMetadataReferenceCollectionType aRefCollection = new ServiceMetadataReferenceCollectionType();
for (final IDocumentTypeIdentifier aDocTypeID : aServiceInfoMgr.getAllSMPDocumentTypesOfServiceGroup(aServiceGroup)) {
// Ignore all service information without endpoints
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo != null && aServiceInfo.getTotalEndpointCount() > 0) {
final ServiceMetadataReferenceType aMetadataReference = new ServiceMetadataReferenceType();
aMetadataReference.setHref(m_aAPIDataProvider.getServiceMetadataReferenceHref(aPathServiceGroupID, aDocTypeID));
aRefCollection.addServiceMetadataReference(aMetadataReference);
}
}
final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectBDXR1();
aSG.setServiceMetadataReferenceCollection(aRefCollection);
// a CompleteSG may be empty
final CompleteServiceGroupType aCompleteServiceGroup = new CompleteServiceGroupType();
aCompleteServiceGroup.setServiceGroup(aSG);
for (final ISMPServiceInformation aServiceInfo : aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup)) {
final ServiceMetadataType aSM = aServiceInfo.getAsJAXBObjectBDXR1();
if (aSM != null)
aCompleteServiceGroup.addServiceMetadata(aSM);
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aCompleteServiceGroup;
} 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.serviceinfo.ISMPServiceInformationManager in project phoss-smp by phax.
the class BDXR1ServerAPI method saveServiceRegistration.
@Nonnull
public ESuccess saveServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + "/services/" + sPathDocumentTypeID;
final String sAction = "saveServiceRegistration";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " ==> " + aServiceMetadata);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
// Parse provided identifiers
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocumentTypeID);
if (aPathDocTypeID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseDocType(sPathDocumentTypeID, m_aAPIDataProvider.getCurrentURI());
}
// May be null for a Redirect!
final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
if (aServiceInformation != null) {
// metadata (body) must equal path
if (aServiceInformation.getParticipantIdentifier() == null) {
throw new SMPBadRequestException("Save Service Metadata has inconsistent values.\n" + "Service Information Participant ID: <none>\n" + "URL Parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
}
final IParticipantIdentifier aPayloadServiceGroupID;
if (aServiceInformation.getParticipantIdentifier() == null) {
// Can happen when tampering with the input data
aPayloadServiceGroupID = null;
} else {
aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceInformation.getParticipantIdentifier().getScheme(), aServiceInformation.getParticipantIdentifier().getValue());
}
if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
// Participant ID in URL must match the one in XML structure
throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Infoformation Participant ID: " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'") + "\n" + "URL parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
}
if (aServiceInformation.getDocumentIdentifier() == null) {
throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: <none>\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPayloadDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(aServiceInformation.getDocumentIdentifier().getScheme(), aServiceInformation.getDocumentIdentifier().getValue());
if (!aPathDocTypeID.hasSameContent(aPayloadDocTypeID)) {
// Document type ID in URL must match the one in XML structure
throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: '" + aPayloadDocTypeID.getURIEncoded() + "'\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
}
}
// Main save
final IUser aDataUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aDataUser);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aPathServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aPathServiceGroup == null) {
// Service group not found
throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
}
if (aServiceMetadata.getRedirect() != null) {
// Handle redirect
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
// not available in OASIS BDXR SMP v1 mode
final X509Certificate aCertificate = null;
if (aRedirectMgr.createOrUpdateSMPRedirect(aPathServiceGroup, aPathDocTypeID, aServiceMetadata.getRedirect().getHref(), aServiceMetadata.getRedirect().getCertificateUID(), aCertificate, BDXR1ExtensionConverter.convertToString(aServiceMetadata.getRedirect().getExtension())) == null) {
if (LOGGER.isErrorEnabled())
LOGGER.error(sLog + " - ERROR - Redirect");
STATS_COUNTER_ERROR.increment(sAction);
return ESuccess.FAILURE;
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - Redirect");
} else if (aServiceInformation != null) {
// Handle service information
final ProcessListType aJAXBProcesses = aServiceInformation.getProcessList();
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final ProcessType aJAXBProcess : aJAXBProcesses.getProcess()) {
final ICommonsList<SMPEndpoint> aEndpoints = new CommonsArrayList<>();
for (final EndpointType aJAXBEndpoint : aJAXBProcess.getServiceEndpointList().getEndpoint()) {
final SMPEndpoint aEndpoint = new SMPEndpoint(aJAXBEndpoint.getTransportProfile(), aJAXBEndpoint.getEndpointURI(), BooleanHelper.getBooleanValue(aJAXBEndpoint.isRequireBusinessLevelSignature(), false), aJAXBEndpoint.getMinimumAuthenticationLevel(), aJAXBEndpoint.getServiceActivationDate(), aJAXBEndpoint.getServiceExpirationDate(), Base64.encodeBytes(aJAXBEndpoint.getCertificate()), aJAXBEndpoint.getServiceDescription(), aJAXBEndpoint.getTechnicalContactUrl(), aJAXBEndpoint.getTechnicalInformationUrl(), BDXR1ExtensionConverter.convertToString(aJAXBEndpoint.getExtension()));
aEndpoints.add(aEndpoint);
}
final SMPProcess aProcess = new SMPProcess(SimpleProcessIdentifier.wrap(aJAXBProcess.getProcessIdentifier()), aEndpoints, BDXR1ExtensionConverter.convertToString(aJAXBProcess.getExtension()));
aProcesses.add(aProcess);
}
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final String sExtensionXML = BDXR1ExtensionConverter.convertToString(aServiceInformation.getExtension());
if (aServiceInfoMgr.mergeSMPServiceInformation(new SMPServiceInformation(aPathServiceGroup, aPathDocTypeID, aProcesses, sExtensionXML)).isFailure()) {
if (LOGGER.isErrorEnabled())
LOGGER.error(sLog + " - ERROR - ServiceInformation");
STATS_COUNTER_ERROR.increment(sAction);
return ESuccess.FAILURE;
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - ServiceInformation");
} else {
throw new SMPBadRequestException("Save Service Metadata was called with neither a Redirect nor a ServiceInformation", m_aAPIDataProvider.getCurrentURI());
}
if (false)
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return ESuccess.SUCCESS;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
Aggregations