Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

# Conflicts:
#	dmp-backend/core/src/main/java/eu/eudat/commons/enums/ExternalReferencesType.java
This commit is contained in:
Efstratios Giannopoulos 2023-10-20 19:17:14 +03:00
commit 30bff76163
24 changed files with 457 additions and 34 deletions

View File

@ -0,0 +1,29 @@
package eu.eudat.commons.enums;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum DMPStatus implements DatabaseEnum<Short> {
ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99);
private final Short value;
DMPStatus(Short value) {
this.value = value;
}
@Override
public Short getValue() {
return null;
}
private static final Map<Short, DMPStatus> map = EnumUtils.getEnumValueMap(DMPStatus.class);
public static DMPStatus of(Short i) {
return map.get(i);
}
}

View File

@ -0,0 +1,285 @@
package eu.eudat.data;
import eu.eudat.commons.enums.DMPStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.*;
import org.hibernate.annotations.GenericGenerator;
import java.time.Instant;
import java.util.UUID;
//TODO: (thgiannos) Wire up when all other dependent entities are refactored
//@Entity
//@Table(name = "\"DMP\"")
public class DMPEntity {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
public static final String _id = "id";
@Column(name = "label")
private String label;
public static final String _label = "label";
@Column(name = "version")
private Integer version;
public static final String _version = "version";
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false)
private DMPStatus status;
public static final String _status = "status";
@Column(name = "properties")
private String properties;
public static final String _properties = "properties";
@Column(name = "dmp_properties")
private String dmpProperties;
public static final String _dmpProperties = "dmpProperties";
@Column(name = "group_id", columnDefinition = "BINARY(16)")
private UUID groupId;
public static final String _groupId = "groupId";
@Column(name = "description")
private String description;
public static final String _description = "description";
@Column(name = "is_public", nullable = false)
private boolean isPublic;
public static final String _isPublic = "isPublic";
@Column(name = "extra_properties")
private String extraProperties;
public static final String _extraProperties = "extraProperties";
@Column(name = "created_at")
@Convert(converter = DateToUTCConverter.class)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "updated_at")
@Convert(converter = DateToUTCConverter.class)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
//TODO: (thgiannos) Handle using the DMPEntity builder
// @OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
// private Set<Dataset> dataset;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Grant\"")
//TODO: (thgiannos) Previously 'Grant'
private UUID grant;
//TODO: (thgiannos) Handle using the DMPEntity builder
// @OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp")
// private Set<DMPDatasetProfile> associatedDmps;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Profile\"")
//TODO: (thgiannos) Previously 'DMPProfile'
private UUID profile;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Creator\"")
//TODO: (thgiannos) Previously 'UserInfo'
private UUID creator;
//TODO: (thgiannos) Handle using the DMPEntity builder
// @OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY)
// private Set<EntityDoiEntity> dois;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Project\"")
//TODO: (thgiannos) Previously 'Project'
private UUID project;
// TODO: (thgiannos) Implement join entity
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPOrganisation\"",
// joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}
// )
// private Set<Organisation> organisations;
// TODO: (thgiannos) Implement join entity
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPResearcher\"",
// joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}
// )
// private Set<Researcher> researchers;
//TODO: (thgiannos) Handle using the DMPEntity builder
// private Set<UserDMP> users;
// @Column(name = "\"FinalizedAt\"")
// @Convert(converter = DateToUTCConverter.class)
// private Date finalizedAt;
//
// @Column(name = "\"PublishedAt\"")
// @Convert(converter = DateToUTCConverter.class)
// private Date publishedAt;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public DMPStatus getStatus() {
return status;
}
public void setStatus(DMPStatus status) {
this.status = status;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
public String getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(String extraProperties) {
this.extraProperties = extraProperties;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public UUID getGrant() {
return grant;
}
public void setGrant(UUID grant) {
this.grant = grant;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public UUID getCreator() {
return creator;
}
public void setCreator(UUID creator) {
this.creator = creator;
}
public UUID getProject() {
return project;
}
public void setProject(UUID project) {
this.project = project;
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.DMPStatus;
import jakarta.persistence.Converter;
@Converter
public class DMPStatusConverter extends DatabaseEnumConverter<DMPStatus, Short> {
@Override
protected DMPStatus of(Short i) {
return DMPStatus.of(i);
}
}

View File

@ -342,7 +342,6 @@ public class DMP implements DataEntity<DMP, UUID> {
this.publishedAt = publishedAt;
}
//TODO: Dois will no longer be fetched by hibernate but using the query builders eventually. Use builder where this is called.
public Set<EntityDoiEntity> getDois() {
return dois;
}

View File

@ -0,0 +1,5 @@
package eu.eudat.model;
public class DMP {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.model.builder;
public class DMPBuilder {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.model.censorship;
public class DMPCensor {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.model.deleter;
public class DMPDeleter {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.model.persist;
public class DMPPersist {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.query;
public class DMPQueryV2 {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.query.lookup;
public class DMPLookup {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.service;
public interface DMPService {
}

View File

@ -0,0 +1,5 @@
package eu.eudat.service;
public class DMPServiceImpl implements DMPService {
}

View File

@ -39,7 +39,6 @@ import java.util.List;
import java.util.UUID;
@Service
@RequestScope
public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTypeService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeServiceImpl.class));

View File

@ -70,14 +70,15 @@ public class ExternalReferencesController extends BaseController {
@GetMapping(path = {"data-repo/{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") ExternalReferencesType externalType,
@GetMapping(path = {"{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@PathVariable(value = "externalType") int externalType,
@RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReferencesType externalReferencesType = ExternalReferencesType.of((short) externalType);
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalType, query, type);
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalReferencesType, query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
}

View File

@ -5,7 +5,7 @@ import eu.eudat.controllers.BaseController;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.ValidationService;
import eu.eudat.logic.services.ExternalValidationService;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -17,15 +17,15 @@ import org.springframework.web.bind.annotation.*;
@RestController
@CrossOrigin
@RequestMapping(path = {"api/validation"})
public class ValidationController extends BaseController {
public class ExternalValidationController extends BaseController {
private ValidationService validationService;
private ExternalValidationService externalValidationService;
private final AuthorizationService authorizationService;
@Autowired
public ValidationController(ApiContext apiContext, ValidationService validationService, AuthorizationService authorizationService) {
public ExternalValidationController(ApiContext apiContext, ExternalValidationService externalValidationService, AuthorizationService authorizationService) {
super(apiContext);
this.validationService = validationService;
this.externalValidationService = externalValidationService;
this.authorizationService = authorizationService;
}
@ -36,7 +36,7 @@ public class ValidationController extends BaseController {
) throws HugeResultSet, NoURLFound {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
Boolean isValid = this.validationService.validateIdentifier(query, type);
Boolean isValid = this.externalValidationService.validateIdentifier(query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -367,7 +367,7 @@ public class DataManagementPlanManager {
throw new UnauthorisedException();
} else
if (!isPublic && dataManagementPlanEntity.getUsers()
.stream().noneMatch(userInfo -> userInfo.getUser().getId() == this.userScope.getUserIdSafe())) {
.stream().noneMatch(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe()))) {
throw new UnauthorisedException();
} else if (isPublic && !dataManagementPlanEntity.isPublic()) {
throw new ForbiddenException("Selected DMP is not public");
@ -1321,7 +1321,7 @@ public class DataManagementPlanManager {
XWPFDocument document = configLoader.getDocument();
DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == this.userScope.getUserIdSafe()).collect(Collectors.toList()).size() == 0)
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe())).collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException();
wordBuilder.fillFirstPage(dmpEntity, null, document, false);

View File

@ -9,13 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ValidationService {
public class ExternalValidationService {
private RemoteFetcher remoteFetcher;
private final UserScope userScope;
@Autowired
public ValidationService(RemoteFetcher remoteFetcher, UserScope userScope) {
public ExternalValidationService(RemoteFetcher remoteFetcher, UserScope userScope) {
super();
this.remoteFetcher = remoteFetcher;
this.userScope = userScope;

View File

@ -25,7 +25,7 @@ import java.util.Map;
import java.util.stream.Collectors;
@org.springframework.stereotype.Service
public class ExternalReferencesService {//implements ExternalReferencesService{
public class ExternalReferencesService {
private final ApiContext apiContext;
private final UserScope userScope;

View File

@ -217,7 +217,11 @@ public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManag
}
this.isPublic = entity.isPublic();
this.publishedAt = entity.getPublishedAt();
if (entity.getDois() != null) {
this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
} else {
this.dois = new ArrayList<>();
}
return this;
}

View File

@ -0,0 +1,18 @@
export enum ExternalReferencesType {
Taxonomies = 0,
Licenses = 1,
Publications = 2,
Journals = 3,
PubRepositories = 4,
DataRepositories = 5,
Registries = 6,
Services = 7,
Project = 8,
Funder = 9,
Datasets = 10,
Organizations = 11,
Grants = 12,
Validators = 13,
Researcher = 14,
Prefillings = 15
}

View File

@ -0,0 +1,19 @@
export interface ExternalReference {
id: string;
name: string;
abbreviation: string;
pid: string;
originalId: string;
key: string;
pidTypeField: string;
uri: string;
description: string;
source: string;
count: string;
path: string;
host: string;
types: string;
firstName: string;
lastName: string;
tag: string;
}

View File

@ -14,7 +14,8 @@ import { BaseHttpService } from '../http/base-http.service';
import { ConfigurationService } from '../configuration/configuration.service';
import { LicenseCriteria } from '@app/core/query/license/license-criteria';
import {PublicationCriteria} from "@app/core/query/publication/publication-criteria";
import { ExternalReference } from '@app/core/model/external-reference/external-reference';
import { ExternalReferencesType } from '@app/core/common/enum/external-references-type';
@Injectable()
export class ExternalSourcesService {
@ -58,6 +59,13 @@ export class ExternalSourcesService {
return this.http.get<ExternalSourceItemModel[]>(this.actionUrl + 'licenses' + '?query=' + requestItem.criteria.like + '&type=' + requestItem.criteria.type, { headers: this.headers });
}
public listExternal(externalType: ExternalReferencesType, query: string, type: string): Observable<ExternalReference[]> {
const url = this.configurationService.server + `external-references/${externalType}`;
const options = { params: { query: query, type: type } };
return this.http.get<ExternalReference[]>(url, options);
}
public searchDatasetTags(requestItem: RequestItem<TagCriteria>): Observable<ExternalSourceItemModel[]> {
// return Observable.of([
// { id: '1', name: 'Tag 1', description: '' },

View File

@ -48,6 +48,8 @@ import {MatDialog} from "@angular/material/dialog";
import {HttpError} from "@common/modules/errors/error-handling/http-error-handling.service";
import {HttpErrorResponse} from "@angular/common/http";
import * as FileSaver from "file-saver";
import { ExternalReference } from '@app/core/model/external-reference/external-reference';
import { ExternalReferencesType } from '@app/core/common/enum/external-references-type';
@Component({
selector: 'app-form-field',
@ -470,63 +472,63 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem);
}
searchDatasetExternalDataRepositories(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalDataRepositories(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<DataRepositoryCriteria> = new RequestItem();
requestItem.criteria = new DataRepositoryCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchDatasetRepository(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.DataRepositories, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalPubRepositories(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalPubRepositories(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<DataRepositoryCriteria> = new RequestItem();
requestItem.criteria = new DataRepositoryCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchPublicationRepository(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.PubRepositories, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalJournalRepositories(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalJournalRepositories(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<DataRepositoryCriteria> = new RequestItem();
requestItem.criteria = new DataRepositoryCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchJournals(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Journals, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalTaxonomies(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalTaxonomies(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<TaxonomyCriteria> = new RequestItem();
requestItem.criteria = new TaxonomyCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchTaxonomies(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Taxonomies, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalLicences(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalLicences(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<LicenseCriteria> = new RequestItem();
requestItem.criteria = new LicenseCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchLicense(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Licenses, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalPublications(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalPublications(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<PublicationCriteria> = new RequestItem();
requestItem.criteria = new PublicationCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchPublications(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Publications, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalRegistries(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalRegistries(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<RegistryCriteria> = new RequestItem();
requestItem.criteria = new RegistryCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchDatasetRegistry(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Registries, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetExternalServices(query: string): Observable<ExternalSourceItemModel[]> {
searchDatasetExternalServices(query: string): Observable<ExternalReference[]> {
const requestItem: RequestItem<ServiceCriteria> = new RequestItem();
requestItem.criteria = new ServiceCriteria();
requestItem.criteria.like = query;
requestItem.criteria.type = '';
return this.externalSourcesService.searchDatasetService(requestItem);
return this.externalSourcesService.listExternal(ExternalReferencesType.Services, requestItem.criteria.like, requestItem.criteria.type);
}
searchDatasetTags(query: string): Observable<ExternalSourceItemModel[]> {