Search in sources :

Example 1 with ConversationDirection

use of no.difi.meldingsutveksling.nextmove.ConversationDirection in project efm-integrasjonspunkt by felleslosninger.

the class SvarInnPutMessageForwarder method forward.

private void forward(Forsendelse forsendelse, Reject reject) {
    MDC.put(NextMoveConsts.CORRELATION_ID, forsendelse.getId());
    SvarInnPutMessageBuilder builder = new SvarInnPutMessageBuilder(forsendelse, clock, putMessageRequestFactory);
    svarInnService.getAttachments(forsendelse, reject).forEach(builder::streamedFile);
    if (!Strings.isNullOrEmpty(properties.getFiks().getInn().getFallbackSenderOrgNr())) {
        builder.setFallbackSenderOrgNr(properties.getFiks().getInn().getFallbackSenderOrgNr());
    }
    PutMessageRequestType putMessage = builder.build();
    if (builder.getDokumentTypeList().isEmpty()) {
        Audit.error("Zipfile is empty: skipping message", Markers.append("fiks-id", forsendelse.getId()));
        return;
    }
    Conversation c = conversationService.registerConversation(new MessageInformable() {

        @Override
        public String getConversationId() {
            return forsendelse.getId();
        }

        @Override
        public String getMessageId() {
            return forsendelse.getId();
        }

        @Override
        public Organisasjonsnummer getSender() {
            return Organisasjonsnummer.from(putMessage.getEnvelope().getSender().getOrgnr());
        }

        @Override
        public Organisasjonsnummer getReceiver() {
            return Organisasjonsnummer.from(putMessage.getEnvelope().getReceiver().getOrgnr());
        }

        @Override
        public String getProcessIdentifier() {
            return properties.getArkivmelding().getDefaultProcess();
        }

        @Override
        public String getDocumentIdentifier() {
            return properties.getArkivmelding().getDefaultDocumentType();
        }

        @Override
        public ConversationDirection getDirection() {
            return ConversationDirection.INCOMING;
        }

        @Override
        public ServiceIdentifier getServiceIdentifier() {
            return ServiceIdentifier.DPF;
        }

        @Override
        public OffsetDateTime getExpiry() {
            return OffsetDateTime.now(clock).plusHours(properties.getNextmove().getDefaultTtlHours());
        }
    });
    conversationService.registerStatus(c.getMessageId(), INNKOMMENDE_MOTTATT);
    String missingFields = getMissingFields(forsendelse, putMessage, builder.getDokumentTypeList());
    if (!missingFields.isEmpty()) {
        handleError(putMessage, forsendelse.getId(), "Validation failed - missing fields: " + missingFields);
        return;
    }
    final PutMessageResponseType response = localNoark.sendEduMelding(putMessage);
    if ("OK".equals(response.getResult().getType())) {
        Audit.info("Message successfully forwarded");
        conversationService.registerStatus(c.getMessageId(), INNKOMMENDE_LEVERT);
        svarInnService.confirmMessage(forsendelse.getId());
    } else if ("WARNING".equals(response.getResult().getType())) {
        Audit.info(format("Archive system responded with warning for message with fiks-id %s", forsendelse.getId()), PutMessageResponseMarkers.markerFrom(response));
        conversationService.registerStatus(c.getMessageId(), INNKOMMENDE_LEVERT);
        svarInnService.confirmMessage(forsendelse.getId());
    } else {
        Audit.error(format("Message with fiks-id %s failed", forsendelse.getId()), PutMessageResponseMarkers.markerFrom(response));
        handleError(putMessage, forsendelse.getId(), "Archive system responded with error: " + response.getResult().getMessage().get(0).getText());
    }
}
Also used : SvarInnPutMessageBuilder(no.difi.meldingsutveksling.ks.svarinn.SvarInnPutMessageBuilder) MessageInformable(no.difi.meldingsutveksling.MessageInformable) Organisasjonsnummer(no.difi.meldingsutveksling.domain.Organisasjonsnummer) PutMessageRequestType(no.difi.meldingsutveksling.noarkexchange.schema.PutMessageRequestType) PutMessageResponseType(no.difi.meldingsutveksling.noarkexchange.schema.PutMessageResponseType) OffsetDateTime(java.time.OffsetDateTime) Conversation(no.difi.meldingsutveksling.status.Conversation) ServiceIdentifier(no.difi.meldingsutveksling.ServiceIdentifier) ConversationDirection(no.difi.meldingsutveksling.nextmove.ConversationDirection)

Aggregations

OffsetDateTime (java.time.OffsetDateTime)1 MessageInformable (no.difi.meldingsutveksling.MessageInformable)1 ServiceIdentifier (no.difi.meldingsutveksling.ServiceIdentifier)1 Organisasjonsnummer (no.difi.meldingsutveksling.domain.Organisasjonsnummer)1 SvarInnPutMessageBuilder (no.difi.meldingsutveksling.ks.svarinn.SvarInnPutMessageBuilder)1 ConversationDirection (no.difi.meldingsutveksling.nextmove.ConversationDirection)1 PutMessageRequestType (no.difi.meldingsutveksling.noarkexchange.schema.PutMessageRequestType)1 PutMessageResponseType (no.difi.meldingsutveksling.noarkexchange.schema.PutMessageResponseType)1 Conversation (no.difi.meldingsutveksling.status.Conversation)1