Search in sources :

Example 36 with ValueType

use of org.geotoolkit.ows.xml.v110.ValueType in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchHistoryAPIControllerTest method testReadPenRequestBatchPaginated_GivenSchoolGroupCodeOrPenReqBatchStatusCodeFilterAndMatchedCountOrFixableCount_ShouldReturnStatusOk.

/**
 * Test read pen request batch paginated given school group code or pen req batch status code filter and matched count or fixable count should return status ok.
 *
 * @throws Exception the exception
 */
@Test
public void testReadPenRequestBatchPaginated_GivenSchoolGroupCodeOrPenReqBatchStatusCodeFilterAndMatchedCountOrFixableCount_ShouldReturnStatusOk() throws Exception {
    final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock_pen_req_batch.json")).getFile());
    final List<PenRequestBatch> entities = new ObjectMapper().readValue(file, new TypeReference<>() {
    });
    final var models = entities.stream().map(mapper::toModel).collect(Collectors.toList()).stream().map(PenRequestBatchTestUtils::populateAuditColumnsAndHistory).collect(Collectors.toList());
    this.penRequestBatchRepository.saveAll(models);
    final SearchCriteria criteria = SearchCriteria.builder().key("schoolGroupCode").operation(FilterOperation.EQUAL).value(SchoolGroupCodes.K12.getCode()).valueType(ValueType.STRING).build();
    final SearchCriteria criteria2 = SearchCriteria.builder().key("penRequestBatchStatusCode").condition(OR).operation(FilterOperation.IN).value("LOADED,ACTIVE").valueType(ValueType.STRING).build();
    final List<SearchCriteria> criteriaList = new LinkedList<>();
    criteriaList.add(criteria);
    criteriaList.add(criteria2);
    final SearchCriteria criteria3 = SearchCriteria.builder().key("matchedCount").operation(FilterOperation.GREATER_THAN).value("0").valueType(ValueType.LONG).build();
    final SearchCriteria criteria4 = SearchCriteria.builder().key("fixableCount").condition(OR).operation(FilterOperation.GREATER_THAN).value("0").valueType(ValueType.LONG).build();
    final List<SearchCriteria> criteriaList1 = new LinkedList<>();
    criteriaList1.add(criteria3);
    criteriaList1.add(criteria4);
    final List<Search> searches = new LinkedList<>();
    searches.add(Search.builder().searchCriteriaList(criteriaList).build());
    searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
    final ObjectMapper objectMapper = new ObjectMapper();
    final String criteriaJSON = objectMapper.writeValueAsString(searches);
    final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/history/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH_HISTORY"))).param("searchCriteriaList", criteriaJSON).contentType(APPLICATION_JSON)).andReturn();
    this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk());
}
Also used : MockMvcRequestBuilders.asyncDispatch(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) java.util(java.util) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) PenRequestBatchStudentRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) MockMvc(org.springframework.test.web.servlet.MockMvc) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) MockitoAnnotations(org.mockito.MockitoAnnotations) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OR(ca.bc.gov.educ.penreg.api.struct.v1.Condition.OR) MvcResult(org.springframework.test.web.servlet.MvcResult) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) Before(org.junit.Before) PenRequestBatchStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes) PenRequestBatchHistoryRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchHistoryRepository) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) MvcResult(org.springframework.test.web.servlet.MvcResult) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 37 with ValueType

use of org.geotoolkit.ows.xml.v110.ValueType in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchAPIControllerTest method testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk.

/**
 * Test read pen request batch student paginated given pen request batch ids and all student status codes and other conditions should return status ok.
 *
 * @throws Exception the exception
 */
