use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class BusinessCardServerAPI method createBusinessCard.
@Nonnull
public ESuccess createBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final PDBusinessCard aBusinessCard, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "PUT /businesscard/" + sServiceGroupID;
final String sAction = "createBusinessCard";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " ==> " + aBusinessCard);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
// Parse and validate identifier
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
}
final IParticipantIdentifier aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aBusinessCard.getParticipantIdentifier().getScheme(), aBusinessCard.getParticipantIdentifier().getValue());
if (!aServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
// Business identifiers must be equal
throw new SMPBadRequestException("Participant Inconsistency. The URL points to '" + aServiceGroupID.getURIEncoded() + "' whereas the BusinessCard contains '" + aPayloadServiceGroupID.getURIEncoded() + "'", m_aAPIProvider.getCurrentURI());
}
// Retrieve the service group
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup == null) {
// No such service group (on this server)
throw new SMPNotFoundException("Unknown serviceGroup '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
// Check credentials and verify service group is owned by provided user
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aServiceGroupID, aSMPUser);
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr == null) {
throw new SMPBadRequestException("This SMP server does not support the BusinessCard API", m_aAPIProvider.getCurrentURI());
}
final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
for (final PDBusinessEntity aEntity : aBusinessCard.businessEntities()) aEntities.add(SMPBusinessCardEntity.createFromGenericObject(aEntity));
if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aEntities) == null) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR");
STATS_COUNTER_ERROR.increment(sAction);
return ESuccess.FAILURE;
}
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;
}
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServerAPI method getServiceRegistration.
@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
final String sAction = "getServiceRegistration";
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 ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
if (aPathServiceGroup == null) {
throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
if (aPathDocTypeID == null) {
throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
}
// First check for redirection, then for actual service
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
if (aRedirect != null) {
aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectPeppol());
} else {
// Get as regular service information
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectPeppol();
if (aSM != null) {
aSignedServiceMetadata.setServiceMetadata(aSM);
} else {
// Neither nor is present, or no endpoint is available
throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
}
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aSignedServiceMetadata;
} 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.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceInformationTest method testBasic.
@Test
public void testBasic() {
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:dummy");
final ISMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
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/>");
assertEquals("tp", aEP.getTransportProfile());
assertEquals("http://localhost/as2", aEP.getEndpointReference());
assertFalse(aEP.isRequireBusinessLevelSignature());
assertEquals("minauth", aEP.getMinimumAuthenticationLevel());
assertEquals(aStartDT, aEP.getServiceActivationDateTime());
assertEquals(aEndDT, aEP.getServiceExpirationDateTime());
assertEquals("cert", aEP.getCertificate());
assertEquals("sd", aEP.getServiceDescription());
assertEquals("tc", aEP.getTechnicalContactUrl());
assertEquals("ti", aEP.getTechnicalInformationUrl());
assertEquals("[{\"Any\":\"<extep />\"}]", aEP.getExtensionsAsString());
final IProcessIdentifier aProcessID = new SimpleProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
final SMPProcess aProcess = new SMPProcess(aProcessID, CollectionHelper.newList(aEP), "<extproc/>");
assertEquals(aProcessID, aProcess.getProcessIdentifier());
assertEquals(1, aProcess.getAllEndpoints().size());
assertEquals("[{\"Any\":\"<extproc />\"}]", aProcess.getExtensionsAsString());
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
final SMPServiceInformation aSI = new SMPServiceInformation(aSG, aDocTypeID, CollectionHelper.newList(aProcess), "<extsi/>");
assertSame(aSG, aSI.getServiceGroup());
assertEquals(aDocTypeID, aSI.getDocumentTypeIdentifier());
assertEquals(1, aSI.getAllProcesses().size());
assertEquals("[{\"Any\":\"<extsi />\"}]", aSI.getExtensionsAsString());
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServerAPI 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.getAsJAXBObjectPeppol();
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.getAsJAXBObjectPeppol();
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.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServerAPI method getServiceGroupReferenceList.
@Nonnull
public ServiceGroupReferenceListType getServiceGroupReferenceList(@Nonnull final String sPathUserID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /list/" + sPathUserID;
final String sAction = "getServiceGroupReferenceList";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
if (!aCredentials.getUserName().equals(sPathUserID)) {
throw new SMPUnauthorizedException("URL user name '" + sPathUserID + "' does not match HTTP Basic Auth user name '" + aCredentials.getUserName() + "'", m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ICommonsList<ISMPServiceGroup> aServiceGroups = aSGMgr.getAllSMPServiceGroupsOfOwner(aSMPUser.getID());
final ServiceGroupReferenceListType aRefList = new ServiceGroupReferenceListType();
for (final ISMPServiceGroup aServiceGroup : aServiceGroups) {
final String sHref = m_aAPIDataProvider.getServiceGroupHref(aServiceGroup.getParticipantIdentifier());
final ServiceGroupReferenceType aServGroupRefType = new ServiceGroupReferenceType();
aServGroupRefType.setHref(sHref);
aRefList.addServiceGroupReference(aServGroupRefType);
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aRefList;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
Aggregations