diff options
author | Steve Smokowski <ss835w@att.com> | 2019-04-15 12:44:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-15 12:44:23 +0000 |
commit | 12b45bae2c59a276098582d858eed13eca1a1c54 (patch) | |
tree | de82d32e99e164590e0a8566f8b3307560c83acc /asdc-controller/src/main | |
parent | 6864971d1fec3e58a7581b38a75c6bed6f390f4f (diff) | |
parent | a2aea243a8a0c16209cd6b48d83c19aec1183ed5 (diff) |
Merge "Deploy activities to SDC from Catalog"
Diffstat (limited to 'asdc-controller/src/main')
-rw-r--r-- | asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java index 46d0f78e35..87008f1d8f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java @@ -20,14 +20,18 @@ package org.onap.so.asdc.activity; -import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.onap.so.asdc.activity.beans.ActivitySpec; -import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.asdc.activity.beans.Input; +import org.onap.so.asdc.activity.beans.Output; +import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecCategories; +import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecParameters; +import org.onap.so.db.catalog.beans.ActivitySpecParameters; +import org.onap.so.db.catalog.data.repository.ActivitySpecRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,17 +43,24 @@ public class DeployActivitySpecs { @Autowired private Environment env; + @Autowired + private ActivitySpecRepository activitySpecRepository; + private static final String SDC_ENDPOINT = "mso.asdc.config.activity.endpoint"; + private static final String DIRECTION_INPUT = "input"; + private static final String DIRECTION_OUTPUT = "output"; protected static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class); - public void deployActivities() throws Exception { - String hostname = this.env.getProperty(SDC_ENDPOINT); - List<ActivitySpec> activitySpecs = new ArrayList<ActivitySpec>(); - // Initialize activitySpecs from Catalog DB - - for (ActivitySpec activitySpec : activitySpecs) { + public void deployActivities() throws Exception { + String hostname = env.getProperty(SDC_ENDPOINT); + if (hostname == null || hostname.isEmpty()) { + return; + } + List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll(); + for (org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog : activitySpecsFromCatalog) { + ActivitySpec activitySpec = mapActivitySpecFromCatalogToSdc(activitySpecFromCatalog); String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec); if (activitySpecId != null) { logger.info("{} {}", "Successfully created activitySpec", activitySpec.getName()); @@ -64,4 +75,62 @@ public class DeployActivitySpecs { } } } + + public ActivitySpec mapActivitySpecFromCatalogToSdc( + org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog) { + ActivitySpec activitySpec = new ActivitySpec(); + activitySpec.setName(activitySpecFromCatalog.getName()); + activitySpec.setDescription(activitySpecFromCatalog.getDescription()); + mapCategoryList(activitySpecFromCatalog.getActivitySpecActivitySpecCategories(), activitySpec); + mapInputsAndOutputs(activitySpecFromCatalog.getActivitySpecActivitySpecParameters(), activitySpec); + return activitySpec; + } + + private void mapCategoryList(List<ActivitySpecActivitySpecCategories> activitySpecActivitySpecCategories, + ActivitySpec activitySpec) { + if (activitySpecActivitySpecCategories == null || activitySpecActivitySpecCategories.size() == 0) { + return; + } + List<String> categoryList = new ArrayList<String>(); + for (ActivitySpecActivitySpecCategories activitySpecCat : activitySpecActivitySpecCategories) { + if (activitySpecCat != null) { + if (activitySpecCat.getActivitySpecCategories() != null) { + categoryList.add(activitySpecCat.getActivitySpecCategories().getName()); + } + } + } + activitySpec.setCategoryList(categoryList); + } + + private void mapInputsAndOutputs(List<ActivitySpecActivitySpecParameters> activitySpecActivitySpecParameters, + ActivitySpec activitySpec) { + if (activitySpecActivitySpecParameters == null || activitySpecActivitySpecParameters.size() == 0) { + return; + } + List<Input> inputs = new ArrayList<Input>(); + List<Output> outputs = new ArrayList<Output>(); + for (ActivitySpecActivitySpecParameters activitySpecParam : activitySpecActivitySpecParameters) { + if (activitySpecParam != null) { + if (activitySpecParam.getActivitySpecParameters() != null) { + ActivitySpecParameters activitySpecParameters = activitySpecParam.getActivitySpecParameters(); + if (activitySpecParameters != null) { + if (activitySpecParameters.getDirection().equals(DIRECTION_INPUT)) { + Input input = new Input(); + input.setName(activitySpecParameters.getName()); + input.setType(activitySpecParameters.getType()); + inputs.add(input); + } else if (activitySpecParameters.getDirection().equals(DIRECTION_OUTPUT)) { + Output output = new Output(); + output.setName(activitySpecParameters.getName()); + output.setType(activitySpecParameters.getType()); + outputs.add(output); + } + } + } + } + } + activitySpec.setInputs(inputs); + activitySpec.setOutputs(outputs); + return; + } } |