Search in sources :

Example 1 with Entity

use of p4.v1.P4RuntimeOuterClass.Entity in project webcert by sklintyg.

the class FragaSvarServiceImpl method getFragaSvar.

@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public List<FragaSvarView> getFragaSvar(String intygId) {
    List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId);
    WebCertUser user = webCertUserService.getUser();
    validateSekretessmarkering(intygId, fragaSvarList, user);
    List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet();
    // Filter questions to that current user only sees questions issued to
    // units with active employment role
    fragaSvarList.removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId()));
    // Finally sort by senasteHandelseDatum
    // We do the sorting in code, since we need to sort on a derived
    // property and not a direct entity persisted
    // property in which case we could have used an order by in the query.
    fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR);
    List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId);
    List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository);
    List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream().map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream().filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())).findAny().map(ArendeDraft::getText).orElse(null))).collect(Collectors.toList());
    return fragaSvarWithBesvaratMedIntygInfo;
}
Also used : SendMedicalCertificateAnswerType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType) Amne(se.inera.intyg.webcert.persistence.fragasvar.model.Amne) IntygConverterUtil(se.inera.intyg.webcert.web.converter.util.IntygConverterUtil) Arrays(java.util.Arrays) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) FragaSvarView(se.inera.intyg.webcert.web.web.controller.api.dto.FragaSvarView) FKQuestionConverter(se.inera.intyg.webcert.web.converter.FKQuestionConverter) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) Map(java.util.Map) Status(se.inera.intyg.webcert.persistence.model.Status) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Komplettering(se.inera.intyg.webcert.persistence.fragasvar.model.Komplettering) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) CertificateState(se.inera.intyg.common.support.model.CertificateState) Set(java.util.Set) Collectors(java.util.stream.Collectors) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) Objects(java.util.Objects) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ResultCodeEnum(se.inera.ifv.insuranceprocess.healthreporting.v2.ResultCodeEnum) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SendMedicalCertificateQuestionResponderInterface(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestion.rivtabp20.v1.SendMedicalCertificateQuestionResponderInterface) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) ArendeDraftService(se.inera.intyg.webcert.web.service.arende.ArendeDraftService) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) FragaSvarSenasteHandelseDatumComparator(se.inera.intyg.webcert.web.service.util.FragaSvarSenasteHandelseDatumComparator) LocalDateTime(java.time.LocalDateTime) IntygService(se.inera.intyg.webcert.web.service.intyg.IntygService) HashMap(java.util.HashMap) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) FKAnswerConverter(se.inera.intyg.webcert.web.converter.FKAnswerConverter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Service(org.springframework.stereotype.Service) FragaSvarRepository(se.inera.intyg.webcert.persistence.fragasvar.repository.FragaSvarRepository) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) SendMedicalCertificateAnswerResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) SendMedicalCertificateAnswerResponderInterface(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswer.rivtabp20.v1.SendMedicalCertificateAnswerResponderInterface) AnswerToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.AnswerToFkType) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) FragaSvarConverter(se.inera.intyg.webcert.web.converter.FragaSvarConverter) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Preconditions(com.google.common.base.Preconditions) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Transactional(org.springframework.transaction.annotation.Transactional) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) FragaSvarView(se.inera.intyg.webcert.web.web.controller.api.dto.FragaSvarView) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Entity

use of p4.v1.P4RuntimeOuterClass.Entity in project up4 by omec-project.

the class Up4NorthComponentTest method readCounterTest.

