subcommunities

This commit is contained in:
Michele Artini 2023-06-27 14:04:51 +02:00
parent de36ad03e6
commit b509e13560
2 changed files with 22 additions and 16 deletions

View File

@ -156,15 +156,22 @@ public class CommunityImporterController {
final List<CommunityOrganization> orgs =
getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c));
final List<SubCommunity> subs = new ArrayList<>();
// TODO populate the subs using all the other categories (ie: not projects, organizations and contentproviders)
final List<SubCommunity> 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<SubCommunity> 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<SubCommunity> asSubCommunities(final String communityId, final String parent, final String category, final List<Concept> concepts) {
final List<SubCommunity> 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;
}

View File

@ -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