form to add persintent organizations

This commit is contained in:
Michele Artini 2022-09-23 14:55:25 +02:00
parent 1271f9cf43
commit 75d002c8ba
9 changed files with 243 additions and 0 deletions

View File

@ -20,11 +20,15 @@ import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.organizations.importer.ImportExecution;
import eu.dnetlib.organizations.importer.ImportExecutor;
import eu.dnetlib.organizations.model.PersistentOrganization;
import eu.dnetlib.organizations.model.SystemConfiguration;
import eu.dnetlib.organizations.model.utils.VocabularyTerm;
import eu.dnetlib.organizations.model.view.PersistentOrganizationView;
import eu.dnetlib.organizations.model.view.UserView;
import eu.dnetlib.organizations.repository.PersistentOrganizationRepository;
import eu.dnetlib.organizations.repository.SystemConfigurationRepository;
import eu.dnetlib.organizations.repository.UserRepository;
import eu.dnetlib.organizations.repository.readonly.PersistentOrganizationViewRepository;
import eu.dnetlib.organizations.repository.readonly.UserViewRepository;
import eu.dnetlib.organizations.utils.DatabaseUtils;
import eu.dnetlib.organizations.utils.MailDispatcher;
@ -38,6 +42,12 @@ public class AdminController extends AbstractDnetController {
@Autowired
private UserViewRepository userViewRepository;
@Autowired
private PersistentOrganizationRepository persistentOrganizationRepository;
@Autowired
private PersistentOrganizationViewRepository persistentOrganizationViewRepository;
@Autowired
private SystemConfigurationRepository systemConfigurationRepository;
@ -202,4 +212,22 @@ public class AdminController extends AbstractDnetController {
throw new RuntimeException("User not authorized");
}
}
@GetMapping("/api/persistentOrgs")
public Iterable<PersistentOrganizationView> listPersistentOrgs() {
return persistentOrganizationViewRepository.findAll();
}
@PostMapping("/api/persistentOrgs")
public Iterable<PersistentOrganizationView> addPersistentOrgs(@RequestBody final List<String> ids) {
ids.forEach(id -> persistentOrganizationRepository.save(new PersistentOrganization(id)));
return persistentOrganizationViewRepository.findAll();
}
@DeleteMapping("/api/persistentOrgs")
public Iterable<PersistentOrganizationView> deletePersistentOrgs(@RequestParam final String id) {
persistentOrganizationRepository.deleteById(id);
return persistentOrganizationViewRepository.findAll();
}
}

View File

