[SubCommunity] Extention of communityApis to add also the associations between the subcommunities and organization/project/datasources
This commit is contained in:
parent
cea2de2c37
commit
9dbcf19efb
|
@ -88,4 +88,12 @@ public class QueryCommunityAPI {
|
|||
public static String subcommunityDatasource(String communityId, String subcommunityId, String baseURL) throws IOException {
|
||||
return get(baseURL + communityId + "/subcommunities/datasources?subCommunityId=" + subcommunityId);
|
||||
}
|
||||
|
||||
public static String subcommunityPropagationOrganization(String communityId, String subcommunityId , String baseURL) throws IOException {
|
||||
return get(baseURL + communityId + "/subcommunities/propagationOrganizations?subCommunityId=" + subcommunityId);
|
||||
}
|
||||
|
||||
public static String subcommunityProjects(String communityId, String subcommunityId, String page, String size, String baseURL) throws IOException {
|
||||
return get(baseURL + communityId + "/subcommunities/projects/" + page + "/" + size + "?subCommunityId=" + subcommunityId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,27 +170,51 @@ public class Utils implements Serializable {
|
|||
return MAPPER.readValue(QueryCommunityAPI.subcommunities(communityId, baseURL), SubCommunitySummary.class);
|
||||
}
|
||||
|
||||
private static void getRelatedOrganizations(String communityId, String baseURL, CommunityEntityMap communityEntityMap){
|
||||
|
||||
try {
|
||||
List<String> associatedOrgs = MAPPER
|
||||
.readValue(
|
||||
QueryCommunityAPI.communityPropagationOrganization(communityId, baseURL), OrganizationList.class);
|
||||
associatedOrgs.forEach(o -> updateEntityMap(communityId, o, communityEntityMap, ModelSupport.getIdPrefix(Organization.class)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
private static void getRelatedOrganizations(String communityId, String subcommunityId, String baseURL, CommunityEntityMap communityEntityMap){
|
||||
|
||||
try {
|
||||
List<String> associatedOrgs = MAPPER
|
||||
.readValue(
|
||||
QueryCommunityAPI.subcommunityPropagationOrganization(communityId, subcommunityId, baseURL), OrganizationList.class);
|
||||
associatedOrgs.forEach(o -> updateEntityMap(communityId, o, communityEntityMap, ModelSupport.getIdPrefix(Organization.class)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void updateEntityMap(String communityId, String entityId, CommunityEntityMap communityEntityMap, String entityPrefix){
|
||||
|
||||
if (!communityEntityMap
|
||||
.containsKey(entityPrefix + "|" + entityId))
|
||||
communityEntityMap.put(entityPrefix + "|" + entityId, new ArrayList<>());
|
||||
|
||||
communityEntityMap.get(entityPrefix + "|" + entityId).add(communityId);
|
||||
|
||||
}
|
||||
/**
|
||||
* it returns for each organization the list of associated communities
|
||||
*/
|
||||
public static CommunityEntityMap getCommunityOrganization(String baseURL) throws IOException {
|
||||
CommunityEntityMap organizationMap = new CommunityEntityMap();
|
||||
String entityPrefix = ModelSupport.getIdPrefix(Organization.class);
|
||||
getValidCommunities(baseURL)
|
||||
.forEach(community -> {
|
||||
String id = community.getId();
|
||||
List<CommunityModel> communityList = getValidCommunities(baseURL);
|
||||
communityList.forEach(community -> {
|
||||
getRelatedOrganizations(community.getId(), baseURL, organizationMap );
|
||||
try {
|
||||
List<String> associatedOrgs = MAPPER
|
||||
.readValue(
|
||||
QueryCommunityAPI.communityPropagationOrganization(id, baseURL), OrganizationList.class);
|
||||
associatedOrgs.forEach(o -> {
|
||||
if (!organizationMap
|
||||
.keySet()
|
||||
.contains(
|
||||
entityPrefix + "|" + o))
|
||||
organizationMap.put(entityPrefix + "|" + o, new ArrayList<>());
|
||||
organizationMap.get(entityPrefix + "|" + o).add(community.getId());
|
||||
});
|
||||
List<SubCommunityModel> subcommunities = getSubcommunities(community.getId(), baseURL);
|
||||
subcommunities.forEach(sc -> getRelatedOrganizations(community.getId(), sc.getSubCommunityId(), baseURL, organizationMap));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -201,9 +225,21 @@ public class Utils implements Serializable {
|
|||
|
||||
public static CommunityEntityMap getCommunityProjects(String baseURL) throws IOException {
|
||||
CommunityEntityMap projectMap = new CommunityEntityMap();
|
||||
String entityPrefix = ModelSupport.getIdPrefix(Project.class);
|
||||
|
||||
getValidCommunities(baseURL)
|
||||
.forEach(community -> {
|
||||
addRelevantProjects(community.getId(), baseURL, projectMap);
|
||||
try {
|
||||
List<SubCommunityModel> subcommunities = getSubcommunities(community.getId(), baseURL);
|
||||
subcommunities.forEach(sc -> addRelevantProjects(community.getId(), sc.getSubCommunityId(), baseURL, projectMap));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return projectMap;
|
||||
}
|
||||
|
||||
private static void addRelevantProjects(String communityId, String baseURL, CommunityEntityMap communityEntityMap){
|
||||
int page = -1;
|
||||
int size = 100;
|
||||
ContentModel cm = new ContentModel();
|
||||
|
@ -214,21 +250,37 @@ public class Utils implements Serializable {
|
|||
.readValue(
|
||||
QueryCommunityAPI
|
||||
.communityProjects(
|
||||
community.getId(), String.valueOf(page), String.valueOf(size), baseURL),
|
||||
communityId, String.valueOf(page), String.valueOf(size), baseURL),
|
||||
ContentModel.class);
|
||||
if (cm.getContent().size() > 0) {
|
||||
cm.getContent().forEach(p -> {
|
||||
if (!projectMap.keySet().contains(entityPrefix + "|" + p.getOpenaireId()))
|
||||
projectMap.put(entityPrefix + "|" + p.getOpenaireId(), new ArrayList<>());
|
||||
projectMap.get(entityPrefix + "|" + p.getOpenaireId()).add(community.getId());
|
||||
});
|
||||
if (!cm.getContent().isEmpty()) {
|
||||
cm.getContent().forEach(p -> updateEntityMap(communityId, p.getOpenaireId(),communityEntityMap, ModelSupport.getIdPrefix(Project.class)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} while (!cm.getLast());
|
||||
}
|
||||
|
||||
private static void addRelevantProjects(String communityId, String subcommunityId, String baseURL, CommunityEntityMap communityEntityMap){
|
||||
int page = -1;
|
||||
int size = 100;
|
||||
ContentModel cm = new ContentModel();
|
||||
do {
|
||||
page++;
|
||||
try {
|
||||
cm = MAPPER
|
||||
.readValue(
|
||||
QueryCommunityAPI
|
||||
.subcommunityProjects(
|
||||
communityId, subcommunityId , String.valueOf(page), String.valueOf(size), baseURL),
|
||||
ContentModel.class);
|
||||
if (!cm.getContent().isEmpty()) {
|
||||
cm.getContent().forEach(p -> updateEntityMap(communityId, p.getOpenaireId(),communityEntityMap, ModelSupport.getIdPrefix(Project.class)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} while (!cm.getLast());
|
||||
});
|
||||
return projectMap;
|
||||
}
|
||||
|
||||
public static List<String> getCommunityIdList(String baseURL) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue