@@ -65,19 +65,37 @@ public static List<StateDraft> mapToStateDrafts(
6565 state -> {
6666 final List <StateResourceIdentifier > newTransitions =
6767 replaceTransitionIdsWithKeys (state , referenceIdToKeyCache );
68- return StateDraftBuilder .of ()
69- .key (state .getKey ())
70- .type (state .getType ())
71- .name (state .getName ())
72- .description (state .getDescription ())
73- .initial (state .getInitial ())
74- .roles (state .getRoles ())
75- .transitions (newTransitions )
76- .build ();
68+ return getStateDraft (state , newTransitions );
7769 })
7870 .collect (Collectors .toList ());
7971 }
8072
73+ /**
74+ * Creates a new {@link StateDraft} from given {@link State} and transitions as {@link
75+ * java.util.List}< {@link StateResourceIdentifier}>
76+ *
77+ * @param state - template state to build the draft from
78+ * @param newTransitions - transformed list of state resource identifiers
79+ * @return a new {@link StateDraft} with all fields copied from the {@param state} and transitions
80+ * set {@param newTransitions} - it will return empty StateDraft if key or type are missing.
81+ */
82+ private static StateDraft getStateDraft (
83+ State state , List <StateResourceIdentifier > newTransitions ) {
84+ if (state .getKey () != null && state .getType () != null ) {
85+ return StateDraftBuilder .of ()
86+ .key (state .getKey ())
87+ .type (state .getType ())
88+ .name (state .getName ())
89+ .description (state .getDescription ())
90+ .initial (state .getInitial ())
91+ .roles (state .getRoles ())
92+ .transitions (newTransitions )
93+ .build ();
94+ } else {
95+ return StateDraft .of ();
96+ }
97+ }
98+
8199 @ SuppressWarnings ("PMD.ReturnEmptyCollectionRatherThanNull" )
82100 private static List <StateResourceIdentifier > replaceTransitionIdsWithKeys (
83101 @ Nonnull final State state , @ Nonnull final ReferenceIdToKeyCache referenceIdToKeyCache ) {
0 commit comments