|
|
|
@ -1,23 +1,14 @@
|
|
|
|
|
package org.gcube.application.geoportal.service.legacy;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.UncheckedIOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManagerFactory;
|
|
|
|
|
import javax.persistence.SharedCacheMode;
|
|
|
|
|
import javax.persistence.ValidationMode;
|
|
|
|
|
import javax.persistence.spi.ClassTransformer;
|
|
|
|
|
import javax.persistence.spi.PersistenceUnitInfo;
|
|
|
|
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
import javax.ws.rs.client.Entity;
|
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
|
import javax.ws.rs.core.Application;
|
|
|
|
@ -34,6 +25,7 @@ import org.gcube.application.geoportal.model.content.AssociatedContent;
|
|
|
|
|
import org.gcube.application.geoportal.model.content.UploadedImage;
|
|
|
|
|
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
|
|
|
|
import org.gcube.application.geoportal.model.report.PublicationReport;
|
|
|
|
|
import org.gcube.application.geoportal.model.report.ValidationReport.ValidationStatus;
|
|
|
|
|
import org.gcube.application.geoportal.service.GeoportalService;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.StorageClientProvider;
|
|
|
|
@ -51,7 +43,7 @@ import org.junit.Test;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class Concessioni extends JerseyTest {
|
|
|
|
|
public class ConcessioniTest extends JerseyTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -84,14 +76,6 @@ public class Concessioni extends JerseyTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void failPublish() throws com.fasterxml.jackson.core.JsonProcessingException, IOException {
|
|
|
|
|
Concessione toCreate=TestModel.prepareEmptyConcessione();
|
|
|
|
|
|
|
|
|
|
Concessione conc=pushConcessione(toCreate);
|
|
|
|
|
System.out.println(publish(conc.getId()+"").prettyPrint());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void list() throws JsonProcessingException, IOException{
|
|
|
|
|
WebTarget target=target(InterfaceConstants.Methods.CONCESSIONI);
|
|
|
|
@ -108,6 +92,15 @@ public class Concessioni extends JerseyTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void failPublish() throws com.fasterxml.jackson.core.JsonProcessingException, IOException {
|
|
|
|
|
Concessione toCreate=TestModel.prepareEmptyConcessione();
|
|
|
|
|
|
|
|
|
|
Concessione conc=pushConcessione(toCreate);
|
|
|
|
|
System.out.println(publish(conc.getId()+"").prettyPrint());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void createNew() throws IOException {
|
|
|
|
@ -119,28 +112,49 @@ public class Concessioni extends JerseyTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void publishNew() throws IOException, RemoteBackendException, ConfigurationException {
|
|
|
|
|
Concessione toCreate=TestModel.prepareEmptyConcessione();
|
|
|
|
|
WebTarget target=target(InterfaceConstants.Methods.CONCESSIONI);
|
|
|
|
|
Response resp=target.request(MediaType.APPLICATION_JSON).put(Entity.entity(toCreate.asJson(), MediaType.APPLICATION_JSON));
|
|
|
|
|
String resString=resp.readEntity(String.class);
|
|
|
|
|
System.out.println("Resp String is "+resString);
|
|
|
|
|
Concessione registered=Serialization.read(resString, Concessione.class);
|
|
|
|
|
System.out.println("Registered concessione at : "+registered);
|
|
|
|
|
Concessione registered = pushConcessione(toCreate);
|
|
|
|
|
System.out.println("Registered at "+registered.asJson());
|
|
|
|
|
Concessione fullTemplate=TestModel.prepareConcessione();
|
|
|
|
|
|
|
|
|
|
//Push Relazione
|
|
|
|
|
publishSection(registered.getId()+"",formRequest(Section.RELAZIONE,fullTemplate.getRelazioneScavo(),"concessioni/relazione.pdf"));
|
|
|
|
|
assertNotNull(getById(registered.getId()+"").getRelazioneScavo());
|
|
|
|
|
|
|
|
|
|
//Push Immagini
|
|
|
|
|
for(UploadedImage img:fullTemplate.getImmaginiRappresentative())
|
|
|
|
|
publishSection(registered.getId()+"",formRequest(Section.UPLOADED_IMG,img,"concessioni/immagine.png"));
|
|
|
|
|
assertNotNull(getById(registered.getId()+"").getImmaginiRappresentative());
|
|
|
|
|
assertTrue(getById(registered.getId()+"").getImmaginiRappresentative().size()==fullTemplate.getImmaginiRappresentative().size());
|
|
|
|
|
|
|
|
|
|
//Push Posizinamento
|
|
|
|
|
publishSection(registered.getId()+"",formRequest(Section.POSIZIONAMENTO,fullTemplate.getPosizionamentoScavo(),"concessioni/pos.dbf","concessioni/pos.shp"));
|
|
|
|
|
assertNotNull(getById(registered.getId()+"").getPosizionamentoScavo());
|
|
|
|
|
|
|
|
|
|
//Push piante
|
|
|
|
|
for(LayerConcessione l:fullTemplate.getPianteFineScavo())
|
|
|
|
|
publishSection(registered.getId()+"",formRequest(Section.PIANTA,l,"concessioni/pos.dbf","concessioni/pos.shp"));
|
|
|
|
|
assertNotNull(getById(registered.getId()+"").getPianteFineScavo());
|
|
|
|
|
assertTrue(getById(registered.getId()+"").getPianteFineScavo().size()==fullTemplate.getPianteFineScavo().size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("REPORT IS "+publish(registered.getId()+""));
|
|
|
|
|
|
|
|
|
|
Concessione reloaded = getById(registered.getId()+"");
|
|
|
|
|
System.out.println("Goind to publish "+reloaded.asJson());
|
|
|
|
|
PublicationReport report=publish(registered.getId()+"");
|
|
|
|
|
System.out.println("REPORT IS "+report.prettyPrint()+"");
|
|
|
|
|
// System.out.println("Concessione is "+report.getTheRecord().asJson());
|
|
|
|
|
assertTrue(report.getStatus().equals(ValidationStatus.PASSED));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ACTUAL METHODS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PublicationReport publish(String id) throws com.fasterxml.jackson.core.JsonProcessingException, IOException {
|
|
|
|
|
WebTarget target=target(InterfaceConstants.Methods.CONCESSIONI);
|
|
|
|
|
Response resp=target.path(id).request(MediaType.APPLICATION_JSON).post(null);
|
|
|
|
|
Response resp=target.path("publish").path(id).request(MediaType.APPLICATION_JSON).put(Entity.entity("sopmething", MediaType.APPLICATION_JSON));
|
|
|
|
|
if(resp.getStatus()<200||resp.getStatus()>=300)
|
|
|
|
|
System.err.println("RESP STATUS IS "+resp.getStatus());
|
|
|
|
|
String resString=resp.readEntity(String.class);
|
|
|
|
|
System.out.println("Resp String is "+resString);
|
|
|
|
|
PublicationReport registered=Serialization.read(resString, PublicationReport.class);
|
|
|
|
@ -158,13 +172,19 @@ public class Concessioni extends JerseyTest {
|
|
|
|
|
String sId=ImplementationProvider.get().getStorageProvider().store(
|
|
|
|
|
new FileInputStream(Files.getFileFromResources(f)));
|
|
|
|
|
desc.setShubID(sId);
|
|
|
|
|
toReturn.getStreams().add(desc);
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response publishSection(String id, AddSectionToConcessioneRequest request) {
|
|
|
|
|
WebTarget target=target(InterfaceConstants.Methods.CONCESSIONI);
|
|
|
|
|
return target.path(id).request(MediaType.APPLICATION_JSON).put(Entity.entity(request, MediaType.APPLICATION_JSON));
|
|
|
|
|
Response resp=target.path("section").path(id).request(MediaType.APPLICATION_JSON).put(Entity.entity(request, MediaType.APPLICATION_JSON));
|
|
|
|
|
if(resp.getStatus()<200||resp.getStatus()>=300) {
|
|
|
|
|
System.err.println("RESP STATUS IS "+resp.getStatus());
|
|
|
|
|
System.err.println("RESP IS "+resp.readEntity(String.class));
|
|
|
|
|
}
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Concessione pushConcessione(Concessione c) throws com.fasterxml.jackson.core.JsonProcessingException, IOException {
|
|
|
|
@ -177,118 +197,15 @@ public class Concessioni extends JerseyTest {
|
|
|
|
|
return registered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Concessione getById(String id) throws com.fasterxml.jackson.core.JsonProcessingException, IOException {
|
|
|
|
|
WebTarget target=target(InterfaceConstants.Methods.CONCESSIONI);
|
|
|
|
|
Response resp=target.path(id).request(MediaType.APPLICATION_JSON).get();
|
|
|
|
|
if(resp.getStatus()<200||resp.getStatus()>=300)
|
|
|
|
|
System.err.println("RESP STATUS IS "+resp.getStatus());
|
|
|
|
|
String resString=resp.readEntity(String.class);
|
|
|
|
|
System.out.println("Resp String is "+resString);
|
|
|
|
|
return Serialization.read(resString, Concessione.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static PersistenceUnitInfo archiverPersistenceUnitInfo() {
|
|
|
|
|
|
|
|
|
|
final List<String> MANAGED_CLASSES=Arrays.asList(new String[] {
|
|
|
|
|
"org.gcube.application.geoportal.model.Record",
|
|
|
|
|
"org.gcube.application.geoportal.model.concessioni.Concessione",
|
|
|
|
|
"org.gcube.application.geoportal.model.concessioni.LayerConcessione",
|
|
|
|
|
"org.gcube.application.geoportal.model.concessioni.RelazioneScavo",
|
|
|
|
|
|
|
|
|
|
"org.gcube.application.geoportal.model.content.AssociatedContent",
|
|
|
|
|
"org.gcube.application.geoportal.model.content.GeoServerContent",
|
|
|
|
|
"org.gcube.application.geoportal.model.content.OtherContent",
|
|
|
|
|
"org.gcube.application.geoportal.model.content.PersistedContent",
|
|
|
|
|
"org.gcube.application.geoportal.model.content.UploadedImage",
|
|
|
|
|
"org.gcube.application.geoportal.model.content.WorkspaceContent",
|
|
|
|
|
|
|
|
|
|
"org.gcube.application.geoportal.model.gis.ShapeFileLayerDescriptor",
|
|
|
|
|
"org.gcube.application.geoportal.model.gis.SDILayerDescriptor"});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new PersistenceUnitInfo() {
|
|
|
|
|
@Override
|
|
|
|
|
public String getPersistenceUnitName() {
|
|
|
|
|
return "ApplicationPersistenceUnit";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getPersistenceProviderClassName() {
|
|
|
|
|
return "org.hibernate.jpa.HibernatePersistenceProvider";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PersistenceUnitTransactionType getTransactionType() {
|
|
|
|
|
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DataSource getJtaDataSource() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DataSource getNonJtaDataSource() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getMappingFileNames() {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<URL> getJarFileUrls() {
|
|
|
|
|
try {
|
|
|
|
|
return Collections.list(this.getClass()
|
|
|
|
|
.getClassLoader()
|
|
|
|
|
.getResources(""));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new UncheckedIOException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public URL getPersistenceUnitRootUrl() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getManagedClassNames() {
|
|
|
|
|
return MANAGED_CLASSES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean excludeUnlistedClasses() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SharedCacheMode getSharedCacheMode() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ValidationMode getValidationMode() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Properties getProperties() {
|
|
|
|
|
return new Properties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getPersistenceXMLSchemaVersion() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ClassLoader getClassLoader() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addTransformer(ClassTransformer transformer) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ClassLoader getNewTempClassLoader() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|