Read countByPhase from configuration [#25598] #10
|
@ -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]
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<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>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -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<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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -402,14 +433,14 @@ public class ProjectsCaller {
|
|||
* @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<Project> client = (Projects<Project>) 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);
|
||||
|
|
|
@ -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));
|
||||
|
@ -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
|
||||
public void getRelationshipsChain() throws Exception {
|
||||
System.out.println("getRelationshipsChain test");
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue