Skip to content

Commit

Permalink
service: create version after remotely adding dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
rekt-hard authored and SotosTsepe committed Jan 23, 2024
1 parent e69f9c9 commit dc32585
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.ac.tuwien.damap.rest.invenioDamap;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -14,6 +16,7 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.apache.james.mime4j.dom.datetime.DateTime;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.resteasy.annotations.jaxrs.PathParam;

Expand All @@ -32,6 +35,8 @@
import at.ac.tuwien.damap.rest.dmp.service.DmpService;
import at.ac.tuwien.damap.rest.madmp.dto.Dataset;
import at.ac.tuwien.damap.rest.madmp.service.MaDmpService;
import at.ac.tuwien.damap.rest.version.VersionDO;
import at.ac.tuwien.damap.rest.version.VersionService;
import at.ac.tuwien.damap.security.SecurityService;
import at.ac.tuwien.damap.validation.AccessValidator;
import io.quarkus.security.ForbiddenException;
Expand All @@ -58,6 +63,9 @@ public class InvenioDAMAPResource {
@Inject
MaDmpService madmpService;

@Inject
VersionService versionService;

@ConfigProperty(name = "invenio.shared-secret")
String sharedSecret;

Expand All @@ -80,9 +88,9 @@ public List<DmpDO> getDmpListByPerson(@PathParam String personId,

// This could allow us to authenticate users with OIDC, and allow admins to
// access all DMPs.
// Since this will always evaluate to false as of right now, it will check the
// auth header
if (!(securityService.isAdmin() || securityService.getUserId() == personId)) {
// Since this will always evaluate to false as of right now, it will check the
// auth header
if (!validateAuthHeader(headers)) {
throw new UnauthorizedException();
}
Expand Down Expand Up @@ -117,10 +125,19 @@ public DmpDO addDataSetToDMP(@PathParam long id, @PathParam String personId, Dat
var datasetDO = mapMaDMPDatasetToDatasetDO(dmpDO, new DatasetDO(), dataset, null);

dmpDO.getDatasets().add(datasetDO);
return dmpService.update(dmpDO);
dmpDO = dmpService.update(dmpDO);

VersionDO version = new VersionDO();
version.setDmpId(id);
version.setVersionName(MessageFormat.format("Added dataset `{0}` from remote datasource", dataset.getTitle()));
version.setVersionDate(new Date());
versionService.create(version);

return dmpDO;
}

public DatasetDO mapMaDMPDatasetToDatasetDO(DmpDO dmpDO,
// TODO: move to mapper
private DatasetDO mapMaDMPDatasetToDatasetDO(DmpDO dmpDO,
DatasetDO datasetDO,
Dataset madmpDataset, MapperService mapperService) {

Expand Down

0 comments on commit dc32585

Please sign in to comment.