Read countByPhase from configuration [#25598] #10

Merged
francesco.mangiacrapa merged 1 commits from feature_25598 into master 2023-09-11 14:19:21 +02:00
5 changed files with 56 additions and 12 deletions

View File

@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file. 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). 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] ## [v2.2.1]
- Reduced/Optimized some LOGs [#25539] - Reduced/Optimized some LOGs [#25539]

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.application</groupId> <groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-common</artifactId> <artifactId>geoportal-data-common</artifactId>
<version>2.2.1</version> <version>2.3.0-SNAPSHOT</version>
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description> <description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
<scm> <scm>

View File

@ -58,6 +58,7 @@ import com.mongodb.BasicDBObjectBuilder;
*/ */
public class ProjectsCaller { public class ProjectsCaller {
public static final String DOCUMENT_STORE_COLLECTION = "DOCUMENT-STORE-COLLECTION";
private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class); private static Logger LOG = LoggerFactory.getLogger(GeoportalClientCaller.class);
/** /**
@ -208,7 +209,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) { for (Archive archive : listArchives) {
String theType = archive.getString("_type"); String theType = archive.getString("_type");
if (theType.equalsIgnoreCase("DOCUMENT-STORE-COLLECTION")) { if (theType.equalsIgnoreCase(DOCUMENT_STORE_COLLECTION)) {
String totalDocumentAre = archive.get("count").toString(); String totalDocumentAre = archive.get("count").toString();
int total = Integer.parseInt(totalDocumentAre); int total = Integer.parseInt(totalDocumentAre);
LOG.info("total docs for profileID: {}, are: {}", profileID, total); LOG.info("total docs for profileID: {}, are: {}", profileID, total);
@ -234,7 +235,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) { for (Archive archive : listArchives) {
String theType = archive.getString("_type"); 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() com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build(); .jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson(); String toJSON = archive.toJson();
@ -255,6 +256,36 @@ public class ProjectsCaller {
return null; 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<Project> client = (Projects<Project>) getClient(profileID);
Configuration config = client.getConfiguration();
List<Archive> 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. * Gets the phases into document store collection.
* *
@ -270,7 +301,7 @@ public class ProjectsCaller {
for (Archive archive : listArchives) { for (Archive archive : listArchives) {
String theType = archive.getString("_type"); 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() com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build(); .jsonProvider(new JsonOrgJsonProvider()).build();
String toJSON = archive.toJson(); String toJSON = archive.toJson();
@ -402,14 +433,14 @@ public class ProjectsCaller {
* @return the project * @return the project
* @throws RemoteException the remote exception * @throws RemoteException the remote exception
*/ */
public Project deleteFileset(String profileID, String projectID, String jsonPathToFileset, Boolean force, Boolean ignoreErrors) public Project deleteFileset(String profileID, String projectID, String jsonPathToFileset, Boolean force,
throws RemoteException { Boolean ignoreErrors) throws RemoteException {
LOG.info("deleteFileset called for profileID {} and projectID {}, fileset path: {}", profileID, projectID, LOG.info("deleteFileset called for profileID {} and projectID {}, fileset path: {}", profileID, projectID,
jsonPathToFileset); jsonPathToFileset);
Projects<Project> client = (Projects<Project>) getClient(profileID); Projects<Project> client = (Projects<Project>) getClient(profileID);
ignoreErrors = ignoreErrors==null?false:ignoreErrors; ignoreErrors = ignoreErrors == null ? false : ignoreErrors;
Project project = client.deleteFileSet(projectID, jsonPathToFileset, force, ignoreErrors); Project project = client.deleteFileSet(projectID, jsonPathToFileset, force, ignoreErrors);
LOG.info("fileset {} deleted", jsonPathToFileset); LOG.info("fileset {} deleted", jsonPathToFileset);

View File

@ -100,7 +100,7 @@ public class Project_Tests {
} }
} }
// @Before //@Before
public void init() { public void init() {
readContextSettings(); readContextSettings();
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -295,7 +295,7 @@ public class Project_Tests {
System.out.println(config); System.out.println(config);
} }
// @Test //@Test
public void getTotalDocument() throws Exception { public void getTotalDocument() throws Exception {
System.out.println(clientPrj.getTotalDocument(PROFILE_ID)); System.out.println(clientPrj.getTotalDocument(PROFILE_ID));
@ -314,6 +314,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 // @Test
public void getRelationshipsChain() throws Exception { public void getRelationshipsChain() throws Exception {
System.out.println("getRelationshipsChain test"); System.out.println("getRelationshipsChain test");

View File

@ -32,7 +32,6 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.junit.Before; import org.junit.Before;
import org.junit.Test;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;