22
33import java .util .List ;
44import java .util .Map ;
5+ import java .util .Map .Entry ;
56import java .util .stream .Collectors ;
7+ import java .util .Comparator ;
8+ import java .util .HashMap ;
69
710import lombok .Getter ;
811import tla .domain .dto .extern .SingleDocumentWrapper ;
912import tla .domain .dto .meta .AbstractDto ;
13+ import tla .web .model .Lemma ;
1014import tla .web .model .mappings .MappingConfig ;
1115
1216@ Getter
1317public class ObjectDetails <T extends TLAObject > extends ObjectsContainer {
1418
15- private T object ;
16-
17- public ObjectDetails (T object ) {
18- this .object = object ;
19- }
20-
21- @ SuppressWarnings ("unchecked" )
22- public ObjectDetails (SingleDocumentWrapper <?> dto ) {
23- super (dto );
24- this .object = (T ) MappingConfig .convertDTO (
25- dto .getDoc ()
26- );
27- }
28-
29- public ObjectDetails (T object , Map <String , Map <String , TLAObject >> related ) {
30- super (related );
31- this .object = object ;
32- }
33-
34- /**
35- * Map payload and related objects from DTO to domain model types.
36- */
37- public static ObjectDetails <? extends TLAObject > from (SingleDocumentWrapper <? extends AbstractDto > wrapper ) {
38- var container = new ObjectDetails <>(wrapper );
39- return container ;
40- }
41-
42- /**
43- * Projects objects in a single object details container's <code>related</code>
44- * map to the wrapped object's <code>relations</code> (which are {@link TLAObject} stubs
45- * in objects freshly converted from DTO).
46- */
47- public Map <String , List <TLAObject >> extractRelatedObjects () {
48- return this .getObject ().getRelations ().entrySet ().stream ().collect (
49- Collectors .toMap (
50- entry -> entry .getKey (),
51- entry -> entry .getValue ().stream ().map (
52- reference -> this .expandRelatedObject (reference )
53- ).filter (
54- o -> o != null
55- ).collect (
56- Collectors .toList ()
57- )
58- )
59- );
60- }
61-
62- }
19+ private T object ;
20+
21+ public ObjectDetails (T object ) {
22+ this .object = object ;
23+ }
24+
25+ @ SuppressWarnings ("unchecked" )
26+ public ObjectDetails (SingleDocumentWrapper <?> dto ) {
27+ super (dto );
28+ this .object = (T ) MappingConfig .convertDTO (dto .getDoc ());
29+ }
30+
31+ public ObjectDetails (T object , Map <String , Map <String , TLAObject >> related ) {
32+ super (related );
33+ this .object = object ;
34+ }
35+
36+ /**
37+ * Map payload and related objects from DTO to domain model types.
38+ */
39+ public static ObjectDetails <? extends TLAObject > from (SingleDocumentWrapper <? extends AbstractDto > wrapper ) {
40+ var container = new ObjectDetails <>(wrapper );
41+ return container ;
42+ }
43+
44+ /**
45+ * Projects objects in a single object details container's <code>related</code>
46+ * map to the wrapped object's <code>relations</code> (which are
47+ * {@link TLAObject} stubs in objects freshly converted from DTO).
48+ */
49+
50+ public Map <String , List <TLAObject >> extractRelatedObjects () {
51+ Map <String , List <TLAObject >> extractedRelations = new HashMap <String , List <TLAObject >>();
52+
53+ extractedRelations = this .getObject ().getRelations ().entrySet ().stream ()
54+ .collect (Collectors .toMap (entry -> entry .getKey (),
55+ entry -> entry .getValue ().stream ().map (reference -> this .expandRelatedObject (reference ))
56+ .filter (o -> o != null ).collect (Collectors .toList ())));
57+ for (String key : extractedRelations .keySet ()) {
58+ List <TLAObject > value = extractedRelations .get (key );
59+ value .sort (new NameComparator ());
60+ }
61+ return extractedRelations ;
62+ }
63+
64+ class NameComparator implements Comparator <TLAObject > {
65+ @ Override
66+ public int compare (TLAObject a , TLAObject b ) {
67+ return a .compareObjects (b );
68+ }
69+ }
70+ }
0 commit comments