+ private boolean pushToResources(AaiRestClient aaiClient, ModelLoaderConfig config, String distId,
+ List<Artifact> completedArtifacts) {
+ ResponseEntity<String> getResponse =
+ aaiClient.getResource(getNamedQueryUrl(config), distId, MediaType.APPLICATION_XML, String.class);
+ if (getResponse == null || getResponse.getStatusCode() != HttpStatus.OK) {
+ // Only attempt the PUT if the model doesn't already exist
+ ResponseEntity<String> putResponse = aaiClient.putResource(getNamedQueryUrl(config), getPayload(), distId,
+ MediaType.APPLICATION_XML, String.class);
+ if (putResponse != null && putResponse.getStatusCode() == HttpStatus.CREATED) {
+ completedArtifacts.add(this);
+ logInfoMsg(getType().toString() + " " + getUniqueIdentifier() + " successfully ingested.");
+ } else {
+ logErrorMsg("Ingestion failed for " + getType().toString()
+ + " " + getUniqueIdentifier() + ". Rolling back distribution.");
+ return false;
+ }
+ } else {
+ logInfoMsg(getType().toString() + " " + getUniqueIdentifier() + " already exists. Skipping ingestion.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) {
+ // Gizmo is resilient and doesn't require a rollback. A redistribution will work fine even if
+ // the model is partially loaded.
+ if (config.useGizmo()) {
+ return;
+ }
+
+ // Best effort to delete. Nothing we can do in the event this fails.
+ aaiClient.getAndDeleteResource(getNamedQueryUrl(config), distId);
+ }
+
+ private String getNamedQueryUrl(ModelLoaderConfig config) {
+ String baseURL = config.getAaiBaseUrl().trim();
+ String subURL = config.getAaiNamedQueryUrl(getModelNamespaceVersion()).trim();
+ String instance = this.getNamedQueryUuid();
+
+ if (!baseURL.endsWith("/") && !subURL.startsWith("/")) {
+ baseURL = baseURL + "/";
+ }
+
+ if (baseURL.endsWith("/") && subURL.startsWith("/")) {
+ baseURL = baseURL.substring(0, baseURL.length() - 1);
+ }
+
+ if (!subURL.endsWith("/")) {
+ subURL = subURL + "/";
+ }
+
+ return baseURL + subURL + instance;
+ }