Skip to content

Commit

Permalink
Fixes the namedqueries used by categories
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriovinciarelli authored and valeriovinciarelli committed May 31, 2023
1 parent d93bfb4 commit 148d95d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<EDMIspartofCategory>)edm.getIspartofCategoriesById_0()).get(0).getCategory1Id());


if(edm.getIspartofCategoriesById().size()>0) {
ArrayList<String> narrowers = new ArrayList<>();
for(EDMIspartofCategory ed : ((List<EDMIspartofCategory>)edm.getIspartofCategoriesById())) {
narrowers.add(ed.getCategory2Id());
}
o.setNarrower(narrowers);
}

return o;
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/epos/handler/dbapi/model/EDMCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public int hashCode() {
return Objects.hash(id, description, name);
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMDataproductCategory> getDataproductCategoriesById() {
return dataproductCategoriesById;
}
Expand All @@ -100,7 +100,7 @@ public void setDataproductCategoriesById(Collection<EDMDataproductCategory> data
this.dataproductCategoriesById = dataproductCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMEquipmentCategory> getEquipmentCategoriesById() {
return equipmentCategoriesById;
}
Expand All @@ -109,7 +109,7 @@ public void setEquipmentCategoriesById(Collection<EDMEquipmentCategory> equipmen
this.equipmentCategoriesById = equipmentCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategory1Id")
@OneToMany(mappedBy = "categoryByCategory1Id",fetch=FetchType.EAGER)
public Collection<EDMIspartofCategory> getIspartofCategoriesById() {
return ispartofCategoriesById;
}
Expand All @@ -118,7 +118,7 @@ public void setIspartofCategoriesById(Collection<EDMIspartofCategory> ispartofCa
this.ispartofCategoriesById = ispartofCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategory2Id")
@OneToMany(mappedBy = "categoryByCategory2Id",fetch=FetchType.EAGER)
public Collection<EDMIspartofCategory> getIspartofCategoriesById_0() {
return ispartofCategoriesById_0;
}
Expand All @@ -127,7 +127,7 @@ public void setIspartofCategoriesById_0(Collection<EDMIspartofCategory> ispartof
this.ispartofCategoriesById_0 = ispartofCategoriesById_0;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMPublicationCategory> getPublicationCategoriesById() {
return publicationCategoriesById;
}
Expand All @@ -136,7 +136,7 @@ public void setPublicationCategoriesById(Collection<EDMPublicationCategory> publ
this.publicationCategoriesById = publicationCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMServiceCategory> getServiceCategoriesById() {
return serviceCategoriesById;
}
Expand All @@ -145,7 +145,7 @@ public void setServiceCategoriesById(Collection<EDMServiceCategory> serviceCateg
this.serviceCategoriesById = serviceCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMSoftwareapplicationCategory> getSoftwareapplicationCategoriesById() {
return softwareapplicationCategoriesById;
}
Expand All @@ -154,7 +154,7 @@ public void setSoftwareapplicationCategoriesById(Collection<EDMSoftwareapplicati
this.softwareapplicationCategoriesById = softwareapplicationCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMSoftwaresourcecodeCategory> getSoftwaresourcecodeCategoriesById() {
return softwaresourcecodeCategoriesById;
}
Expand All @@ -163,7 +163,7 @@ public void setSoftwaresourcecodeCategoriesById(Collection<EDMSoftwaresourcecode
this.softwaresourcecodeCategoriesById = softwaresourcecodeCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMWebserviceCategory> getWebserviceCategoriesById() {
return webserviceCategoriesById;
}
Expand All @@ -172,7 +172,7 @@ public void setWebserviceCategoriesById(Collection<EDMWebserviceCategory> webser
this.webserviceCategoriesById = webserviceCategoriesById;
}

@OneToMany(mappedBy = "categoryByCategoryId")
@OneToMany(mappedBy = "categoryByCategoryId",fetch=FetchType.EAGER)
public Collection<EDMFacilityCategory> getFacilityCategoriesById() {
return facilityCategoriesById;
}
Expand Down
59 changes: 44 additions & 15 deletions src/test/java/tests/Tests.java
Original file line number Diff line number Diff line change
@@ -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<Category> categoriesList = cats.getAll();

Tests.recursivePrint(categoriesList, null);


}

public static void recursivePrint(List<Category> 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 -------- ");
}
}

}
}

}

0 comments on commit 148d95d

Please sign in to comment.