@Test
public void testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk() throws Exception {
    final String batchIDs = this.createBatchStudentRecords(2);
    final SearchCriteria criteria = SearchCriteria.builder().key("penRequestBatchEntity.penRequestBatchID").operation(FilterOperation.IN).value(batchIDs).valueType(ValueType.UUID).build();
    final List<SearchCriteria> criteriaList = new LinkedList<>();
    criteriaList.add(criteria);
    final SearchCriteria criteria2 = SearchCriteria.builder().key("penRequestBatchStudentStatusCode").operation(FilterOperation.NOT_EQUAL).value("FIXABLE").valueType(ValueType.STRING).build();
    final SearchCriteria criteria3 = SearchCriteria.builder().key("penRequestBatchEntity.mincode").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("1").valueType(ValueType.STRING).build();
    final SearchCriteria criteria4 = SearchCriteria.builder().key("legalLastName").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("j").valueType(ValueType.STRING).build();
    final List<SearchCriteria> criteriaList1 = new LinkedList<>();
    criteriaList1.add(criteria2);
    criteriaList1.add(criteria3);
    criteriaList1.add(criteria4);
    final List<Search> searches = new LinkedList<>();
    searches.add(Search.builder().searchCriteriaList(criteriaList).build());
    searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
    final ObjectMapper objectMapper = new ObjectMapper();
    final String criteriaJSON = objectMapper.writeValueAsString(searches);
    final String sort = this.createSortParam();
    final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/student/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).param("sort", sort).param("pageSize", "3").contentType(APPLICATION_JSON)).andReturn();
    this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
}
Also used : BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) PenRequestBatchStudentValidationIssueEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentValidationIssueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) MockitoAnnotations(org.mockito.MockitoAnnotations) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) OR(ca.bc.gov.educ.penreg.api.struct.v1.Condition.OR) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) PenRequestBatchSubmission(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission) Collectors(java.util.stream.Collectors) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) java.util(java.util) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) MockMvc(org.springframework.test.web.servlet.MockMvc) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) Before(org.junit.Before) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Matchers(org.hamcrest.Matchers) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) File(java.io.File) Event(ca.bc.gov.educ.penreg.api.struct.Event) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Student(ca.bc.gov.educ.penreg.api.struct.Student) ca.bc.gov.educ.penreg.api.repository(ca.bc.gov.educ.penreg.api.repository) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) MvcResult(org.springframework.test.web.servlet.MvcResult) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 38 with ValueType

use of org.geotoolkit.ows.xml.v110.ValueType in project geotoolkit by Geomatys.

the class SOSClientDemo method main.

