package org.gcube.application.geoportal.clients; import com.fasterxml.jackson.core.JsonProcessingException; import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.gcube.application.geoportal.client.DefaultDocumentsClient; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.configuration.Configuration; import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.junit.Test; import sun.net.www.content.text.Generic; import java.rmi.RemoteException; import java.time.LocalDateTime; import java.util.concurrent.atomic.AtomicLong; import static junit.framework.TestCase.assertTrue; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.*; import static org.gcube.application.geoportal.client.utils.Serialization.write; import static org.junit.Assume.assumeTrue; @Slf4j public class ProfiledDocumentsTest> extends GenericUseCases { // protected String getProfileID(){return "basic";} // protected C getClient(){ // return (C) customModel(getProfileID(), Project.class, DefaultDocumentsClient.class).build(); // } @Test public void registerNew() throws RemoteException, JsonProcessingException { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Projects client = (Projects) getClient(); Document theDoc= Document.parse("{\n" + "\"posizionamentoScavo\" :{\n" + "\t\"titolo\" : \"mio titolo\"}}"); theDoc.put("startTime", LocalDateTime.now()); Project p =client.createNew(theDoc); log.debug("Registered project (AS JSON) : {}", write(p)); } @Test public void getConfiguration() throws Exception { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Projects client = (Projects) getClient(); Configuration config=client.getConfiguration(); System.out.println("Configuration is "+ config); } @Test public void list() throws Exception { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Projects client = (Projects) getClient(); AtomicLong counter=new AtomicLong(0); client.query(new QueryRequest()).forEachRemaining( M -> counter.incrementAndGet()); System.out.println("Found "+counter.get()+" elements"); System.out.println("Getting JSON "); System.out.println(client.queryForJSON(new QueryRequest())); } @Test public void scanStatusByID() throws Exception { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Projects client = (Projects) getClient(); AtomicLong counter=new AtomicLong(0); client.query(new QueryRequest()).forEachRemaining( m -> { System.out.print(counter.incrementAndGet()+ ", ID : "+m.getId()); try { M proj=client.getById(m.getId()); System.out.println("... OK.. STATUS : "+proj.getLifecycleInformation()); } catch (RemoteException e) { System.err.println(" Error with "+m.getId()); System.err.println(e); System.out.println("... ERRR !!!!"); } }); } }