cb5787405be6ef55112c30511972431636d96527
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.action.dao.impl;
18
19 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
20 import static com.datastax.driver.core.querybuilder.QueryBuilder.in;
21 import static com.datastax.driver.core.querybuilder.QueryBuilder.set;
22 import static org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory.getSession;
23 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_CATEGORY;
24 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_MODEL;
25 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NAME;
26 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NONE;
27 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT;
28 import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_VENDOR;
29 import static org.openecomp.sdc.action.ActionConstants.STATUS;
30 import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY;
31 import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY_DB;
32 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER;
33 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE;
34 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG;
35 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST;
36 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE;
37 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE;
38 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_CODE;
39 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_MSG;
40 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_CODE;
41 import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_MSG;
42
43 import com.datastax.driver.core.ResultSet;
44 import com.datastax.driver.core.Row;
45 import com.datastax.driver.core.Statement;
46 import com.datastax.driver.core.exceptions.NoHostAvailableException;
47 import com.datastax.driver.core.querybuilder.QueryBuilder;
48 import com.datastax.driver.mapping.Mapper;
49 import com.datastax.driver.mapping.Result;
50 import com.datastax.driver.mapping.annotations.Accessor;
51 import com.datastax.driver.mapping.annotations.Query;
52 import java.util.ArrayList;
53 import java.util.Collection;
54 import java.util.HashSet;
55 import java.util.LinkedHashMap;
56 import java.util.List;
57 import java.util.Map;
58 import java.util.Set;
59 import java.util.stream.Collectors;
60 import org.openecomp.core.dao.impl.CassandraBaseDao;
61 import org.openecomp.core.nosqldb.api.NoSqlDb;
62 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
63 import org.openecomp.core.utilities.json.JsonUtil;
64 import org.openecomp.sdc.action.ActionConstants;
65 import org.openecomp.sdc.action.dao.ActionDao;
66 import org.openecomp.sdc.action.dao.types.ActionEntity;
67 import org.openecomp.sdc.action.dao.types.OpenEcompComponentEntity;
68 import org.openecomp.sdc.action.errors.ActionException;
69 import org.openecomp.sdc.action.logging.CategoryLogLevel;
70 import org.openecomp.sdc.action.logging.StatusCode;
71 import org.openecomp.sdc.action.types.Action;
72 import org.openecomp.sdc.action.types.ActionStatus;
73 import org.openecomp.sdc.action.types.ActionSubOperation;
74 import org.openecomp.sdc.action.types.OpenEcompComponent;
75 import org.openecomp.sdc.action.util.ActionUtil;
76 import org.openecomp.sdc.logging.api.Logger;
77 import org.openecomp.sdc.logging.api.LoggerFactory;
78 import org.openecomp.sdc.versioning.ActionVersioningManagerFactory;
79 import org.openecomp.sdc.versioning.dao.VersionInfoDao;
80 import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
81 import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
82 import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
83 import org.openecomp.sdc.versioning.dao.types.Version;
84 import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
85 import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
86 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
87 import org.slf4j.MDC;
88
89
90 public class ActionDaoImpl extends CassandraBaseDao<ActionEntity> implements ActionDao {
91   private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
92   private static Mapper<ActionEntity> mapper =
93       noSqlDb.getMappingManager().mapper(ActionEntity.class);
94   private static ActionAccessor accessor =
95       noSqlDb.getMappingManager().createAccessor(ActionAccessor.class);
96   private static VersionInfoDao versionInfoDao =
97       VersionInfoDaoFactory.getInstance().createInterface();
98   private static VersionInfoDeletedDao versionInfoDeletedDao =
99       VersionInfoDeletedDaoFactory.getInstance().createInterface();
100
101   private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
102
103   @Override
104   public void registerVersioning(String versionableEntityType) {
105     ActionVersioningManagerFactory.getInstance().createInterface()
106         .register(versionableEntityType, new VersionableEntityMetadata(
107             mapper.getTableMetadata().getName(),
108             mapper.getTableMetadata().getPartitionKey().get(0).getName(),
109             mapper.getTableMetadata().getPartitionKey().get(1).getName()));
110   }
111
112   @Override
113   public Action createAction(Action action) {
114     try {
115       ActionUtil.actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_ENTITY, TARGET_ENTITY_DB);
116       this.create(action.toEntity());
117       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
118       log.metrics("");
119       return action;
120     } catch (NoHostAvailableException exception) {
121       logGenericException(exception);
122       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
123           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
124     }
125   }
126
127   @Override
128   public Action updateAction(Action action) {
129     try {
130       log.debug(" entering updateAction with actionUUID= " + action.getActionUuId());
131       ActionUtil.actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, TARGET_ENTITY_DB);
132       this.update(action.toEntity());
133       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
134       log.metrics("");
135       log.debug(" exit updateAction with actionUUID= " + action.getActionUuId());
136       return action;
137     } catch (NoHostAvailableException exception) {
138       logGenericException(exception);
139       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
140           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
141     }
142   }
143
144   @Override
145   public void deleteAction(String actionInvariantUuId) {
146     try {
147       log.debug("entering deleteAction with actionInvariantUuId = " + actionInvariantUuId);
148       ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
149       VersionInfoDeletedEntity activeVersionEntity = versionInfoDeletedDao.get(
150           new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE,
151               actionInvariantUuId));
152       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
153       log.metrics("");
154
155       Version activeVersion = activeVersionEntity.getActiveVersion();
156       Statement getNameFromInvUuId = QueryBuilder.select().column("name").from("dox", "Action")
157           .where(eq("actioninvariantuuid", actionInvariantUuId))
158           .and(in("version", activeVersion));
159       ActionUtil
160           .actionLogPreProcessor(ActionSubOperation.GET_NAME_BY_ACTIONINVID, TARGET_ENTITY_DB);
161       ResultSet results = getSession().execute(getNameFromInvUuId);
162       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
163       log.metrics("");
164
165       if (!results.isExhausted()) {
166         String name = results.one().getString("name");
167         List<Version> versions = getVersionsByName(name);
168         updateActionStatusForDelete(actionInvariantUuId, versions);
169       }
170     } catch (NoHostAvailableException noHostAvailableException) {
171       logGenericException(noHostAvailableException);
172       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
173           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
174     }
175     log.debug("exit deleteAction");
176   }
177
178   @Override
179   public List<Action> getFilteredActions(String filterType, String filterId) {
180     List<Action> actions = new ArrayList<>();
181     Result<ActionEntity> result = null;
182     log.debug(
183         " entering getFilteredActions By filterType = " + filterType + " With value = " + filterId);
184     try {
185       switch (filterType) {
186         case FILTER_TYPE_VENDOR:
187           ActionUtil
188               .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_VENDOR,
189                   TARGET_ENTITY_DB);
190           result = accessor.getActionsByVendor(filterId);
191           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
192           log.metrics("");
193           break;
194         case FILTER_TYPE_CATEGORY:
195           ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_CATEGORY,
196               TARGET_ENTITY_DB);
197           result = accessor.getActionsByCategory(filterId);
198           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
199           log.metrics("");
200           break;
201         case FILTER_TYPE_MODEL:
202           ActionUtil
203               .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_MODEL,
204                   TARGET_ENTITY_DB);
205           result = accessor.getActionsByModel(filterId);
206           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
207           log.metrics("");
208           break;
209         case FILTER_TYPE_OPEN_ECOMP_COMPONENT:
210           ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_COMPONENT,
211               TARGET_ENTITY_DB);
212           result = accessor.getActionsByOpenEcompComponent(filterId);
213           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
214           log.metrics("");
215           break;
216         case FILTER_TYPE_NONE:
217           ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ALL_ACTIONS, TARGET_ENTITY_DB);
218           result = accessor.getAllActions();
219           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
220           log.metrics("");
221           break;
222         case FILTER_TYPE_NAME:
223           ActionUtil
224               .actionLogPreProcessor(ActionSubOperation.GET_ACTIONINVID_BY_NAME, TARGET_ENTITY_DB);
225           result = accessor.getInvIdByName(filterId);
226           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE);
227           log.metrics("");
228           List<ActionEntity> actionEntities = result.all();
229           if (actionEntities != null && !actionEntities.isEmpty()) {
230             String actionInvariantUuId = actionEntities.get(0).getActionInvariantUuId();
231             if (actionInvariantUuId != null) {
232               return getActionsByActionInvariantUuId(actionInvariantUuId);
233             } else {
234               return actions;
235             }
236           }
237           break;
238         default:
239           break;
240       }
241       if (result != null) {
242         actions.addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList()));
243       }
244       log.debug(
245           " exit getFilteredActions By filterType = " + filterType + " With value = " + filterId);
246     } catch (NoHostAvailableException noHostAvailableException) {
247       logGenericException(noHostAvailableException);
248       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
249           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
250     }
251     return actions;
252   }
253
254   @Override
255   public Action getActionsByActionUuId(String actionUuId) {
256     try {
257       log.debug(" entering getActionsByActionUuId with actionUUID= " + actionUuId);
258       ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONUUID,
259           TARGET_ENTITY_DB);
260       Result<ActionEntity> result = accessor.actionInvariantUuId(actionUuId);
261       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
262       log.metrics("");
263       if (result != null) {
264         log.debug(" exit getActionsByActionUuId with actionUUID= " + actionUuId);
265         ActionEntity entity = result.one();
266         if (entity != null) {
267           return entity.toDto();
268         }
269       }
270       log.debug(" exit getActionsByActionUuId with actionUUID= " + actionUuId);
271       return null;
272     } catch (NoHostAvailableException noHostAvailableException) {
273       logGenericException(noHostAvailableException);
274       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
275           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
276     }
277   }
278
279   @Override
280   public List<OpenEcompComponent> getOpenEcompComponents() {
281     List<OpenEcompComponent> openEcompComponents = new ArrayList<>();
282     Result<OpenEcompComponentEntity> result;
283     try {
284       log.debug(" entering getOpenEcompComponents ");
285       ActionUtil
286           .actionLogPreProcessor(ActionSubOperation.GET_OPEN_ECOMP_COMPONENTS_ENTITY,
287               TARGET_ENTITY_DB);
288       result = accessor.getOpenEcompComponents();
289       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
290       log.metrics("");
291       if (result != null) {
292         openEcompComponents.addAll(
293             result.all().stream().map(OpenEcompComponentEntity::toDto)
294                 .collect(Collectors.toList()));
295       }
296     } catch (NoHostAvailableException noHostAvailableException) {
297       logGenericException(noHostAvailableException);
298       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
299           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
300     }
301     log.debug(" exit getOpenEcompComponents ");
302     return openEcompComponents;
303   }
304
305   @Override
306   public List<Action> getActionsByActionInvariantUuId(String actionInvariantUuId) {
307     List<Action> actions = new ArrayList<Action>();
308     try {
309       log.debug(" entering getActionsByActionInvariantUuId with actionInvariantUuId= "
310           + actionInvariantUuId);
311       Set<Version> viewableVersions = new HashSet<>();
312       VersionPredicate filter = new VersionPredicate();
313       ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
314       VersionInfoEntity versionInfoEntity = versionInfoDao
315           .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId));
316       if (versionInfoEntity == null) {
317         //Check for action in the Delete version info table
318         VersionInfoDeletedEntity versionInfoDeletedEntity = versionInfoDeletedDao.get(
319             new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE,
320                 actionInvariantUuId));
321         if (versionInfoDeletedEntity != null) {
322           viewableVersions = versionInfoDeletedEntity.getViewableVersions();
323           //Remove intermediate minor versions from viewable versions
324           if (versionInfoDeletedEntity.getActiveVersion() != null) {
325             filter.activeVersion = versionInfoDeletedEntity.getActiveVersion();
326             filter.finalVersion = versionInfoDeletedEntity.getLatestFinalVersion();
327             viewableVersions.removeIf(filter::isIntermediateMinorVersion);
328           }
329         }
330       } else {
331         viewableVersions = versionInfoEntity.getViewableVersions();
332         //Remove intermediate minor versions from viewable versions
333         if (versionInfoEntity.getActiveVersion() != null) {
334           filter.activeVersion = versionInfoEntity.getActiveVersion();
335           filter.finalVersion = versionInfoEntity.getLatestFinalVersion();
336           viewableVersions.removeIf(filter::isIntermediateMinorVersion);
337         }
338         //Add candidate version if available
339         if (versionInfoEntity.getCandidate() != null) {
340           viewableVersions.add(versionInfoEntity.getCandidate().getVersion());
341         }
342       }
343
344       MDC.put(TARGET_ENTITY, TARGET_ENTITY_DB);
345       ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
346       log.metrics("");
347
348       log.debug(
349           "Found " + viewableVersions + " viewable version for action with actionInvariantUuId "
350               + actionInvariantUuId);
351
352       //Fetch action data for the viewable versions
353       if (!viewableVersions.isEmpty()) {
354         ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID,
355             TARGET_ENTITY_DB);
356         Result<ActionEntity> result =
357             accessor.getActionsByInvId(actionInvariantUuId, viewableVersions);
358         ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
359         log.metrics("");
360         if (result != null) {
361           actions
362               .addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList()));
363         }
364       }
365     } catch (NoHostAvailableException noHostAvailableException) {
366       logGenericException(noHostAvailableException);
367       throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE,
368           ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG);
369     }
370     log.debug(
371         " exit getActionsByActionInvariantUuId with actionInvariantUuId= " + actionInvariantUuId);
372     return actions;
373   }
374
375   @Override
376   public Action getLockedAction(String actionInvariantUuId, String user) throws ActionException {
377     log.debug(" entering getLockedAction with actionInvariantUuId= " + actionInvariantUuId);
378     ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
379     Action action = null;
380     VersionInfoEntity versionInfoEntity = versionInfoDao
381         .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId));
382     ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
383     log.metrics("");
384     if (versionInfoEntity != null) {
385       if (versionInfoEntity.getCandidate() != null) {
386         String actionUser = versionInfoEntity.getCandidate().getUser();
387         if (actionUser != null && actionUser.equals(user)) {
388           Set<Version> versions = new HashSet<>();
389           versions.add(versionInfoEntity.getCandidate().getVersion());
390           ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID,
391               TARGET_ENTITY_DB);
392           Result<ActionEntity> result = accessor.getActionsByInvId(actionInvariantUuId, versions);
393           ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
394           log.metrics("");
395           if (result != null) {
396             ActionEntity actionEntity = result.one();
397             action = actionEntity != null ? actionEntity.toDto() : null;
398           }
399         } else {
400           throw new ActionException(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE,
401               String.format(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, actionUser));
402         }
403       } else {
404         throw new ActionException(ACTION_NOT_LOCKED_CODE, ACTION_NOT_LOCKED_MSG);
405       }
406     } else {
407       throw new ActionException(ACTION_ENTITY_NOT_EXIST_CODE, ACTION_ENTITY_NOT_EXIST);
408     }
409     return action;
410   }
411
412   private void logGenericException(Exception exception) {
413     ActionUtil.actionLogPostProcessor(StatusCode.ERROR, ACTION_QUERY_FAILURE_CODE,
414         ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, false);
415     log.metrics("");
416     ActionUtil.actionErrorLogProcessor(CategoryLogLevel.FATAL, ACTION_QUERY_FAILURE_CODE,
417         ACTION_QUERY_FAILURE_MSG);
418     log.error(exception.getMessage());
419   }
420
421   @Override
422   protected Mapper<ActionEntity> getMapper() {
423     return mapper;
424   }
425
426
427   @Override
428   protected Object[] getKeys(ActionEntity entity) {
429     return new Object[]{entity.getActionInvariantUuId(), entity.getVersion()};
430   }
431
432   @Override
433   public Collection<ActionEntity> list(ActionEntity entity) {
434     return accessor.getAllActions().all();
435   }
436
437   private void updateActionStatusForDelete(String actionInvariantUuId, List<Version> versions) {
438     log.debug(
439         "entering updateActionStatusForDelete with actionInvariantUuId = " + actionInvariantUuId
440             + " for versions " + versions);
441     ActionUtil.actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION_STATUS, TARGET_ENTITY_DB);
442     //Update the status column of action table
443     Statement updateStatusStatement =
444         QueryBuilder.update("dox", "Action").with(set("status", ActionStatus.Deleted.name()))
445             .where(eq("actioninvariantuuid", actionInvariantUuId)).and(in("version", versions));
446     getSession().execute(updateStatusStatement);
447     ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
448     log.metrics("");
449     //Update the status in the data field of action table
450     updateStatusInActionData(actionInvariantUuId, versions, ActionStatus.Deleted);
451     log.debug("exit updateActionStatusForDelete with actionInvariantUuId = " + actionInvariantUuId
452         + " for versions " + versions);
453   }
454
455   /**
456    * Update status for a list of versions for a given action.
457    *
458    * @param actionInvariantUuId Invariant UUID of the action.
459    * @param versions            List of {@link Version} for which the status has to be updated.
460    * @param status              The status value.
461    */
462   private void updateStatusInActionData(String actionInvariantUuId, List<Version> versions,
463                                         ActionStatus status) {
464     log.debug("entering updateStatusInActionData for actionInvariantUuId = " + actionInvariantUuId
465         + " and status = " + status + " for versions " + versions);
466     for (Version v : versions) {
467       ActionEntity entity = this.get(new ActionEntity(actionInvariantUuId, v));
468       String currentData = entity.getData();
469       Map<String, Object> currentDataMap = JsonUtil.json2Object(currentData, LinkedHashMap.class);
470       currentDataMap.put(STATUS, status);
471       String updatedActionData = JsonUtil.object2Json(currentDataMap);
472       entity.setData(updatedActionData);
473       this.updateAction(entity.toDto());
474     }
475     log.debug("exit updateStatusInActionData");
476   }
477
478   /**
479    * Get list of all major and minor version values for a given action by action name.
480    *
481    * @param name Name of the action.
482    * @return List of {@link Version} objects for the action.
483    */
484   private List<Version> getVersionsByName(String name) {
485     log.debug("entering getVersionsByName for Action Name = " + name);
486     ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
487     Statement statement =
488         QueryBuilder.select().column("version").from("dox", "Action").where(eq("name", name));
489     ResultSet results = getSession().execute(statement);
490     ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
491     log.metrics("");
492
493     List<Version> versionList = new ArrayList<>();
494     for (Row row : results) {
495       Version version =  row.get("version",Version.class);
496       versionList.add(version);
497     }
498     log.debug("exit getVersionsByName for Action Name = " + name);
499     return versionList;
500   }
501
502   @Accessor
503   interface ActionAccessor {
504
505     @Query("SELECT * FROM Action")
506     Result<ActionEntity> getAllActions();
507
508     @Query("SELECT * FROM Action where actionInvariantUuId = ? and version in ? ")
509     Result<ActionEntity> getActionsByInvId(String actionInvariantUuId, Set<Version> versions);
510
511     @Query("SELECT * FROM Action where supportedModels CONTAINS ?")
512     Result<ActionEntity> getActionsByModel(String resource);
513
514     @Query("SELECT * FROM Action where supportedComponents CONTAINS ?")
515     Result<ActionEntity> getActionsByOpenEcompComponent(String resource);
516
517     @Query("SELECT * FROM Action where vendor_list CONTAINS ?")
518     Result<ActionEntity> getActionsByVendor(String vendor);
519
520     @Query("SELECT * FROM Action where category_list CONTAINS ?")
521     Result<ActionEntity> getActionsByCategory(String vendor);
522
523     @Query("SELECT actionInvariantUuId FROM Action where name = ? limit 1")
524     Result<ActionEntity> getInvIdByName(String name);
525
526     @Query("SELECT * FROM EcompComponent")
527     Result<OpenEcompComponentEntity> getOpenEcompComponents();
528
529     @Query("SELECT * FROM Action where actionUUID = ?")
530     Result<ActionEntity> actionInvariantUuId(String actionUuId);
531
532   }
533
534   class VersionPredicate {
535     Version activeVersion;
536     Version finalVersion;
537
538     public boolean isIntermediateMinorVersion(Version version) {
539       int activeMajorVersion = activeVersion.getMajor();
540       int activeMinorVersion = activeVersion.getMinor();
541       int currentMinorVersion = version.getMinor();
542       int currentMajorVersion = version.getMajor();
543
544       if (finalVersion != null) {
545         if (finalVersion.getMajor() == activeMajorVersion
546             && currentMajorVersion == finalVersion.getMajor()) {
547           if (currentMinorVersion < activeMinorVersion && currentMinorVersion != 0) {
548             return true;
549           }
550         } else {
551           return false;
552         }
553       } else {
554         if (!version.equals(activeVersion)) {
555           return true;
556         }
557       }
558
559       return false;
560     }
561
562   }
563 }