Search in sources :

Example 1 with ProcessingFlags

use of org.onap.so.db.catalog.beans.ProcessingFlags in project so by onap.

the class CatalogDbAdapterRest method getProcessingFlagsImpl.

public Response getProcessingFlagsImpl(String flag) {
    ProcessingFlags processingFlags = null;
    logger.debug("Flag is: " + flag);
    int respStatus = HttpStatus.SC_OK;
    try {
        processingFlags = processingFlagsRepo.findByFlag(flag);
        if (processingFlags == null) {
            logger.debug("ProcessingFlag not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
        } else {
            logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
        }
        return Response.status(respStatus).entity(processingFlags).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception - queryProcesssingFlags", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
}
Also used : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 2 with ProcessingFlags

use of org.onap.so.db.catalog.beans.ProcessingFlags in project so by onap.

the class CatalogDbAdapterRest method updateProcessingFlagsValueImpl.

public Response updateProcessingFlagsValueImpl(String flag, ProcessingFlags updatedProcessingFlag) {
    ProcessingFlags processingFlags = null;
    logger.debug("Flag is: " + flag);
    int respStatus = HttpStatus.SC_OK;
    try {
        if (updatedProcessingFlag == null) {
            logger.debug("No valid updatedProcessingFlag is provided");
            throw new RuntimeException("No valid updatedProcessingFlag is provided");
        }
        String value = updatedProcessingFlag.getValue();
        if (value == null || (!value.equalsIgnoreCase("YES") && !value.equalsIgnoreCase("NO"))) {
            logger.debug("Value " + value + " is invalid, only yes/no are allowed");
            throw new RuntimeException("Invalid value specified");
        }
        processingFlags = processingFlagsRepo.findByFlag(flag);
        if (processingFlags == null) {
            logger.debug("ProcessingFlag not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
        } else {
            logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
            processingFlags.setValue(value);
            processingFlagsRepo.saveAndFlush(processingFlags);
            return Response.status(respStatus).entity(null).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
        }
    } catch (Exception e) {
        logger.error("Exception - queryProcesssingFlags", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
    return Response.status(HttpStatus.SC_NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
}
Also used : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 3 with ProcessingFlags

use of org.onap.so.db.catalog.beans.ProcessingFlags in project so by onap.

the class CatalogDBRestTest method testGetProcessingFlagsByFlag.

@Test
public void testGetProcessingFlagsByFlag() throws Exception {
    HttpEntity<String> entity = new HttpEntity<String>(null, headers);
    headers.set("Accept", MediaType.APPLICATION_JSON);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_PROCESSING_FLAGS)).pathSegment("TESTFLAG");
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    ObjectMapper mapper = new ObjectMapper();
    ProcessingFlags processingFlagsResponse = mapper.readValue(response.getBody(), ProcessingFlags.class);
    assertEquals(processingFlagsResponse.getFlag(), "TESTFLAG");
    assertEquals(processingFlagsResponse.getValue(), "NO");
    assertEquals(processingFlagsResponse.getEndpoint(), "TESTENDPOINT");
    assertEquals(processingFlagsResponse.getDescription(), "TEST FLAG");
}
Also used : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Example 4 with ProcessingFlags

use of org.onap.so.db.catalog.beans.ProcessingFlags in project so by onap.

the class CatalogDBRestTest method testGetAllProcessingFlags.

@Test
public void testGetAllProcessingFlags() throws Exception {
    HttpEntity<String> entity = new HttpEntity<String>(null, headers);
    headers.set("Accept", MediaType.APPLICATION_JSON);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_PROCESSING_FLAGS));
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    ObjectMapper mapper = new ObjectMapper();
    List<ProcessingFlags> processingFlagsResponse = mapper.readValue(response.getBody(), new TypeReference<List<ProcessingFlags>>() {
    });
    boolean testFlagFound = false;
    for (int i = 0; i < processingFlagsResponse.size(); i++) {
        if (processingFlagsResponse.get(i).getFlag().equals("TESTFLAG")) {
            assertEquals(processingFlagsResponse.get(i).getEndpoint(), "TESTENDPOINT");
            assertEquals(processingFlagsResponse.get(i).getDescription(), "TEST FLAG");
            testFlagFound = true;
        }
    }
    assertTrue(testFlagFound);
}
Also used : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Example 5 with ProcessingFlags

use of org.onap.so.db.catalog.beans.ProcessingFlags in project so by onap.

the class CatalogDBRestTest method testSetProcessingFlagsFlagValue.

@Test
public void testSetProcessingFlagsFlagValue() throws JSONException {
    ProcessingFlags updatedProcessingFlag = new ProcessingFlags();
    updatedProcessingFlag.setFlag("TESTFLAG");
    updatedProcessingFlag.setValue("YES");
    HttpEntity<ProcessingFlags> entity = new HttpEntity<ProcessingFlags>(updatedProcessingFlag, headers);
    headers.set("Accept", MediaType.APPLICATION_JSON);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_PROCESSING_FLAGS)).pathSegment("TESTFLAG");
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.PUT, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
}
Also used : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Aggregations

ProcessingFlags (org.onap.so.db.catalog.beans.ProcessingFlags)8 Test (org.junit.Test)5 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)4 CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)3 HttpEntity (org.springframework.http.HttpEntity)3 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 List (java.util.List)1 BaseTest (org.onap.so.db.catalog.BaseTest)1