use of org.onap.so.client.RestClient in project so by onap.
the class GraphInventoryResourcesClient method deleteIfExists.
/**
* Deletes object from GraphInventory only if exists. Automatically handles resource-version.
*
* @param uri
* @return
*/
public void deleteIfExists(SingleUri uri) {
GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone();
RestClient giRC = client.createClient(clone);
Optional<Map<String, Object>> result = giRC.get(new GenericType<Map<String, Object>>() {
});
if (result.isPresent()) {
String resourceVersion = (String) result.get().get("resource-version");
giRC = client.createClient(clone.resourceVersion(resourceVersion));
giRC.delete();
} else {
logger.warn(clone.build() + " already does not exist in " + client.getGraphDBName() + " therefore delete call not executed");
}
}
use of org.onap.so.client.RestClient in project so by onap.
the class AAISingleTransactionClient method execute.
/*
* (non-Javadoc)
*
* @see org.onap.aaiclient.client.aai.GraphInventoryTransactionClient#execute()
*/
@Override
public void execute() throws BulkProcessFailed {
try {
if (!this.request.getOperations().isEmpty()) {
RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
if (response != null) {
final Optional<String> errorMessage = this.locateErrorMessages(response);
if (errorMessage.isPresent()) {
throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
}
} else {
throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
}
}
} finally {
this.request.getOperations().clear();
this.actionCount = 0;
}
}
use of org.onap.so.client.RestClient in project so by onap.
the class GraphInventoryResourcesClient method delete.
/**
* Deletes object from GraphInventory. Automatically handles resource-version.
*
* @param uri
* @return
*/
public void delete(SingleUri uri) {
GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone();
RestClient giRC = client.createClient(clone);
Map<String, Object> result = giRC.get(new GenericType<Map<String, Object>>() {
}).orElseThrow(() -> new NotFoundException(clone.build() + " does not exist in " + client.getGraphDBName()));
String resourceVersion = (String) result.get("resource-version");
giRC = client.createClient(clone.resourceVersion(resourceVersion));
giRC.delete();
}
use of org.onap.so.client.RestClient in project so by onap.
the class GraphInventoryResourcesClient method disconnect.
/**
* Removes relationship from two objects in GraphInventory
*
* @param uriA
* @param uriB
* @return
*/
public void disconnect(SingleUri uriA, SingleUri uriB) {
GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
RestClient giRC = client.createClient(uriAClone.relationshipAPI());
giRC.delete(this.buildRelationship(uriB));
}
use of org.onap.so.client.RestClient in project so by onap.
the class AAIResourcesClientTest method testGetFirstWrongPluralClass.
@Test
public void testGetFirstWrongPluralClass() {
GenericVnf vnf = new GenericVnf();
AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
RestClient restClientMock = mock(RestClient.class);
doReturn(restClientMock).when(client).createClient(uri);
when(restClientMock.get(GenericVnf.class)).thenReturn(Optional.of(vnf));
Optional<GenericVnf> result = aaiClient.getFirst(GenericVnf.class, GenericVnf.class, uri);
assertFalse(result.isPresent());
}
Aggregations