From 7f3b9b70217a818cf940a017175d4260245ef1b5 Mon Sep 17 00:00:00 2001 From: c00149107 Date: Tue, 27 Feb 2018 17:09:18 +0800 Subject: Support csar object query Support csar object query, for model driven work flow. Change-Id: I7207ad8081244d1c38fcdc9ee161d9d1204fdb4a Issue-ID: SO-451 Signed-off-by: c00149107 --- .../openecomp/mso/db/catalog/CatalogDatabase.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index 891b0b27fb..8e7202d46d 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -3822,7 +3822,58 @@ public class CatalogDatabase implements Closeable { LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsar", null); return resultList.get (0); } + + /** + * Return a specific Tosca CSAR Record resource (queried by atrifact uuid). + * + * @param toscaCsarArtifactUUID the artifact uuid of the tosca csar + * @return ToscaCsar object or null if none found + */ + public ToscaCsar getToscaCsarByUUID(String toscaCsarArtifactUUID){ + long startTime = System.currentTimeMillis (); + LOGGER.debug ("Catalog database - get Tosca CSAR record with artifactUUID " + toscaCsarArtifactUUID); + + String hql = "FROM ToscaCsar WHERE artifactUUID = :toscaCsarArtifactUUID"; + Query query = getSession ().createQuery (hql); + query.setParameter ("toscaCsarArtifactUUID", toscaCsarArtifactUUID); + @SuppressWarnings("unchecked") + List resultList = query.list (); + + // See if something came back. Name is unique, so + if (resultList.isEmpty ()) { + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Tosca Csar not found", "CatalogDB", "getToscaCsarByUUID", null); + return null; + } + + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByUUID", null); + return resultList.get (0); + } + + /** + * Return a specific Tosca CSAR Record resource (queried by service model uuid). + *
+ * + * @param serviceModelUUID the service model uuid + * @return ToscaCsar object or null if none found + * @since ONAP Beijing Release + */ + public ToscaCsar getToscaCsarByServiceModelUUID(String serviceModelUUID){ + long startTime = System.currentTimeMillis (); + LOGGER.debug ("Catalog database - get Tosca CSAR record with serviceModelUUID " + serviceModelUUID); + Service service = getServiceByModelUUID(serviceModelUUID); + if(null == service){ + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null); + return null; + } + ToscaCsar csar = getToscaCsarByUUID(service.getToscaCsarArtifactUUID()); + if(null == csar){ + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Tosca csar of the service not found", "CatalogDB", "getToscaCsarByServiceModelUUID", null); + return null; + } + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getToscaCsarByServiceModelUUID", null); + return csar; + } public void saveTempNetworkHeatTemplateLookup (TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup) { long startTime = System.currentTimeMillis (); -- cgit 1.2.3-korg