2022-02-24 18:09:30 +01:00
package org.gcube.application.geoportal.service.profiledDocuments ;
2022-02-14 17:06:32 +01:00
2022-08-31 18:06:19 +02:00
import lombok.extern.slf4j.Slf4j ;
2022-02-14 17:06:32 +01:00
import org.bson.Document ;
2022-02-15 19:02:44 +01:00
import org.gcube.application.cms.serialization.Serialization ;
2022-10-25 16:57:41 +02:00
import org.gcube.application.cms.tests.model.BasicTests ;
2022-03-04 14:23:20 +01:00
import org.gcube.application.geoportal.common.model.document.Project ;
2022-04-11 17:23:27 +02:00
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference ;
2022-02-14 17:06:32 +01:00
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation ;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest ;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest ;
2022-09-26 16:11:20 +02:00
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field ;
2022-10-25 16:57:41 +02:00
import org.gcube.application.geoportal.common.rest.InterfaceConstants ;
2022-02-14 17:06:32 +01:00
import org.gcube.application.geoportal.common.utils.StorageUtils ;
2022-10-25 16:57:41 +02:00
import org.gcube.application.geoportal.common.utils.tests.GCubeTest ;
2022-04-08 11:13:25 +02:00
import org.gcube.application.geoportal.service.utils.UserUtils ;
2022-02-14 17:06:32 +01:00
import org.junit.Test ;
2022-10-25 16:57:41 +02:00
import javax.management.relation.Relation ;
import javax.ws.rs.client.Entity ;
2022-02-14 17:06:32 +01:00
import javax.ws.rs.client.WebTarget ;
2022-10-25 16:57:41 +02:00
import javax.ws.rs.core.MediaType ;
2022-08-31 18:06:19 +02:00
import java.time.LocalDateTime ;
2022-10-25 16:57:41 +02:00
import static org.junit.Assert.assertEquals ;
2022-02-14 17:06:32 +01:00
import static org.junit.Assert.assertTrue ;
2022-10-25 16:57:41 +02:00
import static org.junit.Assume.assumeTrue ;
2022-02-14 17:06:32 +01:00
2022-08-31 18:06:19 +02:00
@Slf4j
2022-02-16 17:12:54 +01:00
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests {
2022-02-14 17:06:32 +01:00
2022-04-08 11:13:25 +02:00
2022-02-14 17:06:32 +01:00
@Override
protected WebTarget baseTarget ( ) {
2022-10-25 16:57:41 +02:00
assumeTrue ( GCubeTest . isTestInfrastructureEnabled ( ) ) ;
2022-02-14 17:06:32 +01:00
String testProfileId = " profiledConcessioni " ;
2022-08-31 18:06:19 +02:00
return super . baseTarget ( ) . path ( testProfileId ) ;
2022-02-14 17:06:32 +01:00
}
@Test
public void testSDI ( ) throws Exception {
2022-10-25 16:57:41 +02:00
assumeTrue ( GCubeTest . isTestInfrastructureEnabled ( ) ) ;
2022-04-08 11:13:25 +02:00
UserUtils . DEFAULT_ROLES . add ( " Data-Manager " ) ;
2022-02-14 17:06:32 +01:00
// Create new
2022-08-31 18:06:19 +02:00
2022-11-29 11:41:40 +01:00
Document theDoc = Document . parse ( " { " +
" \" posizionamentoScavo \" :{ \" titolo \" : \" mio titolo \" }, \" nome \" : \" TEST SDI Extensions \" } " ) ;
2022-03-04 11:30:48 +01:00
2022-08-31 18:06:19 +02:00
theDoc . put ( " startTime " , LocalDateTime . now ( ) ) ;
log . debug ( " Sending {} " , theDoc ) ;
log . debug ( " AS JSON : {} " , Serialization . write ( theDoc ) ) ;
2022-03-04 14:23:20 +01:00
Project doc = createNew ( theDoc ) ;
2022-03-04 11:30:48 +01:00
2022-08-31 18:06:19 +02:00
log . debug ( " Received : {} " , doc ) ;
log . debug ( " AS JSON : {} " , Serialization . write ( doc ) ) ;
2022-03-04 11:30:48 +01:00
2022-02-16 17:12:54 +01:00
2022-02-14 17:06:32 +01:00
// register filesets
doc = upload (
new StorageUtils ( ) ,
2022-02-23 17:13:22 +01:00
doc . getId ( ) ,
2022-05-18 18:24:57 +02:00
" $.posizionamentoScavo " ,
2022-03-22 17:29:25 +01:00
" fileset " ,
2022-05-18 18:24:57 +02:00
" $.posizionamentoScavo. " + Field . CHILDREN + " [?(@.fileset)] " ,
2022-03-04 11:30:48 +01:00
null ,
2022-02-14 17:06:32 +01:00
RegisterFileSetRequest . ClashOptions . MERGE_EXISTING ,
2022-11-29 11:41:40 +01:00
" concessioni/pos.SHP " ) ;
2022-02-14 17:06:32 +01:00
2022-02-15 19:02:44 +01:00
System . out . println ( " Registered posizionamento, result is " + Serialization . write ( doc ) ) ;
2022-02-14 17:06:32 +01:00
// invoke step SUBMIT-FOR-REVIEW
2022-03-07 17:59:06 +01:00
StepExecutionRequest submitReq = new StepExecutionRequest ( ) ;
submitReq . setStepID ( " SUBMIT-FOR-REVIEW " ) ;
2022-09-20 12:20:04 +02:00
// doc=step(doc.getId(),submitReq);
2022-10-18 15:09:49 +02:00
doc = step ( doc . getId ( ) , submitReq ) ;
2022-02-14 17:06:32 +01:00
System . out . println ( doc ) ;
assertTrue ( doc . getLifecycleInformation ( ) . getLastOperationStatus ( ) . equals ( LifecycleInformation . Status . OK ) ) ;
2022-03-07 17:59:06 +01:00
// invoke step Publish
StepExecutionRequest approveDraftReq = new StepExecutionRequest ( ) ;
2022-04-08 13:17:52 +02:00
approveDraftReq . setStepID ( " APPROVE-SUBMITTED " ) ;
2022-03-07 17:59:06 +01:00
doc = step ( doc . getId ( ) , approveDraftReq ) ;
System . out . println ( doc ) ;
assertTrue ( doc . getLifecycleInformation ( ) . getLastOperationStatus ( ) . equals ( LifecycleInformation . Status . OK ) ) ;
2022-04-11 17:23:27 +02:00
assertTrue ( doc . getIdentificationReferenceByType ( SpatialReference . SPATIAL_REFERENCE_TYPE ) . size ( ) = = 1 ) ;
System . out . println ( " Project " + doc . getId ( ) + " published with spatial reference " + doc . getIdentificationReferenceByType ( SpatialReference . SPATIAL_REFERENCE_TYPE ) . get ( 0 ) ) ;
2022-02-14 17:06:32 +01:00
}
2022-08-31 18:06:19 +02:00
2022-10-25 16:57:41 +02:00
@Test
public void testRelations ( ) throws Exception {
assumeTrue ( GCubeTest . isTestInfrastructureEnabled ( ) ) ;
Document theDoc = Document . parse ( " { \ n " +
" \" posizionamentoScavo \" :{ \ n " +
" \ t \" titolo \" : \" mio titolo \" }} " ) ;
Project doc1 = createNew ( theDoc ) ;
Project doc2 = createNew ( theDoc ) ;
String rel = " follows " ;
String reverse = " precedes " ;
log . info ( " Creating relation " ) ;
doc1 = setRelation ( doc1 , doc2 . getId ( ) , null , rel ) ;
log . debug ( " JSON Doc 1 : {} " , Serialization . write ( doc1 ) ) ;
// check relation
assertTrue ( doc1 . getRelationships ( ) . size ( ) = = 1 ) ;
assertEquals ( doc1 . getRelationships ( ) . get ( 0 ) . getTargetID ( ) , doc2 . getId ( ) ) ;
assertEquals ( doc1 . getRelationships ( ) . get ( 0 ) . getTargetUCD ( ) , doc2 . getProfileID ( ) ) ;
assertEquals ( doc1 . getRelationships ( ) . get ( 0 ) . getRelationshipName ( ) , rel ) ;
// check reverse
doc2 = getById ( doc2 . getId ( ) ) ;
log . debug ( " JSON Doc 2 : {} " , Serialization . write ( doc2 ) ) ;
assertTrue ( doc2 . getRelationships ( ) . size ( ) = = 1 ) ;
assertEquals ( doc2 . getRelationships ( ) . get ( 0 ) . getTargetID ( ) , doc1 . getId ( ) ) ;
assertEquals ( doc2 . getRelationships ( ) . get ( 0 ) . getTargetUCD ( ) , doc1 . getProfileID ( ) ) ;
assertEquals ( doc2 . getRelationships ( ) . get ( 0 ) . getRelationshipName ( ) , reverse ) ;
2022-11-09 18:36:03 +01:00
StepExecutionRequest stepReq = new StepExecutionRequest ( ) ;
stepReq . setStepID ( " SUBMIT-FOR-REVIEW " ) ;
step ( doc1 . getId ( ) , stepReq ) ;
2022-10-25 16:57:41 +02:00
// clean
doc2 = deleteRelation ( doc2 , doc1 . getId ( ) , doc1 . getProfileID ( ) , reverse ) ;
log . debug ( " JSON Doc 2 : {} " , Serialization . write ( doc2 ) ) ;
assertTrue ( doc2 . getRelationships ( ) = = null | | doc2 . getRelationships ( ) . isEmpty ( ) ) ;
doc1 = getById ( doc1 . getId ( ) ) ;
log . debug ( " JSON Doc 1 : {} " , Serialization . write ( doc1 ) ) ;
assertTrue ( doc1 . getRelationships ( ) = = null | | doc1 . getRelationships ( ) . isEmpty ( ) ) ;
}
2022-08-31 18:06:19 +02:00
@Test
public void delete ( ) throws Exception {
Document theDoc = Document . parse ( " { \ n " +
" \" posizionamentoScavo \" :{ \ n " +
" \ t \" titolo \" : \" mio titolo \" }} " ) ;
theDoc . put ( " startTime " , LocalDateTime . now ( ) ) ;
log . debug ( " sendi " ) ;
Project doc = createNew ( theDoc ) ;
}
2022-02-14 17:06:32 +01:00
}