@ -0,0 +1,34 @@
package eu.dnetlib.organizations.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "persistent_orgs")
public class PersistentOrganization implements Serializable {
private static final long serialVersionUID = 7684478315366015099L;
@Id
@Column(name = "id")
private String id;
public PersistentOrganization() {}
public PersistentOrganization(final String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
}

View File

@ -0,0 +1,72 @@
package eu.dnetlib.organizations.model.view;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "persistent_orgs_view")
public class PersistentOrganizationView implements Serializable {
private static final long serialVersionUID = -8906936709574708538L;
@Id
@Column(name = "id")
private String id;
@Column(name = "openaire_id")
private String openaireId;
@Column(name = "name")
private String name;
@Column(name = "city")
private String city;
@Column(name = "country")
private String country;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getOpenaireId() {
return openaireId;
}
public void setOpenaireId(final String openaireId) {
this.openaireId = openaireId;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(final String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(final String country) {
this.country = country;
}
}

View File

@ -0,0 +1,11 @@
package eu.dnetlib.organizations.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import eu.dnetlib.organizations.model.PersistentOrganization;
@Repository
public interface PersistentOrganizationRepository extends JpaRepository<PersistentOrganization, String> {
}

View File

@ -0,0 +1,10 @@
package eu.dnetlib.organizations.repository.readonly;
import org.springframework.stereotype.Repository;
import eu.dnetlib.organizations.model.view.PersistentOrganizationView;
@Repository
public interface PersistentOrganizationViewRepository extends ReadOnlyRepository<PersistentOrganizationView, String> {
}

View File

@ -5,6 +5,7 @@ DROP VIEW IF EXISTS users_view;
DROP VIEW IF EXISTS conflict_groups_view;
DROP VIEW IF EXISTS suggestions_info_by_country_view;
DROP VIEW IF EXISTS duplicate_groups_view;
DROP VIEW IF EXISTS persistent_orgs_view;
DROP TABLE IF EXISTS sysconf;
DROP TABLE IF EXISTS other_ids;
@ -14,6 +15,8 @@ DROP TABLE IF EXISTS relationships;
DROP TABLE IF EXISTS urls;
DROP TABLE IF EXISTS oa_duplicates;
DROP TABLE IF EXISTS oa_conflicts;
DROP TABLE IF EXISTS persistent_orgs;
DROP TABLE IF EXISTS organizations;
DROP TABLE IF EXISTS org_types;
@ -374,6 +377,10 @@ CREATE TABLE organizations (
CREATE INDEX organizations_type_idx ON organizations(type);
CREATE INDEX organizations_country_idx ON organizations(country);
CREATE TABLE persistent_orgs (
id text PRIMARY KEY REFERENCES organizations(id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE other_ids (
id text REFERENCES organizations(id) ON UPDATE CASCADE ON DELETE CASCADE,
otherid text,
@ -674,6 +681,17 @@ WHERE
GROUP BY o.id, o.name, o.city, o.country
ORDER BY o.name;
CREATE VIEW persistent_orgs_view AS SELECT
po.id,
substr(po.id, 1, 14)||md5(substr(po.id,15)) as openaire_id,
o.name,
o.city,
o.country
FROM
persistent_orgs po
JOIN organizations o ON (po.id = o.id)
ORDER BY o.name;
CREATE TABLE org_index_search(id text PRIMARY KEY, txt tsvector);
CREATE INDEX org_index_search_txt_gin_idx ON org_index_search USING gin(txt);

View File

@ -0,0 +1,47 @@
<h4>Persistent Organizations</h4>
<p>
<small>It is necessary to persist the identifiers of the organizations associated to an Institutional Dashboard</small>
</p>
<table class="table table-sm small">
<thead class="thead-light">
<tr>
<th style="width: 200px">ID</th>
<th style="width: 300px">OA Graph Node ID</th>
<th>Name</th>
<th style="width: 300px">Place</th>
<th style="width: 40px"></th>
</tr>
</thead>
<tbody ng-show="orgs.length > 0">
<tr ng-repeat="o in orgs">
<td><a href="#!/edit/0/{{o.id}}">{{o.id}}</a></td>
<td>{{o.openaireId}}</td>
<td>{{o.name}}</td>
<td><img ng-src="resources/images/flags/{{o.country}}.gif" /> {{o.city || '-'}}, {{o.country}}</td>
<td class="text-right">
<button type="button" class="btn btn-sm btn-outline-danger" ng-click="deletePersistentOrg(o.id)">
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
</tbody>
<tbody ng-hide="orgs.length > 0">
<tr>
<td colspan="5" class="text-muted">No persistent organizazions</td>
</tr>
</tbody>
<tfoot>
<tr ng-init="newId=''">
<td colspan="4">
<input type="text" class="form-control form-control-sm" placeholder="new persistent organization ID..." ng-model="newId" />
</td>
<td class="text-right">
<button type="button" class="btn btn-sm btn-outline-success" ng-click="addPersistentOrg(newId); newId=''" ng-disabled="!newId">
<i class="fa fa-plus"></i>
</button>
</td>
</tr>
</tfoot>
</table>

View File

@ -379,6 +379,7 @@ orgsModule.config(function($routeProvider) {
.when('/sysconf', { templateUrl: 'resources/html/pages/admin/sysConf.html', controller: 'sysConfCtrl' })
.when('/utils', { templateUrl: 'resources/html/pages/admin/utils.html', controller: 'utilsCtrl' })
.when('/lastImport', { templateUrl: 'resources/html/pages/admin/lastImport.html', controller: 'lastImportCtrl' })
.when('/persistentOrgs', { templateUrl: 'resources/html/pages/admin/persistentOrgs.html', controller: 'persistentOrgsCtrl' })
.otherwise({ redirectTo: '/search' });
});
@ -806,6 +807,26 @@ orgsModule.controller('lastImportCtrl', function ($scope, $http) {
$scope.refresh();
});
orgsModule.controller('persistentOrgsCtrl', function ($scope, $http) {
$scope.orgs = {};
$scope.refresh = function() {
call_http_get($http, 'api/persistentOrgs', function(res) { $scope.orgs = res.data; });
}
$scope.addPersistentOrg = function(id) {
call_http_post($http, 'api/persistentOrgs', [ id ], function(res) { $scope.orgs = res.data; });
}
$scope.deletePersistentOrg = function(id) {
if (confirm("Are you sure ?")) {
call_http_delete($http, 'api/persistentOrgs?id=' + id, function(res) { $scope.orgs = res.data; });
}
}
$scope.refresh();
});
orgsModule.controller('utilsCtrl', function ($scope, $http) {
$scope.fulltextIndexMessage = '';

View File

@ -117,6 +117,8 @@ fieldset > legend { font-size : 1.2rem !important; }
<a class="dropdown-item" href="#!/utils" sec:authorize="hasRole('ROLE_OPENORGS_ADMIN')">System utilities</a>
<a class="dropdown-item" href="#!/lastImport" sec:authorize="hasRole('ROLE_OPENORGS_ADMIN')">Last import of suggestions</a>
<div class="dropdown-divider" sec:authorize="hasRole('ROLE_OPENORGS_ADMIN')"></div>
<a class="dropdown-item" href="#!/persistentOrgs">Configure persistent organizations</a>
<div class="dropdown-divider" sec:authorize="hasRole('ROLE_OPENORGS_ADMIN')"></div>
<a class="dropdown-item" href="#!/users">Manage users</a>
</div>
</li>