From 148d95db50dc9deaf6060012fe18dd3642074c38 Mon Sep 17 00:00:00 2001 From: valeriovinciarelli Date: Wed, 31 May 2023 17:33:59 +0200 Subject: [PATCH] Fixes the namedqueries used by categories --- .../dbapiimplementation/CategoryDBAPI.java | 18 ++++-- .../epos/handler/dbapi/model/EDMCategory.java | 20 +++---- src/test/java/tests/Tests.java | 59 ++++++++++++++----- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/epos/handler/dbapi/dbapiimplementation/CategoryDBAPI.java b/src/main/java/org/epos/handler/dbapi/dbapiimplementation/CategoryDBAPI.java index 0f233ab..9becf40 100644 --- a/src/main/java/org/epos/handler/dbapi/dbapiimplementation/CategoryDBAPI.java +++ b/src/main/java/org/epos/handler/dbapi/dbapiimplementation/CategoryDBAPI.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.UUID; import static org.epos.handler.dbapi.util.DBUtil.getOneFromDB; @@ -51,10 +52,6 @@ public LinkedEntity save(Category eposDataModelObject, EntityManager em, String edmCategoryScheme = getOneFromDB(em, EDMCategoryScheme.class, "EDMCategoryScheme.findByUid", "UID", eposDataModelObject.getInScheme()); - //edmCategoryScheme = new EDMCategoryScheme(); - //edmCategoryScheme.setUid(eposDataModelObject.getInScheme()); - //edmCategoryScheme.setId(UUID.randomUUID().toString()); - //em.persist(edmCategoryScheme); } edmObject.setScheme(edmCategoryScheme.getId()); } @@ -116,12 +113,23 @@ protected Category mapFromDB(Object edmObject) { EDMCategory edm = (EDMCategory) edmObject; - o.setInstanceId(edm.getId()); o.setUid(edm.getUid()); o.setInScheme(edm.getScheme()); o.setName(edm.getName()); o.setDescription(edm.getDescription()); + + if(edm.getIspartofCategoriesById_0().size()==1) + o.setBroader(((List)edm.getIspartofCategoriesById_0()).get(0).getCategory1Id()); + + + if(edm.getIspartofCategoriesById().size()>0) { + ArrayList narrowers = new ArrayList<>(); + for(EDMIspartofCategory ed : ((List)edm.getIspartofCategoriesById())) { + narrowers.add(ed.getCategory2Id()); + } + o.setNarrower(narrowers); + } return o; } diff --git a/src/main/java/org/epos/handler/dbapi/model/EDMCategory.java b/src/main/java/org/epos/handler/dbapi/model/EDMCategory.java index 2922dca..2f2822a 100644 --- a/src/main/java/org/epos/handler/dbapi/model/EDMCategory.java +++ b/src/main/java/org/epos/handler/dbapi/model/EDMCategory.java @@ -91,7 +91,7 @@ public int hashCode() { return Objects.hash(id, description, name); } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getDataproductCategoriesById() { return dataproductCategoriesById; } @@ -100,7 +100,7 @@ public void setDataproductCategoriesById(Collection data this.dataproductCategoriesById = dataproductCategoriesById; } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getEquipmentCategoriesById() { return equipmentCategoriesById; } @@ -109,7 +109,7 @@ public void setEquipmentCategoriesById(Collection equipmen this.equipmentCategoriesById = equipmentCategoriesById; } - @OneToMany(mappedBy = "categoryByCategory1Id") + @OneToMany(mappedBy = "categoryByCategory1Id",fetch=FetchType.EAGER) public Collection getIspartofCategoriesById() { return ispartofCategoriesById; } @@ -118,7 +118,7 @@ public void setIspartofCategoriesById(Collection ispartofCa this.ispartofCategoriesById = ispartofCategoriesById; } - @OneToMany(mappedBy = "categoryByCategory2Id") + @OneToMany(mappedBy = "categoryByCategory2Id",fetch=FetchType.EAGER) public Collection getIspartofCategoriesById_0() { return ispartofCategoriesById_0; } @@ -127,7 +127,7 @@ public void setIspartofCategoriesById_0(Collection ispartof this.ispartofCategoriesById_0 = ispartofCategoriesById_0; } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getPublicationCategoriesById() { return publicationCategoriesById; } @@ -136,7 +136,7 @@ public void setPublicationCategoriesById(Collection publ this.publicationCategoriesById = publicationCategoriesById; } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getServiceCategoriesById() { return serviceCategoriesById; } @@ -145,7 +145,7 @@ public void setServiceCategoriesById(Collection serviceCateg this.serviceCategoriesById = serviceCategoriesById; } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getSoftwareapplicationCategoriesById() { return softwareapplicationCategoriesById; } @@ -154,7 +154,7 @@ public void setSoftwareapplicationCategoriesById(Collection getSoftwaresourcecodeCategoriesById() { return softwaresourcecodeCategoriesById; } @@ -163,7 +163,7 @@ public void setSoftwaresourcecodeCategoriesById(Collection getWebserviceCategoriesById() { return webserviceCategoriesById; } @@ -172,7 +172,7 @@ public void setWebserviceCategoriesById(Collection webser this.webserviceCategoriesById = webserviceCategoriesById; } - @OneToMany(mappedBy = "categoryByCategoryId") + @OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER) public Collection getFacilityCategoriesById() { return facilityCategoriesById; } diff --git a/src/test/java/tests/Tests.java b/src/test/java/tests/Tests.java index faedb65..469174c 100644 --- a/src/test/java/tests/Tests.java +++ b/src/test/java/tests/Tests.java @@ -1,28 +1,57 @@ package tests; -import java.util.ArrayList; +import java.util.List; import org.epos.eposdatamodel.Category; -import org.epos.eposdatamodel.CategoryScheme; -import org.epos.eposdatamodel.DataProduct; -import org.epos.eposdatamodel.Identifier; -import org.epos.eposdatamodel.State; import org.epos.handler.dbapi.dbapiimplementation.CategoryDBAPI; -import org.epos.handler.dbapi.dbapiimplementation.CategorySchemeDBAPI; -import org.epos.handler.dbapi.dbapiimplementation.DataProductDBAPI; -import org.epos.handler.dbapi.model.EDMIspartofCategory; + public class Tests { - + public static void main(String[] args) { - - CategorySchemeDBAPI scheme = new CategorySchemeDBAPI(); - System.out.println(scheme.getAll()); - - CategoryDBAPI cat = new CategoryDBAPI(); - System.out.println(cat.getAll()); + CategoryDBAPI cats = new CategoryDBAPI(); + List categoriesList = cats.getAll(); + + Tests.recursivePrint(categoriesList, null); + + + } + + public static void recursivePrint(List categoriesList, String id) { + if(id==null) { + for(Category cat : categoriesList) { + System.out.println("---------- NODE -------- "); + System.out.println("UID "+cat.getUid()); + System.out.println("NAME "+cat.getName()); + System.out.println("DESCRIPTION "+cat.getDescription()); + + if(cat.getBroader()!=null) { + System.out.println("--------- BROADER ----------"); + recursivePrint(categoriesList, cat.getBroader()); + System.out.println("--------- END BROADER ----------"); + } + if(cat.getNarrower()!=null) { + System.out.println("---------- NARROWERS -------- "); + for(String uid : cat.getNarrower()) { + recursivePrint(categoriesList, uid); + } + System.out.println("----------END NARROWERS -------- "); + } + } + }else { + for(Category cat : categoriesList) { + if(cat.getInstanceId().equals(id)) { + System.out.println("---------- SUBNODE -------- "); + System.out.println("UID "+cat.getUid()); + System.out.println("NAME "+cat.getName()); + System.out.println("DESCRIPTION "+cat.getDescription()); + System.out.println("---------- END SUBNODE -------- "); + } + } + + } } }