4848import javax .ws .rs .core .EntityTag ;
4949import javax .ws .rs .core .MediaType ;
5050import javax .ws .rs .core .Response ;
51+ import java .util .ArrayList ;
52+ import java .util .Collections ;
5153import java .util .HashMap ;
54+ import java .util .LinkedHashMap ;
5255import java .util .List ;
5356import java .util .Map ;
5457import java .util .Scanner ;
@@ -66,6 +69,10 @@ public class APIService {
6669 private static final Logger LOG = Logger .getLogger (APIService .class .getName ());
6770
6871 private Map <MicroProfileVersion , MPOptionsAvailable > mpvToOptions ;
72+ private EntityTag mpvToOptionsEtag ;
73+
74+ private Map <SupportedServer , Map <MicroProfileVersion , List <MicroprofileSpec >>> serversToOptions ;
75+ private EntityTag serversToOptionsEtag ;
6976
7077 private String readme ;
7178 private EntityTag readmeEtag ;
@@ -78,18 +85,26 @@ public class APIService {
7885
7986 @ PostConstruct
8087 public void init () {
81- mpvToOptions =
82- new HashMap <MicroProfileVersion , MPOptionsAvailable >(MicroProfileVersion .values ().length ) {
83- {
84- Stream .of (MicroProfileVersion .values ()).forEach (mpv -> put (mpv , new MPOptionsAvailable (
85- Stream .of (SupportedServer .values ())
86- .filter (v -> v .getMpVersions ().contains (mpv )).collect (Collectors .toList ()),
87- Stream .of (MicroprofileSpec .values ())
88- .filter (v -> v .getMpVersions ().contains (mpv )).collect (Collectors .toList ()))));
89-
90- }
91-
92- };
88+ // Keys are MP versions and values are servers and specs
89+ mpvToOptions = new HashMap <>(MicroProfileVersion .values ().length );
90+ Stream .of (MicroProfileVersion .values ()).filter (mpv -> mpv != MicroProfileVersion .NONE ).forEach (mpv -> {
91+ List <SupportedServer > supportedServers = Stream .of (SupportedServer .values ())
92+ .filter (v -> v .getMpVersions ().contains (mpv )).collect (Collectors .toList ());
93+ List <MicroprofileSpec > specs = Stream .of (MicroprofileSpec .values ())
94+ .filter (v -> v .getMpVersions ().contains (mpv )).collect (Collectors .toList ());
95+ mpvToOptions .put (mpv , new MPOptionsAvailable (supportedServers , specs ));
96+ });
97+ mpvToOptionsEtag = new EntityTag (Integer .toHexString (31 * version .getGit ().hashCode () + mpvToOptions .hashCode ()));
98+ // Keys are servers and values are MP versions and specs
99+ serversToOptions = new HashMap <>(SupportedServer .values ().length );
100+ for (SupportedServer s : SupportedServer .values ()) {
101+ Map <MicroProfileVersion , List <MicroprofileSpec >> mpvToSpec = new HashMap <>(s .getMpVersions ().size ());
102+ s .getMpVersions ().forEach (mpv -> mpvToSpec .put (
103+ mpv ,
104+ Stream .of (MicroprofileSpec .values ()).filter (v -> v .getMpVersions ().contains (mpv )).collect (Collectors .toList ())));
105+ serversToOptions .put (s , mpvToSpec );
106+ }
107+ serversToOptionsEtag = new EntityTag (Integer .toHexString (31 * version .getGit ().hashCode () + serversToOptions .hashCode ()));
93108 try (Scanner s = new Scanner (FilesLocator .class .getClassLoader ()
94109 .getResourceAsStream ("/REST-README.md" )).useDelimiter ("\\ A" )) {
95110 readme = (s .hasNext () ? s .next () : "" ) + "\n " + version .getGit () + "\n " ;
@@ -130,7 +145,7 @@ public Response readme(String ifNoneMatch) {
130145 return Response .notModified ().build ();
131146 }
132147 }
133- return Response .ok (readme ).build ();
148+ return Response .ok (readme ).tag ( readmeEtag ). build ();
134149 }
135150
136151 public Response listMPVersions () {
@@ -142,6 +157,30 @@ public Response listMPVersions() {
142157 ).build ();
143158 }
144159
160+ public Response supportMatrix (String ifNoneMatch ) {
161+ if (ifNoneMatch != null ) {
162+ if (mpvToOptionsEtag .toString ().equals (ifNoneMatch )) {
163+ return Response .notModified ().build ();
164+ }
165+ }
166+ return Response .ok (mpvToOptions , MediaType .APPLICATION_JSON_TYPE ).tag (mpvToOptionsEtag ).build ();
167+ }
168+
169+ public Response supportMatrixServers (String ifNoneMatch ) {
170+ if (ifNoneMatch != null ) {
171+ if (serversToOptionsEtag .toString ().equals (ifNoneMatch )) {
172+ return Response .notModified ().build ();
173+ }
174+ }
175+ List <SupportedServer > servers = new ArrayList <>(serversToOptions .keySet ());
176+ Collections .shuffle (servers );
177+ Map <SupportedServer , Map <MicroProfileVersion , List <MicroprofileSpec >>> rndServersToOptions = new LinkedHashMap <>(servers .size ());
178+ for (SupportedServer s : servers ) {
179+ rndServersToOptions .put (s , serversToOptions .get (s ));
180+ }
181+ return Response .ok (rndServersToOptions , MediaType .APPLICATION_JSON_TYPE ).tag (serversToOptionsEtag ).build ();
182+ }
183+
145184 public Response listOptions (MicroProfileVersion mpVersion ) {
146185 return Response .ok (mpvToOptions .get (mpVersion )).build ();
147186 }
0 commit comments