- // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9')
- String[] parts = modelNamespace.split("/");
- modelNamespaceVersion = parts[parts.length-1].trim();
- }
-
- public String getModelNamespaceVersion() {
- return modelNamespaceVersion;
- }
-
- public abstract String getUniqueIdentifier();
-
- public abstract boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels);
-
- public abstract void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId);
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("\nType=" + getType().toString() +"\nId=" + getUniqueIdentifier() +"\nVersion=" + getModelNamespaceVersion() + "\nDependant models: ");
- for (String dep : referencedModelIds) {
- sb.append(dep + " ");
- }
-
- return sb.toString();
- }
-
-
+ private String modelNamespace;
+ private String modelNamespaceVersion;
+ private Set<String> referencedModelIds = new HashSet<>();
+
+ public AbstractModelArtifact(ArtifactType type) {
+ super(type);
+ }
+
+ public Set<String> getDependentModelIds() {
+ return referencedModelIds;
+ }
+
+ @Override
+ public void addDependentModelId(String dependentModelId) {
+ this.referencedModelIds.add(dependentModelId);
+ }
+
+ public String getModelNamespace() {
+ return modelNamespace;
+ }
+
+ @Override
+ public void setModelNamespace(String modelNamespace) {
+ this.modelNamespace = modelNamespace;
+
+ // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9')
+ String[] parts = modelNamespace.split("/");
+ modelNamespaceVersion = parts[parts.length - 1].trim();
+ }
+
+ public String getModelNamespaceVersion() {
+ return modelNamespaceVersion;
+ }
+
+ public abstract String getUniqueIdentifier();
+
+ public abstract boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId,
+ List<Artifact> completedArtifacts);
+
+ public abstract void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId);
+
+ protected boolean pushToGizmo(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<Artifact> completedArtifacts) {
+ try {
+ String gizmoPayload = GizmoTranslator.translate(getPayload());
+ OperationResult postResponse =
+ aaiClient.postResource(config.getAaiBaseUrl().trim(), gizmoPayload, distId, MediaType.APPLICATION_JSON_TYPE);
+
+ if (postResponse.getResultCode() != HttpStatus.OK.value()) {
+ return false;
+ }
+
+ } catch (Exception e) {
+ logErrorMsg("Ingest failed for " + getType().toString() + " " + getUniqueIdentifier() + ": " + e.getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+ protected void logInfoMsg(String infoMsg) {
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, infoMsg);
+ }
+
+ protected void logErrorMsg(String errorMsg) {
+ logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, errorMsg);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\nType=" + getType().toString() + "\nId=" + getUniqueIdentifier() + "\nVersion="
+ + getModelNamespaceVersion() + "\nDependant models: ");
+ for (String dep : referencedModelIds) {
+ sb.append(dep + " ");
+ }
+
+ return sb.toString();
+ }
+