Project

General

Profile

« Previous | Next » 

Revision 53866

update for concept zenodocommunities

View differences:

CommunityApiCore.java
56 56
		isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription());
57 57
		isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl());
58 58
		isClient.updateContextParam(id, CSUMMARY_STATUS, details.getStatus().name());
59
		//isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getZenodoCommunity());
60 59

  
61 60
		if (details.getManagers() != null) {
62 61
			isClient.updateContextParam(id, CSUMMARY_MANAGER, Joiner.on(CSV_DELIMITER).join(details.getManagers()));
......
128 127
				id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId);
129 128
	}
130 129

  
130

  
131
	public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, CommunityNotFoundException {
132
		getCommunity(id); // ensure the community exists.
133
		return _getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c));
134
	}
135

  
136

  
131 137
	public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, CommunityNotFoundException {
132 138

  
133 139
		final CommunityDetails details = getCommunity(id);
......
158 164
		return details;
159 165
	}
160 166

  
167
	public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException {
168

  
169
		final Map<Integer, CommunityZenodoCommunity> zcomms = getZenodoCommunityMap(id);
170
		if (!zcomms.containsKey(zenodoCommId)) {
171
			throw new CommunityNotFoundException(String.format("Zenodo community '%s' doesn't exist within context '%s'", zenodoCommId, id));
172
		}
173
		isClient.removeConcept(
174
				id,
175
				id + ZENODOCOMMUNITY_ID_SUFFIX,
176
				id + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zenodoCommId);
177
	}
178

  
179
	public CommunityZenodoCommunity addCommunityZenodoCommunity(final String id, final CommunityZenodoCommunity zc) throws CommunityException, CommunityNotFoundException {
180
		if (!StringUtils.equalsIgnoreCase(id, zc.getCommunityId())) {
181
			throw new CommunityException("parameters 'id' and zc.communityId must be coherent");
182
		}
183

  
184
		final TreeMap<Integer, CommunityContentprovider> zcs = getCommunityContentproviderMap(id);
185
		zc.setId(nextId(MapUtils.isNotEmpty(zcs) ? zcs.lastKey() : 0));
186

  
187
		isClient.addConcept(id, id + ZENODOCOMMUNITY_ID_SUFFIX, CommunityMappingUtils.asZenodoCommunityXML(id, zc));
188

  
189
		return zc;
190
	}
191

  
161 192
	// HELPERS
162 193

  
163 194
	private TreeMap<Integer, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, CommunityNotFoundException {
......
184 215
						TreeMap::new));
185 216
	}
186 217

  
218
	private TreeMap<Integer,CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, CommunityNotFoundException{
219
		return getCommunityZenodoCommunities(id).stream()
220
				.collect(Collectors.toMap(
221
						cp -> Integer.valueOf(cp.getId()),
222
						Functions.identity(),
223
						(cp1, cp2) -> {
224
							log.warn(String.format("duplicate Zenodo community found: '%s'", cp1.getId()));
225
							return cp2;
226
						},
227
						TreeMap::new));
228
	}
229

  
187 230
	private Map<String, Context> getContextMap() throws CommunityException {
188 231
		try {
189 232
			return isClient.getCommunityContextMap();

Also available in: Unified diff