Read Concessioni
This commit is contained in:
parent
7326df1ff8
commit
c008ca42da
|
@ -2,21 +2,22 @@ package org.gcube.application.geoportal.client.legacy;
|
||||||
|
|
||||||
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.concessioni;
|
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.concessioni;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.json.Json;
|
|
||||||
import javax.json.JsonArray;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.report.PublicationReport;
|
||||||
import org.gcube.application.geoportal.common.rest.ConcessioniI;
|
import org.gcube.application.geoportal.common.rest.ConcessioniI;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.MappingIterator;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
@ -29,8 +30,8 @@ public class ConcessioniManager {
|
||||||
|
|
||||||
private static ObjectMapper mapper = new ObjectMapper();
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
private static ObjectReader concessioniReader=mapper.readerFor(Concessione.class);
|
private static ObjectReader concessioniReader=null;
|
||||||
private static ObjectReader collectionReader=mapper.readerFor(Collection.class);
|
private static ObjectReader collectionReader=null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||||
|
@ -39,6 +40,10 @@ public class ConcessioniManager {
|
||||||
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||||
mapper.registerModule(new JavaTimeModule());
|
mapper.registerModule(new JavaTimeModule());
|
||||||
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||||
|
|
||||||
|
|
||||||
|
concessioniReader=mapper.readerFor(Concessione.class);
|
||||||
|
collectionReader=mapper.readerFor(Collection.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConcessioniI service;
|
private ConcessioniI service;
|
||||||
|
@ -72,10 +77,24 @@ public class ConcessioniManager {
|
||||||
try {
|
try {
|
||||||
String result=service.getAll();
|
String result=service.getAll();
|
||||||
log.debug("Reading json object : "+result);
|
log.debug("Reading json object : "+result);
|
||||||
JsonArray array=Json.createReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8))).readArray();
|
|
||||||
|
|
||||||
|
Collection<String> coll=collectionReader.readValue(result);
|
||||||
|
// JsonArray array=Json.createReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8))).readArray();
|
||||||
ArrayList<Concessione> toReturn=new ArrayList<Concessione>();
|
ArrayList<Concessione> toReturn=new ArrayList<Concessione>();
|
||||||
for(int i=0;i<array.size();i++)
|
|
||||||
toReturn.add(concessioniReader.readValue(array.get(i).toString()));
|
// MappingIterator<Concessione> it=concessioniReader.readValues(result);
|
||||||
|
// while(it.hasNext())
|
||||||
|
// toReturn.add(it.next());
|
||||||
|
|
||||||
|
for(String s: coll) {
|
||||||
|
toReturn.add(concessioniReader.readValue(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for(int i=0;i<array.size();i++)
|
||||||
|
// for()
|
||||||
|
// toReturn.add(concessioniReader.readValue(array.get(i).toString()));
|
||||||
return toReturn;
|
return toReturn;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -85,5 +104,43 @@ public class ConcessioniManager {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register session
|
||||||
|
private Concessione lastRegistered;
|
||||||
|
|
||||||
|
public Concessione registerNew(Concessione c) throws Exception {
|
||||||
|
try {
|
||||||
|
String response=service.create(mapper.writeValueAsString(c));
|
||||||
|
lastRegistered=concessioniReader.readValue(response);
|
||||||
|
return lastRegistered;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setRelazioneScavo(RelazioneScavo rel, InputStreamDescriptor theFile) {
|
||||||
|
// String response=service.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addImmagineRappresentativa(UploadedImage img, InputStreamDescriptor theFile) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosizionamento(LayerConcessione layer, InputStreamDescriptor...inputStreams ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPiantaScavo(LayerConcessione layer, InputStreamDescriptor...inputStreams ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicationReport commitRegistered() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,21 @@ public class DefaultConcessioni implements ConcessioniI{
|
||||||
return delegate.make(call);
|
return delegate.make(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public String update(final String id, final String updated) throws Exception {
|
||||||
|
// Call<WebTarget,String> call= new Call<WebTarget,String>(){
|
||||||
|
// @Override
|
||||||
|
// public String call(WebTarget endpoint) throws Exception {
|
||||||
|
// return endpoint.path(id).request(MediaType.APPLICATION_JSON).put(Entity.entity(updated, MediaType.APPLICATION_JSON)).readEntity(String.class);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// return delegate.make(call);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String update(final String id, final String updated) throws Exception {
|
public String addSection(String arg0, String arg1) throws Exception {
|
||||||
Call<WebTarget,String> call= new Call<WebTarget,String>(){
|
// TODO Auto-generated method stub
|
||||||
@Override
|
return null;
|
||||||
public String call(WebTarget endpoint) throws Exception {
|
|
||||||
return endpoint.path(id).request(MediaType.APPLICATION_JSON).put(Entity.entity(updated, MediaType.APPLICATION_JSON)).readEntity(String.class);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return delegate.make(call);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,46 @@
|
||||||
package org.gcube.application.geoportal.common.model;
|
package org.gcube.application.geoportal.common.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.gcube.application.geoportal.client.legacy.ConcessioniManager;
|
import org.gcube.application.geoportal.client.legacy.ConcessioniManager;
|
||||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConcessioniTests {
|
public class ConcessioniTests {
|
||||||
|
|
||||||
|
static boolean STOP_ON_FAIL=true;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setScope(){
|
public void setScope(){
|
||||||
TokenSetter.set("/gcube/devNext/NextNext");
|
// TokenSetter.set("/gcube/devNext/NextNext");
|
||||||
|
TokenSetter.set("/gcube/devsec/devVRE");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readAll() throws Exception {
|
public void readAll() throws Exception {
|
||||||
ConcessioniManager manager=new ConcessioniManager();
|
ConcessioniManager manager=new ConcessioniManager();
|
||||||
ArrayList<Concessione> found=manager.getList();
|
ArrayList<Concessione> found=manager.getList();
|
||||||
|
System.out.println("Found "+found.size()+" elements.");
|
||||||
|
final AtomicLong byId=new AtomicLong(0);
|
||||||
|
final AtomicLong valid=new AtomicLong(0);
|
||||||
|
final AtomicLong error=new AtomicLong(0);
|
||||||
|
found.forEach((Concessione c )->{
|
||||||
|
try {
|
||||||
|
manager.getById(c.getId()+"");
|
||||||
|
byId.incrementAndGet();
|
||||||
|
if(c.validate().getStatus().equals(ValidationStatus.PASSED))
|
||||||
|
valid.incrementAndGet();
|
||||||
|
|
||||||
|
}catch(Throwable t) {
|
||||||
|
error.incrementAndGet();
|
||||||
|
if(STOP_ON_FAIL) {
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}else t.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
System.out.println("Valid count "+valid.get()+"Load BY ID : "+byId.get()+" Error : "+error.get()+" OUT OF "+found.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue