invalidate a group of conflicts
This commit is contained in:
parent
b8113cf34b
commit
8f5eacb409
|
@ -33,7 +33,6 @@ import eu.dnetlib.organizations.model.view.OpenaireDuplicateView;
|
|||
import eu.dnetlib.organizations.model.view.OrganizationInfoView;
|
||||
import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
|
||||
import eu.dnetlib.organizations.model.view.OrganizationView;
|
||||
import eu.dnetlib.organizations.repository.OrganizationRepository;
|
||||
import eu.dnetlib.organizations.repository.UserCountryRepository;
|
||||
import eu.dnetlib.organizations.repository.readonly.ConflictGroupViewRepository;
|
||||
import eu.dnetlib.organizations.repository.readonly.DuplicateGroupViewRepository;
|
||||
|
@ -49,8 +48,6 @@ import eu.dnetlib.organizations.utils.OrganizationStatus;
|
|||
@RequestMapping("/api/organizations")
|
||||
public class OrganizationController {
|
||||
|
||||
@Autowired
|
||||
private OrganizationRepository organizationRepository;
|
||||
@Autowired
|
||||
private OrganizationViewRepository organizationViewRepository;
|
||||
@Autowired
|
||||
|
@ -298,18 +295,24 @@ public class OrganizationController {
|
|||
: databaseUtils.browseTypesForUser(authentication.getName());
|
||||
}
|
||||
|
||||
@PostMapping("/conflicts/fix/{masterId}")
|
||||
public List<String> fixConflicts(final Authentication authentication, @PathVariable final String masterId, @RequestBody final List<String> otherIds) {
|
||||
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(masterId, authentication.getName())) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
list.add(masterId);
|
||||
list.addAll(otherIds);
|
||||
final String newOrgId = databaseUtils.fixConflict(list, authentication.getName());
|
||||
|
||||
@PostMapping("/conflicts/fix/similar")
|
||||
public List<String> fixConflictSim(final Authentication authentication, @RequestBody final List<String> ids) {
|
||||
if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(ids.get(0), authentication.getName())) {
|
||||
final String newOrgId = databaseUtils.fixConflictSimilars(ids, authentication.getName());
|
||||
return Arrays.asList(newOrgId);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/conflicts/fix/different")
|
||||
public List<String> fixConflictDiff(final Authentication authentication, @RequestBody final List<String> ids) {
|
||||
if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(ids.get(0), authentication.getName())) {
|
||||
databaseUtils.fixConflictDifferents(ids, authentication.getName());
|
||||
return ids;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ public class DatabaseUtils {
|
|||
|
||||
public List<OrganizationConflict> listConflictsForId(final String id) {
|
||||
final String sql =
|
||||
"select o.id, o.name, o.type, o.city, o.country from oa_conflicts c left outer join organizations o on (c.id2 = o.id) where o.id is not null and c.id1 = ?";
|
||||
"select o.id, o.name, o.type, o.city, o.country from oa_conflicts c left outer join organizations o on (c.id2 = o.id) where o.id is not null and c.id1 = ? and c.reltype = 'suggested'";
|
||||
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(OrganizationConflict.class), id);
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class DatabaseUtils {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public String fixConflict(final List<String> similarIds, final String user) {
|
||||
public String fixConflictSimilars(final List<String> similarIds, final String user) {
|
||||
|
||||
final OffsetDateTime now = OffsetDateTime.now();
|
||||
|
||||
|
@ -388,6 +388,19 @@ public class DatabaseUtils {
|
|||
return masterId;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void fixConflictDifferents(final List<String> differentsIds, final String user) {
|
||||
|
||||
final OffsetDateTime now = OffsetDateTime.now();
|
||||
|
||||
for (int i = 0; i < differentsIds.size(); i++) {
|
||||
for (int j = i + 1; j < differentsIds.size(); j++) {
|
||||
openaireConflictRepository
|
||||
.updateStatusAndResetGroup(differentsIds.get(i), differentsIds.get(j), SimilarityType.is_different.toString(), user, now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String findFirstString(final List<OrganizationView> views, final Function<OrganizationView, String> mapper) {
|
||||
return views.stream().map(mapper).filter(StringUtils::isNotBlank).findFirst().orElse(null);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card border-primary">
|
||||
<div class="card-header text-white bg-primary">Suggested organizations</div>
|
||||
<div class="card-header text-white bg-primary">Organizations</div>
|
||||
<div class="card-body" ng-repeat="o in orgs | filter:{show:'secondary'}" ng-class="{'pb-0' : $index==0 , 'py-0' : $index > 0 }">
|
||||
<org-details org="o" org-title="{{o.id}}" show="{{o.show}}"></org-details>
|
||||
<div class="text-right mb-3">
|
||||
|
@ -23,11 +23,11 @@
|
|||
<div class="card border-primary">
|
||||
<div class="card-header text-white bg-primary">New group</div>
|
||||
<div class="card-body" ng-repeat="o in selectedOrgs" ng-class="{'pb-0' : $index==0 , 'py-0' : $index > 0 }">
|
||||
<org-details org="o" org-title="{{($index==0)?'Master organization':'Secondary organization ' + $index}}" show="{{o.show}}"></org-details>
|
||||
<org-details org="o" org-title="{{($index==0)?'Main organization':'Secondary organization ' + $index}}" show="{{o.show}}"></org-details>
|
||||
</div>
|
||||
<div class="card-body" ng-show="selectedOrgs.length == 0">
|
||||
<div class="card border-secondary">
|
||||
<div class="card-body text-secondary text-center">select master organization</div>
|
||||
<div class="card-body text-secondary text-center">select main organization</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body pt-0" ng-show="selectedOrgs.length == 1">
|
||||
|
@ -37,7 +37,10 @@
|
|||
</div>
|
||||
<div class="card-footer" ng-show="selectedOrgs.length > 0">
|
||||
<button type="button" class="btn btn-sm btn-secondary" ng-click="reset()" ng-show="selectedOrgs.length > 0">reset</button>
|
||||
<button type="button" class="btn btn-sm btn-primary float-right" ng-click="createGroup()" ng-show="selectedOrgs.length > 1">create group</button>
|
||||
<div class="btn-group float-right" ng-show="selectedOrgs.length > 1">
|
||||
<button type="button" class="btn btn-sm btn-danger" ng-click="invalidateGroup()">all differents</button>
|
||||
<button type="button" class="btn btn-sm btn-primary" ng-click="mergeGroup()">merge</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -101,21 +101,31 @@ orgsModule.directive('resolveConflictsModal', function($http, $route) {
|
|||
angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; });
|
||||
}
|
||||
|
||||
scope.createGroup = function() {
|
||||
var masterId = '';
|
||||
var otherIds = [];
|
||||
scope.mergeGroup = function() {
|
||||
var ids = [];
|
||||
angular.forEach(scope.selectedOrgs, function(o, pos) {
|
||||
if (pos == 0) { masterId = o.id; }
|
||||
else { otherIds.push(o.id); }
|
||||
ids.push(o.id);
|
||||
});
|
||||
if (masterId && otherIds.length > 0) {
|
||||
|
||||
call_http_post($http, 'api/organizations/conflicts/fix/' + masterId, otherIds, function(res) {
|
||||
if (ids.length > 0) {
|
||||
call_http_post($http, 'api/organizations/conflicts/fix/similar', ids, function(res) {
|
||||
$('#' + scope.modalId).modal('hide');
|
||||
$('#' + scope.modalId).on('hidden.bs.modal', function (e) { $route.reload(); });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scope.invalidateGroup = function() {
|
||||
var ids = [];
|
||||
angular.forEach(scope.selectedOrgs, function(o, pos) {
|
||||
ids.push(o.id);
|
||||
});
|
||||
if (ids.length > 0) {
|
||||
call_http_post($http, 'api/organizations/conflicts/fix/different', ids, function(res) {
|
||||
$('#' + scope.modalId).modal('hide');
|
||||
$('#' + scope.modalId).on('hidden.bs.modal', function (e) { $route.reload(); });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue