Skip to content

Commit

Permalink
Merge pull request #401 from hmcts/feat/ST-645
Browse files Browse the repository at this point in the history
ST-645 DynamicMultiSelectList object created
  • Loading branch information
ElifDenizEsea authored Apr 14, 2023
2 parents 8e9e92c + fdee124 commit a0d061f
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package uk.gov.hmcts.ccd.sdk.type;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;
import uk.gov.hmcts.ccd.sdk.api.ComplexType;

/**
Expand All @@ -22,7 +19,6 @@
@Data
@ComplexType(generate = false)
@JsonIgnoreProperties(ignoreUnknown = true)
@Jacksonized
public class DynamicMultiSelectList {

/**
Expand All @@ -46,6 +42,14 @@ public DynamicMultiSelectList(
this.listItems = listItems;
}

/**
* Converts a list of elements to the appropriate structure to then be handled correctly by CCD.
*
* @param elements elements to convert into options for the dropdown
* @param selected a {@link DynamicListElement} that will be the default selected element of the list
* @param <T> a class that implements {@link DynamicElementIndicator#toDynamicElement()}
* @return a {@link DynamicMultiSelectList} to be sent to CCD
*/
public static <T extends DynamicElementIndicator> DynamicMultiSelectList toDynamicMultiSelectList(
List<T> elements,
List<DynamicListElement> selected) {
Expand All @@ -54,18 +58,12 @@ public static <T extends DynamicElementIndicator> DynamicMultiSelectList toDynam
return DynamicMultiSelectList.builder().listItems(items).value(selected).build();
}

@JsonIgnore
public String getValueLabel() {
return value == null ? null : value.toString();
public String getValueLabel(DynamicListElement element) {
return element == null ? null : element.getLabel();
}

@JsonIgnore
public UUID getValueCodeAsUuid() {
return Optional.ofNullable(getValueCode()).map(UUID::fromString).orElse(null);
public UUID getValueCode(DynamicListElement element) {
return element == null ? null : element.getCode();
}

@JsonIgnore
public String getValueCode() {
return value == null ? null : value.toString();
}
}

0 comments on commit a0d061f

Please sign in to comment.