Skip to content

Commit

Permalink
invenio-damap: enable connection from InvenioRDM
Browse files Browse the repository at this point in the history
* Update re3data XML with root element
* Update library usages due to library migration

---------

Co-authored-by: Sotiris Tsepelakis <[email protected]>
Co-authored-by: ValentinFutterer <[email protected]>
  • Loading branch information
3 people committed Sep 19, 2024
1 parent f6500db commit ab4f13e
Show file tree
Hide file tree
Showing 26 changed files with 806 additions and 74 deletions.
27 changes: 14 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-component</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
Expand Down Expand Up @@ -126,36 +131,32 @@
<!-- Rest -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-client</artifactId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-client-jaxb</artifactId>
<artifactId>quarkus-rest-client-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<!-- Authentication -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb</artifactId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
<!-- Authentication -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
<artifactId>quarkus-smallrye-jwt</artifactId>
</dependency>
<!-- Database -->
<dependency>
Expand Down Expand Up @@ -260,7 +261,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>xjc</id>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/damap/base/enums/EDataAccessType.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,36 @@ public static EDataAccessType getByValue(String value) {
MAP.put(type.getValue(), type);
}
}

/**
* Compares this {@code EDataAccessType} instance with another {@code EDataAccessType} to
* determine which is more restrictive. The order of restriction is defined as:
*
* <ul>
* <li>{@code CLOSED} is the most restrictive.
* <li>{@code RESTRICTED} is more restrictive than {@code OPEN} but less restrictive than {@code
* CLOSED}.
* <li>{@code OPEN} is the least restrictive.
* </ul>
*
* @param other the other {@code EDataAccessType} to compare to; can be {@code null}. If {@code
* null}, this instance is considered more restrictive.
* @return {@code 1} if this instance is more restrictive than {@code other}, {@code -1} if this
* instance is less restrictive than {@code other}, and {@code 0} if both instances are equal.
*/
public int compare(EDataAccessType other) {
if (other == null) {
return 1;
}

if (this == other) {
return 0;
}

return switch (this) {
case CLOSED -> 1;
case RESTRICTED -> (other == CLOSED) ? -1 : 1;
case OPEN -> -1;
};
}
}
39 changes: 19 additions & 20 deletions src/main/java/org/damap/base/r3data/RepositoriesRemoteResource.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.damap.base.r3data;

import generated.Repository;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.resteasy.annotations.jaxrs.QueryParam;
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestQuery;
import org.re3data.schema._2_2.Re3Data;

/** RepositoriesRemoteResource interface. */
Expand All @@ -23,7 +22,7 @@ public interface RepositoriesRemoteResource {
*/
@GET
@Path("/v1/repositories")
List<Repository> getAll();
generated.List getAll();

/**
* getById.
Expand All @@ -33,7 +32,7 @@ public interface RepositoriesRemoteResource {
*/
@GET
@Path("/v1/repository/{id}")
Re3Data getById(@PathParam String id);
Re3Data getById(@RestPath String id);

/**
* search.
Expand All @@ -56,19 +55,19 @@ public interface RepositoriesRemoteResource {
*/
@GET
@Path("/beta/repositories")
List<Repository> search(
@QueryParam("subjects[]") List<String> subjects,
@QueryParam("contentTypes[]") List<String> contentTypes,
@QueryParam("countries[]") List<String> countries,
@QueryParam("certificates[]") List<String> certificates,
@QueryParam("pidSystems[]") List<String> pidSystems,
@QueryParam("aidSystems[]") List<String> aidSystems,
@QueryParam("repositoryAccess[]") List<String> repositoryAccess,
@QueryParam("dataAccess[]") List<String> dataAccess,
@QueryParam("dataUpload[]") List<String> dataUpload,
@QueryParam("dataLicenses[]") List<String> dataLicenses,
@QueryParam("repositoryTypes[]") List<String> repositoryTypes,
@QueryParam("institutionTypes[]") List<String> institutionTypes,
@QueryParam("versioning[]") List<String> versioning,
@QueryParam("metadataStandards[]") List<String> metadataStandards);
generated.List search(
@RestQuery("subjects[]") List<String> subjects,
@RestQuery("contentTypes[]") List<String> contentTypes,
@RestQuery("countries[]") List<String> countries,
@RestQuery("certificates[]") List<String> certificates,
@RestQuery("pidSystems[]") List<String> pidSystems,
@RestQuery("aidSystems[]") List<String> aidSystems,
@RestQuery("repositoryAccess[]") List<String> repositoryAccess,
@RestQuery("dataAccess[]") List<String> dataAccess,
@RestQuery("dataUpload[]") List<String> dataUpload,
@RestQuery("dataLicenses[]") List<String> dataLicenses,
@RestQuery("repositoryTypes[]") List<String> repositoryTypes,
@RestQuery("institutionTypes[]") List<String> institutionTypes,
@RestQuery("versioning[]") List<String> versioning,
@RestQuery("metadataStandards[]") List<String> metadataStandards);
}
10 changes: 5 additions & 5 deletions src/main/java/org/damap/base/r3data/RepositoriesResource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.damap.base.r3data;

