- try {
- putResponse = aaiClient.putResource(getModelVerUrl(config), nodeToString(getModelVer()), distId, AaiRestClient.MimeType.XML);
- } catch (TransformerException e) {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " " + getUniqueIdentifier()
- + ": " + e.getMessage() + ". Rolling back distribution.");
- return false;
- }
- if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) {
- addedModels.add(this);
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " successfully ingested.");
- }
- else {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " "
- + getUniqueIdentifier() + ". Rolling back distribution.");
- return false;
+ private static final String FAILURE_MSG_PREFIX = "Ingestion failed for ";
+ private static final String ROLLBACK_MSG_SUFFIX = ". Rolling back distribution.";
+
+
+ private String modelVerId;
+ private String modelInvariantId;
+ private Node modelVer;
+ private boolean firstVersionOfModel = false;
+
+ public ModelArtifact() {
+ super(ArtifactType.MODEL);
+ }
+
+ public String getModelVerId() {
+ return modelVerId;
+ }
+
+ public void setModelVerId(String modelVerId) {
+ this.modelVerId = modelVerId;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public Node getModelVer() {
+ return modelVer;
+ }
+
+ public void setModelVer(Node modelVer) {
+ this.modelVer = modelVer;
+ }
+
+ @Override
+ public String getUniqueIdentifier() {
+ return getModelInvariantId() + "|" + getModelVerId();
+ }
+
+
+ /**
+ * Test whether the specified resource (URL) can be requested successfully
+ *
+ * @param aaiClient
+ * @param distId
+ * @param xmlResourceUrl
+ * @return true if a request to GET this resource as XML media is successful (status OK)
+ */
+ private boolean xmlResourceCanBeFetched(AaiRestClient aaiClient, String distId, String xmlResourceUrl) {
+ OperationResult getResponse = getResourceModel(aaiClient, distId, xmlResourceUrl);
+ return getResponse != null && getResponse.getResultCode() == Response.Status.OK.getStatusCode();
+ }
+
+ /**
+ * Test whether the specified resource (URL) can be requested successfully
+ *
+ * @param aaiClient
+ * @param distId
+ * @param xmlResourceUrl
+ * @return OperationResult the result of the operation
+ */
+ private OperationResult getResourceModel(AaiRestClient aaiClient, String distId, String xmlResourceUrl) {
+ return aaiClient.getResource(xmlResourceUrl, distId, MediaType.APPLICATION_XML_TYPE);
+ }
+
+ /**
+ * PUT the specified XML resource
+ *
+ * @param aaiClient
+ * @param distId
+ * @param resourceUrl
+ * @param payload
+ * @return true if the resource PUT as XML media was successful (status OK)
+ */
+ private boolean putXmlResource(AaiRestClient aaiClient, String distId, String resourceUrl, String payload) {
+ OperationResult putResponse =
+ aaiClient.putResource(resourceUrl, payload, distId, MediaType.APPLICATION_XML_TYPE);
+ return putResponse != null && putResponse.getResultCode() == Response.Status.CREATED.getStatusCode();
+ }
+
+ @Override
+ public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId,
+ List<Artifact> completedArtifacts) {
+ if (config.useGizmo()) {
+ return pushToGizmo(aaiClient, config, distId);