diff --git a/CHANGELOG.md b/CHANGELOG.md
index 313edcf..c671e74 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v2.3.0-SNAPSHOT]
+
+- Read countByPhase from configuration [#25598]
+
## [v2.2.1]
- Reduced/Optimized some LOGs [#25539]
diff --git a/pom.xml b/pom.xml
index 270d7ca..8b85a8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.application
geoportal-data-common
- 2.2.1
+ 2.3.0-SNAPSHOT
GeoPortal Data Common is common library used by GUI components developed for GeoNA
diff --git a/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java b/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java
index 86a7ed2..43d989c 100644
--- a/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java
+++ b/src/main/java/org/gcube/application/geoportalcommon/geoportal/ProjectsCaller.java
@@ -58,6 +58,7 @@ import com.mongodb.BasicDBObjectBuilder;
*/
public class ProjectsCaller {
+ public static final String DOCUMENT_STORE_COLLECTION = "DOCUMENT-STORE-COLLECTION";
private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class);
/**
@@ -208,7 +209,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
- if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
+ if (theType.equalsIgnoreCase(DOCUMENT_STORE_COLLECTION)) {
String totalDocumentAre = archive.get("count").toString();
int total = Integer.parseInt(totalDocumentAre);
LOG.info("total docs for profileID: {}, are: {}", profileID, total);
@@ -234,7 +235,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
- if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
+ if (theType.equalsIgnoreCase(DOCUMENT_STORE_COLLECTION)) {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson();
@@ -255,6 +256,36 @@ public class ProjectsCaller {
return null;
}
+ public Integer getCountByPhaseFor(String profileID, String phase, String status) throws Exception {
+ LOG.info("getCountByPhaseFor called for profileID: {}, phase: {}, status: {}", profileID, phase, status);
+ Projects client = (Projects) getClient(profileID);
+ Configuration config = client.getConfiguration();
+ List listArchives = config.getArchives();
+ Integer count = null;
+ for (Archive archive : listArchives) {
+ String theType = archive.getString("_type");
+ if (theType.equalsIgnoreCase(DOCUMENT_STORE_COLLECTION)) {
+ com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
+ .jsonProvider(new JsonOrgJsonProvider()).build();
+ String toJSON = archive.toJson();
+ JSONObject jObject = new JSONObject(toJSON);
+ String query = String.format("$.countByPhase[*][?(@._id.phase == '%s' && @._id.status == '%s')].count",
+ phase, status);
+ LOG.debug("Performing query: " + query);
+ JsonPath jsonPath = JsonPath.compile(query);
+ JSONArray counts = jsonPath.read(jObject, configuration);
+ try {
+ count = counts.getInt(0);
+ } catch (Exception e) {
+ LOG.warn("getCountByPhaseFor error: " + e.getLocalizedMessage());
+ }
+ }
+ }
+
+ LOG.info("getCountByPhaseFor returning: " + count);
+ return count;
+ }
+
/**
* Gets the phases into document store collection.
*
@@ -270,7 +301,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) {
String theType = archive.getString("_type");
- if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) {
+ if (theType.equalsIgnoreCase(DOCUMENT_STORE_COLLECTION)) {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson();
@@ -398,19 +429,19 @@ public class ProjectsCaller {
* @param projectID the project ID
* @param jsonPathToFileset the json path to fileset
* @param force the force
- * @param ignoreErrors the ignore errors
+ * @param ignoreErrors the ignore errors
* @return the project
* @throws RemoteException the remote exception
*/
- public Project deleteFileset(String profileID, String projectID, String jsonPathToFileset, Boolean force, Boolean ignoreErrors)
- throws RemoteException {
+ public Project deleteFileset(String profileID, String projectID, String jsonPathToFileset, Boolean force,
+ Boolean ignoreErrors) throws RemoteException {
LOG.info("deleteFileset called for profileID {} and projectID {}, fileset path: {}", profileID, projectID,
jsonPathToFileset);
Projects client = (Projects) getClient(profileID);
- ignoreErrors = ignoreErrors==null?false:ignoreErrors;
-
+ ignoreErrors = ignoreErrors == null ? false : ignoreErrors;
+
Project project = client.deleteFileSet(projectID, jsonPathToFileset, force, ignoreErrors);
LOG.info("fileset {} deleted", jsonPathToFileset);
LOG.debug("returning new project: {} ", project.getTheDocument());
diff --git a/src/test/java/org/gcube/application/Project_Tests.java b/src/test/java/org/gcube/application/Project_Tests.java
index d85d080..24561ed 100644
--- a/src/test/java/org/gcube/application/Project_Tests.java
+++ b/src/test/java/org/gcube/application/Project_Tests.java
@@ -100,7 +100,7 @@ public class Project_Tests {
}
}
- // @Before
+ //@Before
public void init() {
readContextSettings();
ScopeProvider.instance.set(CONTEXT);
@@ -295,7 +295,7 @@ public class Project_Tests {
System.out.println(config);
}
- // @Test
+ //@Test
public void getTotalDocument() throws Exception {
System.out.println(clientPrj.getTotalDocument(PROFILE_ID));
@@ -313,6 +313,16 @@ public class Project_Tests {
}
}
+
+ // @Test
+ public void getCountByPhase() throws Exception {
+
+ Integer integer = clientPrj.getCountByPhaseFor(PROFILE_ID, "Published", "OK");
+ System.out.println(integer);
+ integer = clientPrj.getCountByPhaseFor(PROFILE_ID, "Pending Approval", "OK");
+ System.out.println(integer);
+
+ }
// @Test
public void getRelationshipsChain() throws Exception {
diff --git a/src/test/java/org/gcube/application/UCD_Tests.java b/src/test/java/org/gcube/application/UCD_Tests.java
index 001e661..ba038e1 100644
--- a/src/test/java/org/gcube/application/UCD_Tests.java
+++ b/src/test/java/org/gcube/application/UCD_Tests.java
@@ -32,7 +32,6 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
-import org.junit.Test;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;