summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src/main')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java19
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java11
2 files changed, 30 insertions, 0 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java
new file mode 100644
index 0000000000..61e23b8de2
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactAccessor.java
@@ -0,0 +1,19 @@
+package org.openecomp.sdc.be.dao.cassandra;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Param;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
+
+
+/**
+ * Created by chaya on 7/5/2017.
+ */
+@Accessor
+public interface ArtifactAccessor {
+ // ***** get the number of artifacts with a specific id
+ @Query("SELECT COUNT(*) FROM sdcartifact.resources WHERE ID = :uniqueId")
+ ResultSet getNumOfArtifactsById(@Param("uniqueId") String uniqueId);
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
index a9a4a99de1..5b37d3df2c 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.dao.cassandra;
import javax.annotation.PostConstruct;
+import com.datastax.driver.core.ResultSet;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.resources.data.ESArtifactData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
@@ -38,6 +39,7 @@ import fj.data.Either;
public class ArtifactCassandraDao extends CassandraDao {
private static Logger logger = LoggerFactory.getLogger(ArtifactCassandraDao.class.getName());
+ private ArtifactAccessor artifactAccessor;
public ArtifactCassandraDao() {
super();
@@ -52,6 +54,7 @@ public class ArtifactCassandraDao extends CassandraDao {
if (result.isLeft()) {
session = result.left().value().left;
manager = result.left().value().right;
+ artifactAccessor = manager.createAccessor(ArtifactAccessor.class);
logger.info("** ArtifactCassandraDao created");
} else {
logger.info("** ArtifactCassandraDao failed");
@@ -107,4 +110,12 @@ public class ArtifactCassandraDao extends CassandraDao {
return super.isTableEmpty(tableName);
}
+ public Either<Long, CassandraOperationStatus> getCountOfArtifactById(String uniqeId) {
+ ResultSet artifactCount = artifactAccessor.getNumOfArtifactsById(uniqeId);
+ if (artifactCount == null) {
+ return Either.right(CassandraOperationStatus.NOT_FOUND);
+ }
+ return Either.left(artifactCount.one().getLong(0));
+ }
+
}