Revision 55852
Added by Miriam Baglioni almost 5 years ago
CommunityApiCore.java | ||
---|---|---|
146 | 146 |
id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId); |
147 | 147 |
} |
148 | 148 |
|
149 |
public void removeCommunityOrganization(String id, Integer organizationId) throws CommunityException, CommunityNotFoundException { |
|
150 |
final Map<Integer, CommunityOrganization> organizations = getCommunityOrganizationMap(id); |
|
151 |
if (!organizations.containsKey(organizationId)) { |
|
152 |
throw new CommunityNotFoundException(String.format("organization '%s' doesn't exist within context '%s'", organizationId, id)); |
|
153 |
} |
|
154 |
isClient.removeConcept( |
|
155 |
id, |
|
156 |
id + ORGANIZATION_ID_SUFFIX, |
|
157 |
id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organizationId); |
|
158 |
} |
|
149 | 159 |
|
150 | 160 |
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, CommunityNotFoundException { |
151 | 161 |
// cc.getCommunity(id); // ensure the community exists. |
... | ... | |
153 | 163 |
return cc.getCommunityZenodoCommunities(id); |
154 | 164 |
} |
155 | 165 |
|
166 |
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, CommunityNotFoundException { |
|
167 |
cc.getCommunity(id); |
|
168 |
return cc.getCommunityInfo(id,ORGANIZATION_ID_SUFFIX,c->CommunityMappingUtils.asCommunityOrganization(id,c)); |
|
169 |
} |
|
156 | 170 |
|
171 |
|
|
157 | 172 |
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, CommunityNotFoundException { |
158 | 173 |
|
159 | 174 |
final CommunityDetails details = cc.getCommunity(id); |
... | ... | |
267 | 282 |
TreeMap::new)); |
268 | 283 |
} |
269 | 284 |
|
285 |
private TreeMap<Integer, CommunityOrganization> getCommunityOrganizationMap(final String id) throws CommunityException, CommunityNotFoundException { |
|
286 |
return getCommunityOrganizations(id).stream() |
|
287 |
.collect(Collectors.toMap( |
|
288 |
o -> Integer.valueOf(o.getId()), |
|
289 |
Functions.identity(), |
|
290 |
(o1, o2) -> { |
|
291 |
log.warn(String.format("duplicate content provider found: '%s'", o1.getId())); |
|
292 |
return o2; |
|
293 |
}, |
|
294 |
TreeMap::new)); |
|
295 |
} |
|
296 |
|
|
270 | 297 |
private Map<String, Context> getContextMap() throws CommunityException { |
271 | 298 |
try { |
272 | 299 |
return isClient.getCommunityContextMap(); |
... | ... | |
275 | 302 |
} |
276 | 303 |
} |
277 | 304 |
|
305 |
public CommunityOrganization addCommunityOrganization(String id, CommunityOrganization organization) throws CommunityException, CommunityNotFoundException { |
|
306 |
if (!StringUtils.equalsIgnoreCase(id, organization.getCommunityId())) { |
|
307 |
throw new CommunityException("parameters 'id' and organization.communityId must be coherent"); |
|
308 |
} |
|
278 | 309 |
|
310 |
final TreeMap<Integer, CommunityOrganization> cps = getCommunityOrganizationMap(id); |
|
311 |
organization.setId(nextId(MapUtils.isNotEmpty(cps) ? cps.lastKey() : 0)); |
|
279 | 312 |
|
313 |
isClient.addConcept(id, id + ORGANIZATION_ID_SUFFIX, CommunityMappingUtils.asOrganizationXML(id, organization)); |
|
314 |
|
|
315 |
return organization; |
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
280 | 321 |
// private <R> List<R> _getCommunityInfo(final String id, final String idSuffix, final Function<Concept, R> mapping) throws CommunityException { |
281 | 322 |
// final Map<String, Context> contextMap = getContextMap(); |
282 | 323 |
// final Context context = contextMap.get(id); |
Also available in: Unified diff
Update for the Organization. Access point to the controller and implementation of the logic to handle the new category for the community