diff --git a/cedar-submission-server-application/src/main/java/org/metadatacenter/submission/resources/ImmPortSubmissionServerResource.java b/cedar-submission-server-application/src/main/java/org/metadatacenter/submission/resources/ImmPortSubmissionServerResource.java index 9774109..e17a0d3 100644 --- a/cedar-submission-server-application/src/main/java/org/metadatacenter/submission/resources/ImmPortSubmissionServerResource.java +++ b/cedar-submission-server-application/src/main/java/org/metadatacenter/submission/resources/ImmPortSubmissionServerResource.java @@ -146,7 +146,7 @@ public Response immPortWorkspaces() throws CedarException { c.must(c.user()).be(LoggedIn); Optional 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 } @@ -189,7 +189,7 @@ public Response submitImmPort() throws CedarException { c.must(c.user()).be(LoggedIn); Optional 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 } @@ -275,7 +275,7 @@ public Response submitImmPortOld() throws CedarException { } Optional 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 } diff --git a/cedar-submission-server-core/pom.xml b/cedar-submission-server-core/pom.xml index f7c7465..9dbf991 100644 --- a/cedar-submission-server-core/pom.xml +++ b/cedar-submission-server-core/pom.xml @@ -47,8 +47,8 @@ - org.apache.httpcomponents - httpclient + org.apache.httpcomponents.client5 + httpclient5 diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/immport/ImmPortUtil.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/immport/ImmPortUtil.java index 8e3d68c..42d9ca5 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/immport/ImmPortUtil.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/immport/ImmPortUtil.java @@ -56,7 +56,7 @@ public SubmissionStatus getImmPortSubmissionStatus(String submissionID) { CloseableHttpClient client = null; Optional 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"); } @@ -109,11 +109,11 @@ public Optional 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 { diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonUtil.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonUtil.java index 7ede2e7..75ba2ed 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonUtil.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonUtil.java @@ -104,11 +104,10 @@ public static List extractSraFileNames(JsonNode instance, String sraElem for (JsonNode sra : sras) { - if (sra.hasNonNull(sraFieldNameField) && sra.get(sraFieldNameField).size() > 0) { - Iterator 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 fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField); sraFileNames.add(fileName.get()); } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonValidator.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonValidator.java index b0f9624..c7928d5 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonValidator.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/NcbiPipelinesCommonValidator.java @@ -4,8 +4,6 @@ import java.util.*; -import static org.metadatacenter.submission.ncbi.pipelines.cairr.NcbiCairrConstants.*; - public class NcbiPipelinesCommonValidator { public static List validateBioproject(JsonNode bioproject, List bioprojectFields, List bioprojectRequiredFieldValues) { @@ -39,11 +37,10 @@ public static List validateSra(JsonNode sras, List sraFields, St } } // File type and file names - Iterator fileNamesIt = sra.get(sraFileNameField).iterator(); - while (fileNamesIt.hasNext()) { - String fileNameField = fileNamesIt.next().asText(); + for (JsonNode jsonNode : sra.get(sraFileNameField)) { + String fileNameField = jsonNode.asText(); Optional fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField); - if (!fileName.isPresent()) { + if (fileName.isEmpty()) { messages.add("File name field not present: " + fileNameField); } } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrConstants.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrConstants.java index c61b97c..32a56d8 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrConstants.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrConstants.java @@ -34,19 +34,19 @@ public class NcbiCairrConstants { protected static final List BIOPROJECT_FIELDS = - Collections.unmodifiableList(Arrays.asList( + List.of( BIOPROJECT_STUDY_ID_FIELD, BIOPROJECT_CONTACT_INFO_FIELD, BIOPROJECT_LAB_NAME_FIELD - )); + ); protected static final List 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 @@ -97,7 +97,7 @@ public class NcbiCairrConstants { protected static final String BIOSAMPLE_OPTIONAL_ATTRIBUTE_FIELD = "Optional BioSample Attribute"; protected static final List BIOSAMPLE_FIELDS = - Collections.unmodifiableList(Arrays.asList( + List.of( BIOSAMPLE_SUBJECT_ID_FIELD, BIOSAMPLE_SYNTHETIC_LIBRARY_FIELD, BIOSAMPLE_ORGANISM_FIELD, @@ -138,10 +138,10 @@ public class NcbiCairrConstants { BIOSAMPLE_CELL_ISOLATION_FIELD, BIOSAMPLE_PROCESSING_PROTOCOL_FIELD, BIOSAMPLE_OPTIONAL_ATTRIBUTE_FIELD - )); + ); protected static final List BIOSAMPLE_REQUIRED_FIELD_VALUES = - Collections.unmodifiableList(Arrays.asList( + List.of( BIOSAMPLE_SUBJECT_ID_FIELD, BIOSAMPLE_SYNTHETIC_LIBRARY_FIELD, BIOSAMPLE_ORGANISM_FIELD, @@ -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"; @@ -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 SRA_FIELDS = Collections.unmodifiableList(Arrays.asList( + protected static final List SRA_FIELDS = List.of( SRA_SAMPLE_ID_FIELD, SRA_TARGET_SUBSTRATE_FIELD, SRA_TARGET_SUBSTRATE_QUALITY_FIELD, @@ -238,7 +238,7 @@ public class NcbiCairrConstants { SRA_SEQUENCING_KIT_FIELD, SRA_FILE_TYPE_FIELD, SRA_FILE_NAME_FIELD - )); + ); protected static final List SRA_REQUIRED_FIELD_VALUES = SRA_FIELDS; diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrTemplateInstance2XMLConverter.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrTemplateInstance2XMLConverter.java index 37485c4..65a16d1 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrTemplateInstance2XMLConverter.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/cairr/NcbiCairrTemplateInstance2XMLConverter.java @@ -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 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 fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField); diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericConstants.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericConstants.java index 014cb17..86c3d6b 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericConstants.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericConstants.java @@ -33,20 +33,20 @@ public class NcbiGenericConstants { protected static final String BIOPROJECT_RELEVANT_PUBLICATIONS_FIELD = "Relevant Publications"; protected static final List 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 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 ***/ @@ -78,7 +78,7 @@ public class NcbiGenericConstants { protected static final String BIOSAMPLE_DESCRIPTION_FIELD = "Sample Description"; protected static final List BIOSAMPLE_FIELDS = - Collections.unmodifiableList(Arrays.asList( + List.of( BIOSAMPLE_SAMPLE_NAME_FIELD, BIOSAMPLE_SAMPLE_TITLE_FIELD, BIOSAMPLE_ORGANISM_FIELD, @@ -103,10 +103,10 @@ public class NcbiGenericConstants { BIOSAMPLE_SAMPLE_TYPE_FIELD, BIOSAMPLE_TREATMENT_FIELD, BIOSAMPLE_DESCRIPTION_FIELD - )); + ); protected static final List BIOSAMPLE_REQUIRED_FIELD_VALUES = - Collections.unmodifiableList(Arrays.asList( + List.of( BIOSAMPLE_SAMPLE_NAME_FIELD, BIOSAMPLE_ORGANISM_FIELD, BIOSAMPLE_ISOLATE_FIELD, @@ -114,7 +114,7 @@ public class NcbiGenericConstants { BIOSAMPLE_BIOMATERIAL_PROVIDER_FIELD, BIOSAMPLE_SEX_FIELD, BIOSAMPLE_TISSUE_FIELD - )); + ); /*** SRA section ***/ protected static final String SRA_ELEMENT = "NCBI SRA for Human Tissue"; @@ -132,7 +132,7 @@ public class NcbiGenericConstants { protected static final String SRA_FILE_NAME_FIELD = "File Name"; protected static final List SRA_FIELDS = - Collections.unmodifiableList(Arrays.asList( + List.of( SRA_SAMPLE_NAME_FIELD, SRA_LIBRARY_ID_FIELD, SRA_TITLE_FIELD, @@ -145,10 +145,10 @@ public class NcbiGenericConstants { SRA_DESIGN_DESCRIPTION_FIELD, SRA_FILE_TYPE_FIELD, SRA_FILE_NAME_FIELD - )); + ); protected static final List SRA_REQUIRED_FIELD_VALUES = - Collections.unmodifiableList(Arrays.asList( + List.of( SRA_SAMPLE_NAME_FIELD, SRA_LIBRARY_ID_FIELD, SRA_TITLE_FIELD, @@ -161,7 +161,7 @@ public class NcbiGenericConstants { SRA_DESIGN_DESCRIPTION_FIELD, SRA_FILE_TYPE_FIELD, SRA_FILE_NAME_FIELD - )); + ); // PRIVATE // diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericSubmissionXMLFileGenerator.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericSubmissionXMLFileGenerator.java index 61c23de..fa121dc 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericSubmissionXMLFileGenerator.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericSubmissionXMLFileGenerator.java @@ -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; diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericTemplateInstance2XMLConverter.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericTemplateInstance2XMLConverter.java index 7de76a9..dc8f811 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericTemplateInstance2XMLConverter.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/pipelines/generic/NcbiGenericTemplateInstance2XMLConverter.java @@ -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 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 fileName = NcbiPipelinesCommonUtil.getTemplateFieldValue(sra, fileNameField); diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/queue/NcbiSubmissionQueueEvent.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/queue/NcbiSubmissionQueueEvent.java index 739a71e..8deb86f 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/queue/NcbiSubmissionQueueEvent.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/queue/NcbiSubmissionQueueEvent.java @@ -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; diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiFtpStatusChecker.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiFtpStatusChecker.java index fe860ad..8a24fac 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiFtpStatusChecker.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiFtpStatusChecker.java @@ -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 @@ -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) diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiSubmissionStatusUtil.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiSubmissionStatusUtil.java index f79b19d..57057f2 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiSubmissionStatusUtil.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/NcbiSubmissionStatusUtil.java @@ -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 @@ -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); } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/report/NcbiSubmissionStatusReport.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/report/NcbiSubmissionStatusReport.java index e67b68d..cca76d9 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/report/NcbiSubmissionStatusReport.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/status/report/NcbiSubmissionStatusReport.java @@ -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; - } } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/validation/BioSampleValidator.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/validation/BioSampleValidator.java index 94dc269..1896ca8 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/validation/BioSampleValidator.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/ncbi/validation/BioSampleValidator.java @@ -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; @@ -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; diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/notifications/StatusNotifier.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/notifications/StatusNotifier.java index ec115f0..a380159 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/notifications/StatusNotifier.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/notifications/StatusNotifier.java @@ -53,22 +53,22 @@ public void sendMessage(SubmissionStatusDescriptor submissionStatusDescriptor) { logger.info("Notification url:" + url); Map content = new HashMap<>(); - content.put("subject", submissionStatusDescriptor.getSubmissionStatusTask().getSubmissionType().getValue() - + " Submission " + submissionStatusDescriptor.getSubmissionStatus().getSubmissionState()); - content.put("body", submissionStatusDescriptor.getSubmissionStatus().getStatusMessage()); + content.put("subject", submissionStatusDescriptor.submissionStatusTask().getSubmissionType().getValue() + + " Submission " + submissionStatusDescriptor.submissionStatus().submissionState()); + content.put("body", submissionStatusDescriptor.submissionStatus().statusMessage()); Map to = new HashMap<>(); to.put("recipientType", "user"); - to.put("@id", submissionStatusDescriptor.getUserID()); + to.put("@id", submissionStatusDescriptor.userID()); content.put("to", to); Map from = new HashMap<>(); from.put("senderType", "process"); String processId = null; - if (submissionStatusDescriptor.getSubmissionStatusTask().getSubmissionType().equals(SubmissionType.IMMPORT)) { + if (submissionStatusDescriptor.submissionStatusTask().getSubmissionType().equals(SubmissionType.IMMPORT)) { processId = "submission.IMMPORT"; - } else if (submissionStatusDescriptor.getSubmissionStatusTask().getSubmissionType().equals(SubmissionType + } else if (submissionStatusDescriptor.submissionStatusTask().getSubmissionType().equals(SubmissionType .NCBI)) { processId = "submission.NCBI"; // It aligns with name in messaging server } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatus.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatus.java index d044f4c..dd030dc 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatus.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatus.java @@ -1,27 +1,6 @@ package org.metadatacenter.submission.status; -public class SubmissionStatus { - private final String submissionID; - private final SubmissionState submissionState; - private final String statusMessage; - - public SubmissionStatus(String submissionID, SubmissionState submissionState, String statusMessage) { - this.submissionID = submissionID; - this.submissionState = submissionState; - this.statusMessage = statusMessage; - } - - public String getSubmissionID() { - return submissionID; - } - - public SubmissionState getSubmissionState() { - return submissionState; - } - - public String getStatusMessage() { - return statusMessage; - } +public record SubmissionStatus(String submissionID, SubmissionState submissionState, String statusMessage) { @Override public String toString() { diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusDescriptor.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusDescriptor.java index e685048..77bd3bd 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusDescriptor.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusDescriptor.java @@ -1,38 +1,4 @@ package org.metadatacenter.submission.status; -public class SubmissionStatusDescriptor { - private final String submissionID; - private final String userID; - private final String statusURL; - private final SubmissionStatus submissionStatus; - private final SubmissionStatusTask submissionStatusTask; - - public SubmissionStatusDescriptor(String submissionID, String userID, String statusURL, - SubmissionStatus submissionStatus, SubmissionStatusTask submissionStatusTask) { - this.submissionID = submissionID; - this.userID = userID; - this.statusURL = statusURL; - this.submissionStatus = submissionStatus; - this.submissionStatusTask = submissionStatusTask; - } - - public String getSubmissionID() { - return submissionID; - } - - public String getUserID() { - return userID; - } - - public String getStatusURL() { - return statusURL; - } - - public SubmissionStatusTask getSubmissionStatusTask() { - return submissionStatusTask; - } - - public SubmissionStatus getSubmissionStatus() { - return submissionStatus; - } +public record SubmissionStatusDescriptor(String submissionID, String userID, String statusURL, SubmissionStatus submissionStatus, SubmissionStatusTask submissionStatusTask) { } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManager.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManager.java index b0041b9..635e033 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManager.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManager.java @@ -69,24 +69,24 @@ public String addSubmission(SubmissionStatusTask submissionStatusTask) { } public void updateSubmission(SubmissionStatus submissionStatus) { - String submissionID = submissionStatus.getSubmissionID(); + String submissionID = submissionStatus.submissionID(); if (!this.submissions.containsKey(submissionID)) { logger.warn("Attempt to update unknown submission " + submissionID); } else { SubmissionStatusDescriptor currentSubmissionStatusDescriptor = submissions.get(submissionID); SubmissionStatusDescriptor newSubmissionStatusDescriptor = new SubmissionStatusDescriptor(submissionID, - currentSubmissionStatusDescriptor.getUserID(), currentSubmissionStatusDescriptor.getStatusURL(), - submissionStatus, currentSubmissionStatusDescriptor.getSubmissionStatusTask()); + currentSubmissionStatusDescriptor.userID(), currentSubmissionStatusDescriptor.statusURL(), + submissionStatus, currentSubmissionStatusDescriptor.submissionStatusTask()); // If the status has changed, notify user. We consider that the status has changed in the following cases: // 1. The new state is different than the previous one (e.g., STARTED vs SUBMITTED) // 2. The new state is the same, but the messages are different (except for the STARTED state) - SubmissionStatus currentStatus = currentSubmissionStatusDescriptor.getSubmissionStatus(); - SubmissionStatus newStatus = newSubmissionStatusDescriptor.getSubmissionStatus(); - if ((currentStatus.getSubmissionState() != newStatus.getSubmissionState()) || - (!currentStatus.getStatusMessage().equals(newStatus.getStatusMessage()) && - !currentStatus.getSubmissionState().equals(SubmissionState.SUBMITTED))) { + SubmissionStatus currentStatus = currentSubmissionStatusDescriptor.submissionStatus(); + SubmissionStatus newStatus = newSubmissionStatusDescriptor.submissionStatus(); + if ((currentStatus.submissionState() != newStatus.submissionState()) || + (!currentStatus.statusMessage().equals(newStatus.statusMessage()) && + !currentStatus.submissionState().equals(SubmissionState.SUBMITTED))) { notifyUser(newSubmissionStatusDescriptor); } @@ -94,9 +94,9 @@ public void updateSubmission(SubmissionStatus submissionStatus) { this.submissions.put(submissionID, newSubmissionStatusDescriptor); - if (submissionStatus.getSubmissionState() == SubmissionState.SUCCEEDED - || submissionStatus.getSubmissionState() == SubmissionState.REJECTED - || submissionStatus.getSubmissionState() == SubmissionState.ERROR) { + if (submissionStatus.submissionState() == SubmissionState.SUCCEEDED + || submissionStatus.submissionState() == SubmissionState.REJECTED + || submissionStatus.submissionState() == SubmissionState.ERROR) { removeSubmission(submissionID); } } @@ -108,7 +108,7 @@ public void removeSubmission(String submissionID) { } else { SubmissionStatusDescriptor submissionStatusDescriptor = this.submissions.get(submissionID); - if (submissionStatusDescriptor.getSubmissionStatus().getSubmissionState() != SubmissionState.SUCCEEDED) { + if (submissionStatusDescriptor.submissionStatus().submissionState() != SubmissionState.SUCCEEDED) { logger.warn("Removing incomplete submission " + submissionID); } @@ -125,9 +125,9 @@ public Map getCurrentSubmissions() { } private void notifyUser(SubmissionStatusDescriptor submissionStatusDescriptor) { - logger.info("Notifying user for submission " + submissionStatusDescriptor.getSubmissionID() + "; status = " - + submissionStatusDescriptor.getSubmissionStatus().getSubmissionState() + ", message = " - + submissionStatusDescriptor.getSubmissionStatus().getStatusMessage()); + logger.info("Notifying user for submission " + submissionStatusDescriptor.submissionID() + "; status = " + + submissionStatusDescriptor.submissionStatus().submissionState() + ", message = " + + submissionStatusDescriptor.submissionStatus().statusMessage()); StatusNotifier.getInstance().sendMessage(submissionStatusDescriptor); } diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManagerRunnable.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManagerRunnable.java index 8711db0..ca8633f 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManagerRunnable.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/status/SubmissionStatusManagerRunnable.java @@ -32,15 +32,15 @@ public void run() { if (!currentSubmissions.isEmpty()) { for (SubmissionStatusDescriptor submissionStatusDescriptor : currentSubmissions.values()) { - SubmissionStatusTask submissionStatusTask = submissionStatusDescriptor.getSubmissionStatusTask(); + SubmissionStatusTask submissionStatusTask = submissionStatusDescriptor.submissionStatusTask(); Future submissionStatusFuture = pool.submit(submissionStatusTask); - futures.put(submissionStatusDescriptor.getSubmissionID(), submissionStatusFuture); + futures.put(submissionStatusDescriptor.submissionID(), submissionStatusFuture); } for (int i = 0; i < currentSubmissions.size(); i++) { SubmissionStatus submissionStatus = pool.take().get(1000, TimeUnit.MILLISECONDS); - String submissionID = submissionStatus.getSubmissionID(); + String submissionID = submissionStatus.submissionID(); futures.remove(submissionID); this.submissionStatusManager.updateSubmission(submissionStatus); diff --git a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/upload/flow/FlowUploadUtil.java b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/upload/flow/FlowUploadUtil.java index 84bb6cd..7e9fe95 100644 --- a/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/upload/flow/FlowUploadUtil.java +++ b/cedar-submission-server-core/src/main/java/org/metadatacenter/submission/upload/flow/FlowUploadUtil.java @@ -175,11 +175,11 @@ public static String getDateBasedFolderName(DateTimeZone dateTimeZone) { } public static String getLastFragmentOfUrl(String url) { - return url.substring(url.lastIndexOf("/") + 1, url.length()); + return url.substring(url.lastIndexOf("/") + 1); } public static List commaSeparatedStringToList(String string) { - if (string.trim().length() == 0) { + if (string.trim().isEmpty()) { return new ArrayList<>(); } else { //Remove whitespaces and split by comma