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;
}
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));
}
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));
}
}
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;
}
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());
}
}
Aggregations