add evaluation rda maDMP config
This commit is contained in:
parent
e64045725c
commit
6758f2adbd
|
@ -13,14 +13,17 @@ import gr.cite.tools.exception.MyNotFoundException;
|
|||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import gr.cite.tools.logging.MapLogEntry;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
|
||||
import org.opencdmp.commonmodels.models.description.DescriptionModel;
|
||||
import org.opencdmp.commons.JsonHandlingService;
|
||||
import org.opencdmp.commons.enums.*;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.commons.types.evaluator.EvaluatorSourceEntity;
|
||||
import org.opencdmp.depositbase.repository.DepositClient;
|
||||
import org.opencdmp.evaluatorbase.interfaces.EvaluatorClient;
|
||||
import org.opencdmp.evaluatorbase.interfaces.EvaluatorConfiguration;
|
||||
import org.opencdmp.commons.types.tenantconfiguration.EvaluatorTenantConfigurationEntity;
|
||||
|
@ -31,10 +34,11 @@ import org.opencdmp.data.TenantConfigurationEntity;
|
|||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.evaluatorbase.models.misc.RankModel;
|
||||
import org.opencdmp.event.TenantConfigurationTouchedEvent;
|
||||
import org.opencdmp.model.builder.commonmodels.DepositConfigurationBuilder;
|
||||
import org.opencdmp.model.StorageFile;
|
||||
import org.opencdmp.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
|
||||
import org.opencdmp.model.builder.commonmodels.plan.PlanCommonModelBuilder;
|
||||
import org.opencdmp.model.description.Description;
|
||||
import org.opencdmp.model.persist.StorageFilePersist;
|
||||
import org.opencdmp.model.plan.Plan;
|
||||
import org.opencdmp.commonmodels.models.plan.PlanModel;
|
||||
import org.opencdmp.model.tenantconfiguration.TenantConfiguration;
|
||||
|
@ -43,6 +47,9 @@ import org.opencdmp.query.PlanQuery;
|
|||
import org.opencdmp.query.TenantConfigurationQuery;
|
||||
import org.opencdmp.service.accounting.AccountingService;
|
||||
import org.opencdmp.service.encryption.EncryptionService;
|
||||
import org.opencdmp.service.filetransformer.FileTransformerService;
|
||||
import org.opencdmp.service.storage.StorageFileProperties;
|
||||
import org.opencdmp.service.storage.StorageFileService;
|
||||
import org.opencdmp.service.tenant.TenantProperties;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -62,13 +69,13 @@ import javax.crypto.IllegalBlockSizeException;
|
|||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.io.IOException;
|
||||
import java.net.URLConnection;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static org.opencdmp.authorization.AuthorizationFlags.Public;
|
||||
|
||||
@Service
|
||||
public class EvaluatorServiceImpl implements EvaluatorService {
|
||||
|
||||
|
@ -89,9 +96,14 @@ public class EvaluatorServiceImpl implements EvaluatorService {
|
|||
private final EvaluatorSourcesCacheService evaluatorSourcesCacheService;
|
||||
private final AccountingService accountingService;
|
||||
private final TenantEntityManager entityManager;
|
||||
private final FileTransformerService fileTransformerService;
|
||||
private final UserScope userScope;
|
||||
private final StorageFileService storageFileService;
|
||||
private final StorageFileProperties storageFileProperties;
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
||||
@Autowired
|
||||
public EvaluatorServiceImpl(EvaluatorProperties evaluatorProperties, Map<String, EvaluatorClientImpl> clients, TokenExchangeCacheService tokenExchangeCacheService, EvaluatorConfigurationCacheService evaluatorConfigurationCacheService, AuthorizationService authorizationService, QueryFactory queryFactory, BuilderFactory builderFactory, MessageSource messageSource, ConventionService conventionService, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, JsonHandlingService jsonHandlingService, EvaluatorSourcesCacheService evaluatorSourcesCacheService, AccountingService accountingService, TenantEntityManager entityManager) {
|
||||
public EvaluatorServiceImpl(EvaluatorProperties evaluatorProperties, Map<String, EvaluatorClientImpl> clients, TokenExchangeCacheService tokenExchangeCacheService, EvaluatorConfigurationCacheService evaluatorConfigurationCacheService, AuthorizationService authorizationService, QueryFactory queryFactory, BuilderFactory builderFactory, MessageSource messageSource, ConventionService conventionService, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, JsonHandlingService jsonHandlingService, EvaluatorSourcesCacheService evaluatorSourcesCacheService, AccountingService accountingService, TenantEntityManager entityManager, FileTransformerService fileTransformerService, UserScope userScope, StorageFileService storageFileService, StorageFileProperties storageFileProperties, ValidatorFactory validatorFactory) {
|
||||
this.evaluatorProperties = evaluatorProperties;
|
||||
this.clients = clients;
|
||||
this.tokenExchangeCacheService = tokenExchangeCacheService;
|
||||
|
@ -108,6 +120,11 @@ public class EvaluatorServiceImpl implements EvaluatorService {
|
|||
this.evaluatorSourcesCacheService = evaluatorSourcesCacheService;
|
||||
this.accountingService = accountingService;
|
||||
this.entityManager = entityManager;
|
||||
this.fileTransformerService = fileTransformerService;
|
||||
this.userScope = userScope;
|
||||
this.storageFileService = storageFileService;
|
||||
this.storageFileProperties = storageFileProperties;
|
||||
this.validatorFactory = validatorFactory;
|
||||
}
|
||||
private EvaluatorClientImpl getEvaluatorClient(String repoId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
|
||||
String repositoryIdByTenant = this.getRepositoryIdByTenant(repoId);
|
||||
|
@ -262,7 +279,15 @@ public class EvaluatorServiceImpl implements EvaluatorService {
|
|||
PlanEntity planEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(planId).first();
|
||||
if (planEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planId, PlanEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
|
||||
PlanModel evaluatorModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).setEvaluatorId(repository.getConfiguration().getEvaluatorId()).isPublic(isPublic).authorize(AuthorizationFlags.All).build(planEntity);
|
||||
org.opencdmp.model.file.FileEnvelope rda = this.fileTransformerService.exportPlan(planId, "rda-file-transformer", "json", isPublic);
|
||||
FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel();
|
||||
jsonEnvelope.setFilename(rda.getFilename());
|
||||
jsonEnvelope.setMimeType("application/json");
|
||||
|
||||
if (!repository.getConfiguration().isUseSharedStorage()) jsonEnvelope.setFile(rda.getFile());
|
||||
else jsonEnvelope.setFileRef(this.addFileToSharedStorage(rda));
|
||||
|
||||
PlanModel evaluatorModel = this.builderFactory.builder(PlanCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).setEvaluatorId(repository.getConfiguration().getEvaluatorId()).isPublic(isPublic).setRdaJsonFile(jsonEnvelope).authorize(AuthorizationFlags.All).build(planEntity);
|
||||
if(evaluatorModel == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planId, Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
|
||||
this.accountingService.increase(UsageLimitTargetMetric.FILE_TRANSFORMER_EXPORT_PLAN_EXECUTION_COUNT.getValue());
|
||||
|
@ -320,6 +345,19 @@ public class EvaluatorServiceImpl implements EvaluatorService {
|
|||
});
|
||||
}
|
||||
|
||||
private String addFileToSharedStorage(org.opencdmp.model.file.FileEnvelope file) throws IOException {
|
||||
StorageFilePersist storageFilePersist = new StorageFilePersist();
|
||||
storageFilePersist.setName(FilenameUtils.removeExtension(file.getFilename()));
|
||||
storageFilePersist.setExtension(FilenameUtils.getExtension(file.getFilename()));
|
||||
storageFilePersist.setMimeType(URLConnection.guessContentTypeFromName(file.getFilename()));
|
||||
storageFilePersist.setOwnerId(this.userScope.getUserIdSafe());
|
||||
storageFilePersist.setStorageType(StorageType.Temp);
|
||||
storageFilePersist.setLifetime(Duration.ofSeconds(this.storageFileProperties.getTempStoreLifetimeSeconds())); //TODO
|
||||
this.validatorFactory.validator(StorageFilePersist.StorageFilePersistValidator.class).validateForce(storageFilePersist);
|
||||
StorageFile persisted = this.storageFileService.persistBytes(storageFilePersist, file.getFile(), new BaseFieldSet(StorageFile._id, StorageFile._fileRef));
|
||||
return persisted.getFileRef();
|
||||
}
|
||||
|
||||
private void increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric metric, String repositoryId) throws InvalidApplicationException {
|
||||
this.accountingService.increase(metric.getValue() + repositoryId);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class EvaluatorController {
|
|||
public ResponseEntity<RankModel> rankPlan(@RequestBody EvaluateRequestModel requestModel) throws Exception {
|
||||
logger.debug(new MapLogEntry("ranking plan"));
|
||||
|
||||
RankModel rankModel = this.evaluatorService.rankPlan(requestModel.getId(), requestModel.getEvaluatorId(), requestModel.getFormat(), true);
|
||||
RankModel rankModel = this.evaluatorService.rankPlan(requestModel.getId(), requestModel.getEvaluatorId(), requestModel.getFormat(), false);
|
||||
|
||||
return new ResponseEntity<>(rankModel, HttpStatus.OK);
|
||||
}
|
||||
|
|
|
@ -7,3 +7,10 @@ evaluator:
|
|||
client-secret: ${IDP_APIKEY_CLIENT_SECRET}
|
||||
scope: ${IDP_APIKEY_SCOPE}
|
||||
maxInMemorySizeInBytes: 6554000
|
||||
- url: http://localhost:8083
|
||||
evaluatorId: rda-maDMP
|
||||
issuer-url: ${IDP_ISSUER_URI_TOKEN}
|
||||
client-id: ${IDP_APIKEY_CLIENT_ID}
|
||||
client-secret: ${IDP_APIKEY_CLIENT_SECRET}
|
||||
scope: ${IDP_APIKEY_SCOPE}
|
||||
maxInMemorySizeInBytes: 6554000
|
Loading…
Reference in New Issue