Search in sources :

Example 1 with Organisasjonsnummer

use of no.difi.meldingsutveksling.domain.Organisasjonsnummer in project efm-integrasjonspunkt by felleslosninger.

the class NextMoveOutMessageFactory method setDefaults.

private void setDefaults(StandardBusinessDocument sbd, ServiceRecord serviceRecord) {
    sbd.getScopes().stream().filter(p -> !StringUtils.hasText(p.getInstanceIdentifier())).forEach(p -> p.setInstanceIdentifier(uuidGenerator.generate()));
    if (sbd.getSenderIdentifier() == null) {
        Organisasjonsnummer org = Organisasjonsnummer.from(properties.getOrg().getNumber());
        sbd.getStandardBusinessDocumentHeader().addSender(new Sender().setIdentifier(new PartnerIdentification().setValue(org.asIso6523()).setAuthority(org.authority())));
    }
    DocumentIdentification documentIdentification = sbd.getStandardBusinessDocumentHeader().getDocumentIdentification();
    if (documentIdentification.getInstanceIdentifier() == null) {
        documentIdentification.setInstanceIdentifier(uuidGenerator.generate());
    }
    if (documentIdentification.getCreationDateAndTime() == null) {
        documentIdentification.setCreationDateAndTime(OffsetDateTime.now(clock));
    }
    if (!sbd.getExpectedResponseDateTime().isPresent()) {
        OffsetDateTime ttl = OffsetDateTime.now(clock).plusHours(properties.getNextmove().getDefaultTtlHours());
        if (sbd.getScope(ScopeType.CONVERSATION_ID).getScopeInformation().isEmpty()) {
            CorrelationInformation ci = new CorrelationInformation().setExpectedResponseDateTime(ttl);
            sbd.getScope(ScopeType.CONVERSATION_ID).getScopeInformation().add(ci);
        } else {
            sbd.getScope(ScopeType.CONVERSATION_ID).getScopeInformation().stream().findFirst().ifPresent(ci -> ci.setExpectedResponseDateTime(ttl));
        }
    }
    if (serviceRecord.getServiceIdentifier() == DPO && !isNullOrEmpty(properties.getDpo().getMessageChannel())) {
        Optional<Scope> mcScope = sbd.findScope(ScopeType.MESSAGE_CHANNEL);
        if (!mcScope.isPresent()) {
            sbd.getScopes().add(ScopeFactory.fromIdentifier(ScopeType.MESSAGE_CHANNEL, properties.getDpo().getMessageChannel()));
        }
        if (mcScope.isPresent() && isNullOrEmpty(mcScope.get().getIdentifier())) {
            mcScope.get().setIdentifier(properties.getDpo().getMessageChannel());
        }
    }
    if (serviceRecord.getServiceIdentifier() == DPI) {
        setDpiDefaults(sbd, serviceRecord);
    }
}
Also used : PropertyUtils(org.apache.commons.beanutils.PropertyUtils) ApiType(no.difi.meldingsutveksling.ApiType) Utskriftsfarge(no.difi.sdp.client2.domain.fysisk_post.Utskriftsfarge) RequiredArgsConstructor(lombok.RequiredArgsConstructor) no.difi.meldingsutveksling.nextmove(no.difi.meldingsutveksling.nextmove) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) no.difi.meldingsutveksling.domain.sbdh(no.difi.meldingsutveksling.domain.sbdh) UnknownMessageTypeException(no.difi.meldingsutveksling.exceptions.UnknownMessageTypeException) Returhaandtering(no.difi.sdp.client2.domain.fysisk_post.Returhaandtering) MessageType(no.difi.meldingsutveksling.MessageType) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceRecord(no.difi.meldingsutveksling.serviceregistry.externalmodel.ServiceRecord) Component(org.springframework.stereotype.Component) Organisasjonsnummer(no.difi.meldingsutveksling.domain.Organisasjonsnummer) OffsetDateTime(java.time.OffsetDateTime) DPI(no.difi.meldingsutveksling.ServiceIdentifier.DPI) DPO(no.difi.meldingsutveksling.ServiceIdentifier.DPO) Clock(java.time.Clock) Optional(java.util.Optional) Posttype(no.difi.sdp.client2.domain.fysisk_post.Posttype) ScopeFactory(no.difi.meldingsutveksling.sbd.ScopeFactory) IntegrasjonspunktProperties(no.difi.meldingsutveksling.config.IntegrasjonspunktProperties) UUIDGenerator(no.difi.meldingsutveksling.UUIDGenerator) StringUtils(org.springframework.util.StringUtils) Organisasjonsnummer(no.difi.meldingsutveksling.domain.Organisasjonsnummer) OffsetDateTime(java.time.OffsetDateTime)

Example 2 with Organisasjonsnummer

use of no.difi.meldingsutveksling.domain.Organisasjonsnummer 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)2 Organisasjonsnummer (no.difi.meldingsutveksling.domain.Organisasjonsnummer)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Clock (java.time.Clock)1 Optional (java.util.Optional)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 ApiType (no.difi.meldingsutveksling.ApiType)1 MessageInformable (no.difi.meldingsutveksling.MessageInformable)1 MessageType (no.difi.meldingsutveksling.MessageType)1 ServiceIdentifier (no.difi.meldingsutveksling.ServiceIdentifier)1 DPI (no.difi.meldingsutveksling.ServiceIdentifier.DPI)1 DPO (no.difi.meldingsutveksling.ServiceIdentifier.DPO)1 UUIDGenerator (no.difi.meldingsutveksling.UUIDGenerator)1 IntegrasjonspunktProperties (no.difi.meldingsutveksling.config.IntegrasjonspunktProperties)1 no.difi.meldingsutveksling.domain.sbdh (no.difi.meldingsutveksling.domain.sbdh)1 UnknownMessageTypeException (no.difi.meldingsutveksling.exceptions.UnknownMessageTypeException)1 SvarInnPutMessageBuilder (no.difi.meldingsutveksling.ks.svarinn.SvarInnPutMessageBuilder)1 no.difi.meldingsutveksling.nextmove (no.difi.meldingsutveksling.nextmove)1 ConversationDirection (no.difi.meldingsutveksling.nextmove.ConversationDirection)1