From deeb1d4685387fc463378937749ea237ad262019 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Thu, 26 Nov 2020 13:18:34 +0100 Subject: [PATCH] Fix storing (lost list) --- .../managers/AbstractRecordManager.java | 105 ++-- .../managers/ConcessioneManager.java | 129 ++--- .../managers/DefatulEMFProvider.java | 3 +- .../application/geoportal/model/Record.java | 6 +- .../model/concessioni/Concessione.java | 468 +++++++++--------- .../model/concessioni/LayerConcessione.java | 144 +++--- .../model/concessioni/RelazioneScavo.java | 86 ++-- .../model/content/AssociatedContent.java | 129 ++--- .../model/content/UploadedImage.java | 103 ++-- .../geoportal/CheckContextConfiguration.java | 2 +- .../application/geoportal/HibernateTest.java | 23 + .../gcube/application/geoportal/UseCases.java | 69 ++- src/test/resources/log4j.properties | 4 +- 13 files changed, 678 insertions(+), 593 deletions(-) create mode 100644 src/test/java/org/gcube/application/geoportal/HibernateTest.java diff --git a/src/main/java/org/gcube/application/geoportal/managers/AbstractRecordManager.java b/src/main/java/org/gcube/application/geoportal/managers/AbstractRecordManager.java index db4ca59..0c2fc04 100644 --- a/src/main/java/org/gcube/application/geoportal/managers/AbstractRecordManager.java +++ b/src/main/java/org/gcube/application/geoportal/managers/AbstractRecordManager.java @@ -37,7 +37,7 @@ public abstract class AbstractRecordManager { } private static EMFProvider defaultProvider=new DefatulEMFProvider(); - + @Synchronized protected static EntityManagerFactory getEMF() { return defaultProvider.getFactory(); @@ -53,10 +53,8 @@ public abstract class AbstractRecordManager { try { log.debug("Looking for record by ID : "+id); EntityTransaction tr=em.getTransaction(); - tr.begin(); Record toReturn=em.find(Record.class, id); log.debug("Loaded Record "+toReturn); - tr.commit(); return toReturn; }finally { if(em.isJoinedToTransaction()) @@ -65,7 +63,7 @@ public abstract class AbstractRecordManager { } } - + public static Collection getList(){ EntityManager em=getEMF().createEntityManager(); try { @@ -73,7 +71,7 @@ public abstract class AbstractRecordManager { EntityTransaction tr=em.getTransaction(); tr.begin(); List toReturn=em.createQuery("select r from Record r ", - Record.class).getResultList(); + Record.class).getResultList(); log.debug("Loaded size "+toReturn.size()); tr.commit(); return toReturn; @@ -83,18 +81,18 @@ public abstract class AbstractRecordManager { em.close(); } } - + public static Collection getListByClass(Class clazz){ EntityManager em=getEMF().createEntityManager(); try { log.debug("Getting entire list"); EntityTransaction tr=em.getTransaction(); tr.begin(); - + String simpleClassName=clazz.getName().substring(clazz.getName().lastIndexOf(".")+1); List toReturn=em.createQuery("select r from "+simpleClassName+" r", - clazz).getResultList(); + clazz).getResultList(); log.debug("Loaded size "+toReturn.size()); tr.commit(); return toReturn; @@ -104,12 +102,12 @@ public abstract class AbstractRecordManager { em.close(); } } -// protected T storeInfo() -// { -// log.debug("Storing Record "+theRecord); -// entityManager.persist(theRecord); -// return theRecord; -// } + // protected T storeInfo() + // { + // log.debug("Storing Record "+theRecord); + // entityManager.persist(theRecord); + // return theRecord; + // } //Transaction management @@ -127,7 +125,7 @@ public abstract class AbstractRecordManager { transaction=entityManager.getTransaction(); transaction.begin(); this.theRecord=theRecord; -// log.debug("Storing Record "+theRecord); + // log.debug("Storing Record "+theRecord); if(theRecord.getId()==0) { log.debug("Passed record ID = 0. Assuming new .."); entityManager.persist(theRecord); @@ -139,7 +137,7 @@ public abstract class AbstractRecordManager { this.contentHandler=new ContentHandler(theRecord); } - + @@ -162,30 +160,44 @@ public abstract class AbstractRecordManager { public T commit(boolean publish) throws PersistenceException,ValidationException, PublishException { log.trace("Committing record "+theRecord+" Publish is "+publish); - ValidationReport report=theRecord.validate(); - log.debug("Validated Report is "+report); - if(publish && report.getStatus().equals(ValidationStatus.ERROR)) - throw new ValidationException(report,"Cannot publish project. See validation report"); + try { + ValidationReport report=theRecord.validate(); + log.debug("Validated Report is "+report); + if(publish && report.getStatus().equals(ValidationStatus.ERROR)) + throw new ValidationException(report,"Cannot publish project. See validation report"); - // storeInfo(); + // storeInfo(); - log.debug("Record is valid, storing changed content"); - contentHandler.storeChanges(publish); - // storeInfo(); + log.debug("Record is valid, storing changed content"); + contentHandler.storeChanges(publish); + // storeInfo(); - if(publish) { - log.debug("Registering centroid of "+theRecord); - registerCentroid(); - // storeInfo(); + if(publish) { + log.debug("Registering centroid of "+theRecord); + registerCentroid(); + // storeInfo(); + } + + + log.debug("Successufully committing "+theRecord); + transaction.commit(); + log.debug("Calling postCommit"); + postcommit(); + return theRecord; + }catch(ValidationException | PublishException | PersistenceException e) { + log.warn("Committing session for "+theRecord); + transaction.rollback(); + throw e; } - - transaction.commit(); - return theRecord; } + protected abstract void postcommit(); + public PublicationReport commitSafely(boolean publish) { log.debug("Safely publishing "+theRecord); + + PublicationReport toReturn=new PublicationReport("Publication Report"); toReturn.setTheRecord(getRecord()); @@ -206,17 +218,23 @@ public abstract class AbstractRecordManager { registerCentroid(); toReturn.addMessage(ValidationStatus.PASSED, "Inserito centroide per record "+theRecord.getId()); } + + log.debug("Committing session for "+theRecord); transaction.commit(); - + } catch (PersistenceException e) { toReturn.addChild(e.getReport()); log.warn("Unexpected internal exception ",e); + log.debug("Rollback Session for "+theRecord); + transaction.rollback(); } catch (PublishException e) { toReturn.addMessage(ValidationStatus.WARNING, "Centroide non registrato"); log.warn("Unexpected internal exception ",e); + log.debug("Committing session for "+theRecord); + transaction.commit(); } - - + + try { log.info("Report is "+toReturn.prettyPrint()); }catch (Exception e) { @@ -227,15 +245,20 @@ public abstract class AbstractRecordManager { } + public void close() { + try { + if(transaction.isActive()) { + transaction.rollback(); + } + entityManager.close(); + }catch(Throwable t) { + log.warn("Exception while closing ",t); + } + } + @Override protected void finalize() throws Throwable { - if(transaction.isActive()) { - transaction.rollback(); - } - entityManager.flush(); - entityManager.close(); - - shutdown(); + close(); } private void registerCentroid() throws PublishException{ diff --git a/src/main/java/org/gcube/application/geoportal/managers/ConcessioneManager.java b/src/main/java/org/gcube/application/geoportal/managers/ConcessioneManager.java index 7b169c8..f14f2e8 100644 --- a/src/main/java/org/gcube/application/geoportal/managers/ConcessioneManager.java +++ b/src/main/java/org/gcube/application/geoportal/managers/ConcessioneManager.java @@ -25,19 +25,30 @@ public class ConcessioneManager extends AbstractRecordManager { protected ConcessioneManager(Concessione theRecord) { super(theRecord); } -@Override -protected PostgisTable getCentroidsTable() { - return DBConstants.Concessioni.CENTROIDS; -} + @Override + protected PostgisTable getCentroidsTable() { + return DBConstants.Concessioni.CENTROIDS; + } + @Override + protected void postcommit() { + transaction.begin(); + log.debug("Updating references.. "); + for(UploadedImage img:getRecord().getImmaginiRappresentative()) { + entityManager.createNativeQuery("Update uploadedimage set record_id="+getRecord().getId()+" where id = "+img.getId()).executeUpdate(); + } + for(LayerConcessione l:getRecord().getPianteFineScavo()) { + entityManager.createNativeQuery("Update layerconcessione set record_id="+getRecord().getId()+" where id = "+l.getId()).executeUpdate(); + } + transaction.commit(); + } + @Override + protected void initCentroidLayer() throws SDIInteractionException { + log.debug("Checking for centroid layer configuration.. "); + SDIManager sdiManager=new SDIManager(); -@Override -protected void initCentroidLayer() throws SDIInteractionException { - log.debug("Checking for centroid layer configuration.. "); - SDIManager sdiManager=new SDIManager(); - - sdiManager.configureCentroidLayer("centroids_concessioni", "gna", "gna_postgis"); -} + sdiManager.configureCentroidLayer("centroids_concessioni", "gna", "gna_postgis"); + } public Concessione setRelazioneScavo(RelazioneScavo rel, InputStreamDescriptor theFile) throws IOException { ContentHandler handler=getContentHandler(); @@ -48,7 +59,7 @@ protected void initCentroidLayer() throws SDIInteractionException { } rel.setRecord(record); - + //Register relazione record.setRelazioneScavo(rel); handler.register(rel, theFile); @@ -60,7 +71,7 @@ protected void initCentroidLayer() throws SDIInteractionException { ContentHandler handler=getContentHandler(); Concessione record=getRecord(); //Add immagine - + img.setRecord(record); if(record.getImmaginiRappresentative()==null) record.setImmaginiRappresentative(new ArrayList()); @@ -82,7 +93,7 @@ protected void initCentroidLayer() throws SDIInteractionException { handler.dispose(record.getPosizionamentoScavo()); layer.setRecord(record); - + //Register posizionamneot record.setPosizionamentoScavo(layer); handler.register(layer, inputStreams); @@ -95,7 +106,7 @@ protected void initCentroidLayer() throws SDIInteractionException { Concessione record=getRecord(); //Add pianta layer.setRecord(record); - + if(record.getPianteFineScavo()==null) record.setPianteFineScavo(new ArrayList()); record.getPianteFineScavo().add(layer); @@ -107,51 +118,51 @@ protected void initCentroidLayer() throws SDIInteractionException { -// @Override -// protected Concessione storeInfo(Concessione toInsert) { -// log.debug("Storing Record "+toInsert); -// EntityManager em=getEMF().createEntityManager(); -// try { -// em.getTransaction().begin(); -// RelazioneScavo relScavo=toInsert.getRelazioneScavo(); -// toInsert.setRelazioneScavo(null); -// List uploadedImages=toInsert.getImmaginiRappresentative(); -// toInsert.setImmaginiRappresentative(null); -// LayerConcessione posizionamentoScavo=toInsert.getPosizionamentoScavo(); -// toInsert.setPosizionamentoScavo(null); -// List pianteFineScavo= toInsert.getPianteFineScavo(); -// toInsert.setPianteFineScavo(null); -// List genericContent=toInsert.getGenericContent(); -// toInsert.setGenericContent(null); -// -// log.debug("Storing empty concessione.. "+toInsert); -// em.persist(toInsert); -// -// if(relScavo!=null) { -// log.debug("Atttaching relazione .. "+relScavo); -// relScavo.setRecord(toInsert); -// toInsert.setRelazioneScavo(relScavo); -// } -// -// if(uploadedImages!=null) { -// log.debug("Attaching images.. "+uploadedImages); -// for(UploadedImage image: uploadedImages) -// image.setRecord(toInsert); -// toInsert.setImmaginiRappresentative(uploadedImages); -// } -// -// if(posizionamentoScavo!=null) { -// toInsert.get -// } -// -// -// em.getTransaction().commit(); -// }finally { -// em.close(); -// } -// } + // @Override + // protected Concessione storeInfo(Concessione toInsert) { + // log.debug("Storing Record "+toInsert); + // EntityManager em=getEMF().createEntityManager(); + // try { + // em.getTransaction().begin(); + // RelazioneScavo relScavo=toInsert.getRelazioneScavo(); + // toInsert.setRelazioneScavo(null); + // List uploadedImages=toInsert.getImmaginiRappresentative(); + // toInsert.setImmaginiRappresentative(null); + // LayerConcessione posizionamentoScavo=toInsert.getPosizionamentoScavo(); + // toInsert.setPosizionamentoScavo(null); + // List pianteFineScavo= toInsert.getPianteFineScavo(); + // toInsert.setPianteFineScavo(null); + // List genericContent=toInsert.getGenericContent(); + // toInsert.setGenericContent(null); + // + // log.debug("Storing empty concessione.. "+toInsert); + // em.persist(toInsert); + // + // if(relScavo!=null) { + // log.debug("Atttaching relazione .. "+relScavo); + // relScavo.setRecord(toInsert); + // toInsert.setRelazioneScavo(relScavo); + // } + // + // if(uploadedImages!=null) { + // log.debug("Attaching images.. "+uploadedImages); + // for(UploadedImage image: uploadedImages) + // image.setRecord(toInsert); + // toInsert.setImmaginiRappresentative(uploadedImages); + // } + // + // if(posizionamentoScavo!=null) { + // toInsert.get + // } + // + // + // em.getTransaction().commit(); + // }finally { + // em.close(); + // } + // } + - @Override protected Map evaluateCentroid(){ diff --git a/src/main/java/org/gcube/application/geoportal/managers/DefatulEMFProvider.java b/src/main/java/org/gcube/application/geoportal/managers/DefatulEMFProvider.java index 0e37744..8d7a477 100644 --- a/src/main/java/org/gcube/application/geoportal/managers/DefatulEMFProvider.java +++ b/src/main/java/org/gcube/application/geoportal/managers/DefatulEMFProvider.java @@ -54,7 +54,8 @@ public class DefatulEMFProvider implements EMFProvider { .put(AvailableSettings.USE_STRUCTURED_CACHE, false) .put(AvailableSettings.STATEMENT_BATCH_SIZE, 20) .put(AvailableSettings.JPA_JDBC_USER, conn.getUser()) - .put(AvailableSettings.JPA_JDBC_PASSWORD, conn.getPwd()) + .put(AvailableSettings.JPA_JDBC_PASSWORD,conn.getPwd()) +// .put(AvailableSettings.AUTO_CLOSE_SESSION, true) .build()); }catch(ConfigurationException e) { diff --git a/src/main/java/org/gcube/application/geoportal/model/Record.java b/src/main/java/org/gcube/application/geoportal/model/Record.java index e28dfe1..858fa3c 100644 --- a/src/main/java/org/gcube/application/geoportal/model/Record.java +++ b/src/main/java/org/gcube/application/geoportal/model/Record.java @@ -63,9 +63,9 @@ public abstract class Record { this.setLastUpdateUser(user.getName()); } - public String asJson() throws JsonProcessingException { - return Serialization.asJSON(this); - } +// public String asJson() throws JsonProcessingException { +// return Serialization.asJSON(this); +// } public ValidationReport validate() { diff --git a/src/main/java/org/gcube/application/geoportal/model/concessioni/Concessione.java b/src/main/java/org/gcube/application/geoportal/model/concessioni/Concessione.java index ace0f75..872300f 100644 --- a/src/main/java/org/gcube/application/geoportal/model/concessioni/Concessione.java +++ b/src/main/java/org/gcube/application/geoportal/model/concessioni/Concessione.java @@ -126,62 +126,62 @@ public class Concessione extends Record{ } - @Override - public String asJson() throws JsonProcessingException { - // Detaching Content ... - if(relazioneScavo!=null) { - relazioneScavo.setRecord(null); - relazioneScavo.detachContent(); - } - if(immaginiRappresentative!=null) - for(UploadedImage img:immaginiRappresentative) { - img.setRecord(null); - img.detachContent(); - } - if(posizionamentoScavo!=null) { - posizionamentoScavo.setRecord(null); - posizionamentoScavo.detachContent(); - } - if(pianteFineScavo!=null) - for(LayerConcessione l:pianteFineScavo) { - l.setRecord(null); - l.detachContent(); - } - if(genericContent!=null) - for(OtherContent o:genericContent) { - o.setRecord(null); - o.detachContent(); - } - - try { - return super.asJson(); - }finally { - //Reattaching content - if(relazioneScavo!=null) { - relazioneScavo.setRecord(this); - relazioneScavo.reattachContent(); - } - if(immaginiRappresentative!=null) - for(UploadedImage img:immaginiRappresentative) { - img.setRecord(this); - img.reattachContent(); - } - if(posizionamentoScavo!=null) { - posizionamentoScavo.setRecord(this); - posizionamentoScavo.reattachContent(); - } - if(pianteFineScavo!=null) - for(LayerConcessione l:pianteFineScavo) { - l.setRecord(this); - l.reattachContent(); - } - if(genericContent!=null) - for(OtherContent o:genericContent) { - o.setRecord(this); - o.reattachContent(); - } - } - } +// @Override +// public String asJson() throws JsonProcessingException { +// // Detaching Content ... +// if(relazioneScavo!=null) { +// relazioneScavo.setRecord(null); +// relazioneScavo.detachContent(); +// } +// if(immaginiRappresentative!=null) +// for(UploadedImage img:immaginiRappresentative) { +// img.setRecord(null); +// img.detachContent(); +// } +// if(posizionamentoScavo!=null) { +// posizionamentoScavo.setRecord(null); +// posizionamentoScavo.detachContent(); +// } +// if(pianteFineScavo!=null) +// for(LayerConcessione l:pianteFineScavo) { +// l.setRecord(null); +// l.detachContent(); +// } +// if(genericContent!=null) +// for(OtherContent o:genericContent) { +// o.setRecord(null); +// o.detachContent(); +// } +// +// try { +// return super.asJson(); +// }finally { +// //Reattaching content +// if(relazioneScavo!=null) { +// relazioneScavo.setRecord(this); +// relazioneScavo.reattachContent(); +// } +// if(immaginiRappresentative!=null) +// for(UploadedImage img:immaginiRappresentative) { +// img.setRecord(this); +// img.reattachContent(); +// } +// if(posizionamentoScavo!=null) { +// posizionamentoScavo.setRecord(this); +// posizionamentoScavo.reattachContent(); +// } +// if(pianteFineScavo!=null) +// for(LayerConcessione l:pianteFineScavo) { +// l.setRecord(this); +// l.reattachContent(); +// } +// if(genericContent!=null) +// for(OtherContent o:genericContent) { +// o.setRecord(this); +// o.reattachContent(); +// } +// } +// } @Override public ValidationReport validate() { @@ -343,196 +343,196 @@ public class Concessione extends Record{ } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; -// result = prime * result + ((authors == null) ? 0 : authors.hashCode()); - result = prime * result + CollectionsUtils.hashCode(authors); -// result = prime * result + ((fontiFinanaziamento == null) ? 0 : fontiFinanaziamento.hashCode()); - result = prime * result + CollectionsUtils.hashCode(fontiFinanziamento); -// result = prime * result + ((immaginiRappresentative == null) ? 0 : immaginiRappresentative.hashCode()); - result = prime * result + CollectionsUtils.hashCode(immaginiRappresentative); -// result = prime * result + ((paroleChiaveICCD == null) ? 0 : paroleChiaveICCD.hashCode()); - result = prime * result + CollectionsUtils.hashCode(paroleChiaveICCD); -// result = prime * result + ((paroleChiaveLibere == null) ? 0 : paroleChiaveLibere.hashCode()); - result = prime * result + CollectionsUtils.hashCode(paroleChiaveLibere); -// result = prime * result + ((pianteFineScavo == null) ? 0 : pianteFineScavo.hashCode()); - result = prime * result + CollectionsUtils.hashCode(pianteFineScavo); -// result = prime * result + ((risorseCorrelate == null) ? 0 : risorseCorrelate.hashCode()); - result = prime * result + CollectionsUtils.hashCode(risorseCorrelate); -// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); - result = prime * result + CollectionsUtils.hashCode(soggetto); -// result = prime * result + ((titolari == null) ? 0 : titolari.hashCode()); - result = prime * result + CollectionsUtils.hashCode(titolari); - - result = prime * result + ((centroidLat == null) ? 0 : centroidLat.hashCode()); - result = prime * result + ((centroidLong == null) ? 0 : centroidLong.hashCode()); - result = prime * result + ((contributore == null) ? 0 : contributore.hashCode()); - result = prime * result + ((dataFineProgetto == null) ? 0 : dataFineProgetto.hashCode()); - result = prime * result + ((dataInizioProgetto == null) ? 0 : dataInizioProgetto.hashCode()); - result = prime * result + ((descrizioneContenuto == null) ? 0 : descrizioneContenuto.hashCode()); - result = prime * result + ((editore == null) ? 0 : editore.hashCode()); - result = prime * result + ((genericContent == null) ? 0 : genericContent.hashCode()); - result = prime * result + ((introduzione == null) ? 0 : introduzione.hashCode()); - - result = prime * result + ((posizionamentoScavo == null) ? 0 : posizionamentoScavo.hashCode()); - result = prime * result + ((relazioneScavo == null) ? 0 : relazioneScavo.hashCode()); - result = prime * result + ((responsabile == null) ? 0 : responsabile.hashCode()); - result = prime * result + ((titolareCopyright == null) ? 0 : titolareCopyright.hashCode()); - result = prime * result + ((titolareLicenza == null) ? 0 : titolareLicenza.hashCode()); - return result; - } +// @Override +// public int hashCode() { +// final int prime = 31; +// int result = 1; +//// result = prime * result + ((authors == null) ? 0 : authors.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(authors); +//// result = prime * result + ((fontiFinanaziamento == null) ? 0 : fontiFinanaziamento.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(fontiFinanziamento); +//// result = prime * result + ((immaginiRappresentative == null) ? 0 : immaginiRappresentative.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(immaginiRappresentative); +//// result = prime * result + ((paroleChiaveICCD == null) ? 0 : paroleChiaveICCD.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(paroleChiaveICCD); +//// result = prime * result + ((paroleChiaveLibere == null) ? 0 : paroleChiaveLibere.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(paroleChiaveLibere); +//// result = prime * result + ((pianteFineScavo == null) ? 0 : pianteFineScavo.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(pianteFineScavo); +//// result = prime * result + ((risorseCorrelate == null) ? 0 : risorseCorrelate.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(risorseCorrelate); +//// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(soggetto); +//// result = prime * result + ((titolari == null) ? 0 : titolari.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(titolari); +// +// result = prime * result + ((centroidLat == null) ? 0 : centroidLat.hashCode()); +// result = prime * result + ((centroidLong == null) ? 0 : centroidLong.hashCode()); +// result = prime * result + ((contributore == null) ? 0 : contributore.hashCode()); +// result = prime * result + ((dataFineProgetto == null) ? 0 : dataFineProgetto.hashCode()); +// result = prime * result + ((dataInizioProgetto == null) ? 0 : dataInizioProgetto.hashCode()); +// result = prime * result + ((descrizioneContenuto == null) ? 0 : descrizioneContenuto.hashCode()); +// result = prime * result + ((editore == null) ? 0 : editore.hashCode()); +// result = prime * result + ((genericContent == null) ? 0 : genericContent.hashCode()); +// result = prime * result + ((introduzione == null) ? 0 : introduzione.hashCode()); +// +// result = prime * result + ((posizionamentoScavo == null) ? 0 : posizionamentoScavo.hashCode()); +// result = prime * result + ((relazioneScavo == null) ? 0 : relazioneScavo.hashCode()); +// result = prime * result + ((responsabile == null) ? 0 : responsabile.hashCode()); +// result = prime * result + ((titolareCopyright == null) ? 0 : titolareCopyright.hashCode()); +// result = prime * result + ((titolareLicenza == null) ? 0 : titolareLicenza.hashCode()); +// return result; +// } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Concessione other = (Concessione) obj; -// if (authors == null) { -// if (other.authors != null) +// @Override +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (obj == null) +// return false; +// if (getClass() != obj.getClass()) +// return false; +// Concessione other = (Concessione) obj; +//// if (authors == null) { +//// if (other.authors != null) +//// return false; +//// } else if (!authors.equals(other.authors)) +//// return false; +// if(!CollectionsUtils.equalsCollections(authors, other.authors)) return false; +// +//// if (fontiFinanaziamento == null) { +//// if (other.fontiFinanaziamento != null) +//// return false; +//// } else if (!fontiFinanaziamento.equals(other.fontiFinanaziamento)) +//// return false; +// if (!CollectionsUtils.equalsCollections(fontiFinanziamento, other.fontiFinanziamento)) return false; +// +//// if (immaginiRappresentative == null) { +//// if (other.immaginiRappresentative != null) +//// return false; +//// } else if (!immaginiRappresentative.equals(other.immaginiRappresentative)) +//// return false; +// if (!CollectionsUtils.equalsCollections(immaginiRappresentative, other.immaginiRappresentative)) return false; +// +//// if (paroleChiaveICCD == null) { +//// if (other.paroleChiaveICCD != null) +//// return false; +//// } else if (!paroleChiaveICCD.equals(other.paroleChiaveICCD)) +//// return false; +// if (!CollectionsUtils.equalsCollections(paroleChiaveICCD, other.paroleChiaveICCD)) return false; +// +//// if (paroleChiaveLibere == null) { +//// if (other.paroleChiaveLibere != null) +//// return false; +//// } else if (!paroleChiaveLibere.equals(other.paroleChiaveLibere)) +//// return false; +// if (!CollectionsUtils.equalsCollections(paroleChiaveLibere, other.paroleChiaveLibere)) return false; +// +//// if (piantaFineScavo == null) { +//// if (other.piantaFineScavo != null) +//// return false; +//// } else if (!piantaFineScavo.equals(other.piantaFineScavo)) +//// return false; +// if (!CollectionsUtils.equalsCollections(pianteFineScavo, other.pianteFineScavo)) return false; +// +//// if (risorseCorrelate == null) { +//// if (other.risorseCorrelate != null) +//// return false; +//// } else if (!risorseCorrelate.equals(other.risorseCorrelate)) +//// return false; +// if (!CollectionsUtils.equalsCollections(risorseCorrelate, other.risorseCorrelate)) return false; +// +//// if (soggetto == null) { +//// if (other.soggetto != null) +//// return false; +//// } else if (!soggetto.equals(other.soggetto)) +//// return false; +// if (!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; +// +//// if (titolari == null) { +//// if (other.titolari != null) +//// return false; +//// } else if (!titolari.equals(other.titolari)) +//// return false; +// if (!CollectionsUtils.equalsCollections(titolari, other.titolari)) return false; +// +// +// if (centroidLat == null) { +// if (other.centroidLat != null) // return false; -// } else if (!authors.equals(other.authors)) +// } else if (!centroidLat.equals(other.centroidLat)) // return false; - if(!CollectionsUtils.equalsCollections(authors, other.authors)) return false; - -// if (fontiFinanaziamento == null) { -// if (other.fontiFinanaziamento != null) +// if (centroidLong == null) { +// if (other.centroidLong != null) +// return false; +// } else if (!centroidLong.equals(other.centroidLong)) // return false; -// } else if (!fontiFinanaziamento.equals(other.fontiFinanaziamento)) -// return false; - if (!CollectionsUtils.equalsCollections(fontiFinanziamento, other.fontiFinanziamento)) return false; - -// if (immaginiRappresentative == null) { -// if (other.immaginiRappresentative != null) +// if (contributore == null) { +// if (other.contributore != null) +// return false; +// } else if (!contributore.equals(other.contributore)) // return false; -// } else if (!immaginiRappresentative.equals(other.immaginiRappresentative)) -// return false; - if (!CollectionsUtils.equalsCollections(immaginiRappresentative, other.immaginiRappresentative)) return false; - -// if (paroleChiaveICCD == null) { -// if (other.paroleChiaveICCD != null) +// if (dataFineProgetto == null) { +// if (other.dataFineProgetto != null) +// return false; +// } else if (!dataFineProgetto.equals(other.dataFineProgetto)) // return false; -// } else if (!paroleChiaveICCD.equals(other.paroleChiaveICCD)) -// return false; - if (!CollectionsUtils.equalsCollections(paroleChiaveICCD, other.paroleChiaveICCD)) return false; - -// if (paroleChiaveLibere == null) { -// if (other.paroleChiaveLibere != null) +// if (dataInizioProgetto == null) { +// if (other.dataInizioProgetto != null) +// return false; +// } else if (!dataInizioProgetto.equals(other.dataInizioProgetto)) // return false; -// } else if (!paroleChiaveLibere.equals(other.paroleChiaveLibere)) -// return false; - if (!CollectionsUtils.equalsCollections(paroleChiaveLibere, other.paroleChiaveLibere)) return false; - -// if (piantaFineScavo == null) { -// if (other.piantaFineScavo != null) +// if (descrizioneContenuto == null) { +// if (other.descrizioneContenuto != null) +// return false; +// } else if (!descrizioneContenuto.equals(other.descrizioneContenuto)) // return false; -// } else if (!piantaFineScavo.equals(other.piantaFineScavo)) -// return false; - if (!CollectionsUtils.equalsCollections(pianteFineScavo, other.pianteFineScavo)) return false; - -// if (risorseCorrelate == null) { -// if (other.risorseCorrelate != null) +// if (editore == null) { +// if (other.editore != null) +// return false; +// } else if (!editore.equals(other.editore)) // return false; -// } else if (!risorseCorrelate.equals(other.risorseCorrelate)) -// return false; - if (!CollectionsUtils.equalsCollections(risorseCorrelate, other.risorseCorrelate)) return false; - -// if (soggetto == null) { -// if (other.soggetto != null) +// if (genericContent == null) { +// if (other.genericContent != null) +// return false; +// } else if (!genericContent.equals(other.genericContent)) // return false; -// } else if (!soggetto.equals(other.soggetto)) -// return false; - if (!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; - -// if (titolari == null) { -// if (other.titolari != null) +// if (introduzione == null) { +// if (other.introduzione != null) +// return false; +// } else if (!introduzione.equals(other.introduzione)) // return false; -// } else if (!titolari.equals(other.titolari)) -// return false; - if (!CollectionsUtils.equalsCollections(titolari, other.titolari)) return false; - - - if (centroidLat == null) { - if (other.centroidLat != null) - return false; - } else if (!centroidLat.equals(other.centroidLat)) - return false; - if (centroidLong == null) { - if (other.centroidLong != null) - return false; - } else if (!centroidLong.equals(other.centroidLong)) - return false; - if (contributore == null) { - if (other.contributore != null) - return false; - } else if (!contributore.equals(other.contributore)) - return false; - if (dataFineProgetto == null) { - if (other.dataFineProgetto != null) - return false; - } else if (!dataFineProgetto.equals(other.dataFineProgetto)) - return false; - if (dataInizioProgetto == null) { - if (other.dataInizioProgetto != null) - return false; - } else if (!dataInizioProgetto.equals(other.dataInizioProgetto)) - return false; - if (descrizioneContenuto == null) { - if (other.descrizioneContenuto != null) - return false; - } else if (!descrizioneContenuto.equals(other.descrizioneContenuto)) - return false; - if (editore == null) { - if (other.editore != null) - return false; - } else if (!editore.equals(other.editore)) - return false; - if (genericContent == null) { - if (other.genericContent != null) - return false; - } else if (!genericContent.equals(other.genericContent)) - return false; - if (introduzione == null) { - if (other.introduzione != null) - return false; - } else if (!introduzione.equals(other.introduzione)) - return false; - - if (posizionamentoScavo == null) { - if (other.posizionamentoScavo != null) - return false; - } else if (!posizionamentoScavo.equals(other.posizionamentoScavo)) - return false; - if (relazioneScavo == null) { - if (other.relazioneScavo != null) - return false; - } else if (!relazioneScavo.equals(other.relazioneScavo)) - return false; - if (responsabile == null) { - if (other.responsabile != null) - return false; - } else if (!responsabile.equals(other.responsabile)) - return false; - if (titolareCopyright == null) { - if (other.titolareCopyright != null) - return false; - } else if (!titolareCopyright.equals(other.titolareCopyright)) - return false; - if (titolareLicenza == null) { - if (other.titolareLicenza != null) - return false; - } else if (!titolareLicenza.equals(other.titolareLicenza)) - return false; - - return true; - } - +// +// if (posizionamentoScavo == null) { +// if (other.posizionamentoScavo != null) +// return false; +// } else if (!posizionamentoScavo.equals(other.posizionamentoScavo)) +// return false; +// if (relazioneScavo == null) { +// if (other.relazioneScavo != null) +// return false; +// } else if (!relazioneScavo.equals(other.relazioneScavo)) +// return false; +// if (responsabile == null) { +// if (other.responsabile != null) +// return false; +// } else if (!responsabile.equals(other.responsabile)) +// return false; +// if (titolareCopyright == null) { +// if (other.titolareCopyright != null) +// return false; +// } else if (!titolareCopyright.equals(other.titolareCopyright)) +// return false; +// if (titolareLicenza == null) { +// if (other.titolareLicenza != null) +// return false; +// } else if (!titolareLicenza.equals(other.titolareLicenza)) +// return false; +// +// return true; +// } +// } diff --git a/src/main/java/org/gcube/application/geoportal/model/concessioni/LayerConcessione.java b/src/main/java/org/gcube/application/geoportal/model/concessioni/LayerConcessione.java index 8ac1527..284769a 100644 --- a/src/main/java/org/gcube/application/geoportal/model/concessioni/LayerConcessione.java +++ b/src/main/java/org/gcube/application/geoportal/model/concessioni/LayerConcessione.java @@ -80,79 +80,79 @@ public class LayerConcessione extends SDILayerDescriptor{ return toReturn; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode()); -// result = prime * result + ((authors == null) ? 0 : authors.hashCode()); - result = prime * result + CollectionsUtils.hashCode(authors); - - - result = prime * result + ((bbox == null) ? 0 : bbox.hashCode()); - result = prime * result + ((metodoRaccoltaDati == null) ? 0 : metodoRaccoltaDati.hashCode()); - result = prime * result + ((scalaAcquisizione == null) ? 0 : scalaAcquisizione.hashCode()); - result = prime * result + ((subTopic == null) ? 0 : subTopic.hashCode()); - result = prime * result + ((topicCategory == null) ? 0 : topicCategory.hashCode()); - result = prime * result + ((valutazioneQualita == null) ? 0 : valutazioneQualita.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - LayerConcessione other = (LayerConcessione) obj; - if (abstractSection == null) { - if (other.abstractSection != null) - return false; - } else if (!abstractSection.equals(other.abstractSection)) - return false; -// if (authors == null) { -// if (other.authors != null) -// return false; -// } else if (!authors.equals(other.authors)) +// @Override +// public int hashCode() { +// final int prime = 31; +// int result = super.hashCode(); +// result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode()); +//// result = prime * result + ((authors == null) ? 0 : authors.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(authors); +// +// +// result = prime * result + ((bbox == null) ? 0 : bbox.hashCode()); +// result = prime * result + ((metodoRaccoltaDati == null) ? 0 : metodoRaccoltaDati.hashCode()); +// result = prime * result + ((scalaAcquisizione == null) ? 0 : scalaAcquisizione.hashCode()); +// result = prime * result + ((subTopic == null) ? 0 : subTopic.hashCode()); +// result = prime * result + ((topicCategory == null) ? 0 : topicCategory.hashCode()); +// result = prime * result + ((valutazioneQualita == null) ? 0 : valutazioneQualita.hashCode()); +// return result; +// } +// +// @Override +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (!super.equals(obj)) // return false; - if(!CollectionsUtils.equalsCollections(authors, other.authors)) return false; - - - if (bbox == null) { - if (other.bbox != null) - return false; - } else if (!bbox.equals(other.bbox)) - return false; - if (metodoRaccoltaDati == null) { - if (other.metodoRaccoltaDati != null) - return false; - } else if (!metodoRaccoltaDati.equals(other.metodoRaccoltaDati)) - return false; - if (scalaAcquisizione == null) { - if (other.scalaAcquisizione != null) - return false; - } else if (!scalaAcquisizione.equals(other.scalaAcquisizione)) - return false; - if (subTopic == null) { - if (other.subTopic != null) - return false; - } else if (!subTopic.equals(other.subTopic)) - return false; - if (topicCategory == null) { - if (other.topicCategory != null) - return false; - } else if (!topicCategory.equals(other.topicCategory)) - return false; - if (valutazioneQualita == null) { - if (other.valutazioneQualita != null) - return false; - } else if (!valutazioneQualita.equals(other.valutazioneQualita)) - return false; - return true; - } - +// if (getClass() != obj.getClass()) +// return false; +// LayerConcessione other = (LayerConcessione) obj; +// if (abstractSection == null) { +// if (other.abstractSection != null) +// return false; +// } else if (!abstractSection.equals(other.abstractSection)) +// return false; +//// if (authors == null) { +//// if (other.authors != null) +//// return false; +//// } else if (!authors.equals(other.authors)) +//// return false; +// if(!CollectionsUtils.equalsCollections(authors, other.authors)) return false; +// +// +// if (bbox == null) { +// if (other.bbox != null) +// return false; +// } else if (!bbox.equals(other.bbox)) +// return false; +// if (metodoRaccoltaDati == null) { +// if (other.metodoRaccoltaDati != null) +// return false; +// } else if (!metodoRaccoltaDati.equals(other.metodoRaccoltaDati)) +// return false; +// if (scalaAcquisizione == null) { +// if (other.scalaAcquisizione != null) +// return false; +// } else if (!scalaAcquisizione.equals(other.scalaAcquisizione)) +// return false; +// if (subTopic == null) { +// if (other.subTopic != null) +// return false; +// } else if (!subTopic.equals(other.subTopic)) +// return false; +// if (topicCategory == null) { +// if (other.topicCategory != null) +// return false; +// } else if (!topicCategory.equals(other.topicCategory)) +// return false; +// if (valutazioneQualita == null) { +// if (other.valutazioneQualita != null) +// return false; +// } else if (!valutazioneQualita.equals(other.valutazioneQualita)) +// return false; +// return true; +// } +// } diff --git a/src/main/java/org/gcube/application/geoportal/model/concessioni/RelazioneScavo.java b/src/main/java/org/gcube/application/geoportal/model/concessioni/RelazioneScavo.java index dbe9b49..769d73d 100644 --- a/src/main/java/org/gcube/application/geoportal/model/concessioni/RelazioneScavo.java +++ b/src/main/java/org/gcube/application/geoportal/model/concessioni/RelazioneScavo.java @@ -45,49 +45,49 @@ public class RelazioneScavo extends AssociatedContent { return toReturn; } - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode()); -// result = prime * result + ((responsabili == null) ? 0 : responsabili.hashCode()); - result = prime * result + CollectionsUtils.hashCode(responsabili); -// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); - result = prime * result + CollectionsUtils.hashCode(soggetto); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - RelazioneScavo other = (RelazioneScavo) obj; - if (abstractSection == null) { - if (other.abstractSection != null) - return false; - } else if (!abstractSection.equals(other.abstractSection)) - return false; -// if (responsabili == null) { -// if (other.responsabili != null) -// return false; -// } else if (!responsabili.equals(other.responsabili)) +// @Override +// public int hashCode() { +// final int prime = 31; +// int result = super.hashCode(); +// result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode()); +//// result = prime * result + ((responsabili == null) ? 0 : responsabili.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(responsabili); +//// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(soggetto); +// return result; +// } +// +// @Override +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (!super.equals(obj)) // return false; - if(!CollectionsUtils.equalsCollections(responsabili, other.responsabili)) return false; - - -// if (soggetto == null) { -// if (other.soggetto != null) -// return false; -// } else if (!soggetto.equals(other.soggetto)) +// if (getClass() != obj.getClass()) // return false; - if(!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; - - - return true; - } - +// RelazioneScavo other = (RelazioneScavo) obj; +// if (abstractSection == null) { +// if (other.abstractSection != null) +// return false; +// } else if (!abstractSection.equals(other.abstractSection)) +// return false; +//// if (responsabili == null) { +//// if (other.responsabili != null) +//// return false; +//// } else if (!responsabili.equals(other.responsabili)) +//// return false; +// if(!CollectionsUtils.equalsCollections(responsabili, other.responsabili)) return false; +// +// +//// if (soggetto == null) { +//// if (other.soggetto != null) +//// return false; +//// } else if (!soggetto.equals(other.soggetto)) +//// return false; +// if(!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; +// +// +// return true; +// } +// } diff --git a/src/main/java/org/gcube/application/geoportal/model/content/AssociatedContent.java b/src/main/java/org/gcube/application/geoportal/model/content/AssociatedContent.java index f88a601..b030fed 100644 --- a/src/main/java/org/gcube/application/geoportal/model/content/AssociatedContent.java +++ b/src/main/java/org/gcube/application/geoportal/model/content/AssociatedContent.java @@ -13,6 +13,7 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; import javax.persistence.OneToMany; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElements; @@ -82,72 +83,72 @@ public abstract class AssociatedContent { }) private List actualContent=new ArrayList<>(); - public void detachContent() { - if(actualContent!=null) - for(PersistedContent p:actualContent) - p.setAssociated(null); - } - - public void reattachContent() { - if(actualContent!=null) - for(PersistedContent p:actualContent) - p.setAssociated(this); - } +// public void detachContent() { +// if(actualContent!=null) +// for(PersistedContent p:actualContent) +// p.setAssociated(null); +// } +// +// public void reattachContent() { +// if(actualContent!=null) +// for(PersistedContent p:actualContent) +// p.setAssociated(this); +// } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; -// result = prime * result + ((actualContent == null) ? 0 : actualContent.hashCode()); - result = prime * result + CollectionsUtils.hashCode(actualContent); - - result = prime * result + ((creationTime == null) ? 0 : creationTime.hashCode()); - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((licenseID == null) ? 0 : licenseID.hashCode()); - result = prime * result + ((policy == null) ? 0 : policy.hashCode()); - result = prime * result + ((titolo == null) ? 0 : titolo.hashCode()); - return result; - } - - - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AssociatedContent other = (AssociatedContent) obj; -// if (actualContent == null) { -// if (other.actualContent != null) -// return false; -// } else if (!actualContent.equals(other.actualContent)) +// @Override +// public int hashCode() { +// final int prime = 31; +// int result = 1; +//// result = prime * result + ((actualContent == null) ? 0 : actualContent.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(actualContent); +// +// result = prime * result + ((creationTime == null) ? 0 : creationTime.hashCode()); +// result = prime * result + (int) (id ^ (id >>> 32)); +// result = prime * result + ((licenseID == null) ? 0 : licenseID.hashCode()); +// result = prime * result + ((policy == null) ? 0 : policy.hashCode()); +// result = prime * result + ((titolo == null) ? 0 : titolo.hashCode()); +// return result; +// } +// +// +// +// @Override +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (obj == null) // return false; - if(!CollectionsUtils.equalsCollections(actualContent, other.actualContent)) return false; - - if (creationTime == null) { - if (other.creationTime != null) - return false; - } else if (!creationTime.equals(other.creationTime)) - return false; - if (id != other.id) - return false; - if (licenseID == null) { - if (other.licenseID != null) - return false; - } else if (!licenseID.equals(other.licenseID)) - return false; - if (policy != other.policy) - return false; - if (titolo == null) { - if (other.titolo != null) - return false; - } else if (!titolo.equals(other.titolo)) - return false; - return true; - } +// if (getClass() != obj.getClass()) +// return false; +// AssociatedContent other = (AssociatedContent) obj; +//// if (actualContent == null) { +//// if (other.actualContent != null) +//// return false; +//// } else if (!actualContent.equals(other.actualContent)) +//// return false; +// if(!CollectionsUtils.equalsCollections(actualContent, other.actualContent)) return false; +// +// if (creationTime == null) { +// if (other.creationTime != null) +// return false; +// } else if (!creationTime.equals(other.creationTime)) +// return false; +// if (id != other.id) +// return false; +// if (licenseID == null) { +// if (other.licenseID != null) +// return false; +// } else if (!licenseID.equals(other.licenseID)) +// return false; +// if (policy != other.policy) +// return false; +// if (titolo == null) { +// if (other.titolo != null) +// return false; +// } else if (!titolo.equals(other.titolo)) +// return false; +// return true; +// } diff --git a/src/main/java/org/gcube/application/geoportal/model/content/UploadedImage.java b/src/main/java/org/gcube/application/geoportal/model/content/UploadedImage.java index ad163a9..517acb1 100644 --- a/src/main/java/org/gcube/application/geoportal/model/content/UploadedImage.java +++ b/src/main/java/org/gcube/application/geoportal/model/content/UploadedImage.java @@ -5,7 +5,10 @@ import java.util.List; import javax.persistence.DiscriminatorValue; import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import org.gcube.application.geoportal.model.Record; import org.gcube.application.geoportal.utils.CollectionsUtils; import lombok.Getter; @@ -14,7 +17,6 @@ import lombok.ToString; @Getter @Setter -@ToString(callSuper=true) @Entity @DiscriminatorValue("IMAGE") @@ -29,53 +31,60 @@ public class UploadedImage extends AssociatedContent { @ElementCollection(targetClass=String.class) private List soggetto; - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((didascalia == null) ? 0 : didascalia.hashCode()); - result = prime * result + ((format == null) ? 0 : format.hashCode()); -// result = prime * result + ((responsabili == null) ? 0 : responsabili.hashCode()); - result = prime * result + CollectionsUtils.hashCode(responsabili); -// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); - result = prime * result + CollectionsUtils.hashCode(soggetto); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - UploadedImage other = (UploadedImage) obj; - if (didascalia == null) { - if (other.didascalia != null) - return false; - } else if (!didascalia.equals(other.didascalia)) - return false; - if (format == null) { - if (other.format != null) - return false; - } else if (!format.equals(other.format)) - return false; -// if (responsabili == null) { -// if (other.responsabili != null) -// return false; -// } else if (!responsabili.equals(other.responsabili)) + + + + + + + +// @Override +// public int hashCode() { +// final int prime = 31; +// int result = super.hashCode(); +// result = prime * result + ((didascalia == null) ? 0 : didascalia.hashCode()); +// result = prime * result + ((format == null) ? 0 : format.hashCode()); +//// result = prime * result + ((responsabili == null) ? 0 : responsabili.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(responsabili); +//// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode()); +// result = prime * result + CollectionsUtils.hashCode(soggetto); +// return result; +// } +// +// @Override +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (!super.equals(obj)) // return false; - if(!CollectionsUtils.equalsCollections(responsabili, other.responsabili)) return false; - -// if (soggetto == null) { -// if (other.soggetto != null) -// return false; -// } else if (!soggetto.equals(other.soggetto)) +// if (getClass() != obj.getClass()) // return false; - if(!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; - - return true; - } +// UploadedImage other = (UploadedImage) obj; +// if (didascalia == null) { +// if (other.didascalia != null) +// return false; +// } else if (!didascalia.equals(other.didascalia)) +// return false; +// if (format == null) { +// if (other.format != null) +// return false; +// } else if (!format.equals(other.format)) +// return false; +//// if (responsabili == null) { +//// if (other.responsabili != null) +//// return false; +//// } else if (!responsabili.equals(other.responsabili)) +//// return false; +// if(!CollectionsUtils.equalsCollections(responsabili, other.responsabili)) return false; +// +//// if (soggetto == null) { +//// if (other.soggetto != null) +//// return false; +//// } else if (!soggetto.equals(other.soggetto)) +//// return false; +// if(!CollectionsUtils.equalsCollections(soggetto, other.soggetto)) return false; +// +// return true; +// } } diff --git a/src/test/java/org/gcube/application/geoportal/CheckContextConfiguration.java b/src/test/java/org/gcube/application/geoportal/CheckContextConfiguration.java index 7669cdc..cc493d1 100644 --- a/src/test/java/org/gcube/application/geoportal/CheckContextConfiguration.java +++ b/src/test/java/org/gcube/application/geoportal/CheckContextConfiguration.java @@ -20,7 +20,7 @@ public class CheckContextConfiguration { TokenSetter.set("/gcube/devNext/NextNext"); // TokenSetter.set("/pred4s/preprod/preVRE"); - TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"); +// TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype"); // System.out.println("Checking for internal .. "); // ConcessioneManager manager=ManagerFactory.getByRecord(new Concessione()); diff --git a/src/test/java/org/gcube/application/geoportal/HibernateTest.java b/src/test/java/org/gcube/application/geoportal/HibernateTest.java new file mode 100644 index 0000000..0c0c6c9 --- /dev/null +++ b/src/test/java/org/gcube/application/geoportal/HibernateTest.java @@ -0,0 +1,23 @@ +package org.gcube.application.geoportal; + +import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; + +import org.gcube.application.geoportal.managers.DefatulEMFProvider; +import org.gcube.application.geoportal.managers.EMFProvider; + +public class HibernateTest { + + public static void main(String[] args) { + TokenSetter.set("/gcube/devsec/devVRE"); + EMFProvider provider=new DefatulEMFProvider(); + EntityManager manager=provider.getFactory().createEntityManager(); + EntityTransaction t=manager.getTransaction(); + t.begin(); +// manager.createNativeQuery("Update uploadedimages set record_id="" where id = "").executeUpdate(); + t.commit(); + manager.close(); + provider.shutdown(); + } + +} diff --git a/src/test/java/org/gcube/application/geoportal/UseCases.java b/src/test/java/org/gcube/application/geoportal/UseCases.java index 6f9baaf..8098589 100644 --- a/src/test/java/org/gcube/application/geoportal/UseCases.java +++ b/src/test/java/org/gcube/application/geoportal/UseCases.java @@ -13,7 +13,9 @@ import org.gcube.application.geoportal.model.concessioni.Concessione; import org.gcube.application.geoportal.model.concessioni.LayerConcessione; import org.gcube.application.geoportal.model.concessioni.RelazioneScavo; import org.gcube.application.geoportal.model.content.UploadedImage; -import org.gcube.application.geoportal.model.report.PublicationReport; +import org.gcube.application.geoportal.model.fault.PersistenceException; +import org.gcube.application.geoportal.model.fault.PublishException; +import org.gcube.application.geoportal.model.fault.ValidationException; import org.gcube.application.geoportal.model.report.ValidationReport; import org.gcube.application.geoportal.model.report.ValidationReport.ValidationStatus; import org.gcube.application.geoportal.utils.Files; @@ -29,24 +31,33 @@ public class UseCases { // TokenSetter.set("/pred4s/preprod/preVRE"); - try { + try { + + //CREATE NEW int numConcessioni=1; - Concessione conc=null; + Concessione registered=null; System.out.println("Try to create.. "+numConcessioni); for(int i=0;i data are published into the SDI - Boolean publish=true; + Boolean publish=false; //NB la validazione viene CMQ triggerata a commit time. //In caso di errore viene lanciata una ValidationException @@ -130,19 +142,19 @@ public class UseCases { *scrittura sul DB di applicazione sia dei meta che dei vari link */ //Metodo con eccezioni -// Concessione registered=manager.commit(publish); + Concessione registered=manager.commit(publish); //Metodo con report - PublicationReport pubReport=manager.commitSafely(publish); - Concessione registered=(Concessione) pubReport.getTheRecord(); - - System.out.println("REGISTERED "+registered); - - System.out.println("Report is "+pubReport.prettyPrint()); - Assert.assertFalse(pubReport.getStatus().equals(ValidationStatus.ERROR)); - +// PublicationReport pubReport=manager.commitSafely(publish); +// Concessione registered=(Concessione) pubReport.getTheRecord(); +// +// System.out.println("REGISTERED "+registered); +// +// System.out.println("Report is "+pubReport.prettyPrint()); +// Assert.assertFalse(pubReport.getStatus().equals(ValidationStatus.ERROR)); + manager.close(); return registered; //--- FINALLY --/ @@ -150,10 +162,15 @@ public class UseCases { public static Concessione readConcessione(long id) { - - ConcessioneManager manager=ManagerFactory.getByRecordID(id); + ConcessioneManager manager=null; + try { + manager=ManagerFactory.getByRecordID(id); System.out.println(manager.getRecord()); return manager.getRecord(); + }finally { + if(manager!=null) + manager.close(); + } } @@ -170,7 +187,7 @@ public class UseCases { StringBuilder builder=new StringBuilder(); for(Concessione r : ManagerFactory.getList(Concessione.class)) { try{ - r.asJson(); + Serialization.asJSON(r); }catch(Throwable t) { System.err.println(t); } diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties index 719fa38..eb1d9b9 100644 --- a/src/test/resources/log4j.properties +++ b/src/test/resources/log4j.properties @@ -1,8 +1,8 @@ -log4j.rootLogger=DEBUG, stdout +log4j.rootLogger=WARN, stdout +log4j.org.gcube.application=DEBUG, stdout #CONSOLE log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Threshold=INFO log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %d{dd MMM yyyy ;HH:mm:ss.SSS} - %m%n