Skip to content

Commit

Permalink
#414 small java 17 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thopap committed Apr 27, 2024
1 parent eaec225 commit 9296575
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ public static class UnmarshallerListener extends Unmarshaller.Listener {

@Override
public void afterUnmarshal(Object target, Object parent) {
if (target instanceof ExtrinsicObjectType) {
var ebXml = (ExtrinsicObjectType) target;
if (target instanceof ExtrinsicObjectType ebXml) {
findExtraMetadata(ebXml.getSlot(), ebXml);
} else if (target instanceof RegistryPackageType) {
var ebXml = (RegistryPackageType) target;
} else if (target instanceof RegistryPackageType ebXml) {
findExtraMetadata(ebXml.getSlot(), ebXml);
} else if (target instanceof AssociationType1) {
var ebXml = (AssociationType1) target;
} else if (target instanceof AssociationType1 ebXml) {
findExtraMetadata(ebXml.getSlot(), ebXml);
} else if ((target instanceof SubmitObjectsRequest) && Boolean.TRUE.equals(RESULTS.get())) {
getCamelHeaders(target).put(SUBMISSION_SET_HAS_EXTRA_METADATA, Boolean.TRUE);
Expand Down Expand Up @@ -108,14 +105,11 @@ private static void findExtraMetadata(List<SlotType1> slots, ExtraMetadataHolder
public static class MarshallerListener extends Marshaller.Listener {
@Override
public void beforeMarshal(Object source) {
if (source instanceof ExtrinsicObjectType) {
var ebXml = (ExtrinsicObjectType) source;
if (source instanceof ExtrinsicObjectType ebXml) {
injectExtraMetadata(ebXml.getSlot(), ebXml);
} else if (source instanceof RegistryPackageType) {
var ebXml = (RegistryPackageType) source;
} else if (source instanceof RegistryPackageType ebXml) {
injectExtraMetadata(ebXml.getSlot(), ebXml);
} else if (source instanceof AssociationType1) {
var ebXml = (AssociationType1) source;
} else if (source instanceof AssociationType1 ebXml) {
injectExtraMetadata(ebXml.getSlot(), ebXml);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public XdsIRetrieveAuditStrategy30(boolean serverSide) {

@Override
public XdsNonconstructiveDocumentSetRequestAuditDataset enrichAuditDatasetFromRequest(XdsNonconstructiveDocumentSetRequestAuditDataset auditDataset, Object pojo, Map<String, Object> parameters) {
if (pojo instanceof RetrieveImagingDocumentSetRequestType) {
var request = (RetrieveImagingDocumentSetRequestType) pojo;
if (pojo instanceof RetrieveImagingDocumentSetRequestType request) {
var requestedStudies = request.getStudyRequest();
if (requestedStudies != null) {
for (var studyRequest : requestedStudies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
*/
package org.openehealth.ipf.commons.ihe.xds.core.audit;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
* Audit dataset specific for non-constructive operations (Read+Delete as opposed to Create+Update in CRUD)
Expand All @@ -49,9 +50,9 @@ public static class Document implements Serializable {
@Getter @Setter private Status status;

public boolean matches(String documentUniqueId, String repositoryUniqueId, String homeCommunityId) {
return StringUtils.equals(this.documentUniqueId, documentUniqueId)
&& StringUtils.equals(this.repositoryUniqueId, repositoryUniqueId)
&& StringUtils.equals(this.homeCommunityId, homeCommunityId);
return Objects.equals(this.documentUniqueId, documentUniqueId)
&& Objects.equals(this.repositoryUniqueId, repositoryUniqueId)
&& Objects.equals(this.homeCommunityId, homeCommunityId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public XdsNonconstructiveDocumentSetRequestAuditStrategy30(boolean serverSide) {

@Override
public XdsNonconstructiveDocumentSetRequestAuditDataset enrichAuditDatasetFromRequest(XdsNonconstructiveDocumentSetRequestAuditDataset auditDataset, Object pojo, Map<String, Object> parameters) {
if (pojo instanceof RetrieveDocumentSetRequestType) {
var request = (RetrieveDocumentSetRequestType) pojo;
if (pojo instanceof RetrieveDocumentSetRequestType request) {
if (request.getDocumentRequest() != null) {
request.getDocumentRequest().forEach(document ->
auditDataset.getDocuments().add(new Document(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ public XdsQueryAuditStrategy30(boolean serverSide) {

@Override
public XdsQueryAuditDataset enrichAuditDatasetFromRequest(XdsQueryAuditDataset auditDataset, Object pojo, Map<String, Object> parameters) {
if (pojo instanceof AdhocQueryRequest) {
var request = (AdhocQueryRequest) pojo;
if (pojo instanceof AdhocQueryRequest request) {
var adHocQuery = request.getAdhocQuery();
if (adHocQuery != null) {
auditDataset.setQueryUuid(adHocQuery.getId());
auditDataset.setHomeCommunityId(adHocQuery.getHome());
}

var slotHelper = new QuerySlotHelper(new EbXMLAdhocQueryRequest30(request));

PATIENT_QUERY_PARAMS.stream().map(slotHelper::toStringList).filter(Objects::nonNull).forEach(p -> auditDataset.getPatientIds().addAll(p));
}
return auditDataset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public XdsNonconstructiveDocumentSetRequestAuditDataset.Status getDefaultDocumen

@Override
public boolean enrichAuditDatasetFromResponse(XdsNonconstructiveDocumentSetRequestAuditDataset auditDataset, Object pojo, AuditContext auditContext) {
if (pojo instanceof RegistryResponseType) {
var response = (RegistryResponseType) pojo;
if (pojo instanceof RegistryResponseType response) {
if (Status.FAILURE.getOpcode30().equals(response.getStatus())) {
auditDataset.getDocuments().forEach(x -> x.setStatus(NOT_SUCCESSFUL));
} else if (Status.PARTIAL_SUCCESS.getOpcode30().equals(response.getStatus()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public XdsRemoveMetadataAuditStrategy30(boolean serverSide) {

@Override
public XdsRemoveMetadataAuditDataset enrichAuditDatasetFromRequest(XdsRemoveMetadataAuditDataset auditDataset, Object pojo, Map<String, Object> parameters) {
if (pojo instanceof RemoveObjectsRequest) {
var request = (RemoveObjectsRequest) pojo;
if (pojo instanceof RemoveObjectsRequest request) {

var references = request.getObjectRefList().getObjectRef();
if (references != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public abstract class XdsRetrieveAuditStrategy30 extends XdsNonconstructiveDocumentSetRequestAuditStrategy30 {

public XdsRetrieveAuditStrategy30(boolean serverSide) {
// These transactions define source and destination in reverse direction, so we need to
// These transactions define source and destination in reverse direction, so we need to
// toggle server side indicator
super(!serverSide);
}
Expand All @@ -49,8 +49,7 @@ public XdsNonconstructiveDocumentSetRequestAuditDataset createAuditDataset() {

@Override
public boolean enrichAuditDatasetFromResponse(XdsNonconstructiveDocumentSetRequestAuditDataset auditDataset, Object pojo, AuditContext auditContext) {
if (pojo instanceof RetrieveDocumentSetResponseType) {
var response = (RetrieveDocumentSetResponseType) pojo;
if (pojo instanceof RetrieveDocumentSetResponseType response) {
if (response.getDocumentResponse() != null) {
for (var documentResponse : response.getDocumentResponse()) {
auditDataset.registerProcessedDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected static void enrichDatasetFromSubmitObjectsRequest(XdsSubmitAuditDatase

@Override
public XdsSubmitAuditDataset enrichAuditDatasetFromRequest(XdsSubmitAuditDataset auditDataset, Object pojo, Map<String, Object> parameters) {
if (pojo instanceof SubmitObjectsRequest) {
var submitObjectsRequest = (SubmitObjectsRequest) pojo;
if (pojo instanceof SubmitObjectsRequest submitObjectsRequest) {
EbXMLSubmitObjectsRequest<SubmitObjectsRequest> ebXML = new EbXMLSubmitObjectsRequest30(submitObjectsRequest);
enrichDatasetFromSubmitObjectsRequest(auditDataset, ebXML);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30;

import java.util.Collections;
import java.util.List;

import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLInternationalString;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.InternationalStringType;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.LocalizedStringType;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Encapsulation of {@link InternationalStringType}.
* @author Jens Riemschneider
Expand Down Expand Up @@ -88,7 +87,7 @@ public List<LocalizedString> getLocalizedStrings() {
var list = international.getLocalizedString();
return list.stream()
.map(this::createLocalizedString)
.collect(Collectors.toList());
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/
package org.openehealth.ipf.commons.ihe.xds.core.metadata.jaxbadapters;

import org.apache.commons.lang3.NotImplementedException;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLClassification30;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ClassificationType;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLClassification30;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ClassificationType;

/**
* @author Dmytro Rud
*/
Expand All @@ -47,8 +46,8 @@ public ClassificationList marshal(List<EbXMLClassification> ebXMLClassifications
}
ArrayList<ClassificationType> classifications = new ArrayList<>();
for (EbXMLClassification ebXml : ebXMLClassifications) {
if (ebXml instanceof EbXMLClassification30) {
classifications.add(((EbXMLClassification30) ebXml).getInternal());
if (ebXml instanceof EbXMLClassification30 ebxml30) {
classifications.add(ebxml30.getInternal());
} else {
throw new UnsupportedOperationException("Only ebXML 3.0 is supported at the moment");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Abstract builder to support build for certain types of
Expand Down Expand Up @@ -99,12 +98,12 @@ public R build() {

/**
* Supportive operation for constructing a submission request (ITI-41 + ITI-42).
* The following information will be set if not defined:
* The following information will be set if not defined:
* SubmissionSet.submissionTime, UniqueId's, EntryUuid's and HasMember
* associations
*/
private void supportivePostProcess() {
var docEntries = documents.stream().map(documentMapper).collect(Collectors.toList());
var docEntries = documents.stream().map(documentMapper).toList();
assignDefault(folders, XDSMetaClass::getUniqueId, XDSMetaClass::assignUniqueId);
assignDefault(folders, XDSMetaClass::getEntryUuid, XDSMetaClass::assignEntryUuid);
assignDefault(docEntries, XDSMetaClass::getUniqueId, XDSMetaClass::assignUniqueId);
Expand All @@ -116,17 +115,17 @@ private void supportivePostProcess() {

associations.addAll(docEntries.stream()
.filter(metadata -> !hasAssociationFromSubmissionSetWithHasMemberTo(metadata.getEntryUuid()))
.map(metadata -> createHasMemberAssocationWithOriginalLabel(metadata.getEntryUuid())).collect(Collectors.toList()));
.map(metadata -> createHasMemberAssocationWithOriginalLabel(metadata.getEntryUuid())).toList());
associations.addAll(folders.stream()
.filter(metadata -> !hasAssociationFromSubmissionSetWithHasMemberTo(metadata.getEntryUuid()))
.map(metadata -> createHasMemberAssocation(metadata.getEntryUuid())).collect(Collectors.toList()));
.map(metadata -> createHasMemberAssocation(metadata.getEntryUuid())).toList());
associations.addAll(associations.stream()
.filter(assoc -> AssociationType.HAS_MEMBER.equals(assoc.getAssociationType()))
.filter(assoc -> !Objects.equals(assoc.getSourceUuid(), submissionSet.getEntryUuid()))
.filter(assoc -> !hasAssociationFromSubmissionSetWithHasMemberTo(assoc.getEntryUuid()))
.map(assoc -> createHasMemberAssocation(assoc.getEntryUuid())).collect(Collectors.toList()));
.map(assoc -> createHasMemberAssocation(assoc.getEntryUuid())).toList());
}

private Association createHasMemberAssocationWithOriginalLabel(String entryUuid) {
var assoc = createHasMemberAssocation(entryUuid);
assoc.setLabel(AssociationLabel.ORIGINAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.util.List;
import java.util.stream.Collectors;

/**
* A JAXB {@link XmlAdapter} that helps serialize generic lists of lists. This sort of thing is used by the
Expand All @@ -36,14 +35,14 @@ public class ListOfListAdapter<T> extends XmlAdapter<ListOfListAdapter.ListOfLis
public List<List<T>> unmarshal(ListOfListWrapper<T> v) {
return v.getInnerList().stream()
.map(ListWrapper::getValue)
.collect(Collectors.toList());
.toList();
}

@Override
public ListOfListWrapper<T> marshal(List<List<T>> v) {
var outerList = v.stream()
.map(ListWrapper::new)
.collect(Collectors.toList());
.toList();
return new ListOfListWrapper<>(outerList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.openehealth.ipf.commons.ihe.xds.core.responses;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.openehealth.ipf.commons.ihe.xds.core.XdsRuntimeException;
import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;

Expand Down Expand Up @@ -95,17 +93,15 @@ public ErrorInfo(
this(defaultError, throwable.getMessage(), Severity.ERROR, defaultLocation, null);
var t = throwable;
while (t != null) {
if (t instanceof XDSMetaDataException) {
var metaDataException = (XDSMetaDataException) t;
if (t instanceof XDSMetaDataException metaDataException) {
this.errorCode = metaDataException.getValidationMessage().getErrorCode();
if (this.errorCode == null) {
this.errorCode = defaultMetaDataError;
}
this.codeContext = metaDataException.getMessage();
return;
}
if (t instanceof XdsRuntimeException) {
var exception = (XdsRuntimeException) t;
if (t instanceof XdsRuntimeException exception) {
this.errorCode = exception.getErrorCode();
this.codeContext = exception.getCodeContext();
this.severity = exception.getSeverity();
Expand Down
Loading

0 comments on commit 9296575

Please sign in to comment.