@ -13,6 +13,7 @@ import eu.eudat.model.Description;
import eu.eudat.model.Dmp ;
import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder ;
import eu.eudat.model.builder.commonmodels.dmp.DmpCommonModelBuilder ;
import eu.eudat.model.file.RepositoryFileFormat ;
import eu.eudat.model.file.TransformerCacheModel ;
import eu.eudat.query.DescriptionQuery ;
import eu.eudat.query.DmpQuery ;
@ -47,20 +48,18 @@ public class FileTransformerServiceImpl implements FileTransformerService {
private final TokenExchangeCacheService tokenExchangeCacheService ;
private final FileTransformerConfigurationCache fileTransformerConfigurationCache ;
private final AuthorizationService authorizationService ;
private final WebClient . Builder webClientBuilder ;
private final QueryFactory queryFactory ;
private final BuilderFactory builderFactory ;
private final StorageFileService storageFileService ;
private final MessageSource messageSource ;
@Autowired
public FileTransformerServiceImpl ( TransformerProperties transformerProperties , TokenExchangeCacheService tokenExchangeCacheService , FileTransformerConfigurationCache fileTransformerConfigurationCache , WebClient. Builder builder , AuthorizationService authorizationService ,
public FileTransformerServiceImpl ( TransformerProperties transformerProperties , TokenExchangeCacheService tokenExchangeCacheService , FileTransformerConfigurationCache fileTransformerConfigurationCache , AuthorizationService authorizationService ,
QueryFactory queryFactory , BuilderFactory builderFactory , StorageFileService storageFileService , MessageSource messageSource ) {
this . transformerProperties = transformerProperties ;
this . tokenExchangeCacheService = tokenExchangeCacheService ;
this . fileTransformerConfigurationCache = fileTransformerConfigurationCache ;
this . authorizationService = authorizationService ;
this . webClientBuilder = builder ;
this . queryFactory = queryFactory ;
this . builderFactory = builderFactory ;
this . storageFileService = storageFileService ;
@ -72,16 +71,17 @@ public class FileTransformerServiceImpl implements FileTransformerService {
if ( this . clients . containsKey ( repoId ) ) return this . clients . get ( repoId ) ;
//GK: It's register time
TransformerProperties . TransformerSource source = transformerProperties . getSources ( ) . stream ( ) . filter ( depositSource - > depositSource . get Codes( ) . contain s( repoId ) ) . findFirst ( ) . orElse ( null ) ;
TransformerProperties . TransformerSource source = transformerProperties . getSources ( ) . stream ( ) . filter ( depositSource - > depositSource . get TransformerId( ) . equal s( repoId ) ) . findFirst ( ) . orElse ( null ) ;
if ( source ! = null ) {
String host = URI . create ( source . getUrl ( ) ) . getHost ( ) ;
TokenExchangeModel tokenExchangeModel = new TokenExchangeModel ( host + "_" + source . getClientId ( ) , source . getIssuerUrl ( ) , source . getClientId ( ) , source . getClientSecret ( ) , source . getScope ( ) ) ;
TokenExchangeFilterFunction tokenExchangeFilterFunction = new TokenExchangeFilterFunction ( this . tokenExchangeCacheService , tokenExchangeModel ) ;
TransformerRepository repository = new TransformerRepository ( webClientBuilder . baseUrl ( source . getUrl ( ) + "/api/file-transformer" ) . filters ( exchangeFilterFunctions - > {
TransformerRepository repository = new TransformerRepository ( WebClient . builder ( ) . baseUrl ( source . getUrl ( ) + "/api/file-transformer" ) . filters ( exchangeFilterFunctions - > {
exchangeFilterFunctions . add ( tokenExchangeFilterFunction ) ;
exchangeFilterFunctions . add ( logRequest ( ) ) ;
} ) . build ( ) ) ;
source . getCodes ( ) . forEach ( code - > this . clients . put ( code, repository ) ) ;
this . clients . put ( source. getTransformerId ( ) , repository ) ;
return repository ;
}
return null ;
@ -89,12 +89,12 @@ public class FileTransformerServiceImpl implements FileTransformerService {
@Override
public List < FileFormat> getAvailableExportFileFormats ( ) {
List < FileFormat> formats = new ArrayList < > ( ) ;
public List < Repository FileFormat> getAvailableExportFileFormats ( ) {
List < Repository FileFormat> formats = new ArrayList < > ( ) ;
List < FileTransformerConfiguration > configurations = this . getAvailableConfigurations ( ) ;
if ( configurations ! = null ) {
for ( FileTransformerConfiguration configuration : configurations ) {
if ( configuration ! = null & & configuration . getExportVariants ( ) ! = null ) formats . addAll ( configuration . getExportVariants ( ) );
if ( configuration ! = null & & configuration . getExportVariants ( ) ! = null ) formats . addAll ( configuration . getExportVariants ( ) .stream ( ) . map ( x - > new RepositoryFileFormat ( configuration . getFileTransformerId ( ) , x ) ) . toList ( ) );
}
}
return formats ;
@ -105,7 +105,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
if ( configs = = null ) {
List < FileTransformerConfiguration > configurations = new ArrayList < > ( ) ;
//GK: So much for lazy loading
List < TransformerRepository > repositories = transformerProperties . getSources ( ) . stream ( ) . map ( depositSource - > getRepository ( depositSource . get Codes( ) . getFirst ( ) ) ) . toList ( ) ;
List < TransformerRepository > repositories = transformerProperties . getSources ( ) . stream ( ) . map ( depositSource - > getRepository ( depositSource . get TransformerId ( ) ) ) . toList ( ) ;
repositories = new ArrayList < > ( repositories ) ;
repositories . forEach ( ( client ) - > {
@ -131,10 +131,10 @@ public class FileTransformerServiceImpl implements FileTransformerService {
this . authorizationService . authorize ( Permission . EditDmp ) ;
//GK: First get the right client
TransformerRepository repository = getRepository ( repositoryId ) ;
if ( repository = = null ) throw new MyNotFoundException ( messageSource . getMessage ( "General_ItemNotFound" , new Object [ ] { repositoryId , TransformerRepository . class . getSimpleName ( ) } , LocaleContextHolder . getLocale ( ) ) ) ;
if ( repository = = null ) throw new MyNotFoundException ( messageSource . getMessage ( "General_ItemNotFound" , new Object [ ] { format , TransformerRepository . class . getSimpleName ( ) } , LocaleContextHolder . getLocale ( ) ) ) ;
//GK: Second get the Target Data Management Plan
DmpQuery query = this . queryFactory . query ( DmpQuery . class ) . authorize ( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . ids ( dmpId ) ;
DmpModel dmpFileTransformerModel = this . builderFactory . builder ( DmpCommonModelBuilder . class ) . useSharedStorage ( repository . getConfiguration ( ) . isUseSharedStorage ( ) ) . authorize( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . build ( query . first ( ) ) ;
DmpModel dmpFileTransformerModel = this . builderFactory . builder ( DmpCommonModelBuilder . class ) . useSharedStorage ( repository . getConfiguration ( ) . isUseSharedStorage ( ) ) . setRepositoryId( repository . getConfiguration ( ) . getFileTransformerId ( ) ) . authorize( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . build ( query . first ( ) ) ;
if ( dmpFileTransformerModel = = null ) throw new MyNotFoundException ( messageSource . getMessage ( "General_ItemNotFound" , new Object [ ] { dmpId , Dmp . class . getSimpleName ( ) } , LocaleContextHolder . getLocale ( ) ) ) ;
FileEnvelopeModel fileEnvelope = repository . exportDmp ( dmpFileTransformerModel , format ) ;
@ -147,15 +147,15 @@ public class FileTransformerServiceImpl implements FileTransformerService {
}
@Override
public eu . eudat . model . file . FileEnvelope exportDescription ( UUID descriptionId , String format) {
public eu . eudat . model . file . FileEnvelope exportDescription ( UUID descriptionId , String repositoryId, String format) {
this . authorizationService . authorize ( Permission . EditDmp ) ;
//GK: First get the right client
TransformerRepository repository = getRepository ( format ) ;
TransformerRepository repository = getRepository ( repositoryId ) ;
if ( repository = = null ) throw new MyNotFoundException ( messageSource . getMessage ( "General_ItemNotFound" , new Object [ ] { format , TransformerRepository . class . getSimpleName ( ) } , LocaleContextHolder . getLocale ( ) ) ) ;
//GK: Second get the Target Data Management Plan
DescriptionQuery query = this . queryFactory . query ( DescriptionQuery . class ) . authorize ( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . ids ( descriptionId ) ;
DescriptionModel descriptionFileTransformerModel = this . builderFactory . builder ( DescriptionCommonModelBuilder . class ) . useSharedStorage( repository . getConfiguration ( ) . isUseSharedStorage ( ) ) . authorize ( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . build ( query . first ( ) ) ;
DescriptionModel descriptionFileTransformerModel = this . builderFactory . builder ( DescriptionCommonModelBuilder . class ) . setRepositoryId( repository . getConfiguration ( ) . getFileTransformerId ( ) ) . useSharedStorage( repository . getConfiguration ( ) . isUseSharedStorage ( ) ) . authorize ( AuthorizationFlags . OwnerOrDmpAssociatedOrPermission ) . build ( query . first ( ) ) ;
if ( descriptionFileTransformerModel = = null ) throw new MyNotFoundException ( messageSource . getMessage ( "General_ItemNotFound" , new Object [ ] { descriptionId , Description . class . getSimpleName ( ) } , LocaleContextHolder . getLocale ( ) ) ) ;
FileEnvelopeModel fileEnvelope = repository . exportDescription ( descriptionFileTransformerModel , format ) ;