From b509e13560bd08c0a902f093f23afc6f44f8cc07 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Tue, 27 Jun 2023 14:04:51 +0200 Subject: [PATCH] subcommunities --- .../CommunityImporterController.java | 37 +++++++++++-------- .../community/db/CommunityService.java | 1 - 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityImporterController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityImporterController.java index e8fe1407..04d85026 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityImporterController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityImporterController.java @@ -156,15 +156,22 @@ public class CommunityImporterController { final List orgs = getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c)); - final List subs = new ArrayList<>(); - // TODO populate the subs using all the other categories (ie: not projects, organizations and contentproviders) + final List subs = context.getCategories() + .entrySet() + .stream() + .filter(e -> !e.getKey().equals(context.getId() + CONTENTPROVIDERS_ID_SUFFIX)) + .filter(e -> !e.getKey().equals(context.getId() + PROJECTS_ID_SUFFIX)) + .filter(e -> !e.getKey().equals(context.getId() + ORGANIZATION_ID_SUFFIX)) + .map(e -> e.getValue()) + .map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts())) + .flatMap(List::stream) + .collect(Collectors.toList()); service.saveCommunity(community); service.addCommunityProjectList(context.getId(), projects); service.addCommunityContentProvidersList(context.getId(), datasources); service.addCommunityOrganizationList(context.getId(), orgs); service.addSubCommunityList(subs); - // TODO MANAGE new fields and tables } catch (final Exception e) { throw new RuntimeException("Error importing community: " + context.getId(), e); } @@ -274,19 +281,19 @@ public class CommunityImporterController { return o; } - // TODO - private static List asSubCommunities(final String communityId, final String parent, final String category, final Concept c) { - final SubCommunity sc = new SubCommunity(); - sc.setSubCommunityId(c.getId()); - sc.setCommunityId(communityId); - sc.setParent(parent); - sc.setCategory(category); - sc.setLabel(c.getLabel()); - sc.setParams(c.getParams()); - + private static List asSubCommunities(final String communityId, final String parent, final String category, final List concepts) { final List list = new ArrayList<>(); - list.add(sc); - c.getConcepts().forEach(child -> list.addAll(asSubCommunities(communityId, c.getId(), category, child))); + for (final Concept c : concepts) { + final SubCommunity sc = new SubCommunity(); + sc.setSubCommunityId(c.getId()); + sc.setCommunityId(communityId); + sc.setParent(parent); + sc.setCategory(category); + sc.setLabel(c.getLabel()); + sc.setParams(c.getParams()); + list.add(sc); + list.addAll(asSubCommunities(communityId, c.getId(), category, c.getConcepts())); + } return list; } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/db/CommunityService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/db/CommunityService.java index 5aae015a..1c38675e 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/db/CommunityService.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/db/CommunityService.java @@ -48,7 +48,6 @@ public class CommunityService { // TODO // 1) Import tramite profili: // 1.1) Completare CommunityImporterController - // 1.2) Considerare anche le Subcommunities: importazione tramite profili // 2) Subcommunities: visualizzazione tramite le context api // 3) Come ritornare i campi delle community_orgs ? // 4) Verificare Tickets: #8835, #8854, #6483, #3259, #3494