private void readCounterTest(PiCounterId counterId, long expectedPackets, long expectedBytes) {
    MockStreamObserver<P4RuntimeOuterClass.ReadResponse> responseObserver = new MockStreamObserver<>();
    int cellIndex = 1;
    PiCounterCell requestedCell = new PiCounterCell(PiCounterCellId.ofIndirect(counterId, cellIndex), 0, 0);
    P4RuntimeOuterClass.Entity entity;
    try {
        entity = Codecs.CODECS.entity().encode(requestedCell, null, pipeconf);
    } catch (CodecException e) {
        fail("Unable to encode counter cell to p4runtime entity.");
        return;
    }
    P4RuntimeOuterClass.ReadRequest request = P4RuntimeOuterClass.ReadRequest.newBuilder().addEntities(entity).setDeviceId(NorthTestConstants.P4RUNTIME_DEVICE_ID).build();
    up4NorthService.read(request, responseObserver);
    var response = responseObserver.lastResponse();
    PiCounterCell expectedCell = new PiCounterCell(PiCounterCellId.ofIndirect(counterId, cellIndex), expectedPackets, expectedBytes);
    P4RuntimeOuterClass.Entity expectedEntity;
    try {
        expectedEntity = Codecs.CODECS.entity().encode(expectedCell, null, pipeconf);
    } catch (CodecException e) {
        fail("Unable to encode counter cell to p4runtime entity.");
        return;
    }
    assertThat(response.getEntitiesCount(), equalTo(1));
    assertThat(response.getEntitiesList().get(0), equalTo(expectedEntity));
}
Also used : P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException)

Example 3 with Entity

use of p4.v1.P4RuntimeOuterClass.Entity in project up4 by omec-project.

the class Up4NorthComponentTest method readPartialWildcardCounterTest.

private void readPartialWildcardCounterTest(PiCounterId counterId) {
    // A counter read request with a counterID but no cellId
    // Encode a dummy cell just so we can get the p4runtime counter integer ID from the encoder
    PiCounterCell dummyCell = new PiCounterCell(PiCounterCellId.ofIndirect(counterId, 1), 0, 0);
    P4RuntimeOuterClass.Entity dummyEntity;
    try {
        dummyEntity = Codecs.CODECS.entity().encode(dummyCell, null, pipeconf);
    } catch (CodecException e) {
        fail("Unable to encode counter cell to p4runtime entity.");
        return;
    }
    int intCounterId = dummyEntity.getCounterEntry().getCounterId();
    // Now build the actual request
    MockStreamObserver<P4RuntimeOuterClass.ReadResponse> responseObserver = new MockStreamObserver<>();
    P4RuntimeOuterClass.ReadRequest request = P4RuntimeOuterClass.ReadRequest.newBuilder().addEntities(P4RuntimeOuterClass.Entity.newBuilder().setCounterEntry(P4RuntimeOuterClass.CounterEntry.newBuilder().setCounterId(intCounterId).build()).build()).build();
    up4NorthService.read(request, responseObserver);
    var response = responseObserver.lastResponse();
    assertThat(response.getEntitiesList().size(), equalTo(TestImplConstants.PHYSICAL_COUNTER_SIZE));
    for (P4RuntimeOuterClass.Entity entity : response.getEntitiesList()) {
        PiCounterCell responseCell = entityToCounterCell(entity);
        assertThat(responseCell.cellId().counterId(), equalTo(counterId));
    }
}
Also used : P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException)

Example 4 with Entity

use of p4.v1.P4RuntimeOuterClass.Entity in project up4 by omec-project.

the class Up4NorthComponent method readEntriesAndTranslate.

/**
 * Find all table entries or meter entries that match the requested entry,
 * and translate them to p4runtime entities for responding to a read request.
 *
 * @param requestedEntry the entry from a p4runtime read request
 * @return all entries that match the request, translated to p4runtime entities
 * @throws StatusException if the requested entry fails translation
 */
