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