2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.activitylog.dao.impl;
22 import com.datastax.driver.mapping.Mapper;
23 import com.datastax.driver.mapping.Result;
24 import com.datastax.driver.mapping.annotations.Accessor;
25 import com.datastax.driver.mapping.annotations.Query;
26 import org.openecomp.core.dao.impl.CassandraBaseDao;
27 import org.openecomp.core.nosqldb.api.NoSqlDb;
28 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
29 import org.openecomp.sdc.activitylog.dao.ActivityLogDao;
30 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
32 import java.util.Collection;
33 import java.util.Date;
35 public class ActivityLogDaoCassandraImpl extends CassandraBaseDao<ActivityLogEntity> implements ActivityLogDao{
36 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
37 private static final Mapper<ActivityLogEntity> mapper =
38 noSqlDb.getMappingManager().mapper(ActivityLogEntity.class);
39 private static final ActivityLogAccessor accessor =
40 noSqlDb.getMappingManager().createAccessor(ActivityLogAccessor.class);
43 protected Mapper<ActivityLogEntity> getMapper() {
48 protected Object[] getKeys(ActivityLogEntity entity) {
53 public Collection<ActivityLogEntity> list(ActivityLogEntity entity) {
54 return accessor.list().all();
58 public void create(ActivityLogEntity activityLogEntity) {
59 accessor.create(activityLogEntity.getItemId(), activityLogEntity.getVersionId(),activityLogEntity.getId(),
60 activityLogEntity.getType(),activityLogEntity.getUser(), activityLogEntity.getTimestamp(), activityLogEntity.isSuccess(),
61 activityLogEntity.getMessage(), activityLogEntity.getComment());
65 public Collection<ActivityLogEntity> getActivityLogListForItem(String itemId, String versionId) {
66 return accessor.getForItem(itemId, versionId).all();
71 interface ActivityLogAccessor {
72 @Query("select item_id, version_id, activity_id, type, user, timestamp, success, message, comment"
73 + " from activity_log")
74 Result<ActivityLogEntity> list();
76 @Query("select item_id, version_id, activity_id, type, user, timestamp, success, message, comment"
77 + " from activity_log where item_id=? and version_id=?")
78 Result<ActivityLogEntity> getForItem(String itemId, String versionId);
80 @Query("insert into activity_log " +
81 " (item_id, version_id, activity_id, type, user, timestamp, success, message, comment)" +
82 " values (?,?,?,?,?,?,?,?,?)")
83 Result<ActivityLogEntity> create(String itemId, String versionId, String id, String type,
84 String user, Date timestamp, boolean success,
85 String message, String comment);