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