Search in sources :

Example 51 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolDocumentTypeIdentifierTest method testValue.

@Test
public void testValue() throws Exception {
    final IIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
    final String documentIdAsText = "urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2::ApplicationResponse##urn:www.cenbii.eu:transaction:biicoretrdm057:ver1.0:#urn:www.peppol.eu:bis:peppol1a:ver1.0::2.0";
    final IDocumentTypeIdentifier documentTypeIdentifier = aIF.createDocumentTypeIdentifierWithDefaultScheme(documentIdAsText);
    assertEquals(documentTypeIdentifier.getValue(), documentIdAsText);
    assertTrue(documentTypeIdentifier.hasValue(documentIdAsText));
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 52 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolSBDHDocumentWriterTest method testBadCase.

@Test
public void testBadCase() {
    final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
    final PeppolSBDHDocument aData = new PeppolSBDHDocument(aIF);
    try {
        // Not all fields are set
        new PeppolSBDHDocumentWriter().createStandardBusinessDocument(aData);
        fail();
    } catch (final IllegalArgumentException ex) {
    // Expected
    }
}
Also used : PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 53 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolSBDHDocumentTest method testText.

@Test
public void testText() {
    final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
    final PeppolSBDHDocument dd = new PeppolSBDHDocument(aIF);
    dd.setBusinessMessageTextOnly("abc", CMimeType.APPLICATION_OCTET_STREAM);
    assertNotNull(dd.getBusinessMessage());
    assertEquals("<TextContent xmlns=\"http://peppol.eu/xsd/ticc/envelope/1.0\" mimeType=\"application/octet-stream\">abc</TextContent>", XMLWriter.getNodeAsString(dd.getBusinessMessage()).trim());
    final TextContentType aTC = dd.getBusinessMessageAsTextContent();
    assertNotNull(aTC);
    assertEquals("abc", aTC.getValue());
    assertEquals(CMimeType.APPLICATION_OCTET_STREAM.getAsString(), aTC.getMimeType());
    assertNull(dd.getBusinessMessageAsBinaryContent());
}
Also used : TextContentType(com.helger.peppol.sbdh.spec12.TextContentType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 54 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolSBDHDocumentTest method testBasic.

@Test
public void testBasic() {
    final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
    final PeppolSBDHDocument dd = new PeppolSBDHDocument(aIF);
    assertNull(dd.getSenderScheme());
    assertNull(dd.getSenderValue());
    assertNull(dd.getReceiverScheme());
    assertNull(dd.getReceiverValue());
    assertNull(dd.getDocumentTypeScheme());
    assertNull(dd.getDocumentTypeValue());
    assertNull(dd.getProcessScheme());
    assertNull(dd.getProcessValue());
    assertNull(dd.getStandard());
    assertNull(dd.getTypeVersion());
    assertNull(dd.getType());
    assertNull(dd.getInstanceIdentifier());
    assertNull(dd.getCreationDateAndTime());
    assertFalse(dd.hasBusinessMessage());
    assertNull(dd.getBusinessMessage());
    assertEquals(0, dd.additionalAttributes().size());
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF));
    assertNotNull(dd.getSenderAsIdentifier());
    assertNotNull(dd.getReceiverAsIdentifier());
    assertNotNull(dd.getDocumentTypeAsIdentifier());
    assertNotNull(dd.getProcessAsIdentifier());
    assertFalse(dd.areAllFieldsSet());
    assertTrue(dd.areAllAdditionalAttributesValid());
    // Sender
    dd.setSenderWithDefaultScheme("abc");
    assertEquals(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, dd.getSenderScheme());
    assertEquals("abc", dd.getSenderValue());
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSender("scheme", "abc"));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc"));
    // Receiver
    dd.setReceiverWithDefaultScheme("def");
    assertEquals(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, dd.getReceiverScheme());
    assertEquals("def", dd.getReceiverValue());
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc"));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiver("scheme", "def"));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def"));
    // Document type 1
    dd.setDocumentTypeWithBusdoxDocidQns("doctype");
    assertEquals(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, dd.getDocumentTypeScheme());
    assertEquals("doctype", dd.getDocumentTypeValue());
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithBusdoxDocidQns("other"));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithBusdoxDocidQns("doctype"));
    // Document type 2
    dd.setDocumentTypeWithPeppolDoctypeWildcard("doctype");
    assertEquals(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_PEPPOL_DOCTYPE_WILDCARD, dd.getDocumentTypeScheme());
    assertEquals("doctype", dd.getDocumentTypeValue());
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("other"));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype"));
    // Process type
    dd.setProcessWithDefaultScheme("proctype");
    assertEquals(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, dd.getProcessScheme());
    assertEquals("proctype", dd.getProcessValue());
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype").setProcessWithDefaultScheme("other"));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype").setProcessWithDefaultScheme("proctype"));
}
Also used : IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 55 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory 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;
    }
}
Also used : CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ServiceMetadataReferenceType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)84 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)57 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)34 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)33 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)30 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 IUser (com.helger.photon.security.user.IUser)20 Nonnull (javax.annotation.Nonnull)19 Test (org.junit.Test)19 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)17 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)13 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)11 Locale (java.util.Locale)11 Nullable (javax.annotation.Nullable)11 HCEdit (com.helger.html.hc.html.forms.HCEdit)10 RequestField (com.helger.photon.core.form.RequestField)10