persistent orgs filter and creation using OpenaireIDs

This commit is contained in:
Michele Artini 2022-11-14 11:59:31 +01:00
parent 91d341c7be
commit 39d335439f
3 changed files with 74 additions and 47 deletions

View File

@ -1,5 +1,7 @@
package eu.dnetlib.organizations.repository.readonly; package eu.dnetlib.organizations.repository.readonly;
import java.util.Optional;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import eu.dnetlib.organizations.model.view.OrganizationView; import eu.dnetlib.organizations.model.view.OrganizationView;
@ -7,4 +9,5 @@ import eu.dnetlib.organizations.model.view.OrganizationView;
@Repository @Repository
public interface OrganizationViewRepository extends ReadOnlyRepository<OrganizationView, String> { public interface OrganizationViewRepository extends ReadOnlyRepository<OrganizationView, String> {
Optional<OrganizationView> findByOpenaireId(String openaireId);
} }

View File

@ -657,13 +657,28 @@ public class DatabaseUtils {
return persistentOrganizationViewRepository.findAll(); return persistentOrganizationViewRepository.findAll();
} }
public void addPersistentOrgs(final String id) { public String addPersistentOrgs(final String id) {
final boolean valid = organizationRepository.findById(id)
final boolean valid;
final String ooid;
if (id.length() == 46) {
final Optional<OrganizationView> orgView = organizationViewRepository.findByOpenaireId(id);
valid = orgView.map(OrganizationView::getStatus)
.filter(s -> s.equals(OrganizationStatus.approved.toString()))
.isPresent();
ooid = orgView.get().getId();
} else {
valid = organizationRepository.findById(id)
.map(Organization::getStatus) .map(Organization::getStatus)
.filter(s -> s.equals(OrganizationStatus.approved.toString())) .filter(s -> s.equals(OrganizationStatus.approved.toString()))
.isPresent(); .isPresent();
ooid = id;
}
if (valid) { if (valid) {
persistentOrganizationRepository.save(new PersistentOrganization(id)); persistentOrganizationRepository.save(new PersistentOrganization(ooid));
return ooid;
} else { } else {
throw new RuntimeException("The ID does not refer to an approved Organization"); throw new RuntimeException("The ID does not refer to an approved Organization");
} }

View File

@ -4,7 +4,13 @@
<small>It is necessary to persist the identifiers of the organizations associated to an Institutional Dashboard</small> <small>It is necessary to persist the identifiers of the organizations associated to an Institutional Dashboard</small>
</p> </p>
<table class="table table-sm small">
<div class="row">
<div class="col-sm-12">
<input type="text" class="form-control form-control-sm mb-3" ng-model="poFilter" placeholder="Filter...">
<form>
<table class="table table-sm small">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
<th style="width: 200px">ID</th> <th style="width: 200px">ID</th>
@ -15,7 +21,7 @@
</tr> </tr>
</thead> </thead>
<tbody ng-show="orgs.length > 0"> <tbody ng-show="orgs.length > 0">
<tr ng-repeat="o in orgs"> <tr ng-repeat="o in orgs | filter:poFilter">
<td><a href="#!/edit/0/{{o.id}}">{{o.id}}</a></td> <td><a href="#!/edit/0/{{o.id}}">{{o.id}}</a></td>
<td>{{o.openaireId}}</td> <td>{{o.openaireId}}</td>
<td>{{o.name}}</td> <td>{{o.name}}</td>
@ -35,13 +41,16 @@
<tfoot> <tfoot>
<tr ng-init="newId=''"> <tr ng-init="newId=''">
<td colspan="4"> <td colspan="4">
<input type="text" class="form-control form-control-sm" placeholder="new persistent organization ID..." ng-model="newId" /> <input type="text" class="form-control form-control-sm" placeholder="example: openorgs____::0123456789 (OpenOrgs ID, 24 chars) or openorgs____::781e5e245d69b566979b86e28d23f2c7 (OA Graph Node ID, 64 chars) ..." ng-model="newId" />
</td> </td>
<td class="text-right"> <td class="text-right">
<button type="button" class="btn btn-sm btn-outline-success" ng-click="addPersistentOrg(newId); newId=''" ng-disabled="!newId"> <button type="submit" class="btn btn-sm btn-outline-success" ng-click="addPersistentOrg(newId); newId=''" ng-disabled="!newId">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
</button> </button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
</form>
</div>
</div>