Apply requested changes to RepositoryDepositService

This commit is contained in:
George Kalampokis 2023-11-06 16:56:59 +02:00
parent d8b1211a12
commit c6cdcc4b15
6 changed files with 106 additions and 72 deletions

View File

@ -22,14 +22,16 @@ public class DepositProperties {
public static class DepositSource { public static class DepositSource {
private final String url; private final String url;
private final List<String> codes;
private final String issuerUrl; private final String issuerUrl;
private final String clientId; private final String clientId;
private final String clientSecret; private final String clientSecret;
private final String scope; private final String scope;
@ConstructorBinding @ConstructorBinding
public DepositSource(String url, String issuerUrl, String clientId, String clientSecret, String scope) { public DepositSource(String url, List<String> codes, String issuerUrl, String clientId, String clientSecret, String scope) {
this.url = url; this.url = url;
this.codes = codes;
this.issuerUrl = issuerUrl; this.issuerUrl = issuerUrl;
this.clientId = clientId; this.clientId = clientId;
this.clientSecret = clientSecret; this.clientSecret = clientSecret;
@ -55,5 +57,9 @@ public class DepositProperties {
public String getScope() { public String getScope() {
return scope; return scope;
} }
public List<String> getCodes() {
return codes;
}
} }
} }

View File

@ -34,6 +34,8 @@ public class EntityDoiQuery extends QueryBase<EntityDoiEntity> {
private Collection<String> dois; private Collection<String> dois;
private Collection<UUID> entityIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public EntityDoiQuery ids(UUID value) { public EntityDoiQuery ids(UUID value) {
@ -111,6 +113,21 @@ public class EntityDoiQuery extends QueryBase<EntityDoiEntity> {
return this; return this;
} }
public EntityDoiQuery entityIds(Collection<UUID> values) {
this.entityIds = values;
return this;
}
public EntityDoiQuery entityIds(UUID value) {
this.entityIds = List.of(value);
return this;
}
public EntityDoiQuery entityIds(UUID... value) {
this.entityIds = Arrays.asList(value);
return this;
}
public EntityDoiQuery authorize(EnumSet<AuthorizationFlags> values) { public EntityDoiQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;

View File

@ -2,76 +2,94 @@ package eu.eudat.service.deposit;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.cache.deposit.RepositoryDepositConfigurationCache; import eu.eudat.cache.deposit.RepositoryDepositConfigurationCache;
import eu.eudat.commons.enums.EntityType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.configurations.deposit.DepositProperties; import eu.eudat.configurations.deposit.DepositProperties;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.depositinterface.models.DMPDepositModel; import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.models.FileEnvelope; import eu.eudat.depositinterface.models.FileEnvelope;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration; import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import eu.eudat.model.EntityDoi;
import eu.eudat.model.doi.DepositRequest; import eu.eudat.model.doi.DepositRequest;
import eu.eudat.model.doi.Doi;
import eu.eudat.model.doi.RepositoryConfig; import eu.eudat.model.doi.RepositoryConfig;
import eu.eudat.model.doi.RepositoryConfigs; import eu.eudat.model.doi.RepositoryConfigs;
import eu.eudat.model.mapper.deposit.DmpEntityDepositMapper; import eu.eudat.model.mapper.deposit.DmpEntityDepositMapper;
import eu.eudat.model.persist.EntityDoiPersist;
import eu.eudat.query.DmpQuery;
import eu.eudat.query.EntityDoiQuery;
import eu.eudat.repository.DepositRepository; import eu.eudat.repository.DepositRepository;
import eu.eudat.service.entitydoi.EntityDoiService;
import eu.eudat.utilities.pdf.PDFUtils; import eu.eudat.utilities.pdf.PDFUtils;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService; import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService;
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction; import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel; import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
import gr.cite.tools.data.query.Ordering;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.NoResultException;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.Root;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import javax.management.InvalidApplicationException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.time.Instant; import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service @Service
public class RepositoryDepositService { public class RepositoryDepositService {
private static final Logger logger = LoggerFactory.getLogger(RepositoryDepositService.class); private static final Logger logger = LoggerFactory.getLogger(RepositoryDepositService.class);
private final DepositProperties depositProperties; private final DepositProperties depositProperties;
private final List<DepositRepository> clients; private final Map<String, DepositRepository> clients;
private final ApiKeyCacheService apiKeyCacheService; private final ApiKeyCacheService apiKeyCacheService;
private final RepositoryDepositConfigurationCache repositoryDepositConfigurationCache; private final RepositoryDepositConfigurationCache repositoryDepositConfigurationCache;
private final EntityManager entityManager;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final ConventionService conventionService; private final ConventionService conventionService;
private final Environment environment; private final Environment environment;
private final DmpEntityDepositMapper depositMapper; private final DmpEntityDepositMapper depositMapper;
private final WebClient.Builder webClientBuilder;
private final EntityDoiService doiService;
private final ApplicationContext applicationContext;
@Autowired @Autowired
public RepositoryDepositService(DepositProperties depositProperties, ApiKeyCacheService apiKeyCacheService, RepositoryDepositConfigurationCache repositoryDepositConfigurationCache, WebClient.Builder builder, EntityManager entityManager, AuthorizationService authorizationService, ConventionService conventionService, Environment environment, DmpEntityDepositMapper depositMapper) { public RepositoryDepositService(DepositProperties depositProperties, ApiKeyCacheService apiKeyCacheService, RepositoryDepositConfigurationCache repositoryDepositConfigurationCache, WebClient.Builder builder, EntityManager entityManager, AuthorizationService authorizationService, ConventionService conventionService, Environment environment, DmpEntityDepositMapper depositMapper, DmpQuery dmpQuery, EntityDoiQuery doiQuery, EntityDoiService doiService, ApplicationContext applicationContext) {
this.depositProperties = depositProperties; this.depositProperties = depositProperties;
this.apiKeyCacheService = apiKeyCacheService; this.apiKeyCacheService = apiKeyCacheService;
this.repositoryDepositConfigurationCache = repositoryDepositConfigurationCache; this.repositoryDepositConfigurationCache = repositoryDepositConfigurationCache;
this.clients = depositRepositories(builder);
this.entityManager = entityManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.conventionService = conventionService; this.conventionService = conventionService;
this.environment = environment; this.environment = environment;
this.depositMapper = depositMapper; this.depositMapper = depositMapper;
//GK: I don't like this but that way you can both cache the available configurations and set Configuration Ids for each client this.webClientBuilder = builder;
getAvailableConfigurations(); this.doiService = doiService;
this.applicationContext = applicationContext;
this.clients = new HashMap<>();
}
private DepositRepository getRepository(String repoId) {
if (this.clients.containsKey(repoId)) return this.clients.get(repoId);
//GK: It's register time
DepositProperties.DepositSource source = depositProperties.getSources().stream().filter(depositSource -> depositSource.getCodes().contains(repoId)).findFirst().orElse(null);
if (source != null) {
String host = URI.create(source.getUrl()).getHost();
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
DepositRepository repository = new DepositRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build());
source.getCodes().forEach(code -> this.clients.put(code, repository));
return repository;
}
return null;
} }
@ -79,11 +97,12 @@ public class RepositoryDepositService {
RepositoryConfigs configs = repositoryDepositConfigurationCache.lookup("base"); RepositoryConfigs configs = repositoryDepositConfigurationCache.lookup("base");
if (configs == null) { if (configs == null) {
List<RepositoryConfig> configurations = new ArrayList<>(); List<RepositoryConfig> configurations = new ArrayList<>();
//GK: So much for lazy loading
List<DepositRepository> repositories = depositProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().get(0))).toList();
clients.forEach((client) -> { repositories.forEach((client) -> {
List<RepositoryDepositConfiguration> repositoryConfigs = client.getConfiguration(); List<RepositoryDepositConfiguration> repositoryConfigs = client.getConfiguration();
if (repositoryConfigs != null && !repositoryConfigs.isEmpty()) { if (repositoryConfigs != null && !repositoryConfigs.isEmpty()) {
client.getConfigurationIds().addAll(repositoryConfigs.stream().map(RepositoryDepositConfiguration::getRepositoryId).toList());
configurations.addAll(repositoryConfigs.stream().map(RepositoryConfig::toModel).toList()); configurations.addAll(repositoryConfigs.stream().map(RepositoryConfig::toModel).toList());
} }
}); });
@ -95,14 +114,15 @@ public class RepositoryDepositService {
return configs.getRepositoryConfigs(); return configs.getRepositoryConfigs();
} }
public Doi deposit(DepositRequest dmpDepositModel) { public EntityDoi deposit(DepositRequest dmpDepositModel) throws InvalidApplicationException {
this.authorizationService.authorize(Permission.EditDmp); this.authorizationService.authorize(Permission.EditDmp);
//GK: Why it is in that service, and why it's not static? //GK: Why it is in that service, and why it's not static?
this.conventionService.isValidGuid(UUID.fromString(dmpDepositModel.getDmpId())); this.conventionService.isValidGuid(UUID.fromString(dmpDepositModel.getDmpId()));
//GK: First get the right client //GK: First get the right client
DepositRepository repository = clients.stream().filter(client -> client.getConfigurationIds().contains(dmpDepositModel.getRepositoryId())).findFirst().orElseThrow(); DepositRepository repository = getRepository(dmpDepositModel.getRepositoryId());
//GK: Second get the Target Data Management Plan //GK: Second get the Target Data Management Plan
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, UUID.fromString(dmpDepositModel.getDmpId())); DmpQuery dmpQuery = applicationContext.getBean(DmpQuery.class);
DmpEntity dmpEntity = dmpQuery.ids(UUID.fromString(dmpDepositModel.getDmpId())).first();
//GK: Third get the DOI from the previous Data Management Plan (if it exists) //GK: Third get the DOI from the previous Data Management Plan (if it exists)
String previousDOI = null; String previousDOI = null;
@ -117,7 +137,7 @@ public class RepositoryDepositService {
FileEnvelope jsonEnvelope = new FileEnvelope(); FileEnvelope jsonEnvelope = new FileEnvelope();
File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip"); File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip");
try { try {
File documentFile = ResourceUtils.getFile(this.environment.getProperty("coniguration.h2020template")); File documentFile = ResourceUtils.getFile(this.environment.getProperty("configuration.h2020template"));
docEnvelope.setFilename("test.docx"); docEnvelope.setFilename("test.docx");
docEnvelope.setFile(documentFile); docEnvelope.setFile(documentFile);
File pdfFile = PDFUtils.convertToPDF(docEnvelope, environment); File pdfFile = PDFUtils.convertToPDF(docEnvelope, environment);
@ -145,52 +165,38 @@ public class RepositoryDepositService {
if (doi.isEmpty()) if (doi.isEmpty())
return null; return null;
//GK: doi is fine store it in database //GK: doi is fine store it in database
EntityDoiEntity doiEntity = new EntityDoiEntity(); EntityDoiPersist doiPersist = new EntityDoiPersist();
doiEntity.setId(UUID.randomUUID()); doiPersist.setRepositoryId(dmpDepositModel.getRepositoryId());
doiEntity.setDoi(doi); doiPersist.setDoi(doi);
doiEntity.setEntityType(EntityType.DMP); doiPersist.setEntityId(dmpEntity.getId());
DMP dmp = new DMP(); FieldSet fieldSet = new BaseFieldSet();
dmp.setId(dmpEntity.getId()); return doiService.persist(doiPersist, fieldSet);
doiEntity.setEntityId(dmp);
doiEntity.setCreatedAt(Instant.now());
doiEntity.setIsActive(IsActive.Active);
entityManager.persist(doiEntity);
return Doi.fromDataModel(doiEntity);
} }
private List<DepositRepository> depositRepositories(WebClient.Builder builder) { public String getLogo(String repoId) {
List<DepositRepository> tclients = new ArrayList<>(); //GK: First get the right client
for (DepositProperties.DepositSource source: depositProperties.getSources()) { DepositRepository repository = getRepository(repoId);
if (repository != null) {
String host = URI.create(source.getUrl()).getHost(); return repository.getLogo(repoId);
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
tclients.add(new DepositRepository(builder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build()));
} }
return tclients; return null;
} }
private String getPreviousDOI(UUID groupId, UUID currentId, String repoId) { private String getPreviousDOI(UUID groupId, UUID currentId, String repoId) {
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
EntityDoiEntity doiEntity = null; EntityDoiEntity doiEntity = null;
//GK: Step one get the previous version of the Data management plan //GK: Step one get the previous version of the Data management plan
CriteriaQuery<DmpEntity> query = builder.createQuery(DmpEntity.class); DmpQuery dmpQuery = this.applicationContext.getBean(DmpQuery.class);
Root<DmpEntity> root = query.from(DmpEntity.class); Ordering ordering = new Ordering();
query = query.select(root.get("id")); ordering.setItems(List.of("-version"));
query = query.where(builder.and(builder.equal(root.get("groupId"), groupId), builder.equal(root.get("isActive"), IsActive.Active))); dmpQuery.setOrder(ordering);
query = query.orderBy(builder.desc(root.get("version"))); FieldSet fieldSet = new BaseFieldSet();
List<UUID> dmpIds = this.entityManager.createQuery(query).getResultList().stream().map(DmpEntity::getId).toList(); fieldSet.ensure("id");
List<UUID> dmpIds = dmpQuery.groupIds(groupId).isActive(IsActive.Active).collectAs(fieldSet).stream().map(DmpEntity::getId).toList();
//GK: Step two get it's doiEntity //GK: Step two get it's doiEntity
CriteriaQuery<EntityDoiEntity> doiQuery = builder.createQuery(EntityDoiEntity.class); EntityDoiQuery doiQuery = this.applicationContext.getBean(EntityDoiQuery.class);
Root<EntityDoiEntity> doiRoot = doiQuery.from(EntityDoiEntity.class); List<EntityDoiEntity> dois = doiQuery.entityIds(dmpIds).isActive(IsActive.Active).collect();
doiQuery = doiQuery.multiselect(doiRoot.get("entityId").get("id"), doiRoot.get("doi"));
doiQuery = doiQuery.where(builder.and(doiRoot.get("entityId").get("id").in(dmpIds), builder.equal(doiRoot.get("isActive"), IsActive.Active), builder.equal(doiRoot.get("repositoryId"), repoId)));
List<EntityDoiEntity> dois = this.entityManager.createQuery(doiQuery).getResultList();
for(UUID uuid: dmpIds) for(UUID uuid: dmpIds)
{ {

View File

@ -42,10 +42,10 @@ public class Admin extends BaseController {
private final DescriptionTemplateTypeService descriptionTemplateTypeService; private final DescriptionTemplateTypeService descriptionTemplateTypeService;
private final FieldDataHelperService fieldDataHelperService; //private final FieldDataHelperService fieldDataHelperService;
@Autowired @Autowired
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader, MetricsManager metricsManager, AuthorizationService authorizationService, UserScope userScope, QueryFactory queryFactory, DescriptionTemplateTypeService descriptionTemplateTypeService, FieldDataHelperService fieldDataHelperService) { public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader, MetricsManager metricsManager, AuthorizationService authorizationService, UserScope userScope, QueryFactory queryFactory, DescriptionTemplateTypeService descriptionTemplateTypeService/*, FieldDataHelperService fieldDataHelperService*/) {
super(apiContext); super(apiContext);
this.datasetProfileManager = datasetProfileManager; this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager; this.userManager = userManager;
@ -55,7 +55,7 @@ public class Admin extends BaseController {
this.userScope = userScope; this.userScope = userScope;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.descriptionTemplateTypeService = descriptionTemplateTypeService; this.descriptionTemplateTypeService = descriptionTemplateTypeService;
this.fieldDataHelperService = fieldDataHelperService; //this.fieldDataHelperService = fieldDataHelperService;
} }
// @Transactional // @Transactional

View File

@ -3,11 +3,13 @@ package eu.eudat.controllers;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.logic.managers.DepositManager; import eu.eudat.logic.managers.DepositManager;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.EntityDoi;
import eu.eudat.model.doi.DepositCode; import eu.eudat.model.doi.DepositCode;
import eu.eudat.model.doi.DepositRequest; import eu.eudat.model.doi.DepositRequest;
import eu.eudat.model.doi.Doi; import eu.eudat.model.doi.Doi;
import eu.eudat.model.doi.RepositoryConfig; import eu.eudat.model.doi.RepositoryConfig;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.service.deposit.RepositoryDepositService;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -27,12 +29,14 @@ public class DepositController extends BaseController {
private final DepositManager depositManager; private final DepositManager depositManager;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final RepositoryDepositService repositoryDepositService;
@Autowired @Autowired
public DepositController(ApiContext apiContext, DepositManager depositManager, AuthorizationService authorizationService){ public DepositController(ApiContext apiContext, DepositManager depositManager, AuthorizationService authorizationService, RepositoryDepositService repositoryDepositService){
super(apiContext); super(apiContext);
this.depositManager = depositManager; this.depositManager = depositManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.repositoryDepositService = repositoryDepositService;
} }
@RequestMapping(method = RequestMethod.GET, value = {"/repos"}) @RequestMapping(method = RequestMethod.GET, value = {"/repos"})
@ -40,7 +44,7 @@ public class DepositController extends BaseController {
ResponseEntity<ResponseItem<List<RepositoryConfig>>> getAvailableRepos() { ResponseEntity<ResponseItem<List<RepositoryConfig>>> getAvailableRepos() {
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole);
List<RepositoryConfig> ids = this.depositManager.getAvailableRepos(); List<RepositoryConfig> ids = this.repositoryDepositService.getAvailableConfigurations();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RepositoryConfig>>().status(ApiMessageCode.NO_MESSAGE).payload(ids)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RepositoryConfig>>().status(ApiMessageCode.NO_MESSAGE).payload(ids));
} }
@ -55,19 +59,19 @@ public class DepositController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/createDoi"}) @RequestMapping(method = RequestMethod.POST, value = {"/createDoi"})
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<Doi>> createDoi(@RequestBody DepositRequest depositRequest) { ResponseEntity<ResponseItem<EntityDoi>> createDoi(@RequestBody DepositRequest depositRequest) {
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole);
try { try {
Doi doi = this.depositManager.deposit(depositRequest); EntityDoi doi = this.repositoryDepositService.deposit(depositRequest);
if(doi != null){ if(doi != null){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Doi>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(doi)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<EntityDoi>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(doi));
} }
else{ else{
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Doi>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<EntityDoi>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan"));
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Doi>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan: " + e.getMessage())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<EntityDoi>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan: " + e.getMessage()));
} }
} }
@ -76,7 +80,7 @@ public class DepositController extends BaseController {
ResponseEntity<ResponseItem<String>> getLogo(@PathVariable("repositoryId") String repositoryId) { ResponseEntity<ResponseItem<String>> getLogo(@PathVariable("repositoryId") String repositoryId) {
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole); this.authorizationService.authorizeForce(Permission.AdminRole, Permission.ManagerRole, Permission.UserRole, Permission.AnonymousRole);
try { try {
String encodedLogo = this.depositManager.getRepositoryLogo(repositoryId); String encodedLogo = this.repositoryDepositService.getLogo(repositoryId);
if(encodedLogo != null){ if(encodedLogo != null){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully loaded " + repositoryId + "'s logo.").payload(encodedLogo)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully loaded " + repositoryId + "'s logo.").payload(encodedLogo));
} }

View File

@ -1,6 +1,7 @@
deposit: deposit:
sources: sources:
- url: http://localhost:8082 - url: http://localhost:8082
codes: [ zenodo ]
issuer-url: ${ZENODO_ISSUER_URI:IDP_APIKEY_ISSUER_URI} issuer-url: ${ZENODO_ISSUER_URI:IDP_APIKEY_ISSUER_URI}
client-id: ${ZENODO_DEPOSIT_CLIENT_ID:} client-id: ${ZENODO_DEPOSIT_CLIENT_ID:}
client-secret: ${ZENODO_DEPOSIT_CLIENT_SECRET:} client-secret: ${ZENODO_DEPOSIT_CLIENT_SECRET:}