From 17d254a18dbd790ba3ef3a9ff383abe8a5d39c8f Mon Sep 17 00:00:00 2001 From: c00149107 Date: Wed, 7 Mar 2018 10:24:57 +0800 Subject: Support query ar recipe by ar model uuid Support query ar recipe by ar model uuid Change-Id: I846bc1f55f2c15be02ba44496e1fc1b33fdaf8e2 Issue-ID: SO-456 Signed-off-by: c00149107 --- .../openecomp/mso/db/catalog/CatalogDatabase.java | 64 ++++++++++++++++++++++ 1 file changed, 64 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 a01527ed8d..26b641d883 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 @@ -36,6 +36,7 @@ import org.hibernate.Session; import org.openecomp.mso.db.AbstractSessionFactoryManager; import org.openecomp.mso.db.catalog.beans.AllottedResource; import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization; +import org.openecomp.mso.db.catalog.beans.ArRecipe; import org.openecomp.mso.db.catalog.beans.HeatEnvironment; import org.openecomp.mso.db.catalog.beans.HeatFiles; import org.openecomp.mso.db.catalog.beans.HeatNestedTemplate; @@ -5147,4 +5148,67 @@ public class CatalogDatabase implements Closeable { } return theObjects; } + + + /** + * get allotted resource recipe by module name and version and action. + *
+ * + * @param modelName + * @param modelVersion + * @param action + * @return + * @since ONAP Beijing Release + */ + public ArRecipe getArRecipeByNameVersion(String modelName, String modelVersion, String action) { + + long startTime = System.currentTimeMillis (); + LOGGER.debug ("Catalog database - get ar recipe with ar model name " + modelName + +"model version " + modelVersion + " and action " + action); + + try { + String hql = "FROM ArRecipe 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 allotted resource recipe that matches a given MODEL_UUID and ACTION + * + * @param modelName + * @param action + * @return ArRecipe object or null if none found + */ + public ArRecipe getArRecipeByModuleUuid (String ArModelUuid, String action) { + LOGGER.debug ("Catalog database - get ar recipe with ar model uuid " + ArModelUuid + + " and action " + + action + ); + AllottedResource arResource = this.getAllottedResourceByModelUuid(ArModelUuid); + if(null == arResource){ + return null; + } + + ArRecipe recipe = getArRecipeByNameVersion(arResource.getModelName(), arResource.getModelVersion(), action); + return recipe; + } + } -- cgit 1.2.3-korg