add repository logo

This commit is contained in:
Bernaldo Mihasi 2023-01-17 14:41:04 +02:00
parent 95c9d599e1
commit 030f1ccf8e
5 changed files with 39 additions and 9 deletions

View File

@ -64,4 +64,21 @@ public class DepositController extends BaseController {
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()));
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/logo/{repositoryId}"})
public @ResponseBody
ResponseEntity<ResponseItem<String>> getLogo(@PathVariable("repositoryId") String repositoryId, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
try {
String encodedLogo = this.depositManager.getRepositoryLogo(repositoryId);
if(encodedLogo != null){
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully loaded " + repositoryId + "'s logo.").payload(encodedLogo));
}
else{
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message(repositoryId + " has no logo").payload(null));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to load " + repositoryId + "'s logo: " + e.getMessage()));
}
}
}

View File

@ -1,13 +1,7 @@
package eu.eudat.logic.managers;
import eu.eudat.data.entities.DMP;
import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.repository.RepositoryDeposit;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import eu.eudat.exceptions.security.NonValidTokenException;
import eu.eudat.logic.security.repositorydeposit.mapper.DMPToDepositMapper;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.pdf.PDFUtils;
import eu.eudat.models.data.doi.DepositRequest;
import eu.eudat.models.data.doi.Doi;
import eu.eudat.models.data.doi.RepositoryConfig;
@ -15,11 +9,8 @@ import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -57,4 +48,11 @@ public class DepositManager {
public Doi deposit(DepositRequest depositRequest, Principal principal) throws Exception {
return this.dataManagementPlanManager.createDoi(depositRequest, principal);
}
public String getRepositoryLogo(String repositoryId){
Optional<RepositoryDeposit> repo = repositories.stream().filter(x -> x.getConfiguration().getRepositoryId().equals(repositoryId)).findFirst();
return repo.map(repositoryDeposit ->
(repositoryDeposit.getConfiguration().isHasLogo()) ? repositoryDeposit.getLogo() : null
).orElse(null);
}
}

View File

@ -10,6 +10,7 @@ public class RepositoryConfig {
private String repositoryRecordUrl;
private String repositoryClientId;
private String redirectUri;
private boolean hasLogo;
public int getDepositType() {
return depositType;
@ -53,6 +54,13 @@ public class RepositoryConfig {
this.redirectUri = redirectUri;
}
public boolean isHasLogo() {
return hasLogo;
}
public void setHasLogo(boolean hasLogo) {
this.hasLogo = hasLogo;
}
public RepositoryConfig toModel(RepositoryDepositConfiguration r){
this.setDepositType(r.getDepositType());
this.setRepositoryId(r.getRepositoryId());
@ -60,6 +68,7 @@ public class RepositoryConfig {
this.setRepositoryRecordUrl(r.getRepositoryRecordUrl());
this.setRepositoryClientId(r.getRepositoryClientId());
this.setRedirectUri(r.getRedirectUri());
this.setHasLogo(r.isHasLogo());
return this;
}
}

View File

@ -7,4 +7,5 @@ export class DepositConfigurationModel {
repositoryRecordUrl: string;
repositoryClientId: string;
redirectUri: string;
hasLogo: boolean;
}

View File

@ -35,4 +35,9 @@ export class DepositRepositoriesService {
depositRequest.accessToken = accessToken;
return this.http.post<DoiModel>(this.actionUrl + 'createDoi', depositRequest, { headers: this.headers });
}
getLogo(repositoryId: string): Observable<string> {
return this.http.get<string>(this.actionUrl + 'logo/' + repositoryId, { headers: this.headers });
}
}