280 lines
9.9 KiB
Java
280 lines
9.9 KiB
Java
package org.gcube.application;
|
|
|
|
import java.io.IOException;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
|
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
|
|
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
|
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
|
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
|
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
|
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
|
public class Project_Tests {
|
|
|
|
private ProjectsCaller client = null;
|
|
// private static String CONTEXT = "/pred4s/preprod/preVRE";
|
|
// private static String TOKEN = ""; //preVRE
|
|
|
|
private static String CONTEXT = "/gcube/devsec/devVRE";
|
|
private static String TOKEN = ""; // devVRE
|
|
private static String PROFILE_ID = "profiledConcessioni";
|
|
private static String PROJECT_ID = "632c633155e2947b0278c999";
|
|
|
|
@Before
|
|
public void getClient() {
|
|
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
client = GeoportalClientCaller.projects();
|
|
}
|
|
|
|
// @Test
|
|
public void getList() throws Exception {
|
|
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
|
|
|
int i = 0;
|
|
for (Project project : listOfProjects) {
|
|
System.out.println(++i + ") " + project);
|
|
}
|
|
}
|
|
|
|
// @Test
|
|
public void getByID() throws Exception {
|
|
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
|
System.out.println(projectDV);
|
|
|
|
LinkedHashMap<String, Object> theMap = projectDV.getTheDocument().getDocumentAsMap();
|
|
for (String key : theMap.keySet()) {
|
|
Object theValue = theMap.get(key);
|
|
System.out.println("The key: " + key + " has value: " + theValue);
|
|
}
|
|
}
|
|
|
|
// @Test
|
|
public void getListProjectsDV() throws Exception {
|
|
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
int i = 0;
|
|
for (Project project : listOfProjects) {
|
|
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
|
System.out.println(++i + ") " + projectDV);
|
|
}
|
|
|
|
}
|
|
|
|
// @Test
|
|
public void getResultDocumentForID() {
|
|
try {
|
|
ProjectsCaller projects = GeoportalClientCaller.projects();
|
|
Project project = projects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
ResultDocumentDV documentDV = ConvertToDataValueObjectModel.toResultDocumentDV(project);
|
|
System.out.println("returning: " + documentDV);
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
// @Test
|
|
public void getListProjectsDVFiltered() throws Exception {
|
|
// List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
|
|
|
SearchingFilter filter = new SearchingFilter();
|
|
|
|
// Where Clause
|
|
List<WhereClause> conditions = new ArrayList<WhereClause>();
|
|
Map<String, Object> searchInto = new HashMap<String, Object>();
|
|
// searchInto.put("_id", "61f0299baf51592c36795f52");
|
|
// searchInto.put("_theDocument.nome", "Test progetto con clustering di
|
|
// fileset");
|
|
WhereClause whereClause = new WhereClause(LOGICAL_OP.AND, searchInto);
|
|
conditions.add(whereClause);
|
|
filter.setConditions(conditions);
|
|
|
|
LinkedHashMap<String, Object> projection = new LinkedHashMap<String, Object>();
|
|
// default
|
|
projection.put("_theDocument.nome", 1);
|
|
projection.put("_profileID", 1);
|
|
projection.put("_profileVersion", 1);
|
|
projection.put("_version", 1);
|
|
projection.put("_theDocument", 1);
|
|
|
|
projection.put("_theDocument.paroleChiaveLibere", 1);
|
|
projection.put("_theDocument.editore", 1);
|
|
projection.put("_theDocument.paroleChiaveICCD", 1);
|
|
projection.put("_theDocument.responsabile", 1);
|
|
|
|
projection.put("_theDocument.introduzione", 1);
|
|
projection.put("_theDocument.authors", 1);
|
|
projection.put("_theDocument.dataInizioProgetto", 1);
|
|
|
|
filter.setProjection(projection);
|
|
|
|
Integer totalDocs = client.getTotalDocument(PROFILE_ID);
|
|
|
|
Iterator<Project> projects = client.queryOnMongo(PROFILE_ID, totalDocs, 0, 10, filter);
|
|
|
|
List<ResultDocumentDV> results = ConvertToDataValueObjectModel.toListResultDocument(projects);
|
|
int i = 0;
|
|
for (ResultDocumentDV projectDV : results) {
|
|
System.out.println(++i + ") " + projectDV);
|
|
}
|
|
|
|
// TEST TO PROJECT DV
|
|
/*
|
|
* ProjectDVBuilder projectBuilder =
|
|
* ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
*
|
|
* List<ProjectDV> listProjects =
|
|
* ConvertToDataValueObjectModel.toListProject(projects, projectBuilder); i = 0;
|
|
* for (ProjectDV projectDV : listProjects) { System.out.println(++i + ") " +
|
|
* projectDV); }
|
|
*/
|
|
}
|
|
|
|
// @Test
|
|
public void getLifecycleForProjectId() throws Exception {
|
|
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
LifecycleInformation lci = project.getLifecycleInformation();
|
|
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lci);
|
|
System.out.println(liDV);
|
|
//
|
|
}
|
|
|
|
// @Test
|
|
public void getConfiguration() throws Exception {
|
|
Configuration config = client.getConfiguration(PROFILE_ID);
|
|
System.out.println(config);
|
|
}
|
|
|
|
// @Test
|
|
public void getTotalDocument() throws Exception {
|
|
|
|
System.out.println(client.getTotalDocument(PROFILE_ID));
|
|
}
|
|
|
|
// @Test
|
|
public void getListPhases() throws Exception {
|
|
|
|
List<String> idsPhases = client.getIDsPhases(PROFILE_ID);
|
|
System.out.println(idsPhases);
|
|
|
|
PhaseDV[] phases = client.getPhasesIntoDocumentStoreCollection(PROFILE_ID);
|
|
for (PhaseDV phaseDV : phases) {
|
|
System.out.println(phaseDV);
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
public void getRelationshipsChain() throws Exception {
|
|
System.out.println("getRelationshipsChain test");
|
|
|
|
Iterator<RelationshipNavigationObject> iterator = client.getRelationshipChain(PROFILE_ID, PROJECT_ID);
|
|
|
|
while (iterator.hasNext()) {
|
|
RelationshipNavigationObject nav = (RelationshipNavigationObject) iterator.next();
|
|
visitRelationshipsChain(nav);
|
|
}
|
|
}
|
|
|
|
public void visitRelationshipsChain(RelationshipNavigationObject nav) {
|
|
|
|
if (nav == null)
|
|
return;
|
|
|
|
printObject(nav.getTarget());
|
|
|
|
for (RelationshipNavigationObject relationship : nav.getChildren()) {
|
|
visitRelationshipsChain(relationship);
|
|
}
|
|
}
|
|
|
|
public void printObject(Project project) {
|
|
|
|
System.out.println("Project id: " + project.getId() + ", profile: " + project.getProfileID() + ", doc: "
|
|
+ project.getTheDocument().toJson());
|
|
}
|
|
|
|
// @Test
|
|
public void deserializeISOJSONObjectAsDate() throws Exception {
|
|
|
|
String jsonDate = "{hour=0, minute=0, " + "dayOfYear=259, " + "dayOfWeek=MONDAY, " + "dayOfMonth=16, "
|
|
+ "monthValue=9, " + "year=2019, " + "month=SEPTEMBER, " + "second=0, " + "nano=0, "
|
|
+ "chronology={calendarType=iso8601, id=ISO}" + "}";
|
|
|
|
try {
|
|
|
|
/*
|
|
* ObjectMapper objectMapper = new ObjectMapper(); JavaTimeModule javaTimeModule
|
|
* = new JavaTimeModule(); javaTimeModule.addDeserializer(LocalDate.class, new
|
|
* MyLocalDateDeserializer()); javaTimeModule.addSerializer(LocalDate.class, new
|
|
* MyLocalDateSerializer()); objectMapper.registerModule(javaTimeModule);
|
|
*
|
|
* objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
* objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
|
|
* false); objectMapper.configure(SerializationFeature.
|
|
* WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false); LocalDate date =
|
|
* objectMapper.readerFor(LocalDate.class).readValue(jsonDate);
|
|
* System.out.println(date);
|
|
*/
|
|
|
|
// checking if the jsonDate is a LocalDate
|
|
// LocalDateTime date =
|
|
// org.gcube.application.geoportal.client.utils.Serialization.read(jsonDate,
|
|
// LocalDateTime.class);
|
|
LocalDate date = org.gcube.application.geoportal.client.utils.Serialization.read(jsonDate, LocalDate.class);
|
|
System.out.println(date);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static final DateTimeFormatter FULL_FORMATTER = DateTimeFormatter.ofPattern("uuuuMMdd_HH-mm-ss");
|
|
|
|
public static class MyLocalDateSerializer extends JsonSerializer<LocalDate> {
|
|
@Override
|
|
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
|
gen.writeString(value.format(FULL_FORMATTER));
|
|
}
|
|
}
|
|
|
|
public static class MyLocalDateDeserializer extends JsonDeserializer<LocalDate> {
|
|
|
|
@Override
|
|
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
|
return LocalDate.parse(p.getValueAsString(), FULL_FORMATTER);
|
|
}
|
|
}
|
|
}
|