Skip to content

Commit

Permalink
updates the categories broaders handling
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriovinciarelli authored and valeriovinciarelli committed Aug 29, 2023
1 parent 96f0429 commit ba9e3b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ public LinkedEntity save(Category eposDataModelObject, EntityManager em, String
}

if (eposDataModelObject.getBroader() != null) {

System.out.println(eposDataModelObject.getBroader());

for (String categoryName : eposDataModelObject.getBroader()) {
EDMCategory edmCategory = getOneFromDB(em, EDMCategory.class, "EDMCategory.findByUid",
"UID", categoryName);

boolean exists = true;

if (edmCategory == null) {
exists = false;
edmCategory = new EDMCategory();
edmCategory.setScheme(edmCategoryScheme.getId());
edmCategory.setUid(categoryName);
Expand All @@ -78,9 +77,8 @@ public LinkedEntity save(Category eposDataModelObject, EntityManager em, String
edmIspartOfCategory.setCategoryByCategory1Id(edmCategory);
edmIspartOfCategory.setCategory2Id(edmInstanceId);
edmIspartOfCategory.setCategoryByCategory2Id(edmObject);

if(exists)em.merge(edmIspartOfCategory);
else em.persist(edmIspartOfCategory);

em.persist(edmIspartOfCategory);
}
}

Expand All @@ -89,10 +87,7 @@ public LinkedEntity save(Category eposDataModelObject, EntityManager em, String
EDMCategory edmCategory = getOneFromDB(em, EDMCategory.class, "EDMCategory.findByUid",
"UID", categoryName);

boolean exists = true;

if (edmCategory == null) {
exists = false;
edmCategory = new EDMCategory();
edmCategory.setScheme(edmCategoryScheme.getId());
edmCategory.setUid(categoryName);
Expand All @@ -107,8 +102,7 @@ public LinkedEntity save(Category eposDataModelObject, EntityManager em, String
edmIspartOfCategory.setCategory1Id(edmInstanceId);
edmIspartOfCategory.setCategoryByCategory1Id(edmObject);

if(exists)em.merge(edmIspartOfCategory);
else em.persist(edmIspartOfCategory);
em.persist(edmIspartOfCategory);
}

}
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/tests/APITests.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ public static void main(String[] args) {
tsunamidata.setNarrower(Arrays.asList("category:sealevelstatimitgfacilitydatavliz"));
catAPI.save(tsunamidata);

Category tsunamitest = new Category();
tsunamitest.setUid("category:tsunamitest");
tsunamitest.setName("Tsunami Test");
tsunamitest.setDescription("TCS Subdomain");
tsunamitest.setInScheme("category:tsunami");
tsunamitest.setNarrower(Arrays.asList("category:sealevelstatimitgfacilitydatavliz"));
catAPI.save(tsunamidata);

Category sealevelstatimitgfacilitydatavliz = new Category();
sealevelstatimitgfacilitydatavliz.setUid("category:sealevelstatimitgfacilitydatavliz");
sealevelstatimitgfacilitydatavliz.setName("Tsunami Data");
sealevelstatimitgfacilitydatavliz.setDescription("TCS Subdomain");
sealevelstatimitgfacilitydatavliz.setInScheme("category:tsunami");
sealevelstatimitgfacilitydatavliz.setBroader(Arrays.asList("category:tsunamidata"));
sealevelstatimitgfacilitydatavliz.setBroader(Arrays.asList("category:tsunamidata","category:tsunamitest"));
catAPI.save(sealevelstatimitgfacilitydatavliz);
}

Expand Down

0 comments on commit ba9e3b5

Please sign in to comment.