private List<P4RuntimeOuterClass.Entity> readEntriesAndTranslate(PiEntity requestedEntry) throws StatusException {
    List<P4RuntimeOuterClass.Entity> translatedEntries = new ArrayList<>();
    // TODO: return more specific responses matching the requested entry
    try {
        UpfEntityType entityType = up4Translator.getEntityType(requestedEntry);
        boolean isMeter = entityType.equals(UpfEntityType.SESSION_METER) || entityType.equals(UpfEntityType.APPLICATION_METER);
        Collection<? extends UpfEntity> entities = up4Service.readAll(entityType);
        for (UpfEntity entity : entities) {
            log.debug("Translating a {} entity for a read request: {}", entity.type(), entity);
            P4RuntimeOuterClass.Entity responseEntity;
            if (isMeter) {
                responseEntity = Codecs.CODECS.entity().encode(up4Translator.upfEntityToUp4MeterEntry(entity), null, pipeconf);
            } else {
                responseEntity = Codecs.CODECS.entity().encode(up4Translator.upfEntityToUp4TableEntry(entity), null, pipeconf);
            }
            translatedEntries.add(responseEntity);
        }
    } catch (Up4Translator.Up4TranslationException | UpfProgrammableException | CodecException e) {
        log.warn("Unable to encode/translate a read entry to a UP4 read response: {}", e.getMessage());
        throw INVALID_ARGUMENT.withDescription("Unable to translate a read table entry to a p4runtime entity.").asException();
    }
    return translatedEntries;
}
Also used : UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) PiEntity(org.onosproject.net.pi.runtime.PiEntity) P4RuntimeOuterClass(p4.v1.P4RuntimeOuterClass) ArrayList(java.util.ArrayList) UpfEntityType(org.onosproject.net.behaviour.upf.UpfEntityType) UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) UpfEntity(org.onosproject.net.behaviour.upf.UpfEntity) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException)

Example 5 with Entity

use of p4.v1.P4RuntimeOuterClass.Entity in project onos by opennetworkinglab.

the class P4RuntimeGroupTest method testInsertPiActionProfileGroup.

@Test
public void testInsertPiActionProfileGroup() throws Exception {
    CompletableFuture<Void> complete = p4RuntimeServerImpl.expectRequests(1);
    client.write(P4_DEVICE_ID, PIPECONF).insert(GROUP).submitSync();
    assertTrue(client.write(P4_DEVICE_ID, PIPECONF).insert(GROUP).submitSync().isSuccess());
    complete.get(DEFAULT_TIMEOUT_TIME, TimeUnit.SECONDS);
    WriteRequest result = p4RuntimeServerImpl.getWriteReqs().get(0);
    assertEquals(1, result.getDeviceId());
    assertEquals(1, result.getUpdatesCount());
    assertEquals(DEFAULT_ELECTION_ID, result.getElectionId());
    Update update = result.getUpdatesList().get(0);
    assertEquals(Update.Type.INSERT, update.getType());
    Entity entity = update.getEntity();
    ActionProfileGroup actionProfileGroup = entity.getActionProfileGroup();
    assertNotNull(actionProfileGroup);
    assertEquals(P4_INFO_ACT_PROF_ID, actionProfileGroup.getActionProfileId());
    assertEquals(3, actionProfileGroup.getMembersCount());
    List<ActionProfileGroup.Member> members = actionProfileGroup.getMembersList();
    for (ActionProfileGroup.Member member : members) {
        // XXX: We can't guarantee the order of member, just make sure we
        // have these member ids
        assertTrue(MEMBER_IDS.contains(member.getMemberId()));
        assertEquals(DEFAULT_MEMBER_WEIGHT, member.getWeight());
    }
}
Also used : Entity(p4.v1.P4RuntimeOuterClass.Entity) WriteRequest(p4.v1.P4RuntimeOuterClass.WriteRequest) ActionProfileGroup(p4.v1.P4RuntimeOuterClass.ActionProfileGroup) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) Update(p4.v1.P4RuntimeOuterClass.Update) ActionProfileMember(p4.v1.P4RuntimeOuterClass.ActionProfileMember) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) Test(org.junit.Test)

Aggregations

CodecException (org.onosproject.p4runtime.ctl.codec.CodecException)3 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 PiActionProfileMember (org.onosproject.net.pi.runtime.PiActionProfileMember)2 PiCounterCell (org.onosproject.net.pi.runtime.PiCounterCell)2 ActionProfileMember (p4.v1.P4RuntimeOuterClass.ActionProfileMember)2 Entity (p4.v1.P4RuntimeOuterClass.Entity)2 Update (p4.v1.P4RuntimeOuterClass.Update)2 WriteRequest (p4.v1.P4RuntimeOuterClass.WriteRequest)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ByteString (com.google.protobuf.ByteString)1 LocalDateTime (java.time.LocalDateTime)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1