@@ -64,73 +64,83 @@ public PartialRetrievalResponse retrievePartial(PartialRetrievalRequest request)
6464 List <Tuple <String , Tuple <FieldInfo , PartialRetrievalFailureCause >>> results =
6565 patchFieldHelper .extractFieldTuples (request .getFieldsToRetrieve (), businessDtoFacade .fetchablePrefixes ()).stream ().map (tuple -> {
6666
67- String originalFieldName = tuple .getFirst ();
68- PathFailureCause pathFailureCause = tuple .getSecond ();
67+ try {
68+ return buildTupleImpl (tuple , caseData , beanCache );
69+ } catch (RuntimeException e ) {
70+ logger .warn ("Failure during retrieval for [{}]" , tuple , e );
71+ return Tuple .of (tuple .getFirst (), new Tuple <>((FieldInfo ) null , PartialRetrievalFailureCause .TECHNICAL ));
72+ }
6973
70- Tuple < String , PathFailureCause > unAliasedTuple = patchFieldHelper . resolveAlias ( originalFieldName );
74+ }). collect ( Collectors . toList () );
7175
72- PartialRetrievalFailureCause failureCause = Optional .ofNullable (pathFailureCause )
73- .map (PathFailureCause ::getRelatedRetrieveFailureCause )
74- .or (() -> Optional .ofNullable (unAliasedTuple .getSecond ()).map (PathFailureCause ::getRelatedRetrieveFailureCause ))
75- .orElse (null );
76+ Map <String , FieldInfo > successes = results .stream ()
77+ .filter (tuple -> tuple .getSecond ().getSecond () == null )
78+ .collect (Collectors .toMap (Tuple ::getFirst , tuple -> tuple .getSecond ().getFirst ()));
7679
77- if ( failureCause != null ) {
78- return Tuple . of ( originalFieldName , new Tuple <>(( FieldInfo ) null , failureCause ));
79- }
80+ Map < String , PartialRetrievalFailureCause > failures = results . stream ()
81+ . filter ( tuple -> tuple . getSecond (). getSecond () != null )
82+ . collect ( Collectors . toMap ( Tuple :: getFirst , tuple -> tuple . getSecond (). getSecond ()));
8083
81- String pathWithoutAlias = unAliasedTuple . getFirst ( );
82- String physicalPathName = pathWithoutAlias . substring ( pathWithoutAlias . indexOf ( '.' ) + 1 );
84+ return new PartialRetrievalResponse (). setFailuresDictionary ( failures ). setFieldInfoDictionary ( successes );
85+ }
8386
84- String aliasPath = pathAliasHelper .toAliasPath (pathWithoutAlias );
85- Optional <EntityDto > adequateBeanOpt = getAdequateBean (pathWithoutAlias , caseData , beanCache );
87+ private Tuple <String , Tuple <FieldInfo , PartialRetrievalFailureCause >> buildTupleImpl (
88+ Tuple <String , PathFailureCause > tuple ,
89+ CaseDataDto caseData ,
90+ Map <String , Optional <EntityDto >> beanCache ) {
91+ String originalFieldName = tuple .getFirst ();
92+ PathFailureCause pathFailureCause = tuple .getSecond ();
8693
87- if (adequateBeanOpt .isEmpty ()) {
88- return Tuple .of (originalFieldName , new Tuple <>((FieldInfo ) null , PartialRetrievalFailureCause .ENTITY_COULD_NOT_BE_FOUND ));
89- }
94+ Tuple <String , PathFailureCause > unAliasedTuple = patchFieldHelper .resolveAlias (originalFieldName );
9095
91- EntityDto adequateBean = adequateBeanOpt .orElseThrow ();
92- Optional <FieldInfo > specificFieldInfo = specificFieldValueRetrieverRegistry .getFieldInfo (aliasPath , adequateBean );
96+ PartialRetrievalFailureCause failureCause = Optional .ofNullable (pathFailureCause )
97+ .map (PathFailureCause ::getRelatedRetrieveFailureCause )
98+ .or (() -> Optional .ofNullable (unAliasedTuple .getSecond ()).map (PathFailureCause ::getRelatedRetrieveFailureCause ))
99+ .orElse (null );
93100
94- if (specificFieldInfo . isPresent () ) {
95- return Tuple .of (originalFieldName , new Tuple <>(specificFieldInfo . get (), ( PartialRetrievalFailureCause ) null ));
96- }
101+ if (failureCause != null ) {
102+ return Tuple .of (originalFieldName , new Tuple <>(( FieldInfo ) null , failureCause ));
103+ }
97104
98- Tuple < Tuple < Class <?>, Object >, PropertyAccessFailure > propertyType =
99- PropertyAccessor . getPropertyTypeAndValue ( adequateBean , physicalPathName , getFieldVisibilityCheckers ( caseData . getDisease ()) );
105+ String pathWithoutAlias = unAliasedTuple . getFirst ();
106+ String physicalPathName = pathWithoutAlias . substring ( pathWithoutAlias . indexOf ( '.' ) + 1 );
100107
101- PropertyAccessFailure propertyAccessFailure = propertyType .getSecond ();
102- if (propertyAccessFailure != null ) {
103- return Tuple .of (originalFieldName , new Tuple <>((FieldInfo ) null , propertyAccessFailure .getRelatedRetrieveFailureCause ()));
104- }
108+ String aliasPath = pathAliasHelper .toAliasPath (pathWithoutAlias );
109+ Optional <EntityDto > adequateBeanOpt = getAdequateBean (pathWithoutAlias , caseData , beanCache );
105110
106- Tuple <Class <?>, Object > fieldInfo = propertyType .getFirst ();
111+ if (adequateBeanOpt .isEmpty ()) {
112+ return Tuple .of (originalFieldName , new Tuple <>((FieldInfo ) null , PartialRetrievalFailureCause .ENTITY_COULD_NOT_BE_FOUND ));
113+ }
107114
108- // Some fields are translated only by there "physical-path" from root level
109- // example: Person.firstName has translation key "firstName"
110- // example: CaseData.disease has translation key "firstName"
111- String translatedFieldName = Optional .ofNullable (I18nProperties .getCaption (aliasPath , null ))
112- .or (() -> Optional .ofNullable (I18nProperties .getCaption (physicalPathName , null )))
113- .orElseGet (() -> I18nProperties .getDescription (aliasPath , aliasPath ));
115+ EntityDto adequateBean = adequateBeanOpt .orElseThrow ();
116+ Optional <FieldInfo > specificFieldInfo = specificFieldValueRetrieverRegistry .getFieldInfo (aliasPath , adequateBean );
114117
115- return Tuple .of (
116- originalFieldName ,
117- new Tuple <>(
118- new FieldInfo ().setFieldType (fieldInfo .getFirst ())
119- .setFieldValue (fieldInfo .getSecond ())
120- .setTranslatedFieldName (translatedFieldName ),
121- (PartialRetrievalFailureCause ) null ));
118+ if (specificFieldInfo .isPresent ()) {
119+ return Tuple .of (originalFieldName , new Tuple <>(specificFieldInfo .get (), (PartialRetrievalFailureCause ) null ));
120+ }
122121
123- }).collect (Collectors .toList ());
122+ Tuple <Tuple <Class <?>, Object >, PropertyAccessFailure > propertyType =
123+ PropertyAccessor .getPropertyTypeAndValue (adequateBean , physicalPathName , getFieldVisibilityCheckers (caseData .getDisease ()));
124124
125- Map <String , FieldInfo > successes = results .stream ()
126- .filter (tuple -> tuple .getSecond ().getSecond () == null )
127- .collect (Collectors .toMap (Tuple ::getFirst , tuple -> tuple .getSecond ().getFirst ()));
125+ PropertyAccessFailure propertyAccessFailure = propertyType .getSecond ();
126+ if (propertyAccessFailure != null ) {
127+ return Tuple .of (originalFieldName , new Tuple <>((FieldInfo ) null , propertyAccessFailure .getRelatedRetrieveFailureCause ()));
128+ }
128129
129- Map <String , PartialRetrievalFailureCause > failures = results .stream ()
130- .filter (tuple -> tuple .getSecond ().getSecond () != null )
131- .collect (Collectors .toMap (Tuple ::getFirst , tuple -> tuple .getSecond ().getSecond ()));
130+ Tuple <Class <?>, Object > fieldInfo = propertyType .getFirst ();
132131
133- return new PartialRetrievalResponse ().setFailuresDictionary (failures ).setFieldInfoDictionary (successes );
132+ // Some fields are translated only by there "physical-path" from root level
133+ // example: Person.firstName has translation key "firstName"
134+ // example: CaseData.disease has translation key "firstName"
135+ String translatedFieldName = Optional .ofNullable (I18nProperties .getCaption (aliasPath , null ))
136+ .or (() -> Optional .ofNullable (I18nProperties .getCaption (physicalPathName , null )))
137+ .orElseGet (() -> I18nProperties .getDescription (aliasPath , aliasPath ));
138+
139+ return Tuple .of (
140+ originalFieldName ,
141+ new Tuple <>(
142+ new FieldInfo ().setFieldType (fieldInfo .getFirst ()).setFieldValue (fieldInfo .getSecond ()).setTranslatedFieldName (translatedFieldName ),
143+ (PartialRetrievalFailureCause ) null ));
134144 }
135145
136146 @ Override
0 commit comments