Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trm 31933 implement producer #512

Open
wants to merge 7 commits into
base: TRM-31640-mapping-async
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.uniprot.api.async.download.messaging.consumer.mapto.MapToMessageConsumer;
import org.uniprot.api.async.download.model.request.MapToDownloadRequestToArrayConverter;
import org.uniprot.api.async.download.model.request.mapto.UniProtKBToUniRefDownloadRequest;
import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest;
import org.uniprot.api.rest.request.HashGenerator;

/**
Expand Down Expand Up @@ -93,7 +94,13 @@ public MessageListenerContainer mapMessageListenerContainer(
}

@Bean
public HashGenerator<UniProtKBToUniRefDownloadRequest> mapDownloadHashGenerator(
public HashGenerator<UniProtKBToUniRefDownloadRequest> uniProtKbToUniRefMapDownloadHashGenerator(
@Value("${async.download.mapto.hash.salt}") String hashSalt) {
return new HashGenerator<>(new MapToDownloadRequestToArrayConverter<>(), hashSalt);
}

@Bean
public HashGenerator<UniRefToUniProtKBDownloadRequest> unirefToUniProtKBMapDownloadHashGenerator(
@Value("${async.download.mapto.hash.salt}") String hashSalt) {
return new HashGenerator<>(new MapToDownloadRequestToArrayConverter<>(), hashSalt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public UniProtKBToUniRefProducerMessageService(
MapToMessagingService messagingService,
HashGenerator<UniProtKBToUniRefDownloadRequest> hashGenerator,
MapToFileHandler asyncDownloadFileHandler,
MapToJobSubmissionRules<UniProtKBToUniRefDownloadRequest>
UniProtKBToUniRefJobSubmissionRules
asyncDownloadSubmissionRules) {
super(
jobService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.uniprot.api.async.download.messaging.producer.mapto;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest;
import org.uniprot.api.async.download.service.mapto.MapToJobService;

@Component
public class UniRefToUniProtKBJobSubmissionRules
extends MapToJobSubmissionRules<UniRefToUniProtKBDownloadRequest> {
protected UniRefToUniProtKBJobSubmissionRules(
@Value("${async.download.mapto.retryMaxCount}") int maxRetryCount,
@Value("${async.download.mapto.waitingMaxTime}") int maxWaitingTime,
MapToJobService jobService) {
super(maxRetryCount, maxWaitingTime, jobService);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.uniprot.api.async.download.messaging.producer.mapto;

import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.stereotype.Component;
import org.uniprot.api.async.download.messaging.result.mapto.MapToFileHandler;
import org.uniprot.api.async.download.messaging.service.mapto.MapToMessagingService;
import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest;
import org.uniprot.api.async.download.service.mapto.MapToJobService;
import org.uniprot.api.rest.request.HashGenerator;

@Component
public class UniRefToUniProtKBProducerMessageService
extends MapToProducerMessageService<UniRefToUniProtKBDownloadRequest> {
public UniRefToUniProtKBProducerMessageService(
MapToJobService jobService,
MessageConverter messageConverter,
MapToMessagingService messagingService,
HashGenerator<UniRefToUniProtKBDownloadRequest> hashGenerator,
MapToFileHandler asyncDownloadFileHandler,
UniRefToUniProtKBJobSubmissionRules
asyncDownloadSubmissionRules) {
super(
jobService,
messageConverter,
messagingService,
hashGenerator,
asyncDownloadFileHandler,
asyncDownloadSubmissionRules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class UniProtKBToUniRefDownloadRequest extends UniProtKBStreamRequest
TURTLE_MEDIA_TYPE_VALUE,
N_TRIPLES_MEDIA_TYPE_VALUE
})
@Parameter(description = FORMAT_UNIPARC_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE)
@Parameter(description = FORMAT_UNIREF_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE)
private String format;

private boolean force;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.uniprot.api.async.download.model.request.mapto;

import io.swagger.v3.oas.annotations.Parameter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springdoc.api.annotations.ParameterObject;
import org.uniprot.api.async.download.model.request.ValidDownloadRequest;
import org.uniprot.api.rest.request.UniProtKBRequestUtil;
import org.uniprot.api.rest.validation.CustomConstraintGroup;
import org.uniprot.api.rest.validation.ValidAsyncDownloadFormats;
import org.uniprot.api.rest.validation.ValidReturnFields;
import org.uniprot.api.rest.validation.ValidTSVAndXLSFormatOnlyFields;
import org.uniprot.api.uniref.common.service.light.request.UniRefStreamRequest;
import org.uniprot.store.config.UniProtDataType;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.uniprot.api.rest.openapi.OpenAPIConstants.*;
import static org.uniprot.api.rest.output.UniProtMediaType.*;
import static org.uniprot.store.search.SolrCollection.uniprot;
import static org.uniprot.store.search.SolrCollection.uniref;

@Data
@EqualsAndHashCode(callSuper = true)
@ValidDownloadRequest(groups = CustomConstraintGroup.class)
@ParameterObject
public class UniRefToUniProtKBDownloadRequest extends UniRefStreamRequest
implements MapToDownloadRequest {

@ValidAsyncDownloadFormats(
formats = {
FASTA_MEDIA_TYPE_VALUE,
TSV_MEDIA_TYPE_VALUE,
APPLICATION_JSON_VALUE,
XLS_MEDIA_TYPE_VALUE,
LIST_MEDIA_TYPE_VALUE,
RDF_MEDIA_TYPE_VALUE,
TURTLE_MEDIA_TYPE_VALUE,
N_TRIPLES_MEDIA_TYPE_VALUE
})
@Parameter(description = FORMAT_UNIPROTKB_DESCRIPTION, example = FORMAT_UNIPROTKB_EXAMPLE)
private String format;

private boolean force;

@Parameter(description = FIELDS_UNIPROTKB_DESCRIPTION, example = FIELDS_UNIPROTKB_EXAMPLE)
@ValidReturnFields(uniProtDataType = UniProtDataType.UNIPROTKB)
@ValidTSVAndXLSFormatOnlyFields(fieldPattern = "xref_.*_full")
private String fields;

@Parameter(hidden = true)
private String downloadJobId;

@Override
public String getTo() {
return uniprot.name();
}

@Override
public String getFrom() {
return uniref.name();
}

@Override
public void setFormat(String format) {
this.format = UniProtKBRequestUtil.parseFormat(format);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,4 @@ protected DownloadConfigProperties getDownloadConfigProperties() {
"org.uniprot.api.async.download.messaging.producer.mapto"
})
static class MapProducerTestConfig {}

@Override
protected @NotNull String getJobHashForSuccess() {
return "e01159046a85cbd920622f34511d9e4c198c6ca4";
}

@Override
protected @NotNull String getJobHashForSuccessForceAndIdleJobAllowedAndCleanResources() {
return "7a5b14e8b59dd20dcbd27ba8cad1fb45c4806575";
}

@Override
protected @NotNull String getJobHashForWithoutFormatDefaultToJson() {
return "964a9c6154896d88132b6082d397dc6ca9d9f733";
}

@Override
protected @NotNull String getJobHashForAlreadyRunning() {
return "ab3f9709a8a59b7241901f13167686bf124fdd81";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDateTime;

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -23,7 +24,7 @@
RedisConfigTest.class
})
@EnableConfigurationProperties({MapToDownloadConfigProperties.class})
public class UniProtKToUnRefMapProducerMessageServiceIT
public class UniProtKBToUnRefMapProducerMessageServiceIT
extends MapToProducerMessageServiceIT<UniProtKBToUniRefDownloadRequest> {
@Autowired private UniProtKBToUniRefProducerMessageService service;

Expand Down Expand Up @@ -88,4 +89,24 @@ protected UniProtKBToUniRefDownloadRequest getWithoutFormatRequest() {
getService() {
return service;
}

@Override
protected @NotNull String getJobHashForWithoutFormatDefaultToJson() {
return "964a9c6154896d88132b6082d397dc6ca9d9f733";
}

@Override
protected @NotNull String getJobHashForSuccess() {
return "e01159046a85cbd920622f34511d9e4c198c6ca4";
}

@Override
protected @NotNull String getJobHashForSuccessForceAndIdleJobAllowedAndCleanResources() {
return "7a5b14e8b59dd20dcbd27ba8cad1fb45c4806575";
}

@Override
protected @NotNull String getJobHashForAlreadyRunning() {
return "ab3f9709a8a59b7241901f13167686bf124fdd81";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UniProtKBToUniRefProducerMessageServiceTest
uniProtKBMapDownloadRequestHashGenerator;

@Mock
private MapToJobSubmissionRules<UniProtKBToUniRefDownloadRequest>
private UniProtKBToUniRefJobSubmissionRules
uniProtKBMapDownloadRequestMapToJobSubmissionRules;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.uniprot.api.async.download.messaging.producer.mapto;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest;

@ExtendWith(MockitoExtension.class)
class UniRefToUniProtKBJobSubmissionRulesTest
extends MapToJobSubmissionRulesTest<UniRefToUniProtKBDownloadRequest> {
@Mock private UniRefToUniProtKBDownloadRequest mapDownloadRequest;

@BeforeEach
void setUp() {
init();
downloadRequest = mapDownloadRequest;
jobSubmissionRules =
new UniRefToUniProtKBJobSubmissionRules(
MAX_RETRY_COUNT, MAX_WAITING_TIME, mapToJobService);
mock();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.uniprot.api.async.download.messaging.producer.mapto;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.uniprot.api.async.download.messaging.producer.ProducerMessageService;
import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest;
import org.uniprot.api.rest.request.HashGenerator;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.uniprot.api.rest.download.model.JobStatus.NEW;

@ExtendWith(MockitoExtension.class)
public class UniRefToUniProtKBProducerMessageServiceTest
extends MapToProducerMessageServiceTest<UniRefToUniProtKBDownloadRequest> {
public static final String UNIREF_MAP_FIELDS = "uniRefMapFields";
public static final String UNIREF_MAP_SORT = "uniRefMapSort";
public static final String UNIREF_MAP_FORMAT = "uniRefMapFormat";
protected final String UNIREF_MAP_QUERY = "uniRefMapQuery";
@Mock private UniRefToUniProtKBDownloadRequest mapDownloadRequest;

@Mock
private HashGenerator<UniRefToUniProtKBDownloadRequest>
uniProtKBMapDownloadRequestHashGenerator;

@Mock
private UniRefToUniProtKBJobSubmissionRules
uniRefToUniProtKBJobSubmissionRules;

@BeforeEach
void setUp() {
init();
this.downloadRequest = mapDownloadRequest;
this.hashGenerator = uniProtKBMapDownloadRequestHashGenerator;
this.jobSubmissionRules = uniRefToUniProtKBJobSubmissionRules;
this.producerMessageService =
new UniRefToUniProtKBProducerMessageService(
mapToJobService,
mapMessageConverter,
mapToMessagingService,
hashGenerator,
mapDownloadFileHandler,
uniRefToUniProtKBJobSubmissionRules);
}

@Override
protected void mockDownloadRequest() {
mockDownloadRequestWithoutFormat();
when(downloadRequest.getFormat()).thenReturn(UNIREF_MAP_FORMAT);
}

@Override
protected void mockDownloadRequestWithoutFormat() {
when(messageConverter.toMessage(
same(downloadRequest),
argThat(mh -> JOB_ID.equals(mh.getHeader(ProducerMessageService.JOB_ID)))))
.thenReturn(message);
when(downloadRequest.getQuery()).thenReturn(UNIREF_MAP_QUERY);
when(downloadRequest.getFields()).thenReturn(UNIREF_MAP_FIELDS);
when(downloadRequest.getSort()).thenReturn(UNIREF_MAP_SORT);
}

@Override
protected void verifyDownloadJob(UniRefToUniProtKBDownloadRequest request) {
verify(jobService)
.save(
argThat(
job -> {
assertSame(JOB_ID, job.getId());
assertSame(NEW, job.getStatus());
assertNotNull(job.getCreated());
assertNotNull(job.getUpdated());
assertSame(request.getQuery(), job.getQuery());
assertSame(request.getFields(), job.getFields());
assertSame(request.getSort(), job.getSort());
assertSame(request.getFormat(), job.getFormat());
return true;
}));
}
}
Loading