From 04ef8dd312938513493ccf1ca1acb8b02d1a0dca Mon Sep 17 00:00:00 2001 From: c00149107 Date: Tue, 6 Mar 2018 18:07:14 +0800 Subject: Support query network recipe by module uuid Support query network recipe by module uuid Change-Id: I8b49babf73f98c5e9ffe27463bd8227274440390 Issue-ID: SO-456 Signed-off-by: c00149107 --- .../openecomp/mso/db/catalog/CatalogDatabase.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'mso-catalog-db') 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 f59c09a418..bbdb065027 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 @@ -87,6 +87,7 @@ public class CatalogDatabase implements Closeable { private static final String VNF_COMPONENT_TYPE = "vnfComponentType"; private static final String MODEL_ID = "modelId"; private static final String MODEL_NAME = "modelName"; + private static final String MODEL_VERSION = "version"; private static final String TYPE = "type"; private static final String MODEL_TYPE = "modelType"; private static final String MODEL_VERSION_ID = "modelVersionId"; @@ -4443,6 +4444,26 @@ public class CatalogDatabase implements Closeable { } } + /** + * Return a Network recipe that matches a given MODEL_UUID and ACTION + * + * @param modelName + * @param action + * @return NetworkRecipe object or null if none found + */ + public NetworkRecipe getNetworkRecipeByModuleUuid (String networkModelUuid, String action) { + LOGGER.debug ("Catalog database - get network recipe with network model uuid " + networkModelUuid + + " and action " + + action + ); + NetworkResource networkResource = getNetworkResourceByModelUuid(networkModelUuid); + if(null == networkResource){ + return null; + } + + NetworkRecipe recipe = getNetworkRecipeByNameVersion(networkResource.getModelName(), networkResource.getModelVersion(), action); + return recipe; + } /** * Return a Network recipe that matches a given MODEL_NAME and ACTION @@ -4482,6 +4503,46 @@ public class CatalogDatabase implements Closeable { } } + /** + * get network recipe by module name and version and action. + *
+ * + * @param modelName + * @param modelVersion + * @param action + * @return + * @since ONAP Beijing Release + */ + public NetworkRecipe getNetworkRecipeByNameVersion(String modelName, String modelVersion, String action) { + + long startTime = System.currentTimeMillis (); + LOGGER.debug ("Catalog database - get network recipe with network model name " + modelName + +"model version " + modelVersion + " and action " + action); + + try { + String hql = "FROM NetworkRecipe WHERE modelName = :modelName AND version=:version AND action = :action"; + + Query query = getSession ().createQuery (hql); + query.setParameter (MODEL_NAME, modelName); + query.setParameter (MODEL_VERSION, modelVersion); + query.setParameter (ACTION, action); + + @SuppressWarnings("unchecked") + List resultList = query.list (); + + if (resultList.isEmpty ()) { + return null; + } + + Collections.sort (resultList, new MavenLikeVersioningComparator ()); + Collections.reverse (resultList); + + return resultList.get (0); + } finally { + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkRecipe", null); + } + } + /** * Return a Network Resource that matches the Network Customization defined by given MODEL_CUSTOMIZATION_UUID * -- cgit 1.2.3-korg