diff options
author | sebdet <sebastien.determe@intl.att.com> | 2018-12-11 12:43:26 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2018-12-11 15:26:27 +0100 |
commit | 6a0c205f110078c5722f99d184426ec2e8bbb3b7 (patch) | |
tree | b05c02059544c1c28a04984dec51812a0ceebfa1 /src/main | |
parent | 27d3e6c2b963be95f11a9aebb12de6e5028c8cb9 (diff) |
Additional tosca method
new tosca method for future code
Issue-ID: CLAMP-252
Change-Id: I1fbd15e8a76ccb7629c800d8c64e2d526bd77554
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/dao/CldsDao.java | 55 | ||||
-rw-r--r-- | src/main/java/org/onap/clamp/clds/service/CldsService.java | 2 | ||||
-rw-r--r-- | src/main/resources/clds/camel/rest/clds-services.xml | 2 |
3 files changed, 57 insertions, 2 deletions
diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index b6e27c5e..622b6174 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -46,6 +47,8 @@ import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.CldsToscaModel; +import org.onap.clamp.clds.model.CldsToscaModelDetails; +import org.onap.clamp.clds.model.CldsToscaModelRevision; import org.onap.clamp.clds.model.ValueItem; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; @@ -542,6 +545,58 @@ public class CldsDao { return cldsToscaModels; } + // Retrieve Tosca Models & its revisions by policy Type. + private List<CldsToscaModelDetails> getAllToscaModelVersion(String toscaModelName, String policyType, + String version) { + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + List<CldsToscaModelDetails> cldsToscaModelDetailsList = new ArrayList<>(); + String toscaModelSql = "SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, tmr.tosca_model_revision_id, tmr.version, tmr.user_id, tmr.createdTimestamp, tmr.lastUpdatedTimestamp " + + "FROM tosca_model tm, tosca_model_revision tmr " + "WHERE tmr.tosca_model_id = tm.tosca_model_id " + + ((policyType != null) ? (" AND tm.policy_type = '" + policyType + "'") : " ") + + ((toscaModelName != null) ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : " ") + + ((version != null) ? (" AND tmr.version = '" + version + "'") : ""); + + List<Map<String, Object>> rows = jdbcTemplateObject.queryForList(toscaModelSql); + + if (rows != null && !rows.isEmpty()) { + // Get list of all available modelIds + List<String> listofModelIds = new ArrayList<>(); + for (Map<String, Object> r : rows) { + if (r != null) { + listofModelIds.add((String) r.get("tosca_model_id")); + } + } + // Filter Distinct elements using streams + listofModelIds = listofModelIds.stream().distinct().collect(Collectors.toList()); + + // TODO change logic using java8 + for (String modelId : listofModelIds) { + CldsToscaModelDetails cldsToscaModelDetails = new CldsToscaModelDetails(); + List<CldsToscaModelRevision> revisions = new ArrayList<>(); + for (Map<String, Object> row : rows) { + String id = (String) row.get("tosca_model_id"); + if (modelId.equalsIgnoreCase(id)) { + cldsToscaModelDetails.setId(id); + cldsToscaModelDetails.setPolicyType((String) row.get("policy_type")); + cldsToscaModelDetails.setToscaModelName((String) row.get("tosca_model_name")); + cldsToscaModelDetails.setUserId((String) row.get("user_id")); + + CldsToscaModelRevision modelRevision = new CldsToscaModelRevision(); + modelRevision.setRevisionId((String) row.get("tosca_model_revision_id")); + modelRevision.setVersion(((Double) row.get("version"))); + modelRevision.setUserId((String) row.get("user_id")); + modelRevision.setCreatedDate(sdf.format(row.get("createdTimestamp"))); + modelRevision.setLastUpdatedDate(sdf.format(row.get("lastUpdatedTimestamp"))); + revisions.add(modelRevision); + } + } + cldsToscaModelDetails.setToscaModelRevisions(revisions); + cldsToscaModelDetailsList.add(cldsToscaModelDetails); + } + } + return cldsToscaModelDetailsList; + } + /** * Method to upload a new version of Tosca Model Yaml in Database * diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index be19e31c..e895519f 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -163,7 +163,7 @@ public class CldsService extends SecureServiceBase { * used to generate the ClosedLoop model. ACTION_CD | Current state of the * ClosedLoop in CLDS application. */ - public List<CldsMonitoringDetails> getCLDSDetails() { + public List<CldsMonitoringDetails> getCldsDetails() { util.entering(request, "CldsService: GET model details"); Date startTime = new Date(); List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails(); diff --git a/src/main/resources/clds/camel/rest/clds-services.xml b/src/main/resources/clds/camel/rest/clds-services.xml index e67fb162..47681697 100644 --- a/src/main/resources/clds/camel/rest/clds-services.xml +++ b/src/main/resources/clds/camel/rest/clds-services.xml @@ -4,7 +4,7 @@ outType="org.onap.clamp.clds.model.CldsMonitoringDetails" produces="application/json"> <to - uri="bean:org.onap.clamp.clds.service.CldsService?method=getCLDSDetails()" /> + uri="bean:org.onap.clamp.clds.service.CldsService?method=getCldsDetails()" /> </get> <get uri="/clds/cldsInfo" outType="org.onap.clamp.clds.model.CldsInfo" |