import generated.Repository;
import generated.List.Repository;
import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand All @@ -14,7 +14,7 @@
import lombok.extern.jbosslog.JBossLog;
import org.damap.base.r3data.dto.RepositoryDetails;
import org.damap.base.r3data.mapper.RepositoryMapper;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.resteasy.reactive.RestPath;

/** RepositoriesResource class. */
@Path("/api/repositories")
Expand All @@ -33,7 +33,7 @@ public class RepositoriesResource {
@GET
public List<Repository> getAll() {
log.info("Get all repositories");
return repositoriesService.getAll();
return repositoriesService.getAll().getRepository();
}

/**
Expand All @@ -56,7 +56,7 @@ public List<RepositoryDetails> getRecommended() {
*/
@GET
@Path("/{id}")
public RepositoryDetails getById(@PathParam String id) {
public RepositoryDetails getById(@RestPath String id) {
log.info("Get repository with id: " + id);
return RepositoryMapper.mapToRepositoryDetails(repositoriesService.getById(id), id);
}
Expand All @@ -72,6 +72,6 @@ public RepositoryDetails getById(@PathParam String id) {
public List<Repository> search(@Context UriInfo uriInfo) {
log.info("Search repositories: " + uriInfo.getQueryParameters());
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
return repositoriesService.search(params);
return repositoriesService.search(params).getRepository();
}
}
5 changes: 2 additions & 3 deletions src/main/java/org/damap/base/r3data/RepositoriesService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.damap.base.r3data;

import generated.Repository;
import io.quarkus.cache.CacheResult;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -32,7 +31,7 @@ public class RepositoriesService {
* @return a {@link java.util.List} object
*/
@CacheResult(cacheName = "repositories")
public List<Repository> getAll() {
public generated.List getAll() {
return repositoriesRemoteResource.getAll();
}

Expand Down Expand Up @@ -78,7 +77,7 @@ public Re3Data getById(String id) {
* @param params a {@link jakarta.ws.rs.core.MultivaluedMap} object
* @return a {@link java.util.List} object
*/
public List<Repository> search(MultivaluedMap<String, String> params) {
public generated.List search(MultivaluedMap<String, String> params) {
List<String> subjects = params.get("subjects");
List<String> contentTypes = params.get("contentTypes");
List<String> certificates = params.get("certificates");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/damap/base/rest/AccessResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.damap.base.rest.access.service.AccessService;
import org.damap.base.rest.dmp.domain.ContributorDO;
import org.damap.base.validation.AccessValidator;
import org.jboss.resteasy.annotations.jaxrs.PathParam;

/** AccessResource class. */
@Path("/api/access")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.damap.base.rest.dmp.service.DmpService;
import org.damap.base.security.SecurityService;
import org.damap.base.validation.AccessValidator;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.resteasy.reactive.RestPath;

/** DataManagementPlanResource class. */
@Path("/api/dmps")
Expand Down Expand Up @@ -52,7 +52,7 @@ public List<DmpListItemDO> getAll() {
/*@GET
@Path("/person/{personId}")
@RolesAllowed("Damap Admin")
public List<DmpListItemDO> getDmpListByPerson(@PathParam String personId) {
public List<DmpListItemDO> getDmpListByPerson(@RestPath String personId) {
log.info("Return dmp for person id: " + personId);
return dmpService.getDmpListByPersonId(personId);
}*/
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<DmpListItemDO> getDmpsSubordinates() {
*/
@GET
@Path("/{id}")
public DmpDO getDmpById(@PathParam String id) {
public DmpDO getDmpById(@RestPath String id) {
log.info("Return dmp with id: " + id);
String personId = this.getPersonId();
long dmpId = Long.parseLong(id);
Expand Down Expand Up @@ -126,7 +126,7 @@ public DmpDO saveDmp(@Valid DmpDO dmpDO) {
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
public DmpDO updateDmp(@PathParam String id, @Valid DmpDO dmpDO) {
public DmpDO updateDmp(@RestPath String id, @Valid DmpDO dmpDO) {
log.info("Update dmp with id: " + id);
String personId = this.getPersonId();
long dmpId = Long.parseLong(id);
Expand All @@ -143,7 +143,7 @@ public DmpDO updateDmp(@PathParam String id, @Valid DmpDO dmpDO) {
*/
@DELETE
@Path("/{id}")
public void deleteDmp(@PathParam String id) {
public void deleteDmp(@RestPath String id) {
log.info("Delete dmp with id: " + id);
String personId = this.getPersonId();
long dmpId = Long.parseLong(id);
Expand All @@ -169,7 +169,7 @@ private String getPersonId() {
*/
@GET
@Path("/{id}/{revision}")
public DmpDO getDmpByIdAndRevision(@PathParam String id, @PathParam long revision) {
public DmpDO getDmpByIdAndRevision(@RestPath String id, @RestPath long revision) {
log.info("Return dmp with id: " + id + " and revision number: " + revision);
String personId = this.getPersonId();
long dmpId = Long.parseLong(id);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/damap/base/rest/FitsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.damap.base.rest.dmp.domain.MultipartBodyDO;
import org.damap.base.rest.dmp.mapper.DatasetDOMapper;
import org.damap.base.rest.fits.service.FitsService;
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;

/** FitsResource class. */
@Path("/api/fits")
Expand All @@ -29,7 +28,7 @@ public class FitsResource {
*/
@POST
@Path("/examine")
public DatasetDO examine(@MultipartForm MultipartBodyDO data) {
public DatasetDO examine(MultipartBodyDO data) {
log.info("Analyse file");
return DatasetDOMapper.mapEntityToDO(fitsService.analyseFile(data), new DatasetDO());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import lombok.extern.jbosslog.JBossLog;
import org.damap.base.rest.storage.InternalStorageDO;
import org.damap.base.rest.storage.InternalStorageService;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.resteasy.reactive.RestPath;

/** InternalStorageResource class. */
@Path("/api/storages")
Expand All @@ -29,7 +29,7 @@ public class InternalStorageResource {
*/
@GET
@Path("/{languageCode}")
public List<InternalStorageDO> getAllByLanguage(@PathParam String languageCode) {
public List<InternalStorageDO> getAllByLanguage(@RestPath String languageCode) {
log.debug("Return all internal storage options for language " + languageCode);
return internalStorageService.getAllByLanguage(languageCode);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/damap/base/rest/OpenAireResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.damap.base.rest.dmp.domain.DatasetDO;
import org.damap.base.rest.openaire.mapper.OpenAireMapper;
import org.damap.base.rest.openaire.service.OpenAireService;
import org.jboss.resteasy.annotations.jaxrs.QueryParam;
import org.jboss.resteasy.reactive.RestQuery;

/** OpenAireResource class. */
@Path("/api/openaire")
Expand All @@ -28,7 +28,7 @@ public class OpenAireResource {
* @return a {@link org.damap.base.rest.dmp.domain.DatasetDO} object
*/
@GET
public DatasetDO search(@QueryParam String doi) {
public DatasetDO search(@RestQuery String doi) {
log.info("Search for dataset with DOI: " + doi);
return OpenAireMapper.mapAtoB(doi, openAireService.search(doi), new DatasetDO());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/damap/base/rest/VersionResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.damap.base.rest.version.VersionService;
import org.damap.base.security.SecurityService;
import org.damap.base.validation.AccessValidator;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.resteasy.reactive.RestPath;

/** VersionResource class. */
@Path("/api/versions")
Expand All @@ -35,7 +35,7 @@ public class VersionResource {
*/
@GET
@Path("/list/{id}")
public List<VersionDO> getDmpVersions(@PathParam String id) {
public List<VersionDO> getDmpVersions(@RestPath String id) {
log.debug("Return dmp versions for dmp with id: " + id);
String personId = this.getPersonId();
long dmpId = Long.parseLong(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.core.MediaType;
import java.io.InputStream;
import org.jboss.resteasy.annotations.providers.multipart.PartType;
import java.io.File;
import org.jboss.resteasy.reactive.PartType;

/** MultipartBodyDO class. */
public class MultipartBodyDO {

@FormParam("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public InputStream file;
public File file;
}
Loading

0 comments on commit ab4f13e

Please sign in to comment.