Skip to content

Commit

Permalink
https://github.com/metadatacenter/cedar-project/issues/1198
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila L. Egyedi committed Nov 8, 2023
1 parent 537b5c9 commit 28599bc
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public Response immPortWorkspaces() throws CedarException {
c.must(c.user()).be(LoggedIn);

Optional<String> immPortBearerToken = immPortUtil.getImmPortBearerToken();
if (!immPortBearerToken.isPresent()) {
if (immPortBearerToken.isEmpty()) {
logger.warn("Could not get an ImmPort token");
return CedarResponse.status(CedarResponseStatus.INTERNAL_SERVER_ERROR).build(); // TODO CEDAR error response
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public Response submitImmPort() throws CedarException {
c.must(c.user()).be(LoggedIn);

Optional<String> immPortBearerToken = immPortUtil.getImmPortBearerToken();
if (!immPortBearerToken.isPresent()) {
if (immPortBearerToken.isEmpty()) {
logger.warn("No ImmPort token found");
return CedarResponse.status(CedarResponseStatus.INTERNAL_SERVER_ERROR).build(); // TODO CEDAR error response
}
Expand Down Expand Up @@ -275,7 +275,7 @@ public Response submitImmPortOld() throws CedarException {
}

Optional<String> immPortBearerToken = immPortUtil.getImmPortBearerToken();
if (!immPortBearerToken.isPresent()) {
if (immPortBearerToken.isEmpty()) {
logger.warn("No ImmPort token found");
return CedarResponse.status(CedarResponseStatus.INTERNAL_SERVER_ERROR).build(); // TODO CEDAR error response
}
Expand Down
4 changes: 2 additions & 2 deletions cedar-submission-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SubmissionStatus getImmPortSubmissionStatus(String submissionID) {
CloseableHttpClient client = null;

Optional<String> token = getImmPortBearerToken();
if (!token.isPresent()) {
if (token.isEmpty()) {
logger.warn("Could not get an ImmPort token");
return new SubmissionStatus(submissionID, SubmissionState.ERROR, "Could not get an ImmPort token");
}
Expand Down Expand Up @@ -109,11 +109,11 @@ public Optional<String> getImmPortBearerToken() {
ImmPortGetTokenResponse immPortGetTokenResponse = MAPPER
.readValue(entity.getContent(), ImmPortGetTokenResponse.class);

if (immPortGetTokenResponse.getStatus().intValue() == 200) {
if (immPortGetTokenResponse.getStatus() == 200) {
return Optional.of(immPortGetTokenResponse.getToken());
} else {
logger.warn("Failed to get token from host " + submissionUrl + "; ImmPort status code="
+ immPortGetTokenResponse.getStatus().intValue() + ", error=" + immPortGetTokenResponse.getError());
+ immPortGetTokenResponse.getStatus() + ", error=" + immPortGetTokenResponse.getError());
return Optional.empty();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ public static List<String> extractSraFileNames(JsonNode instance, String sraElem

for (JsonNode sra : sras) {

if (sra.hasNonNull(sraFieldNameField) && sra.get(sraFieldNameField).size() > 0) {
Iterator<JsonNode> fileNameFieldsIt = sra.get(sraFieldNameField).iterator();
if (sra.hasNonNull(sraFieldNameField) && !sra.get(sraFieldNameField).isEmpty()) {

while (fileNameFieldsIt.hasNext()) {
String fileNameField = fileNameFieldsIt.next().asText();
for (JsonNode jsonNode : sra.get(sraFieldNameField)) {
String fileNameField = jsonNode.asText();
Optional<String> fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField);
sraFileNames.add(fileName.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import java.util.*;

import static org.metadatacenter.submission.ncbi.pipelines.cairr.NcbiCairrConstants.*;

public class NcbiPipelinesCommonValidator {

public static List<String> validateBioproject(JsonNode bioproject, List<String> bioprojectFields, List<String> bioprojectRequiredFieldValues) {
Expand Down Expand Up @@ -39,11 +37,10 @@ public static List<String> validateSra(JsonNode sras, List<String> sraFields, St
}
}
// File type and file names
Iterator<JsonNode> fileNamesIt = sra.get(sraFileNameField).iterator();
while (fileNamesIt.hasNext()) {
String fileNameField = fileNamesIt.next().asText();
for (JsonNode jsonNode : sra.get(sraFileNameField)) {
String fileNameField = jsonNode.asText();
Optional<String> fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField);
if (!fileName.isPresent()) {
if (fileName.isEmpty()) {
messages.add("File name field not present: " + fileNameField);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public class NcbiCairrConstants {


protected static final List<String> BIOPROJECT_FIELDS =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOPROJECT_STUDY_ID_FIELD,
BIOPROJECT_CONTACT_INFO_FIELD,
BIOPROJECT_LAB_NAME_FIELD
));
);


protected static final List<String> BIOPROJECT_REQUIRED_FIELD_VALUES =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOPROJECT_STUDY_ID_FIELD,
BIOPROJECT_CONTACT_INFO_FIELD,
BIOPROJECT_LAB_NAME_FIELD
));
);

/*** BioSample section ***/
// Subject
Expand Down Expand Up @@ -97,7 +97,7 @@ public class NcbiCairrConstants {
protected static final String BIOSAMPLE_OPTIONAL_ATTRIBUTE_FIELD = "Optional BioSample Attribute";

protected static final List<String> BIOSAMPLE_FIELDS =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOSAMPLE_SUBJECT_ID_FIELD,
BIOSAMPLE_SYNTHETIC_LIBRARY_FIELD,
BIOSAMPLE_ORGANISM_FIELD,
Expand Down Expand Up @@ -138,10 +138,10 @@ public class NcbiCairrConstants {
BIOSAMPLE_CELL_ISOLATION_FIELD,
BIOSAMPLE_PROCESSING_PROTOCOL_FIELD,
BIOSAMPLE_OPTIONAL_ATTRIBUTE_FIELD
));
);

protected static final List<String> BIOSAMPLE_REQUIRED_FIELD_VALUES =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOSAMPLE_SUBJECT_ID_FIELD,
BIOSAMPLE_SYNTHETIC_LIBRARY_FIELD,
BIOSAMPLE_ORGANISM_FIELD,
Expand Down Expand Up @@ -180,7 +180,7 @@ public class NcbiCairrConstants {
BIOSAMPLE_CELL_QUALITY_FIELD,
BIOSAMPLE_CELL_ISOLATION_FIELD,
BIOSAMPLE_PROCESSING_PROTOCOL_FIELD
));
);

/*** SRA section ***/
protected static final String SRA_ELEMENT = "Sequence Read Archive for AIRR NCBI";
Expand Down Expand Up @@ -211,7 +211,7 @@ public class NcbiCairrConstants {
protected static final String SRA_FILE_TYPE_FIELD = "File Type";
protected static final String SRA_FILE_NAME_FIELD = "filename";

protected static final List<String> SRA_FIELDS = Collections.unmodifiableList(Arrays.asList(
protected static final List<String> SRA_FIELDS = List.of(
SRA_SAMPLE_ID_FIELD,
SRA_TARGET_SUBSTRATE_FIELD,
SRA_TARGET_SUBSTRATE_QUALITY_FIELD,
Expand All @@ -238,7 +238,7 @@ public class NcbiCairrConstants {
SRA_SEQUENCING_KIT_FIELD,
SRA_FILE_TYPE_FIELD,
SRA_FILE_NAME_FIELD
));
);

protected static final List<String> SRA_REQUIRED_FIELD_VALUES = SRA_FIELDS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ public String convertTemplateInstanceToXML(JsonNode instance) throws JAXBExcepti

if (sra.hasNonNull(SRA_FILE_NAME_FIELD) && sra.get(SRA_FILE_NAME_FIELD).size() > 0) {

Iterator<JsonNode> fileNameFieldsIt = sra.get(SRA_FILE_NAME_FIELD).iterator();
for (JsonNode jsonNode : sra.get(SRA_FILE_NAME_FIELD)) {

while (fileNameFieldsIt.hasNext()) {

String fileNameField = fileNameFieldsIt.next().asText();
String fileNameField = jsonNode.asText();

Optional<String> fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public class NcbiGenericConstants {
protected static final String BIOPROJECT_RELEVANT_PUBLICATIONS_FIELD = "Relevant Publications";

protected static final List<String> BIOPROJECT_FIELDS =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOPROJECT_STUDY_ID_FIELD,
BIOPROJECT_CONTACT_INFO_FIELD,
BIOPROJECT_CONTACT_EMAIL_FIELD,
BIOPROJECT_LAB_NAME_FIELD
));
);

protected static final List<String> BIOPROJECT_REQUIRED_FIELD_VALUES =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOPROJECT_STUDY_ID_FIELD,
BIOPROJECT_CONTACT_INFO_FIELD,
BIOPROJECT_CONTACT_EMAIL_FIELD,
BIOPROJECT_LAB_NAME_FIELD
));
);


/*** BioSample section ***/
Expand Down Expand Up @@ -78,7 +78,7 @@ public class NcbiGenericConstants {
protected static final String BIOSAMPLE_DESCRIPTION_FIELD = "Sample Description";

protected static final List<String> BIOSAMPLE_FIELDS =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOSAMPLE_SAMPLE_NAME_FIELD,
BIOSAMPLE_SAMPLE_TITLE_FIELD,
BIOSAMPLE_ORGANISM_FIELD,
Expand All @@ -103,18 +103,18 @@ public class NcbiGenericConstants {
BIOSAMPLE_SAMPLE_TYPE_FIELD,
BIOSAMPLE_TREATMENT_FIELD,
BIOSAMPLE_DESCRIPTION_FIELD
));
);

protected static final List<String> BIOSAMPLE_REQUIRED_FIELD_VALUES =
Collections.unmodifiableList(Arrays.asList(
List.of(
BIOSAMPLE_SAMPLE_NAME_FIELD,
BIOSAMPLE_ORGANISM_FIELD,
BIOSAMPLE_ISOLATE_FIELD,
BIOSAMPLE_AGE_FIELD,
BIOSAMPLE_BIOMATERIAL_PROVIDER_FIELD,
BIOSAMPLE_SEX_FIELD,
BIOSAMPLE_TISSUE_FIELD
));
);

/*** SRA section ***/
protected static final String SRA_ELEMENT = "NCBI SRA for Human Tissue";
Expand All @@ -132,7 +132,7 @@ public class NcbiGenericConstants {
protected static final String SRA_FILE_NAME_FIELD = "File Name";

protected static final List<String> SRA_FIELDS =
Collections.unmodifiableList(Arrays.asList(
List.of(
SRA_SAMPLE_NAME_FIELD,
SRA_LIBRARY_ID_FIELD,
SRA_TITLE_FIELD,
Expand All @@ -145,10 +145,10 @@ public class NcbiGenericConstants {
SRA_DESIGN_DESCRIPTION_FIELD,
SRA_FILE_TYPE_FIELD,
SRA_FILE_NAME_FIELD
));
);

protected static final List<String> SRA_REQUIRED_FIELD_VALUES =
Collections.unmodifiableList(Arrays.asList(
List.of(
SRA_SAMPLE_NAME_FIELD,
SRA_LIBRARY_ID_FIELD,
SRA_TITLE_FIELD,
Expand All @@ -161,7 +161,7 @@ public class NcbiGenericConstants {
SRA_DESIGN_DESCRIPTION_FIELD,
SRA_FILE_TYPE_FIELD,
SRA_FILE_NAME_FIELD
));
);

// PRIVATE //

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.metadatacenter.submission.ncbi.NcbiConstants;
import org.metadatacenter.util.json.JsonMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ public String convertTemplateInstanceToXML(JsonNode instance) throws JAXBExcepti

if (sra.hasNonNull(SRA_FILE_NAME_FIELD) && sra.get(SRA_FILE_NAME_FIELD).size() > 0) {

Iterator<JsonNode> fileNameFieldsIt = sra.get(SRA_FILE_NAME_FIELD).iterator();
for (JsonNode jsonNode : sra.get(SRA_FILE_NAME_FIELD)) {

while (fileNameFieldsIt.hasNext()) {

String fileNameField = fileNameFieldsIt.next().asText();
String fileNameField = jsonNode.asText();

Optional<String> fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.metadatacenter.submission.ncbi.queue;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.metadatacenter.constant.CedarConstants;
import org.metadatacenter.submission.ncbi.NcbiSubmission;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static SubmissionStatus getNcbiSubmissionStatus(String submissionID, FTPC
SubmissionStatusDescriptor submissionStatusDescriptor = SubmissionStatusManager.getInstance()
.getCurrentSubmissions().get(submissionID);
NcbiSubmissionStatusTask statusTask = (NcbiSubmissionStatusTask) submissionStatusDescriptor
.getSubmissionStatusTask();
.submissionStatusTask();
statusTask.setLastStatusReportFile(mostRecentReportFileName.get());

// generate submission status from the most recent report file
Expand All @@ -86,7 +86,7 @@ public static SubmissionStatus getNcbiSubmissionStatus(String submissionID, FTPC
logger.info(submissionStatus.toString());
} else { // the report file has already been checked so the status will be the same
submissionStatus =
SubmissionStatusManager.getInstance().getCurrentSubmissions().get(submissionID).getSubmissionStatus();
SubmissionStatusManager.getInstance().getCurrentSubmissions().get(submissionID).submissionStatus();
}
} else { // the folder does not contain any report file yet
String message = SubmissionStatusUtil.getShortStatusMessage(submissionID, SubmissionState.PROCESSING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class NcbiSubmissionStatusUtil {

public static SubmissionStatus toSubmissionStatus(String submissionId, NcbiSubmissionStatusReport report) {
SubmissionState submissionState = null;
if (report.getState().equals(NcbiSubmissionState.SUBMITTED)) {
if (report.state().equals(NcbiSubmissionState.SUBMITTED)) {
submissionState = SubmissionState.PROCESSING;
} else if (report.getState().equals(NcbiSubmissionState.PROCESSING)) {
} else if (report.state().equals(NcbiSubmissionState.PROCESSING)) {
submissionState = SubmissionState.PROCESSING;
} else if (report.getState().equals(NcbiSubmissionState.PROCESSED_ERROR)) {
} else if (report.state().equals(NcbiSubmissionState.PROCESSED_ERROR)) {
submissionState = SubmissionState.ERROR;
} else if (report.getState().equals(NcbiSubmissionState.FAILED)) {
} else if (report.state().equals(NcbiSubmissionState.FAILED)) {
submissionState = SubmissionState.REJECTED;
}
// TODO: complete with all NCBI states
Expand All @@ -37,7 +37,7 @@ public static SubmissionStatus toSubmissionStatus(String submissionId, NcbiSubmi
}

String message = SubmissionStatusUtil.getShortStatusMessage(submissionId, submissionState) +
"\nNCBI STATUS REPORT\n==================" + report.getTextReport();
"\nNCBI STATUS REPORT\n==================" + report.textReport();

return new SubmissionStatus(submissionId, submissionState, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,9 @@

/**
* This class represents the submission status extracted from a report.[number].xml file
*
* @param textReport generated from the xml report
*/
public class NcbiSubmissionStatusReport {
public record NcbiSubmissionStatusReport(NcbiSubmissionState state, String xmlReport, String textReport) {

private final NcbiSubmissionState state;
private final String xmlReport;
private final String textReport; // generated from the xml report

public NcbiSubmissionStatusReport(NcbiSubmissionState state, String xmlReport, String textReport) {
this.state = state;
this.xmlReport = xmlReport;
this.textReport = textReport;
}

public NcbiSubmissionState getState() {
return state;
}

public String getXmlReport() {
return xmlReport;
}

public String getTextReport() {
return textReport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
Expand All @@ -23,7 +22,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

Expand Down
Loading

0 comments on commit 28599bc

Please sign in to comment.