Revision 58410
Added by Michele Artini almost 4 years ago
modules/dnet-orgs-database-application/trunk/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java | ||
---|---|---|
108 | 108 |
orgView.getOtherNames().forEach(n -> otherNameRepository.save(new OtherName(orgId, n.getName(), n.getLang()))); |
109 | 109 |
orgView.getOtherIdentifiers().forEach(id -> otherIdentifierRepository.save(new OtherIdentifier(orgId, id.getId(), id.getType()))); |
110 | 110 |
orgView.getUrls().forEach(u -> urlRepository.save(new Url(orgId, u))); |
111 |
orgView.getRelations().forEach(r -> { |
|
112 |
final Relationship r1 = new Relationship(orgId, r.getRelatedOrgId(), r.getType()); |
|
113 |
final Relationship r2 = new Relationship(r.getRelatedOrgId(), orgId, RelationType.valueOf(r.getType()).getInverse().toString()); |
|
114 |
relationshipRepository.save(r1); |
|
115 |
relationshipRepository.save(r2); |
|
116 |
|
|
117 |
if (r.getType().equals(RelationType.Merged_In.toString()) || r.getType().equals(RelationType.Merges.toString())) { |
|
118 |
openaireConflictRepository.findById(new OpenaireConflictPK(orgId, r.getRelatedOrgId())).ifPresent(openaireConflictRepository::delete); |
|
119 |
openaireConflictRepository.findById(new OpenaireConflictPK(r.getRelatedOrgId(), orgId)).ifPresent(openaireConflictRepository::delete); |
|
120 |
} |
|
121 |
}); |
|
111 |
orgView.getRelations().forEach(r -> makeRelation(orgId, r.getRelatedOrgId(), RelationType.valueOf(r.getType()))); |
|
122 | 112 |
} |
123 | 113 |
|
124 | 114 |
private void cleanOldRelations(final String id) { |
... | ... | |
231 | 221 |
groups.get(gid).add(w.getId1()); |
232 | 222 |
groups.get(gid).add(w.getId2()); |
233 | 223 |
} |
224 |
|
|
225 |
@Transactional |
|
226 |
public List<Relationship> makeRelation(final String id1, final String id2, final RelationType type) { |
|
227 |
final Relationship r1 = new Relationship(id1, id2, type.toString()); |
|
228 |
final Relationship r2 = new Relationship(id2, id1, type.getInverse().toString()); |
|
229 |
relationshipRepository.save(r1); |
|
230 |
relationshipRepository.save(r2); |
|
231 |
|
|
232 |
if (type == RelationType.Merged_In || type == RelationType.Merges) { |
|
233 |
openaireConflictRepository.findById(new OpenaireConflictPK(id1, id2)).ifPresent(openaireConflictRepository::delete); |
|
234 |
openaireConflictRepository.findById(new OpenaireConflictPK(id2, id1)).ifPresent(openaireConflictRepository::delete); |
|
235 |
} |
|
236 |
|
|
237 |
return Arrays.asList(r1, r2); |
|
238 |
} |
|
234 | 239 |
} |
modules/dnet-orgs-database-application/trunk/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java | ||
---|---|---|
9 | 9 |
import java.util.Set; |
10 | 10 |
import java.util.TreeMap; |
11 | 11 |
import java.util.TreeSet; |
12 |
import java.util.stream.Collectors; |
|
12 | 13 |
import java.util.stream.Stream; |
13 | 14 |
|
14 | 15 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
24 | 25 |
import org.springframework.web.bind.annotation.RestController; |
25 | 26 |
|
26 | 27 |
import eu.dnetlib.organizations.model.OpenaireDuplicate; |
28 |
import eu.dnetlib.organizations.model.Relationship; |
|
27 | 29 |
import eu.dnetlib.organizations.model.utils.BrowseEntry; |
28 | 30 |
import eu.dnetlib.organizations.model.utils.OrganizationConflict; |
29 | 31 |
import eu.dnetlib.organizations.model.utils.OrganizationConflictImpl; |
... | ... | |
42 | 44 |
import eu.dnetlib.organizations.repository.readonly.OrganizationViewRepository; |
43 | 45 |
import eu.dnetlib.organizations.repository.readonly.SuggestionInfoViewByCountryRepository; |
44 | 46 |
import eu.dnetlib.organizations.utils.DatabaseUtils; |
47 |
import eu.dnetlib.organizations.utils.RelationType; |
|
45 | 48 |
|
46 | 49 |
@RestController |
47 | 50 |
@RequestMapping("/api/organizations") |
... | ... | |
248 | 251 |
: organizationSimpleViewRepository.browseTypesForUser(authentication.getName()); |
249 | 252 |
} |
250 | 253 |
|
254 |
@RequestMapping(value = "/conflicts/fix/{masterId}", method = RequestMethod.POST) |
|
255 |
public List<Relationship> fixConflicts(final Authentication authentication, @PathVariable final String masterId, @RequestBody final List<String> otherIds) { |
|
256 |
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(masterId, authentication.getName())) { |
|
257 |
|
|
258 |
return otherIds.stream() |
|
259 |
.filter(id -> UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName())) |
|
260 |
.map(id -> databaseUtils.makeRelation(masterId, id, RelationType.Merges)) |
|
261 |
.flatMap(List::stream) |
|
262 |
.collect(Collectors.toList()); |
|
263 |
|
|
264 |
} else { |
|
265 |
return new ArrayList<>(); |
|
266 |
} |
|
267 |
|
|
268 |
} |
|
269 |
|
|
251 | 270 |
} |
modules/dnet-orgs-database-application/trunk/src/main/resources/static/resources/js/organizations.js | ||
---|---|---|
43 | 43 |
} |
44 | 44 |
}); |
45 | 45 |
|
46 |
orgsModule.directive('resolveConflictsModal', function($http) { |
|
46 |
orgsModule.directive('resolveConflictsModal', function($http, $route) {
|
|
47 | 47 |
return { |
48 | 48 |
restrict: 'E', |
49 | 49 |
scope: { |
50 |
'modalId' : '@', |
|
51 |
'orgs' : '=', |
|
52 |
'selectedOrgs': '=' |
|
50 |
'modalId' : '@',
|
|
51 |
'orgs' : '=',
|
|
52 |
'selectedOrgs' : '='
|
|
53 | 53 |
}, |
54 | 54 |
templateUrl: 'resources/html/modals/resolve_conflicts.html', |
55 | 55 |
link: function(scope, element, attrs, ctrl) { |
... | ... | |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
scope.createGroup = function() { |
70 |
alert('todo'); |
|
70 |
var masterId = ''; |
|
71 |
var otherIds = []; |
|
72 |
angular.forEach(scope.selectedOrgs, function(o, pos) { |
|
73 |
if (pos == 0) { masterId = o.id; } |
|
74 |
else { otherIds.push(o.id); } |
|
75 |
}); |
|
76 |
if (masterId && otherIds.length > 0) { |
|
77 |
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; |
|
78 |
$http.post('api/organizations/conflicts/fix/' + masterId, otherIds).then(function successCallback(res) { |
|
79 |
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); } |
|
80 |
$('#' + scope.modalId).modal('hide'); |
|
81 |
$('#' + scope.modalId).on('hidden.bs.modal', function (e) { |
|
82 |
$route.reload(); |
|
83 |
}); |
|
84 |
}, function errorCallback(res) { |
|
85 |
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')'); |
|
86 |
}); |
|
87 |
} |
|
71 | 88 |
} |
72 | 89 |
} |
73 | 90 |
} |
Also available in: Unified diff
save relations