public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException, JAXBException {
    Demos.init();
    final MarshallerPool pool = SOSMarshallerPool.getInstance();
    final Unmarshaller um = pool.acquireUnmarshaller();
    // build a new SOS client
    final SensorObservationServiceClient sosServer = new SensorObservationServiceClient(new URL("http://test.geomatys.com/swe_TS/WS/sos?"), "1.0.0");
    /**
     * make a getCapabilities request
     */
    final GetCapabilitiesRequest getCapa = sosServer.createGetCapabilities();
    InputStream is = getCapa.getResponseStream();
    // unmarshall the response
    Capabilities capabilities = (Capabilities) um.unmarshal(is);
    // print the title of the server
    System.out.println(capabilities.getServiceIdentification().getTitle());
    // extract a sensorML identifier and outputFormat to make a describeSensor request
    Operation describeSensorOperation = capabilities.getOperationsMetadata().getOperation("DescribeSensor");
    String sensorID = ((ValueType) describeSensorOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String outputFormat = ((ValueType) describeSensorOperation.getParameter("outputFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    // extract a all the parameters necessary to make a getObservation request
    Operation getObservationOperation = capabilities.getOperationsMetadata().getOperation("GetObservation");
    String offering = ((ValueType) getObservationOperation.getParameter("offering").getAllowedValues().getValueOrRange().get(0)).getValue();
    String responseFormat = ((ValueType) getObservationOperation.getParameter("responseFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    String phenomenon = ((ValueType) getObservationOperation.getParameter("observedProperty").getAllowedValues().getValueOrRange().get(0)).getValue();
    String procedure = ((ValueType) getObservationOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String featureOfInterest = ((ValueType) getObservationOperation.getParameter("featureOfInterest").getAllowedValues().getValueOrRange().get(0)).getValue();
    /**
     * make a DescribeSensor request
     */
    final DescribeSensorRequest descSensor = sosServer.createDescribeSensor();
    descSensor.setSensorId(sensorID);
    descSensor.setOutputFormat(outputFormat);
    is = descSensor.getResponseStream();
    // unmarshall the response
    AbstractSensorML sensorMLResponse = (AbstractSensorML) um.unmarshal(is);
    System.out.println(sensorMLResponse);
    /**
     * make a GetObservation request
     */
    final GetObservationRequest getObs = sosServer.createGetObservation();
    getObs.setOffering(offering);
    getObs.setObservedProperties(phenomenon);
    getObs.setProcedures(procedure);
    getObs.setResponseFormat(responseFormat);
    getObs.setFeatureOfInterest(new FeatureOfInterest(Arrays.asList(featureOfInterest)));
    is = getObs.getResponseStream();
    // unmarshall the response
    ObservationCollectionType getObsResponse = (ObservationCollectionType) um.unmarshal(is);
    System.out.println(getObsResponse);
    pool.recycle(um);
}
Also used : GetCapabilitiesRequest(org.geotoolkit.sos.GetCapabilitiesRequest) ValueType(org.geotoolkit.ows.xml.v110.ValueType) InputStream(java.io.InputStream) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) MarshallerPool(org.apache.sis.xml.MarshallerPool) SOSMarshallerPool(org.geotoolkit.sos.xml.SOSMarshallerPool) Operation(org.geotoolkit.ows.xml.v110.Operation) URL(java.net.URL) AbstractSensorML(org.geotoolkit.sml.xml.AbstractSensorML) GetObservationRequest(org.geotoolkit.sos.GetObservationRequest) FeatureOfInterest(org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest) Capabilities(org.geotoolkit.sos.xml.v100.Capabilities) Unmarshaller(javax.xml.bind.Unmarshaller) DescribeSensorRequest(org.geotoolkit.sos.DescribeSensorRequest) SensorObservationServiceClient(org.geotoolkit.sos.SensorObservationServiceClient)

Example 39 with ValueType

use of org.geotoolkit.ows.xml.v110.ValueType in project entity-service by hypertrace.

the class NestedValueGetter method getValue.

@Override
public Value getValue(final JsonNode jsonNode) throws ConversionException {
    final JsonNode typeNode = jsonNode.get(VALUE_KEY);
    if (typeNode == null || !typeNode.isObject()) {
        throw new ConversionException(String.format("Type value missing for node: %s", jsonNode));
    }
    final List<Entry<String, JsonNode>> fields = Lists.newArrayList(typeNode.fields());
    if (fields.size() != 1) {
        throw new ConversionException(String.format("Expected exactly 1 field in node: %s", jsonNode));
    }
    final String typeString = fields.get(0).getKey();
    final ValueType type = valueHelper.getPrimitiveValueType(typeString);
    final ValueGetter getter = getterMap.get().get(type);
    if (getter == null) {
        throw new ConversionException(String.format("No getter found for type: %s", type));
    }
    final JsonNode valueNode = fields.get(0).getValue();
    if (!getter.matches(valueNode)) {
        throw new ConversionException(String.format("Getter type does not match for node: %s", valueNode));
    }
    return getter.getValue(valueNode);
}
Also used : ConversionException(org.hypertrace.entity.query.service.converter.ConversionException) Entry(java.util.Map.Entry) ValueType(org.hypertrace.entity.query.service.v1.ValueType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

Test (org.junit.Test)25 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)21 FilterOperation (ca.bc.gov.educ.penreg.api.filter.FilterOperation)21 AND (ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND)21 Search (ca.bc.gov.educ.penreg.api.struct.v1.Search)21 SearchCriteria (ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria)21 ValueType (ca.bc.gov.educ.penreg.api.struct.v1.ValueType)21 PenRequestBatchTestUtils (ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils)21 TypeReference (com.fasterxml.jackson.core.type.TypeReference)21 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 File (java.io.File)21 java.util (java.util)21 Collectors (java.util.stream.Collectors)21 Before (org.junit.Before)21 MockitoAnnotations (org.mockito.MockitoAnnotations)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 APPLICATION_JSON (org.springframework.http.MediaType.APPLICATION_JSON)21 SecurityMockMvcRequestPostProcessors.jwt (org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt)21 MockMvc (org.springframework.test.web.servlet.MockMvc)21 MvcResult (org.springframework.test.web.servlet.MvcResult)21