Search in sources :

Example 21 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.

the class SMPRedirectTest method testCaseSensitivity.

@Test
public void testCaseSensitivity() {
    final IParticipantIdentifier aPI = new SimpleParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:UpperCase");
    final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testDocType");
    final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
    // Create new one
    final ISMPRedirect aRedirect = new SMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect/>");
    assertSame(aSG, aRedirect.getServiceGroup());
    assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
    assertEquals("target", aRedirect.getTargetHref());
    assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
    assertNull(aRedirect.getCertificate());
    assertFalse(aRedirect.hasCertificate());
    assertEquals("[{\"Any\":\"<extredirect />\"}]", aRedirect.getExtensionsAsString());
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 22 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phase4 by phax.

the class MainPhase4CEFSenderToop method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try (final WebScoped w = new WebScoped()) {
        final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
        if (aPayloadBytes == null)
            throw new IllegalStateException();
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9915:tooptest");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }
        };
        if (Phase4CEFSender.builder().documentTypeID(Phase4CEFSender.IF.createDocumentTypeIdentifier("toop-doctypeid-qns", "urn:eu:toop:ns:dataexchange-1p40::Response##urn:eu.toop.response.registeredorganization::1.40")).processID(Phase4CEFSender.IF.createProcessIdentifier("toop-procid-agreement", "urn:eu.toop.process.datarequestresponse")).senderParticipantID(Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9914:phase4-test-sender")).receiverParticipantID(aReceiverID).fromPartyID(new SimpleParticipantIdentifier("type", "POP000306")).fromRole("http://www.toop.eu/edelivery/gateway").toPartyID(new SimpleParticipantIdentifier("type", "POP000306")).toRole("http://www.toop.eu/edelivery/gateway").payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).mimeTypeXML()).smpClient(new BDXRClientReadOnly(Phase4CEFSender.URL_PROVIDER, aReceiverID, SML_TOOP)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).buildMessageCallback(aBuildMessageCallback).sendMessage().isSuccess()) {
            LOGGER.info("Successfully sent CEF message via AS4");
        } else {
            LOGGER.error("Failed to send CEF message via AS4");
        }
    } catch (final Exception ex) {
        LOGGER.error("Error sending CEF message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 23 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-directory by phax.

the class PDStorageManager method deleteEntry.

@CheckForSigned
public int deleteEntry(@Nonnull final IParticipantIdentifier aParticipantID, @Nullable final PDStoredMetaData aMetaData, final boolean bVerifyOwner) throws IOException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    LOGGER.info("Trying to delete entry with participant ID '" + aParticipantID.getURIEncoded() + "'" + (bVerifyOwner && aMetaData != null ? " with owner ID '" + aMetaData.getOwnerID() + "'" : ""));
    Query aParticipantQuery = new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aParticipantID));
    if (getCount(aParticipantQuery) == 0) {
        // Hack e.g. for 9925:everbinding
        final String sOrigValue = aParticipantID.getValue();
        final String sUpperCaseValue = sOrigValue.toUpperCase(Locale.ROOT);
        if (!sUpperCaseValue.equals(sOrigValue)) {
            // Something changed - try again
            // Force case sensitivity
            final IParticipantIdentifier aNewPID = new SimpleParticipantIdentifier(aParticipantID.getScheme(), sUpperCaseValue);
            final Query aOtherQuery = new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aNewPID));
            if (getCount(aOtherQuery) > 0) {
                LOGGER.info("Found something with '" + sUpperCaseValue + "' instead of '" + sOrigValue + "'");
                aParticipantQuery = aOtherQuery;
            }
        }
    }
    final Query aDeleteQuery;
    if (bVerifyOwner && aMetaData != null) {
        // Special handling for predefined owners
        final BooleanQuery.Builder aBuilderOr = new BooleanQuery.Builder();
        aBuilderOr.add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(aMetaData.getOwnerID())), Occur.SHOULD);
        aBuilderOr.add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(CPDStorage.OWNER_DUPLICATE_ELIMINATION)), Occur.SHOULD);
        aBuilderOr.add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(CPDStorage.OWNER_IMPORT_TRIGGERED)), Occur.SHOULD);
        aBuilderOr.add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(CPDStorage.OWNER_MANUALLY_TRIGGERED)), Occur.SHOULD);
        aBuilderOr.add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(CPDStorage.OWNER_SYNC_JOB)), Occur.SHOULD);
        aDeleteQuery = new BooleanQuery.Builder().add(aParticipantQuery, Occur.MUST).add(aBuilderOr.build(), Occur.MUST).build();
    } else
        aDeleteQuery = aParticipantQuery;
    final int nCount = getCount(aDeleteQuery);
    if (m_aLucene.writeLockedAtomic(() -> {
        // Delete
        m_aLucene.deleteDocuments(aDeleteQuery);
    }).isFailure()) {
        LOGGER.error("Failed to delete docs from the index using the query '" + aDeleteQuery + "'");
        return -1;
    }
    LOGGER.info("Deleted " + nCount + " docs from the index using the query '" + aDeleteQuery + "'");
    AuditHelper.onAuditExecuteSuccess("pd-indexer-delete", aParticipantID.getURIEncoded(), Integer.valueOf(nCount), aMetaData, Boolean.toString(bVerifyOwner));
    return nCount;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) CheckForSigned(javax.annotation.CheckForSigned)

