Search in sources :

Example 21 with Event

use of com.google.cloud.video.livestream.v1.Event in project pomocua-ogloszenia by coi-gov-pl.

the class CaptchaValidator method validate.

public boolean validate(String recaptchaResponse) {
    if (!properties.isEnabled()) {
        log.debug("Skip captcha validation. To enable change 'app.captcha.enabled' property");
        return true;
    }
    if (!responseSanityCheck(recaptchaResponse)) {
        log.warn("Response contains invalid characters");
        return false;
    }
    ProjectName projectName = ProjectName.of(properties.getGoogleCloudProjectId());
    Event event = Event.newBuilder().setSiteKey(properties.getSiteKey()).setToken(recaptchaResponse).build();
    CreateAssessmentRequest createAssessmentRequest = CreateAssessmentRequest.newBuilder().setParent(projectName.toString()).setAssessment(Assessment.newBuilder().setEvent(event).build()).build();
    Assessment response = recaptchaClient.createAssessment(createAssessmentRequest);
    if (response == null) {
        log.warn("Empty response from reCaptcha");
        return false;
    }
    // Check if the token is valid.
    if (!response.getTokenProperties().getValid()) {
        String invalidTokenReason = response.getTokenProperties().getInvalidReason().name();
        log.debug("The CreateAssessment call failed because the token was: " + invalidTokenReason);
        return false;
    }
    float score = response.getScore();
    if (score < properties.getAcceptLevel()) {
        List<String> reasons = response.getReasonsList().stream().map(classificationReason -> classificationReason.getDescriptorForType().getFullName()).collect(Collectors.toList());
        log.debug("Validation failed. Score: " + score + ". Reasons: " + String.join(", ", reasons));
        return false;
    }
    log.debug("Validation OK - score: " + score);
    return true;
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Service(org.springframework.stereotype.Service) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) RecaptchaEnterpriseServiceV1Beta1Client(com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Pattern(java.util.regex.Pattern) Collectors(java.util.stream.Collectors) Event(com.google.recaptchaenterprise.v1beta1.Event) StringUtils(org.springframework.util.StringUtils) ProjectName(com.google.recaptchaenterprise.v1beta1.ProjectName) Assessment(com.google.recaptchaenterprise.v1beta1.Assessment) CreateAssessmentRequest(com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest) Event(com.google.recaptchaenterprise.v1beta1.Event)

Example 22 with Event

use of com.google.cloud.video.livestream.v1.Event in project skywalking by apache.

the class EventHookCallback method doAlarm.

@Override
public void doAlarm(List<AlarmMessage> alarmMessage) {
    EventAnalyzerService analyzerService = manager.find(EventAnalyzerModule.NAME).provider().getService(EventAnalyzerService.class);
    alarmMessage.forEach(a -> {
        for (Event event : constructCurrentEvent(a)) {
            analyzerService.analyze(event);
        }
    });
}
Also used : EventAnalyzerService(org.apache.skywalking.oap.server.analyzer.event.EventAnalyzerService) Event(org.apache.skywalking.apm.network.event.v3.Event)

Example 23 with Event

use of com.google.cloud.video.livestream.v1.Event in project prison-api by ministryofjustice.

the class NomisApiV1ResourceTest method getEvents.

@Test
public void getEvents() {
    final var events = List.of(new Event("EVENT", 3L, "noms", "prison", LocalDateTime.now(), "entry"));
    when(service.getEvents(anyString(), any(), anyString(), any(), anyLong())).thenReturn(events);
    final var transfer = nomisApiV1Resource.getOffenderEvents("client", null, "nomis", null, 50L);
    assertThat(transfer).isEqualTo(new Events(events));
}
Also used : Events(uk.gov.justice.hmpps.prison.api.model.v1.Events) Event(uk.gov.justice.hmpps.prison.api.model.v1.Event) Test(org.junit.jupiter.api.Test)

Example 24 with Event

use of com.google.cloud.video.livestream.v1.Event in project prison-api by ministryofjustice.

the class NomisApiV1ServiceTest method getEventsCopesWithAllNull.

@Test
public void getEventsCopesWithAllNull() {
    final var date = LocalDateTime.parse("2020-01-02T03:02:01");
    when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", null, null, null)));
    final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
    assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, "{}"));
}
Also used : OffenderIdentifier(uk.gov.justice.hmpps.prison.api.model.v1.OffenderIdentifier) Event(uk.gov.justice.hmpps.prison.api.model.v1.Event) EventSP(uk.gov.justice.hmpps.prison.repository.v1.model.EventSP) Test(org.junit.jupiter.api.Test)

Example 25 with Event

use of com.google.cloud.video.livestream.v1.Event in project prison-api by ministryofjustice.

the class NomisApiV1ServiceTest method getEventsCopesWithSomeNull.

@Test
public void getEventsCopesWithSomeNull() {
    final var date = LocalDateTime.parse("2020-01-02T03:02:01");
    when(eventsV1Repository.getEvents(anyString(), isNull(), anyLong(), isNull(), anyString(), any(), anyLong())).thenReturn(List.of(new EventSP(5L, date, "MDI", "A1234", "ETYPE", null, " a value ", null)));
    final var events = service.getEvents("prison", new OffenderIdentifier("12345"), "type", LocalDateTime.now(), 5L);
    assertThat(events).containsExactly(new Event("ETYPE", 5L, "A1234", "MDI", date, " a value "));
}
Also used : OffenderIdentifier(uk.gov.justice.hmpps.prison.api.model.v1.OffenderIdentifier) Event(uk.gov.justice.hmpps.prison.api.model.v1.Event) EventSP(uk.gov.justice.hmpps.prison.repository.v1.model.EventSP) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)18 Event (io.requery.test.model3.Event)9 UUID (java.util.UUID)9 Event (org.apache.skywalking.apm.network.event.v3.Event)9 Test (org.junit.jupiter.api.Test)9 LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)5 Event (org.eclipse.bpmn2.Event)5 Event (com.google.cloud.video.livestream.v1.Event)4 Place (io.requery.test.model3.Place)4 Tag (io.requery.test.model3.Tag)4 AlarmMessage (org.apache.skywalking.oap.server.core.alarm.AlarmMessage)4 ListNamespacedEvent (com.marcnuri.yakc.api.events.v1.EventsV1Api.ListNamespacedEvent)3 Event (com.marcnuri.yakc.model.io.k8s.api.events.v1.Event)3 Event (io.fabric8.kubernetes.api.model.events.v1.Event)3 Event (io.requery.test.model2.Event)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Event (uk.gov.justice.hmpps.prison.api.model.v1.Event)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonArray (com.google.gson.JsonArray)2