use of com.helger.xsds.peppol.smp1.ServiceGroupType in project phoss-smp by phax.
the class BusinessCardInterfaceTest method testGetCreateV3GetDeleteGet.
@Test
public void testGetCreateV3GetDeleteGet() {
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
assertNotNull(aSGMgr);
final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
assertNotNull(aBCMgr);
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
final String sPI = aPI.getURIEncoded();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
Response aResponseMsg;
try {
// Create SG
aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get SG - must work
assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
// Get BC - not existing
aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
_testResponseJerseyClient(aResponseMsg, 404);
// Create BC with some entities
final PD3BusinessCardType aBC = new PD3BusinessCardType();
aBC.setParticipantIdentifier(PD3APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
PD3BusinessEntityType aBE = new PD3BusinessEntityType();
aBE.addName(PD3APIHelper.createName("BusinessEntity1", null));
aBE.setCountryCode("AT");
aBE.setGeographicalInformation("Vienna");
aBC.addBusinessEntity(aBE);
aBE = new PD3BusinessEntityType();
aBE.addName(PD3APIHelper.createName("BusinessEntity2", null));
aBE.setCountryCode("DE");
aBE.setGeographicalInformation("Berlin");
aBC.addBusinessEntity(aBE);
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get BC - must work (always V3)
PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
assertNotNull(aReadBC);
assertEquals(2, aReadBC.getBusinessEntityCount());
ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
assertNotNull(aGetBC);
// Update BC - add entity
aBE = new PD3BusinessEntityType();
aBE.addName(PD3APIHelper.createName("BusinessEntity3", null));
aBE.setCountryCode("SE");
aBE.setGeographicalInformation("Stockholm");
aBC.addBusinessEntity(aBE);
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
_testResponseJerseyClient(aResponseMsg, 200);
// Get BC - must work (always V3)
aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
assertNotNull(aReadBC);
assertEquals(3, aReadBC.getBusinessEntityCount());
aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
assertNotNull(aGetBC);
} finally {
// Delete Business Card
aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
// must be deleted
_testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
// Delete service Group
aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
// must be deleted
_testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
}
}
use of com.helger.xsds.peppol.smp1.ServiceGroupType 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.xsds.peppol.smp1.ServiceGroupType 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.xsds.peppol.smp1.ServiceGroupType 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.xsds.peppol.smp1.ServiceGroupType 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;
}
}
Aggregations