Project

General

Profile

« Previous | Next » 

Revision 57642

minors

View differences:

OrganizationController.java
1 1
package eu.dnetlib.organizations.controller;
2 2

  
3 3
import java.util.Arrays;
4
import java.util.Collection;
5
import java.util.HashMap;
6
import java.util.LinkedHashSet;
4 7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10
import java.util.TreeMap;
5 11
import java.util.stream.Collectors;
6 12

  
7 13
import org.apache.commons.lang3.StringUtils;
......
134 140
	}
135 141

  
136 142
	@RequestMapping(value = "/warnings", method = RequestMethod.GET)
137
	public Iterable<WarningView> findWarningsById(final Authentication authentication) {
143
	public Collection<Set<OrganizationSimpleView>> findWarningsById(final Authentication authentication) {
144

  
145
		final Map<String, Set<OrganizationSimpleView>> res = new TreeMap<>();
146

  
147
		final Map<String, String> roots = new HashMap<>();
148

  
138 149
		if (UserInfo.isSuperUser(authentication)) {
139
			return warningViewRepository.findAll();
150
			for (final WarningView w : warningViewRepository.findAll()) {
151
				final String root = findWarningRoot(w, roots);
152
				if (!res.containsKey(root)) {
153
					res.put(root, new LinkedHashSet<OrganizationSimpleView>());
154
					res.get(root).add(new OrganizationSimpleView(w.getId1(), w.getName1(), w.getType1(), w.getCity1(), w.getCountry1(), new String[] {}));
155
				}
156
				res.get(root).add(new OrganizationSimpleView(w.getId2(), w.getName2(), w.getType2(), w.getCity2(), w.getCountry2(), new String[] {}));
157
			}
158
			return res.values();
140 159
		} else {
141 160
			throw new RuntimeException("User not authorized");
142 161
		}
143 162
	}
144 163

  
164
	private String findWarningRoot(final WarningView w, final Map<String, String> roots) {
165
		if (roots.containsKey(w.getId1())) {
166
			return roots.get(w.getId1());
167
		} else if (roots.containsKey(w.getId2())) {
168
			return roots.get(w.getId2());
169
		} else {
170
			// id1 is the new root
171
			roots.put(w.getId1(), w.getId1());
172
			roots.put(w.getId2(), w.getId1());
173
			return w.getId1();
174
		}
175

  
176
	}
177

  
145 178
	@RequestMapping(value = "/similarities", method = RequestMethod.POST)
146 179
	public List<OpenaireSimRel> saveSimilarities(@RequestBody final List<OpenaireSimRel> simrels, final Authentication authentication) {
147 180

  

Also available in: Unified diff