Example 24 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-directory by phax.

the class PDStorageManager method getAllDocumentsOfParticipant.

@Nonnull
public ICommonsList<PDStoredBusinessEntity> getAllDocumentsOfParticipant(@Nonnull final IParticipantIdentifier aParticipantID) {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    ICommonsList<PDStoredBusinessEntity> ret = getAllDocuments(new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aParticipantID)), -1);
    if (ret.isEmpty()) {
        // Hack e.g. for 9925:everbinding
        final String sOrigValue = aParticipantID.getValue();
        final String sUpperCaseValue = sOrigValue.toUpperCase(Locale.ROOT);
        if (!sUpperCaseValue.equals(sOrigValue)) {
            // Something changed - try again
            // Force case sensitivity
            final IParticipantIdentifier aNewPID = new SimpleParticipantIdentifier(aParticipantID.getScheme(), sUpperCaseValue);
            ret = getAllDocuments(new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aNewPID)), -1);
            if (ret.isNotEmpty()) {
                LOGGER.info("Found something with '" + sUpperCaseValue + "' instead of '" + sOrigValue + "'");
            }
        }
    }
    return ret;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 25 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project peppol-commons by phax.

the class MainSMPServiceRegistrationCreate method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    final IDocumentTypeIdentifier DOCUMENT_ID = MockSMPClientConfig.getDocumentTypeID();
    final IProcessIdentifier PROCESS_ID = MockSMPClientConfig.getProcessTypeID();
    final W3CEndpointReference START_AP_ENDPOINTREF = MockSMPClientConfig.getAPEndpointRef();
    final String AP_CERT_STRING = MockSMPClientConfig.getAPCert();
    final String AP_SERVICE_DESCRIPTION = MockSMPClientConfig.getAPServiceDescription();
    final String AP_CONTACT_URL = MockSMPClientConfig.getAPContact();
    final String AP_INFO_URL = MockSMPClientConfig.getAPInfo();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Create the service registration
    final ServiceInformationType aServiceInformation = new ServiceInformationType();
    {
        final ProcessListType aProcessList = new ProcessListType();
        {
            final ProcessType aProcess = new ProcessType();
            {
                final ServiceEndpointList aServiceEndpointList = new ServiceEndpointList();
                {
                    final EndpointType aEndpoint = new EndpointType();
                    aEndpoint.setEndpointReference(START_AP_ENDPOINTREF);
                    aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
                    aEndpoint.setCertificate(AP_CERT_STRING);
                    aEndpoint.setServiceActivationDate(PDTFactory.createXMLOffsetDateTime(2011, Month.JANUARY, 1));
                    aEndpoint.setServiceExpirationDate(PDTFactory.createXMLOffsetDateTime(2020, Month.DECEMBER, 31));
                    aEndpoint.setServiceDescription(AP_SERVICE_DESCRIPTION);
                    aEndpoint.setTechnicalContactUrl(AP_CONTACT_URL);
                    aEndpoint.setTechnicalInformationUrl(AP_INFO_URL);
                    aEndpoint.setMinimumAuthenticationLevel("1");
                    aEndpoint.setRequireBusinessLevelSignature(false);
                    aServiceEndpointList.getEndpoint().add(aEndpoint);
                }
                aProcess.setProcessIdentifier(new SimpleProcessIdentifier(PROCESS_ID));
                aProcess.setServiceEndpointList(aServiceEndpointList);
            }
            aProcessList.getProcess().add(aProcess);
        }
        aServiceInformation.setDocumentIdentifier(new SimpleDocumentTypeIdentifier(DOCUMENT_ID));
        aServiceInformation.setParticipantIdentifier(new SimpleParticipantIdentifier(PARTICIPANT_ID));
        aServiceInformation.setProcessList(aProcessList);
    }
    aClient.saveServiceInformation(aServiceInformation, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) URI(java.net.URI) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)48 Test (org.junit.Test)26 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)25 ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)12 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)12 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)11 Nonnull (javax.annotation.Nonnull)11 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)10 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)9 Response (javax.ws.rs.core.Response)9 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)8 EndpointType (com.helger.xsds.peppol.smp1.EndpointType)7 ProcessListType (com.helger.xsds.peppol.smp1.ProcessListType)7 ProcessType (com.helger.xsds.peppol.smp1.ProcessType)7 ServiceEndpointList (com.helger.xsds.peppol.smp1.ServiceEndpointList)7 ServiceInformationType (com.helger.xsds.peppol.smp1.ServiceInformationType)7 WebTarget (javax.ws.rs.client.WebTarget)7 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)6 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)5 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)5